At first, I wanna say thank you, I really appreciate all your replies!!
It’s the OpenGL State Manager States for CgFX render pass. As Nico said, it equals to the GL statement glEnable(GL_DEPTH_CLAMP_NV);. ^^a
Actually, the original problem I ran into comes from the second pass of depth peeling. I found if I discard the pixel upon the depth in clip space within some threshold, it lost the precision dramatically(I could only get the expected result very close to near plane of the camera). Therefore, I try to discard the pixel according to the depth in viewing space to minimize the numerical error from matrix multiplication(if I could dump the depth without clamping). However, the depth value I dump to 24-bit buffer is always clamped, so I want to experiment with other floating texture to examine the tradeoff. Currently, I’m not sure this way works or not…
I’ve tried the case to write the value with type float4 to a float texture, and it works fine. But it fails when I write a float value to a depth texture in my fragment shader.
Here is my FBO configuration:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_uiFBO);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_uiRBOs[uiDepthRBO]);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_uiWidth, m_uiHeight);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_uiRBOs[uiDepthRBO]);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, eTexTarget, uiTexHnd, 0);
and my pixel shaders…
// Pass 1, write the value to a depth texture
float WRITE_DEPTH_PS(float4 Pos : TEXCOORD0) : DEPTH
{
return 10.0;
}
// Pass 2, read the value from the texture
float4 READ_DEPTH_PS(float4 Pos : TEXCOORD0, uniform sampler2D InputDepthSampler) : COLOR
{
// Pos : The position in projection space
Pos /= Pos.w;
Pos = Pos * 0.5f + 0.5f;
float fDepth = tex2D(InputDepthSampler, Pos.xy).a;
if( fDepth > 1.0 )
{
return float4(1,0,0,1);
}
else
{
return float4(0,1,0,1);
}
}