• Create Account

### #Actualmv348

Posted 07 November 2012 - 09:29 PM

I have been following this tutorialcarefully. Usually these tutorials are very clear but this one has me confused.

The main steps are handled in the RenderSceneCB() function. After setting up a few uniform variables for the shaders, it calls the 3 functions in sequence:


RenderSceneIntoDepth();
glEnable(GL_STENCIL_TEST);



You can find the definitions of each function in the tutorial-they're not that long.

First the entire scene is rendered (a box and a floor quad) depth-only.

Then the shadow-volumes are rendered which populates the stencil buffer based on when the depth-test fails for front and back faces. Cool. Makes sense.

The last bit confuses me. Take a look at the RenderedShadowScene() function:


{
glDrawBuffer(GL_BACK);
glStencilFunc(GL_EQUAL, 0x0, 0xFF);
m_LightingTech.Enable();
m_pointLight.AmbientIntensity = 0.0f;
m_pointLight.DiffuseIntensity = 0.8f;
m_LightingTech.SetPointLights(1, &m_pointLight);
m_pGroundTex->Bind(GL_TEXTURE0);
Pipeline p;
p.SetPerspectiveProj(m_persProjInfo);
p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
p.WorldPos(m_boxPos);
p.Rotate(0, m_scale, 0);
m_LightingTech.SetWVP(p.GetWVPTrans());
m_LightingTech.SetWorldMatrix(p.GetWorldTrans());
m_box.Render();
p.Scale(10.0f, 10.0f, 10.0f);
p.WorldPos(0.0f, 0.0f, 0.0f);
p.Rotate(90.0f, 0.0f, 0.0f);
m_LightingTech.SetWVP(p.GetWVPTrans());
m_LightingTech.SetWorldMatrix(p.GetWorldTrans());
}


Mostly the real meat and potatoes happens in the first two calls I think. glDrawBuffer(GL_BACK) and glDepthMask(GL_FALSE). From my understanding. I have never scene the glDrawBuffer(GL_BACK) call before and the tutorial doesn't explain it. As for glDepthMask, my understanding here is that this means the depth test is still active, but writing new values does not occur.

Apart from not knowing what the point of glDrawBuffer(GL_BACK) is, I don't understand how the depth-test can work here. If the depth test is enabled, we should get Z-fighting, since "RenderSceneIntoDepth();" already filled the depth buffer. On the other hand, if we disable the depth buffer, than the pixels might be rendered out of order.

So confused...

### #1mv348

Posted 07 November 2012 - 09:25 PM

I have been following this tutorial carefully. Usually these tutorials are very clear but this one has me confused.

The main steps are handled in the RenderSceneCB() function. After setting up a few uniform variables for the shaders, it calls the 3 functions in sequence:


RenderSceneIntoDepth();
glEnable(GL_STENCIL_TEST);



You can find the definitions of each function in the tutorial-they're not that long.

First the entire scene is rendered (a box and a floor quad) depth-only.

Then the shadow-volumes are rendered which populates the stencil buffer based on when the depth-test fails for front and back faces. Cool. Makes sense.

The last bit confuses me. Take a look at the RenderedShadowScene() function:


{
glDrawBuffer(GL_BACK);
glStencilFunc(GL_EQUAL, 0x0, 0xFF);
m_LightingTech.Enable();
m_pointLight.AmbientIntensity = 0.0f;
m_pointLight.DiffuseIntensity = 0.8f;
m_LightingTech.SetPointLights(1, &m_pointLight);
m_pGroundTex->Bind(GL_TEXTURE0);
Pipeline p;
p.SetPerspectiveProj(m_persProjInfo);
p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
p.WorldPos(m_boxPos);
p.Rotate(0, m_scale, 0);
m_LightingTech.SetWVP(p.GetWVPTrans());
m_LightingTech.SetWorldMatrix(p.GetWorldTrans());
m_box.Render();
p.Scale(10.0f, 10.0f, 10.0f);
p.WorldPos(0.0f, 0.0f, 0.0f);
p.Rotate(90.0f, 0.0f, 0.0f);
m_LightingTech.SetWVP(p.GetWVPTrans());
m_LightingTech.SetWorldMatrix(p.GetWorldTrans());