Sign in to follow this  

Depth Peeling Issues

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

Dear All,

I'm having some problems with depth peeling. I have previously implemented this before successfully on older hardware, but I cant get my new version to work. I used to simply call into tex2dproj with projective transformed vertexes, but the profile our engine uses with cg for w/e reason no longer supports tex2dproj, so I have to scale the texture vertexes into the required range myself. This seems to be working, but I am having a lot of trouble with the comparison, the results are very low precision. I almost never seem to get any rejection of fragments, unless I use a basis, then the results become very inaccurate.

Here is the code that scales the vertex positions into the range [0,1]


float4x4 ScaleTexture = float4x4(float4(.5,0,0,0),float4(0,.5,0,0),float4(0,0,1,0),float4(0,0,0,1));
float4 finalposition = mul(ProjectionMatrix, pos);
OUT.Position = finalposition;
float4(((finalposition).xyz/(finalposition.w))+float3(1,1,0),1));
projectedtex.y = 1 - projectedtex.y;
OUT.TexCoord3 = projectedtex;


Pixel Shader


MRT_OUT OUT;


color.a = (IN.TexCoord3.z);

if(firstlayer > 0)
{


if( color.a <= tex2D(Texture2, (IN.TexCoord3.xy) ).r)//Depth peeling section
{
discard;

}


OUT.rt2 = color.a;
}
else
{

OUT.rt2 = float4(color.a,color.a,color.a,color.a);
}


I have checked in PIX and the R32 Texture being passed in as depth appears to be correct. Unfortunately I cant seem to debug the pixel shader(pix complains when I try and do this). Anything seem obviously wrong?

Regards,
Jesse

Share this post


Link to post
Share on other sites
Hi,

Depth precision can be the result of many things. The normal mistake is using a huge frustum, instead of tightly bounding your object. The tighter your near and far planes are, the better your results will be.

If this is not your issue, you may be using a FBO with a lower depth resolution. If this is the case, try requesting a 24 or 32 bit depth resolution. If you're encoding the depth in a RGBA texture instead of a depth texture, remember to use float textures, or your depth will only get 8 bits.

-G

Share this post


Link to post
Share on other sites
I am already writing out the depth to a 32 bit texture. I do not think depth accuracy is the issue here, since there is no Z-fighting, but I changed the clipping planes so that most of the scene was clipped out, and I still couldnt get it to work.
Jesse

Share this post


Link to post
Share on other sites

This topic is 2584 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this