我正在尝试根据NVDIA GPU Gems Chapter 9. Efficient Shadow Volume Rendering on iPad 实现阴影体积,但是我的模板缓冲区中出现了前/光帽问题。
我正在尝试在下图中间的盒子上渲染阴影。阴影在盒子的右侧正确生成,但是当我四处移动相机时,盒子的部分亮边被遮住了。在我看来,这可能是深度缓冲区的分辨率问题,无法识别阴影体积何时与框的深度相同并且不应该绘制,但我已经用于glDepthFunc(GL_LESS)
绘制阴影体积尝试纠正这一点,它似乎并没有改变任何东西。
这是我的代码的摘要:
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);
glDisable(GL_BLEND);
[self drawAmbient];
glDepthMask(GL_FALSE);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 0, 0xff);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP_OES, GL_KEEP);
glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP_OES, GL_KEEP);
glDisable(GL_CULL_FACE);
[self drawShadowVolumes];
glStencilFunc(GL_EQUAL, 0, 0xff);
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_KEEP);
glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE);
glDepthMask(GL_TRUE);
glDepthFunc(GL_EQUAL);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glEnable(GL_CULL_FACE);
[self drawDirectionalLight];