   checking depth buffer in ps
  is it possible to check the current value of depth buffer in a given pixel in pixel shader? and the z-value of the given pixel?thanks   
  AFAIK you can not read from the depth buffer in a pixel shader.  The fragment depth you should have access to, gl_FragCoord.z in GLSL, I am sure HLSL has an equivalent.;  Is it possible to do any sort of depth test in ps then? I read from somewhere that you can do depth-test by using depth texture? Could anyone explain how this is done?  Basically, i want to compare the depth value of a given pixel to the old depth value at the location of a given pixel.   ;  Yes, sort of, but not really. The method I'm imagining would involve a multi-pass solution. Render previous frame to a depth texture (or otherwise get the depth values from the previous frame stuffed into a depth texture). Then in the next frame calculate the depth of the pixel and compare it with the value stored in the depth texture. You can then clip the pixel based on the outcome of the comparison.   ;Quote: Render previous frame to a depth texturewhy the previous frame? you can just render everything of this pass into as depth into a rendertarget and acces it in your shader   ;  so, i'm assuming that using depth texture is the only way to do depth test in ps? Correct?   ;  You probably already understood this but -when nts mentioned the fragment depth, that means you can read the current pixel's z-value as a fragment in a pixel shader.  You can also write to the z-value, atleast on my hardware.  But if you start writing to z values, it generally cancels out any early z-fail test (read: slow).I've done this before (as I'm sure many have) to create z-correct parallax mapping :)  Concave intersections then have the correct intersection, it's pretty cool.-Michael g.   ;Quote:Original post by m4gnusQuote: Render previous frame to a depth texturewhy the previous frame? you can just render everything of this pass into as depth into a rendertarget and acces it in your shaderWhy previous? Because as I understand the OP question, he wants to compare the pixel's new depth with the pixel's old depth. And comparing a pixel's depth in a given frame to itself doesn't make sense.   ;Quote:Why previous? Because as I understand the OP question, he wants to compare the pixel's new depth with the pixel's old depth. And comparing a pixel's depth in a given frame to itself doesn't make sense.it does make sense rendering the current frame to a dpeth texture.the following purposes come to my mind:1.You could check if a fragment is visible (Edit: ok this is quite useless,except for changing the depth of the fragment depending on it's visbility)2.Depth-dependant refraction.3.Fog in arbitrary Meshes.that are some that just came to my mind.So it DOES make sense.regards,m4gnus[Edited by - m4gnus on July 13, 2006 8:15:03 AM];  One of the best uses I've seen for reading the depth texture in a pixel shader is for soft particles (as seen in Crysis)...  As the particle's Z value gets closer to the opaque geometry that was written into the Z buffer, the particle is faded out...  No more intersecting particles with the world! Woohoo!   