Skip to content

Instantly share code, notes, and snippets.

@rtroe
Created September 19, 2016 01:47
Show Gist options
  • Save rtroe/ea6b627f4d69ffb197fe2c2222717419 to your computer and use it in GitHub Desktop.
Save rtroe/ea6b627f4d69ffb197fe2c2222717419 to your computer and use it in GitHub Desktop.
EffectParameterCollection parameters = xEngine.Assets.PostProcessShaders.CartoonEdgeDetection.Parameters;
Vector2 resolution = new Vector2(RT_MainScene.Width,
RT_MainScene.Height);
// Pass in the current screen resolution.
parameters["ScreenResolution"].SetValue(resolution);
parameters["NormalTexture"].SetValue(RT_NormalMap);
parameters["DepthTexture"].SetValue(RT_DepthMap);
// Settings controlling the edge detection filter.
parameters["EdgeWidth"].SetValue(Settings.EdgeWidth);
parameters["EdgeIntensity"].SetValue(Settings.EdgeIntensity);
// How sensitive should the edge detection be to tiny variations in the input data?
// Smaller settings will make it pick up more subtle edges, while larger values get
// rid of unwanted noise.
parameters["NormalThreshold"].SetValue(0.5f);
parameters["DepthThreshold"].SetValue(0.001f);
// How dark should the edges get in response to changes in the input data?
parameters["NormalSensitivity"].SetValue(1.0f);
parameters["DepthSensitivity"].SetValue(10000.0f);
Matrix orthoproj = Matrix.CreateOrthographicOffCenter(0,
vxEngine.GraphicsDevice.Viewport.Width,
vxEngine.GraphicsDevice.Viewport.Height,
0, 0, 1);
Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
parameters["MatrixTransform"].SetValue(halfPixelOffset * orthoproj);
// Activate the appropriate effect technique.
vxEngine.Assets.PostProcessShaders.CartoonEdgeDetection.CurrentTechnique = vxEngine.Assets.PostProcessShaders.CartoonEdgeDetection.Techniques["EdgeDetect"];
// Draw a fullscreen sprite to apply the postprocessing effect.
vxEngine.SpriteBatch.Begin(0, BlendState.Opaque, null, null, null, vxEngine.Assets.PostProcessShaders.CartoonEdgeDetection);
vxEngine.SpriteBatch.Draw(RT_FinalScene, Vector2.Zero, Color.White);
vxEngine.SpriteBatch.End();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment