Hello.
I have questions about glCullFace and gl_Fragcoord.z.
First, when I turn on and off glCullFace, the depth value from shader stage does not make sense to me.
This is the scene
[ATTACH=CONFIG]157[/ATTACH]
This is when the cullface is off
[ATTACH=CONFIG]1539[/ATTACH]
This is when culling is on.
[ATTACH=CONFIG]1540[/ATTACH]
void DeferredRenderer::ShadowPass(Entity * gLight, const Scene * scene)
{
if (auto shadowBuffer = mRenderTarget[ShadowBuffer])
{
assert(shadowBuffer->Bind());
glViewport(0, 0, shadowBuffer->GetBuffer().mWidth, shadowBuffer->GetBuffer().mHeight);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
auto shadowShader = this->mOwnerSystem->GetSubManager<ShaderManager>("Static_ESM");
assert(shadowShader != nullptr);
shadowShader->Use();
for (auto drawable : scene->mDrawableList)
{
drawable->Draw(shadowShader);
}
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
}
else DEBUG_PRINT("No shadow buffer");
}
Second, what is the difference between gl_Fragcoord.z and depth value?
Can gl_Fragcoord.z represent depth value in depth buffer?
This is from gl_Fragcoord.z
[ATTACH=CONFIG]1540[/ATTACH]
This is from depth buffer
[ATTACH=CONFIG]1542[/ATTACH]
This is how I created color buffer and depth buffer
mRenderTarget.insert(std::make_pair(ShadowBuffer, new RenderTarget()));
mRenderTarget[ShadowBuffer]->AddColorBuffer(mShadowSize.x, mShadowSize.y,
GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT, GL_RED, GL_R32F, GL_FLOAT);
mRenderTarget[ShadowBuffer]->AddDepthBuffer(mShadowSize.x, mShadowSize.y);
This is the fragment stage.
in float oClipZ;
uniform float uExpConstant;
out float oGShadow;
void main()
{
float depthValue = oClipZ * gl_FragCoord.w * 0.5f + 0.5f;
oGShadow = exp(depthValue * uExpConstant);
oGShadow = depthValue;
oGShadow = gl_FragCoord.z; // gl_FragCoord.z is same with depthValue that I calculated because gl_FragCoord.z = clip.Z / clip.W
}