Smoke Environment

Started by
13 comments, last by L. Spiro 11 years ago

I'm creating a smoke environment, I notice a problem when the smoke particles intersect the terrain.

[attachment=14960:smoke env.png]

How do I fix it?

Advertisement

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.

@ATEFred: Can you point me to a shader example?

http://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf

@ATEFred: So that means I only need to apply shader to my current particles?

@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.

Edit:

If you're googling it's sometimes called "z-feathering".

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 );
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.

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.

Edit:

Hodgmans answer is better.

@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().

This topic is closed to new replies.

Advertisement