# Soft Particles and Linear Depth Buffers

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

## Recommended Posts

Hi again,

I can't seem to stop tweaking my soft particle system. Once I'm fairly happy with it I then a seem to slowly think it isn't quite good enough.. anyway: Questions:

1. My soft particles (kinda a ground fog/mist over a mountain) looks pretty nice when you're in it (no banding really and it seems fairly misty) but if you get a long way away from it it's almost invisible. Or over the skybox it's completely invisible.

I'm doing this:

float4

output.Color.rbga *= fade;

In the pixel shader to fade the particles into the scene.

I can do a bit of a fudge maybe like:

fade += (depthFromMap / 20.0f);

To get the particles to remain visible no matter how far away they are but it doesn't seem like a great way of doing it. Looks ok. Is there some better way?

2. I see a lot of people use a linear depth map for this (and everything else, shadows etc). Should I switch everything to use a linear depth map? Would that fix this issue? Are they vanishing because of no precision to do the compare when the particles are far away?

(I'm currently just outputting the depth from z/w after multiplying the position by viewproj which is a log depth isn't it?)

Thanks

##### Share on other sites

Yes, z/w is very non-linear. If you're using a hardware depth buffer, you can compute the original view-space Z value by using the original projection matrix used for transforming the vertices:

float linearDepth = Projection._43 / (zw - Projection._33);


If you'd like you can then normalize this value to [0, 1] by dividing by the far clip plane, by doing z = (z - nearClip) / (farClip - nearClip).

Using a linear depth value for soft particles should give you much more consistent results across your depth range, so I would recommend doing that.

##### Share on other sites

Thanks MJP (I've read a lot of your great posts/code while trying to learn this stuff)!

I'll give that a try when I get in tonight.

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

• 10
• 9
• 14
• 9
• 33
• ### Forum Statistics

• Total Topics
632592
• Total Posts
3007296

×