Jump to content
  • Advertisement
Sign in to follow this  

Soft Particles and Linear Depth Buffers

This topic is 980 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

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: 




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







Share this post

Link to post
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 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!