glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_FORMAT,480,800,0,GL_RED,GL_FLOAT,NULL);
FBO question
Hello All,
I have a simple FBO question.
I'm trying to implement a deferred shading using openGL.
my question is this, if I attach to the FBO, in Color_attachment0, a Texture using
the API line
This is done in order to render the Z-Buffer to a texture.
In the fragment shader how do I output a single float to the image? does gl_fragColor is the same type has the texture format bound to the RT?
Also if I later want to sample from that texture, does texture2D return type, is the format of the texture?
If not, how do I change the type of the output of the fragment shader?
Thanks all
First, your call is wrong, it's GL_DEPTH_COMPONENT, not GL_DEPTH_FORMAT.
Answering your question, depth is output through gl_FragDepth, gl_FragColor is only for color buffers.
Answering your question, depth is output through gl_FragDepth, gl_FragColor is only for color buffers.
You need to use
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT16,480,800,0,GL_RED,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT24,480,800,0,GL_RED,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT32,480,800,0,GL_RED,GL_FLOAT,NULL);
http://www.opengl.org/wiki/GL_EXT_framebuffer_object#Color_texture.2C_Depth_texture
=====For the shader
Normally, it is best not to write to gl_FragDepth because it disable hierarchal z and early z test. It will automatically output the default depth value of the fragment.
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT16,480,800,0,GL_RED,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT24,480,800,0,GL_RED,GL_FLOAT,NULL);
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT32,480,800,0,GL_RED,GL_FLOAT,NULL);
http://www.opengl.org/wiki/GL_EXT_framebuffer_object#Color_texture.2C_Depth_texture
=====For the shader
Normally, it is best not to write to gl_FragDepth because it disable hierarchal z and early z test. It will automatically output the default depth value of the fragment.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement