Jump to content

  • Log In with Google      Sign In   
  • Create Account


Smoke Environment


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 18 April 2013 - 01:56 AM

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

smoke env.png

 

How do I fix it?



Sponsor:

#2 ATEFred   Members   -  Reputation: 1006

Like
0Likes
Like

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.



#3 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 18 April 2013 - 02:47 AM

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



#4 ATEFred   Members   -  Reputation: 1006

Like
0Likes
Like

Posted 18 April 2013 - 03:02 AM

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



#5 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 18 April 2013 - 02:14 PM

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



#6 siri   Members   -  Reputation: 233

Like
1Likes
Like

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.

 

Edit:

 

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


Edited by siri, 18 April 2013 - 02:32 PM.


#7 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

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


#8 Hodgman   Moderators   -  Reputation: 27770

Like
0Likes
Like

Posted 18 April 2013 - 10:09 PM

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.

#9 siri   Members   -  Reputation: 233

Like
1Likes
Like

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.

 

Edit:

 

Hodgmans answer is better.


Edited by siri, 18 April 2013 - 10:09 PM.


#10 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

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



#11 ATEFred   Members   -  Reputation: 1006

Like
0Likes
Like

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.


#12 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 20 April 2013 - 10:57 PM

I'm still a bit confused.
 
Do I have to use the pixel shader directly when rendering the particles?
 
Or do I have to get the depth information with the fixed functions and then pass it to the pixel shader?


#13 L. Spiro   Crossbones+   -  Reputation: 12290

Like
0Likes
Like

Posted 20 April 2013 - 11:35 PM

The depth values are stored in a texture which your pixel shader will access.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#14 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 21 April 2013 - 12:54 AM

@L. Spiro: Any code sample for creating depth buffer texture in D3D9?

 

Also, I want a pixel shader example for soft particles, I have checked some links but couldn't find a complete sample.


Edited by Medo3337, 21 April 2013 - 01:36 AM.


#15 L. Spiro   Crossbones+   -  Reputation: 12290

Like
0Likes
Like

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.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS