-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1672 from vchelaru/1664-discussion-talk-about-how…
…-to-exclude-layers-from-post-processing Added support for camera-specific post processing effects
- Loading branch information
Showing
9 changed files
with
4,691 additions
and
4,702 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
Engines/FlatRedBallXNA/FlatRedBall/Graphics/PostProcessing/PostProcessLogic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace FlatRedBall.Graphics.PostProcessing; | ||
|
||
internal static class PostProcessLogic | ||
{ | ||
public static void DrawWithPostProcessing(List<IPostProcess> postProcesses, | ||
SwapChain swapChain, Action drawCall) | ||
{ | ||
bool hasGlobalPostProcessing = false; | ||
|
||
foreach (var item in postProcesses) | ||
{ | ||
if (item.IsEnabled) | ||
{ | ||
hasGlobalPostProcessing = true; | ||
break; | ||
} | ||
} | ||
#if DEBUG | ||
if (hasGlobalPostProcessing && swapChain == null) | ||
{ | ||
throw new InvalidOperationException("SwapChain must be set prior to rendering the first frame if using any post processing"); | ||
} | ||
#endif | ||
if (hasGlobalPostProcessing) | ||
{ | ||
SetStatesAndRenderTargetForPostProcessing(swapChain); | ||
} | ||
else | ||
{ | ||
// Just in case we removed all post processing, but are on "B" | ||
swapChain?.ResetForFrame(); | ||
} | ||
|
||
drawCall(); | ||
|
||
if (hasGlobalPostProcessing) | ||
{ | ||
ApplyPostProcessing(postProcesses, swapChain); | ||
} | ||
} | ||
|
||
static void ApplyPostProcessing(List<IPostProcess> postProcesses, SwapChain swapChain) | ||
{ | ||
foreach (var postProcess in postProcesses) | ||
{ | ||
if (postProcess.IsEnabled) | ||
{ | ||
#if DEBUG | ||
Renderer.RenderBreaks.Add(new RenderBreak() { ObjectCausingBreak = postProcess }); | ||
#endif | ||
swapChain.Swap(); | ||
postProcess.Apply(swapChain.CurrentTexture); | ||
} | ||
} | ||
|
||
#if DEBUG | ||
Renderer.RenderBreaks.Add(new RenderBreak() { ObjectCausingBreak = swapChain }); | ||
#endif | ||
swapChain.RenderToScreen(); | ||
} | ||
|
||
static void SetStatesAndRenderTargetForPostProcessing(SwapChain swapChain) | ||
{ | ||
Renderer.ForceSetBlendOperation(); | ||
Renderer.ForceSetColorOperation(Renderer.ColorOperation); | ||
|
||
swapChain.ResetForFrame(); | ||
|
||
// Set the render target before drawing anything | ||
Renderer.GraphicsDevice.SetRenderTarget(swapChain.CurrentRenderTarget); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.