This project is read-only.

Deferred rendering for particles

Jul 1, 2010 at 8:17 AM

How can i render Xen Fog particle system to depth buffer for depth comparison during the final composition?

Jul 1, 2010 at 10:57 AM
By default all the particle drawers disable depth writes, as particles are almost always transparent.
If you look in the drawer classes (in Xen.Ex.Graphics.Display) you will see they all have:
state.RenderState.DepthColourCull.DepthWriteEnabled = false;
The best bet is to copy one of these classes, and make the modifications you require to it yourself. Or add a property to the class to let you specify it.
Hope that helps
Jul 1, 2010 at 11:35 AM
Edited Jul 1, 2010 at 11:39 AM

Thank you for your quick reply.But my question was slightly different and this is precisely what i want to know .

how can i render the particle system to depth texture like Gbuffer so that i can do depth comparison during final composition stage i.e. combining  diffuseColor ,

Light output and particle color ? 

Jul 1, 2010 at 12:19 PM
Edited Jul 1, 2010 at 12:22 PM
Ohh right.

In such a case you will need to make your own particle drawer class, and an associated shader that outputs in the format of your GBuffer.
Basically make a copy of the class you are already using, and it's shader.

The tricky bit is that the shader needs to implement three variations: PC CPU, PC GPU and Xbox GPU, but this is mostly a vertex shader issue. So the code isn't especially clean (although it's tidied up a bit in Xen 2.0 Alpha, if you are using that).
The 1.8 shaders are a bit of a mess, because they have explicit register mapping all over (etc) and aren't very well formatted.
I'm looking to clean it up a bit more before the final release.
Jul 1, 2010 at 12:22 PM

Thank you for your support , i will try this thing and let you know :)

Jul 1, 2010 at 12:27 PM
Edited Jul 1, 2010 at 5:07 PM
I'll mention that most deferred renderers don't actually draw the particles directly into the GBuffer (unless they were solid particles). Transparent particles are going to be pretty close to impossible.
In which case, I'd suggest rendering the particles separately to their own buffer (lower resolution is quite common), compositing onto the screen post lighting (this can be a bit tricky to get the blend modes right).
The annoying thing is XNA doesn't let you reuse a depth buffer - due to how the 360 works it prevents this. So filling the z for a particle pass might be quite expensive. (Unless you refill it using GBuffer depth and depth writing) - but this has it's down sides too, as it pretty much kills any HiZ optimisations).

However particles (that are solid) would look pretty cool if they are lit dynamically :-)