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?
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?
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: 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 );
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().