Sign in to follow this  

Problem with deferred rendering

This topic is 2046 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: [url="http://bat710.univ-lyon1.fr/~jciehl/Public/educ/GAMA/2007/Deferred_Shading_Tutorial_SBGAMES2005.pdf"]http://bat710.univ-lyon1.fr/~jciehl/Public/educ/GAMA/2007/Deferred_Shading_Tutorial_SBGAMES2005.pdf[/url]

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
[img]http://dl.dropbox.com/u/62642107/Screenshot3.jpg[/img]

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:
[img]http://dl.dropbox.com/u/62642107/Screenshot4.jpg[/img]

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:

[img]http://dl.dropbox.com/u/62642107/Screenshot1.jpg[/img]

[img]http://dl.dropbox.com/u/62642107/Screenshot2.jpg[/img]


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

[CODE]
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;
}[/CODE]

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:

[CODE]
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);
[/CODE]

Then I bind the framebuffer with
[CODE]
glBindFramebuffer(GL_FRAMEBUFFER, id);
[/CODE]

Afterwards I render my stuff using:
[CODE]
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();
[/CODE]

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:
[CODE]
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();
[/CODE]

renderGeometry() just sets the material properties for the shader and renders the vertex buffers

Share this post


Link to post
Share on other sites
[quote name='madRenEGadE' timestamp='1336160854' post='4937458']
renderGeometry() just sets the material properties for the shader and renders the vertex buffers
[/quote]
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
[CODE]
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);
}
}
}
[/CODE]

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

This topic is 2046 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this