Hi, I'm pretty new to Sunburn so I'm still trying to get my head around some things. One of those things being custom shaders.
I'm trying to implement a post processor (provided in the XNA "NonPhotoRealistic" sample) to give a nice "toon" edge to my models. I think I've got my head around how to implement a post processor, but the "edge" effect requires a "NormalDepth" map provided by a custom vertex/pixel shader.... and that's where I'm struggling....
It seems that custom shaders are implemented "per material" (so you create a .mat file for each material that you want a custom shader for). However, if I implemented a .mat file and custom shader for EVERY material to generate the "NormalDepth" texture... well... that just sounds daft! And won't the custom shader then override the Sunburn shaders?
I'm considering an alternative of re-drawing the scene outside of Sunburn to a different render target purely for generating the "NormalDepth" texture instead. And then pass this texture to the Post-Processor. Does this sound reasonable? Or is there a better way?
By the way... Sunburn is awesome! Thanks for such a brilliant product!
Hi cj,
cjhazard:It seems that custom shaders are implemented "per material" (so you create a .mat file for each material that you want a custom shader for). However, if I implemented a .mat file and custom shader for EVERY material to generate the "NormalDepth" texture... well... that just sounds daft! And won't the custom shader then override the Sunburn shaders?
It sounds like you want to continue using SunBurn's materials and only need the custom effect to generate a texture for post processing. There are a couple of ways to do this, but two I would try are:
An example of the rendering loop is available in the Custom Renderer kit, and while this is a little more manual the code can be cut and pasted directly from the kit - and is compatible with both forward and deferred rendering.
If using the deferred buffer the post processing shader may not need altering (other than to load the SunBurn g-buffer data via the SunBurn shader library - see the Custom Effects example for details) - it's possible the shader only detects the differences in the depth and normals, and is not dependent on the orientation / space.
Let me know if this helps!
Follow me on Twitter – development and personal tweetsAwesome XNA Videos – Lighting, Rendering, and game videos
Thanks JohnK. The deferred rendering option sounds sounds like it might be the simplest way forward since the edge-effect post processor does indeed seem to only detect differences in the depth and normals, so I could probably just use what is already provided by Sunburn's deferred buffer object. I'll look into it and let you know how I get on.
.... If I get stuck... does anyone fancy writing the code for me?.... for a price of course!
I've just changed my code to use deferred rendering instead and now I'm getting some weird artifacts (I haven't even begun to implement my custom post processor yet).
It appears to be clipping parts of an animated model (using SgMotion). I've tried setting the ClearBackBufferEnabled flag to True but it's not fixed it. However, if I go into the Sunburn editor and set the materials to "double-sided" it appears to fix the problem.
Any ideas what could be causing this?
(sorry to go off topic a little)
It sounds like you may have run into this problem. Let me know if this helps or if it's a different problem altogether.
Must be something I've done wrong since my model works ok on the SgMotion (Deferred) sample program. I'm sure I'll figure it out so ignore the last post.
Sorry JohnK just seen your post. I'll check it out... thanks very much, your help is greatly appreciated! :-)
Nice one John! Setting DepthFillOptimizationEnabled to false has fixed it. That's saved me hours of digging! Thanks again!
I'm confused.
I've created an EdgePostProcessor class derived from BaseRenderTargetPostProcessor. Within the Initialize method I am doing the following:
_edgeEffect = _content.Load<Effect>("Effects\\PostprocessEffect.fx");
Now, within "PostprocessEffect.fx" I've placed a reference to DeferredHelper.fx as follows:
#include <Deferred\DeferredHelper.fx>
However, when I compile the project it complains that it cannot find DeferredHelper.fx
I have the PostprocessEffect.fx properties set to Compile (I think that's right since I'm using the ContentManager to load the effect).
Do I need to copy DeferredHelper into my project?
The reason I haven't done this is because it doesn't do it in the Custom Effects example.
Update: I copied the DeferredHelper.fx file into my project and referenced it from there and it seems to be happy.
I've also managed to implement the SketchJitter effect and it's looking great... sketch effect with real-time shadows!! Whooooo!!
Actually I may not bother with the edge effect although I'll probably still give it a go to see how it's done and what it looks like.
Thanks again for all your help John.
Hey, you got me curious on how it renders :)
Please, share a screenie so we get a feeling of where you are getting ;)
Philippe
if you are looking for an FX GPU toon shader, then look no further than here.....
http://digierr.spaces.live.com/blog/cns!2B7007E9EC2AE37B!420.entry
the code is included :-)
Philippe Da Silva: Hey, you got me curious on how it renders :) Please, share a screenie so we get a feeling of where you are getting ;) Philippe
Sure... (I toned down the effect somewhat so it's a little easier on the eyes)
dug diamond: if you are looking for an FX GPU toon shader, then look no further than here..... http://digierr.spaces.live.com/blog/cns!2B7007E9EC2AE37B!420.entry the code is included :-)
Awesome! Thanks Dug!
cjhazard: dug diamond: if you are looking for an FX GPU toon shader, then look no further than here..... http://digierr.spaces.live.com/blog/cns!2B7007E9EC2AE37B!420.entry the code is included :-) Awesome! Thanks Dug!
Hmmm... tried the edge shader out and it looks pretty awful on my models. Don't think I'll use it but thanks anyway.
cjhazard:
Haha! That looks awesome. :)
I noticed your Jitter-Sketch community resource, thanks a ton for contributing this!
To include files from the shader library without having to copy them into your project make sure to use the SunBurn Effect processor.