Jump to content
  • Advertisement
Sign in to follow this  
madRenEGadE

Problem with deferred rendering

This topic is 2333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Screenshot3.jpg

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:
Screenshot4.jpg

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:

Screenshot1.jpg

Screenshot2.jpg


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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Depth writing is enabled:


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...

Share this post


Link to post
Share on other sites
This is the code for creating the depth buffer:


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...

Share this post


Link to post
Share on other sites
renderStuff does the following:

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

Share this post


Link to post
Share on other sites

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 ...

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Finally solved it... I fixed the overlapping (second screenshot) by enabling the depth test and disabling the depth mask in the shader passes after the geometry pass.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!