I'm running the tutorial 35 from olgdev.atspace.co.uk, and it's so strange that the result is a blank screen. This tutorial is performing the first step of Deferred Shading, which means decoupling of geometry calculations and lighting calclation. This process includes following steps.
- Bouding logical texture to Frame Buffer Object
- Rendering 1: Only writing vertex attributes to such textures.
- Rendering 2: Copy data from such textures, which included inside Frame Buffer Object onto the screen.
At the first step, I bound the texture to the Frame Buffer Object as following:
// Create the FBO
glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
// Create the buffer textures
glGenTextures(ARRAY_SIZE_IN_ELEMENTS(m_textures), m_textures);
glGenTextures(1, &m_depthTexture);
//Set up texture format and bound to FBO
for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_textures) ; i++) {
glBindTexture(GL_TEXTURE_2D, m_textures[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, WindowWidth, WindowHeight, 0, GL_RGB, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_textures[i], 0);
}
// depth
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, WindowWidth, WindowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);
GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0,
GL_COLOR_ATTACHMENT1,
GL_COLOR_ATTACHMENT2,
GL_COLOR_ATTACHMENT3 };
//Set such textures as the output receiver from Fragment Shader
glDrawBuffers(ARRAY_SIZE_IN_ELEMENTS(DrawBuffers), DrawBuffers);
The next is rendering processing, including two main steps.
virtual void RenderSceneCB()
{
m_pGameCamera->OnRender();
DSGeometryPass(); //The first step ==> Only write vertex attributes to logical texture
DSLightPass(); //The second: copy data from such textures to the screen.
RenderFPS();
glutSwapBuffers();
}
At the first step, the fragment shader only pass on vertex attributes to the logical texture, which before bound to the Frame Buffer Object. This is the rendering code
void DSGeometryPass()
{
m_DSGeomPassTech.Enable();
m_gbuffer.BindForWriting();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Pipeline p;
p.Scale(0.1f, 0.1f, 0.1f);
p.Rotate(0.0f, m_scale, 0.0f);
p.WorldPos(-0.8f, -1.0f, 12.0f);
p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
p.SetPerspectiveProj(m_persProjInfo);
m_DSGeomPassTech.SetWVP(p.GetWVPTrans());
m_DSGeomPassTech.SetWorldMatrix(p.GetWorldTrans());
m_mesh.Render();
}
And this is the shader code
struct FSOutput //Fragment shader
{
vec3 WorldSpacePos; //which will be copied to position texture.
vec3 Diffuse; //which will be copied to diffuse texture.
vec3 Normal; //which will be copied to normal texture.
vec3 TexCoord; //which will be copied to texCoord texture.
};
shader FSmain(in VSOutput FSin, out FSOutput FSout)
{
FSout.WorldSpacePos = FSin.WorldSpacePos;
FSout.Diffuse = texture(gColorMap, FSin.TexCoord).xyz;
FSout.Normal = normalize(FSin.Normal);
FSout.TexCoord = vec3(FSin.TexCoord, 0.0);
};
Therefore, the results we got from Fragment Shader are four textures, which is then copied onto the screen and should be seen as following
However,the screen is going to blank. I used gDeDebugger for finding the values of such fours textures after Fragment Shader performed, and it shows that all of thems is blank.
My question is why the Fragment shader pass a blank input to the four textures?
I hope to see your answer.
Many Thanks!