I've just implemented a depth of field post processor which works great apart from the fact it blurs out all my particles since they don't write to the depth buffer (i guess this would be the same for any alpha blended materials). Since the dof processor wipes the depth buffer rendering the particles after the post process fails too.
Currently i think the only option is to recreate the depth buffer after the post processor runs which is simple to do but obviously has some performance impact.
Is there a nicer way to deal with alpha blended materials and particles when using a depth of field effect ?
That's odd. I would have expected the depth buffer to contain the actual particles depth if you are rendering them in between SunBurn RenderManager Render call and SceneInterface.EndFrameRendering().. How else could the gpu knows when to hide particles partially.
I'm using the MS particles sample the which sets device.DepthStencilState = DepthStencilState.DepthRead so the particles can read from the depth buffer and therefore be hidden by geometry however this also means that they don't write to depth buffer. Since they're alpha blended if they did write to the depth buffer they would set the area of the whole quad in which they are drawn to their depth.
I've tried to recreate the depth buffer in the post processor since the shader already has Sunburns depth texture
void PS_DepthOfField(int VertexShaderOutput input, out float4 color:COLOR, out float depth:DEPTH){
float4 originalColor = tex2D(SceneSampler, input.TexCoord);
float4 blurColor = tex2D(BlurSceneSampler, input.TexCoord);
depth = tex2D(DepthSampler, input.TexCoord);
float blurFactor = GetBlurFactor(-depth);
color = lerp(originalColor,blurColor,saturate(blurFactor));
}
Does the last postprocessor in sunburns post process manager draw directly the the graphics device or is there an intermediate render target which is then drawn by the post process manager ?
I'm trying to restore the depth buffer after my post process dof but using the output semantic DEPTH seems to have no effect on anything drawn after the post process manager - all the particles are still drawn on top of all the geometry.
The actual pixel shader i'm using is as follows (minus the typos from the last post)
void PS_DepthOfField(in VertexShaderOutput input, out float4 oColor:COLOR, out float oDepth:DEPTH) {float4 originalColor = tex2D(SceneSampler, input.TexCoord); float4 blurColor = tex2D(BlurSceneSampler, input.TexCoord); float depth = tex2D(DepthSampler, input.TexCoord).r; float blurFactor = GetBlurFactor(-depth);oColor = lerp(originalColor,blurColor,saturate(blurFactor)); oDepth = depth;}
The DepthSampler is using the texture grabbed via the following
RenderTarget2D depth = this.SceneState.FrameBuffers.GetBuffer(FrameBufferType.DeferredDepthAndSpecularPower, false);
And the DOF post process is the only one added to the manager (nothing after it which would switch render targets again and clear the depth buffer)
I'm basing the idea that i should be able to do this on the following article
http://www.catalinzima.com/samples/12-months-12-samples-2008/restoring-the-depth-buffer/
i've even tried just setting oDepth in the above shader to assorted random values 0,1,-1,,-1000,1000 - none of which seem to have any effect - particles are still drawn over everything else.
Just to confirm this wasn't due to my particular post processor i tried swapping it for the sunburn HighDynamicRange post processor which also gives the same issue..(as would any post processor due to the render target changes).
Am i doing something stupid here (and if so how should i go about restoring the depth buffer after the post process manager runs ?)
Hi bamyazi,
The final post processor renders directly to the back buffer - and your code looks like it should work. Are you sure the game's particle rendering code is correctly setting up the device depth state? You should be able to test this by disabling post processing as this renders the entire scene directly to the back buffer and preserves the depth.
Let me know if this helps!
Follow me on Twitter – development and personal tweetsAwesome XNA Videos – Lighting, Rendering, and game videos
Hi John thanks for your post
If i disable post processing (or just don't add any processors to the manager) then the particles render correctly - i'm using code from the MS particle sample which in the ParticleSystem class sets
device.DepthStencilState = DepthStencilState.DepthRead;
which should read from the depth buffer but not write.
The particlesystem effect again from the MS sample doesn't appear to do anything which would affect the state.
I'll trying rendering some geometry in a forward pass after the post processor and see that works to rule out the particle code, and try looking elsewhere if the shader code i posted looks ok.
Cheers
Hello guys!
Can somebody please point me how to start building a DOF post processor for Sunburn ?
I feel from John's posts that deferred rendering would be suitable because it already calculates the depth map of the scene.
Hi cemalsensivas! Instead of writing your own you could always use UjenT's post process plugin...
http://www.synapsegaming.com/downloads/resource.aspx?guid=813c353d-b7e5-4eb1-9798-06e97b150c77
which already has a DOF post processor.
:)
CJ Bailey: Hi cemalsensivas! Instead of writing your own you could always use UjenT's post process plugin... http://www.synapsegaming.com/downloads/resource.aspx?guid=813c353d-b7e5-4eb1-9798-06e97b150c77 which already has a DOF post processor. :)
@camelsensivas, in my ShaderLib you can turn on Depth generation to use all the post-processors with forward rendering easilly.
@UjenT ---- great to hear that because I am working with 2.18.. :(
@CJ Bailey ---- Thanks for letting me know I appreciate :)
UjenT: @CJ Bailey, I'm currently updating my ShaderLib to support the latest Sunburn version plus I'm adding some new features. I'm also thinking of creating a plug-in ui to help tweak things.
@CJ Bailey, I'm currently updating my ShaderLib to support the latest Sunburn version plus I'm adding some new features. I'm also thinking of creating a plug-in ui to help tweak things.
Oops, sorry, I didn't look hard enough. Didn't notice it was currently at 2.0.17. Looking forward to seeing the updated version! :)
Any updates of the DoF for 2.0.18 ? :)
cemalsensivas: Any updates of the DoF for 2.0.18 ? :)
Just need to finish the custom post-processor manager and that will be ready for a release although I also have a new God rays post proessor in the works too.
great news ! i am planning to implement the DoF along with stereoscopic renderer that is done by holophone3D to cover the areas out of the stereo focal length... i mean the areas where the eye is not focused should be a bit blurred to get rid of the "ghost" effect... do you think i can do that in a single pass or do i need to implement your postprocessor after it ?
Hey any news on the new version for .18?Godrays sounds awesome! Any chance of a gamma post processor and some more samples and source?