problems with position and depth range in fbo texture

Started by
3 comments, last by miggs 11 years, 8 months ago
hi

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:

30mlbtl.png

and this is the failed result for the positions (depth buffer result is a white screen, and positions is like the gdebugger output):

104p83c.png



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
Advertisement
i tried repositioning my camera and setting the projection near/far from 0.1/100000 to 10/10000, and now i see the depth texture, and the positions.

still they do not look like they do in gdebugger, but seeing those values, i think it is just a matter of displaying the values sent to the shader differently.

here is my engine output
w7lrgh.png


and this is what gdebugger says:
s113eo.png



how can i change my shader or render calls to visualize the textures in a better color range?

because needing to have the far/near plane at 10/10000 is not accepable if i have a first person camera running on that land/heightmap. i'd at least like them to be 0.3/3000
Are you using GL_FLOAT as your parameter for these textures?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


i tried repositioning my camera and setting the projection near/far from 0.1/100000 to 10/10000, and now i see the depth texture, and the positions.


how can i change my shader or render calls to visualize the textures in a better color range?

because needing to have the far/near plane at 10/10000 is not accepable if i have a first person camera running on that land/heightmap. i'd at least like them to be 0.3/3000


that ratio is simply not acceptable in terms of precision, can you actually justify for why you need such a ratio?, i'd recommend looking up log depth buffer's if you absolutely must.

check this discussion for similar talk on the topic http://www.gamedev.net/topic/626726-how-to-solve-z-buffer-fighting/
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
thanks that helped a lot, i've set mine to 0.35 / 1000 at the moment, and in case i need to see farther i might render in a different clipping context.

one question remains, which is why my postions texture looks so weird. is that normal? because it doesn't look anything like the gdebugger output.

This topic is closed to new replies.

Advertisement