Hello all,
I am currently trying to implement a deferred renderer.
I am mostly following this tutorial: http://bat710.univ-lyon1.fr/~jciehl/Public/educ/GAMA/2007/Deferred_Shading_Tutorial_SBGAMES2005.pdf
Here are some screenshot from my current state. The test scene consists of two cubes and a point light.
1. This first screenshot looks correct
2. The second screenshot is taken from the opposite side. Here you can see that the cube which is further away overlaps the near cube:
3. Because I think this is a problem related to the depth buffer I rendered the depth buffer to the screen and everything was white. Then I manually created a texture and filled it with the z-values. The next two screenshots show this manually created depth texture:
Does anyone have an idea what the problem could be? If you need source code of specific parts just let me know.
Thx in advance.
Problem with deferred rendering
Yeah, that doesn't look like a deferred rendering related issue.
Your depth buffer seems to be set up incorrectly.
Check that you have depth writing enabled and that your depth buffer is properly bound during your geometry pass.
Your depth buffer seems to be set up incorrectly.
Check that you have depth writing enabled and that your depth buffer is properly bound during your geometry pass.
Depth writing is enabled:
So maybe the buffer is not bound...
pass GeometryPass
{
Cullface = Back;
CullFaceEnable = false;
BlendEnable = false;
DepthFunc = LEqual;
Texture2DEnable[0] = false;
Texture2DEnable[1] = false;
ClearColor = float4(1, 1, 1, 1);
ClearDepth = 1.0;
ColorMask = bool4(false, false, false, false);
DepthMask = true;
DepthTestEnable = true;
}
So maybe the buffer is not bound...
This is the code for creating the depth buffer:
Then I bind the framebuffer with
Afterwards I render my stuff using:
Could it be that the depth buffer is changed by the following pass which renders the accumulated buffer to the screen? This would explain why the depth buffer is completely white for the whole screen. But all other passed have DepthTestEnable set to false...
depthTexture = memoryManager->construct(Texture());
depthTexture->bind();
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture->getID(), 0);
Then I bind the framebuffer with
glBindFramebuffer(GL_FRAMEBUFFER, id);
Afterwards I render my stuff using:
GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3};
glDrawBuffers(4, buffers);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
renderStuff();
Could it be that the depth buffer is changed by the following pass which renders the accumulated buffer to the screen? This would explain why the depth buffer is completely white for the whole screen. But all other passed have DepthTestEnable set to false...
renderStuff does the following:
renderGeometry() just sets the material properties for the shader and renders the vertex buffers
GLenum buffers[] = {GL_COLOR_ATTACHMENT0 + firstAttachment, GL_COLOR_ATTACHMENT1 + firstAttachment, GL_COLOR_ATTACHMENT2 + firstAttachment, GL_COLOR_ATTACHMENT3 + firstAttachment};
glDrawBuffers(frameBuffer->getNumColorAttachments()-1, buffers);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
const Math::Matrix4 view(viewport->getCamera()->getViewMatrix());
Effect* effect = effects->get("Default");
effect->activate();
while (effect->hasNextPass())
{
renderGeometry(drawCallList, effect, view);
effect->gotoNextPass();
}
effect->deactivate();
renderGeometry() just sets the material properties for the shader and renders the vertex buffers
renderGeometry() just sets the material properties for the shader and renders the vertex buffers
Maybe show this method too, there must be something different when rendering the two cubes ...
void DeferredRenderer::renderGeometry(const DrawCallOptimizer::DrawCalls& drawCallList, Effect* effect,
const Math::Matrix4& viewMatrix)
{
Texture* texture = 0;
for (auto i = drawCallList.begin(); i != drawCallList.end(); ++i)
{
for (auto t = 0u; t < i->material->textures.size(); ++t)
{
texture = textures->get(i->material->textures[t]);
texture->bind(t);
effect->set(t, texture);
}
effect->set("Diffuse", i->material->diffuse);
effect->set("Specular", i->material->specular);
const Math::Matrix4 mv(i->transform * viewMatrix);
effect->set("ModelView", mv);
effect->set("ModelViewProjection", mv * (viewport->getCamera()->getProjectionMatrix()));
vertexBuffers->get(i->vertexBuffer)->render(indexBuffers->get(i->indexBuffer));
for (auto t = 0u; t != i->material->textures.size(); ++t)
{
textures->get(i->material->textures[t])->unbind(t);
}
}
}
Thanks for taking the time to help me!
Ok I found out why my depth buffer was not correct.
At first I forgot to set the VertexProgram in my CGFX shader. So nothing got rendered to the depth buffer ;)
The second thing was that the depth buffer was not cleared because DepthMask was set to false from the previous frame...
Now the depth buffer looks alright when rendered to the screen. But the final image still looks like the first two screenshots from my initial post...
At first I forgot to set the VertexProgram in my CGFX shader. So nothing got rendered to the depth buffer ;)
The second thing was that the depth buffer was not cleared because DepthMask was set to false from the previous frame...
Now the depth buffer looks alright when rendered to the screen. But the final image still looks like the first two screenshots from my initial post...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement