Jump to content
  • Advertisement
Sign in to follow this  
zenux

Write multi depth buffer

This topic is 2428 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

Hi,

I would like write in several depth buffers for each vertex emitted by my geometry shader.

I have create a FBO and I attach several color textures on it. Here a sample of the first one:

glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, heigh, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID0, 0);


In my fragment shader, I try to write in the first depth buffer:

#version 330
layout (location = 0) out float fragDepth;
void main()
{
fragDepth = gl_FragCoord.z;
}


Unfortunatly, it doesn't work. I guess, it's because the float should be convert it in GL_DEPTH_COMPONENT. How I can do that ?

Thank you in advance.

Share this post


Link to post
Share on other sites
Advertisement
Thank you for your reply.
I already tested your solution. I have also tested with "fragDepth=1.0" and I don't get the expected behavior.

I have tested with a texture GL_RGBA where I put the depth value on one of the component. It works but only 1/4 of the texture is used.

Which kind of texture format can I use to store the depth value on 32 bits ?

Share this post


Link to post
Share on other sites
::glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, m_ui32Width, m_ui32Height, 0UL, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL );
Or:
::glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, m_ui32Width, m_ui32Height, 0UL, GL_DEPTH_COMPONENT, GL_FLOAT, NULL );
If your problem is not solved you should post a screenshot to show why you think your textures are not correct.


L. Spiro

Share this post


Link to post
Share on other sites

I have tested with a texture GL_RGBA where I put the depth value on one of the component. It works but only 1/4 of the texture is used.

Then why not use GL_R32F/GL_RED texture instead?

Share this post


Link to post
Share on other sites
I have tested all possiblities with the GL_DEPTH_COMPONENT* and nothing works. I suppose that it's not a float used behind GL_DEPTH_COMPONENT.
If it's the case: why is not a float ? There is maybe a better encoding for depth values ?

I didn't know the existance GL_R32F. I have tested and it works. Thank you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!