I'm creating a smoke environment, I notice a problem when the smoke particles intersect the terrain.
How do I fix it?
Jump to content
Posted 18 April 2013 - 02:16 AM
You can avoid this by using "soft particles". That entails reading in the depth buffer in your particle pixel shader, and modulating the alpha output of the fragment based on the distance of the point to the geometry in the depth buffer. If you do a search online for soft particles, you can find loads of examples if you need more information.
Posted 18 April 2013 - 03:02 AM
Posted 18 April 2013 - 02:30 PM
@ATEFred: So that means I only need to apply shader to my current particles?
You need to grab the depth of the scene, without the particles, then in a particle shader you compare the scene depth to the depth of the particles and modify the particle alpha accordingly.
If you're googling it's sometimes called "z-feathering".
Edited by siri, 18 April 2013 - 02:32 PM.
Posted 18 April 2013 - 09:56 PM
I couldn't find any D3D9 code example for soft particles.
Can I use the following to get the depth of scene and do calculation to set the particles alpha blending according to the depth?
LPDIRECT3DSURFACE9 pZBuffer; m_d3dDevice->GetDepthStencilSurface( &pZBuffer );
Posted 18 April 2013 - 10:09 PM
Posted 18 April 2013 - 10:09 PM
I don't think you can just grab depth in D3D9. I could be wrong but I think that's a feature that came in with D3D10. You will need to use a shader to render the depth to a floating point render target and then pass that to the particle shader.
Hodgmans answer is better.
Edited by siri, 18 April 2013 - 10:09 PM.
Posted 18 April 2013 - 10:22 PM
@siri: I want way that will be compatible with most graphic cards, not only modern graphic cards.
So I think the best approach is that I use Vertex Shader, my thought is that I could just apply the shader to the particles using device->SetVertexShader, is that true?
I also want example of soft particles Vertex Shader that can work when setting it to device->SetVertexShader().
Posted 19 April 2013 - 12:19 AM
In D3D9, you can't use (normal) depth buffers as textures (readable), only as surfaces (writable).
One workaround is to use MRT during your normal rendering, and manually write depth to a second render target. This however, requires editing all our shaders, and is inefficient.
Another workaround (that I'd recommend) is to create an "INTZ" texutre. This texture is a readable depth texture, and you can get its surface in order to use it as your depth/stencil target (instead of your regular depth buffer).
The only downside to this approach is that creating an INTZ texture will fail on any GPU older than a GeForce 8, so it raises your minimum requirements.
If I remember correctly from back then, you can use RawZ on older NV gpus.
Edited by ATEFred, 19 April 2013 - 12:20 AM.
Posted 20 April 2013 - 11:35 PM
Posted 21 April 2013 - 02:35 AM
There are no code samples because this is extremely dependent on your engine.
Hodgman mentioned the valid point that writing depth to a special texture other than the main depth surface (which normally cannot be read) requires all shaders be modified to write that information, which really will be quite a nuisance when you have a ton of basic shaders that all have to be hand-written.
My engine’s shader system works on permutations based on macros within a single shader, so for me to add this tactic (which is what I did) is nothing.
If you want to do something similar it will really take a huge amount of work and you have to really focus your shader system on a macro-based system. Macros help with permutations, obviously. But implementing your own system really takes a lot of work, and getting to the point where you can use macros may require a whole rewrite of your shader system.
So it is up to you how to proceed.