# soft particles - what kind of falloff?

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

## 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 on other sites
In the nVidia soft particles example, they provide and give an explanation of a contrast function which gives nice results.

Soft Particles [nVidia SDK 10]

Regards,
ViLiO

##### Share on other sites
Quote:
 Original post by JPulhamwhen 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 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 on other sites
Quote:
 Original post by LutzFrom 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 computef = 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 isf = 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 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

*double 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 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

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633682
• Total Posts
3013311
×