Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Problem with deferred rendering


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 madRenEGadE   Members   -  Reputation: 188

Like
0Likes
Like

Posted 03 May 2012 - 01:59 PM

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
Posted Image

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

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:

Posted Image

Posted Image


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.

Sponsor:

#2 Hyunkel   Members   -  Reputation: 336

Like
1Likes
Like

Posted 03 May 2012 - 02:37 PM

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.

#3 madRenEGadE   Members   -  Reputation: 188

Like
0Likes
Like

Posted 03 May 2012 - 02:43 PM

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

#4 madRenEGadE   Members   -  Reputation: 188

Like
0Likes
Like

Posted 03 May 2012 - 03:02 PM

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

#5 Ashaman73   Members   -  Reputation: 4603

Like
1Likes
Like

Posted 04 May 2012 - 12:06 AM

Can you show what you are doing in "renderStuff()" ?

Edited by Ashaman73, 04 May 2012 - 12:08 AM.


#6 madRenEGadE   Members   -  Reputation: 188

Like
0Likes
Like

Posted 04 May 2012 - 01:47 PM

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

#7 Ashaman73   Members   -  Reputation: 4603

Like
1Likes
Like

Posted 04 May 2012 - 07:30 PM

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

#8 madRenEGadE   Members   -  Reputation: 188

Like
0Likes
Like

Posted 05 May 2012 - 12:00 AM

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!

#9 madRenEGadE   Members   -  Reputation: 188

Like
0Likes
Like

Posted 05 May 2012 - 05:53 AM

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

#10 madRenEGadE   Members   -  Reputation: 188

Like
0Likes
Like

Posted 05 May 2012 - 06:08 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS