i have a fbo mrt setup that currently works for normals and color, and i tried to add the possibility to render the depth and position values, and it seems as if my shaders render correctly into the frame buffer (gDebugger screenshot), but when i try rendering them like i do with normals, i either get a white screen for the depth texture, or some red glitch for the positions.
for the depth texture, i'm guessing because of my nearZ and farZ values beeing 1 and 100000, the depth values range between 0.9992 and 0.995, but i don't know how i could transform them to get a decent rendered depth texture.
as for the positions, i'm clueless, maybe my formats are wrong?
the opengl context is 4.2.11733 Compatibility Profile Context
here is what gdebugger shows for the textures:
and this is the failed result for the positions (depth buffer result is a white screen, and positions is like the gdebugger output):
that is how i set up the fbo and textures:
bool KBuffer::Initialize(uint width, uint height)
{
GLint maxBuffers;
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxBuffers);
if(maxBuffers < 3)
FCThrow("MRT max buffer < 3");
m_Width = width;
m_Height = height;
m_Quad = MeshProvider::CreateTexturedScreenQuad();
// generate buffers
glGenFramebuffers(1, &m_Fbo));
glGenRenderbuffers(1, &m_DepthBuffer);
glGenRenderbuffers(1, &m_ColorBuffer);
glGenRenderbuffers(1, &m_PositionBuffer);
glGenRenderbuffers(1, &m_NormalBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_Fbo);
glBindRenderbufferEXT(GL_RENDERBUFFER, m_ColorBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA, width, height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_ColorBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER, m_PositionBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA32F, width, height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, m_PositionBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER, m_NormalBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA16F, width, height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, m_NormalBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER, m_DepthBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, width, height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_DepthBuffer);
// create the textures
glGenTextures(eGBufferTexture::_Count, m_Textures);
// diffuse/color - 8 bit per channel
glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Color]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_Textures[eGBufferTexture::Color], 0);
// position - HDR texture with 32 bit per channel
glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Position]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_Textures[eGBufferTexture::Position], 0);
// normal - 16 bit per channel
glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Normal]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_Textures[eGBufferTexture::Normal], 0));
// depth
glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Depth]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_Textures[eGBufferTexture::Depth], 0);
bool succeeded = OpenGLCheckFramebuffer(__FILE__, __LINE__);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return succeeded;
}
// render completed scene position texture a quad:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_Textures[eGBufferTexture::Position]); // Normals and Color draws correctly
glUniform1i(colorSamplerParam, 0);
m_Quad->Render();
// vertex shader
#version 330 core
precision highp float;
...
out block
{
vec2 TexCoord0;
} Out;
void main()
{
gl_Position = u_mMVP * vec4(a_vPosition, 1.0);
Out.TexCoord0 = a_vTexCoord0;
}
// fragment shader
uniform sampler2D u_sColor;
void main()
{
FragColor = vec4(texture(u_sColor, In.TexCoord0).xyz, 1);
}
EDIT :
i thoght maybe somehow my quad is rendered wrong and tried with
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_Fbo);
glReadBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, 0, m_Width, m_Height, 0, 0, m_Width, m_Height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
but that yields the same wrong result