Jump to content
  • Advertisement
Sign in to follow this  
JPulham

soft particles - what kind of falloff?

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

when implementing a 'soft particle' shader with an early-Z texture, what kind of falloff should be used? i.e. how do you calculate the alpha based on (d - z)? Linear? Exponential? Some complex formula? cheers

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by JPulham
when implementing a 'soft particle' shader with an early-Z texture
Wait, did you just say "soft particle" and "early-Z" in one sentence?
The way I understand soft particles, you have to write to Z in your shader, or they don't intersect with things properly, so early-Z will be off. From how much fill my implementation burns, I don't have the impression early-Z is working, either.

Am I misunderstanding something, is there a trick to keep early-Z enabled? If there is one, please enlighten me, would be very grateful :-)

Share this post


Link to post
Share on other sites
I assume he's just using the texture he has written in the early Z-pass, so he's not doing particles in early Z.

From my memory of reading the NVidia article, I found it strange that they proposed some piece-wise exponential function rather than coming up with a simple polynomial. Say Z0 is the depth value of the soft-particle pixel you're writing, d is the falloff distance and Z is the distance you read from the Z-texture. First you compute
f = saturate((Z - Z0) / d);
If the Z-texture value Z is equal to Z0 of your soft particle pixel, f is zero, and if Z is at distance d to Z0, f will be one. Using f as alpha for the soft-particle pixel will give you the linear ramp. Now all you have to do to make it soft is
f = f * f * (3 - 2 * f)
There might even be a built-in function for this. The curve looks like h01 (blue curve) in here.

- Lutz

Share this post


Link to post
Share on other sites
Quote:
Original post by Lutz
From my memory of reading the NVidia article, I found it strange that they proposed some piece-wise exponential function rather than coming up with a simple polynomial. Say Z0 is the depth value of the soft-particle pixel you're writing, d is the falloff distance and Z is the distance you read from the Z-texture. First you compute
f = saturate((Z - Z0) / d);
If the Z-texture value Z is equal to Z0 of your soft particle pixel, f is zero, and if Z is at distance d to Z0, f will be one. Using f as alpha for the soft-particle pixel will give you the linear ramp. Now all you have to do to make it soft is
f = f * f * (3 - 2 * f)
There might even be a built-in function for this. The curve looks like h01 (blue curve) in here
That gives quite nice results [smile]

Cheers,
ViLiO

Share this post


Link to post
Share on other sites
thanks for the replies.

@samoth:
I do a full scene pass of jus the base geometry and then do particles, water etc as a post process, so Lutz was right :P

@Lutz:
thanks for that, the curve on wikipedia looks quite nice

Share this post


Link to post
Share on other sites
Works very well. Thanks. What is the best way to tweak this algorithm so that it does not fade off the particle completely if the particle (all the pixels associated with it) is very close to the intersection object i.e (d -z) is 0? Say for example if the particle is parallel to the ground and being viewed from the top?

Share this post


Link to post
Share on other sites
Additionally to the depth, you'd have to store the normals as well. Otherwise, you can't tell if the particle is parallel to the ground or not. If you do deferred rendering, you have that anyway. If not, it's probably not worth it.

So if the particle is parallel to the ground, you'd want a smaller fade-off distance. You could achieve this the following way: If Np is the normal of the particle and Ng the normal of the ground (stored in the texture), you'd set

d' = d * (1 - dot(Np, Ng)).

(Both normals are assumed to be normalized.) So if Np and Ng are parallel, d' would be zero (you should probably add some eps to prevent division through 0).

- Lutz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!