Jump to content

  • Log In with Google      Sign In   
  • Create Account


Display stencil part of GL_DEPTH24_STENCIL8_EXT


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 NikolajThorsen   Members   -  Reputation: 150

Like
0Likes
Like

Posted 28 September 2012 - 05:29 AM

First off, id like to thank anyone reading and/or replying to this first thread of mine. I have previous found help in others problems/solutions from this site, but i have been unable to find any help regarding my specific problem. So here i go with my own post.

Im working on a deferred rendering engine at the moment, and i have multiple render targets. Along with storing positions, normals and diffuse color, i want one of these render targets to be used to store the depth and stencil values.

Heres the code i use to create the texture:

..
glGenTextures(1, &depth_stencil_buffer);
glBindTexture(GL_TEXTURE_2D, depth_stencil_buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, width, height, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D , depth_stencil_buffer, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D , depth_stencil_buffer, 0);
..

Now i can bind this texture, depth_stencil_buffer in the above code snippet, and render it on a fullscreen quad, and i can correctly see depth of the scene geometry. Heres the not so special code:

..
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,depth_stencil_buffer);
glUniform1i(glGetUniformLocation(m_uiTextureProgram, "tex"),0);

glBindVertexArray(m_ui_texture_VAO);
glDrawArrays(GL_TRIANGLES, 0,6);
glBindVertexArray(0);
glUseProgram(0);
..

And my GLSL shader code looks something like this:

in vec2 tex_c;
out vec4 output0;
uniform sampler2D tex;

void main()
{
	output0 = texture(tex,tex_c);
}

Using this code its possible for me to display and observe the depth buffer.

However, if I wish to render the stencil part of the texture, all i get is a white screen. I enable stencil testing, and even with a call to glClearStencil(0), which i think should turn the screen black instead of white, i still see only white tho. The way i try to render the stencil buffer, is by grabbing the .w coordinate (which should be the last 8bit containing stencil value) of the depth/stencil texture in the shader, and outputting just this value to screen. Heres the shader code that i use for this:

in vec2 tex_c;
out vec4 output0;
uniform sampler2D tex;
void main()
{
	output0 = vec4(texture(tex,tex_c).w);
}

I read in some OpenGL documentation (something i only vaguely remember), that if .w coordinate is missing (like if its only a vec3), getting .w in a shader always results in the value 1.0f. Could this be whats happening?

This is btw not the only way if tried to render the stencil buffer to screen. But i have yet to find a working solution. Any and all help is appreciated! Posted Image

Edited by NikolajThorsen, 04 October 2012 - 06:47 AM.


Sponsor:

#2 wantnon_cn   Members   -  Reputation: 115

Like
0Likes
Like

Posted 29 September 2012 - 11:28 AM

i know a working way, but maybe not very elegant.
you can attach your fbo a second color texture and render the stencil component to it (just make the second color buffer your render target, enable the stencil test and render a white quade cover the viewport, you know that).
i am a beginner to shader. few days ago, i encounter the same problem you asked above, and can not solve it, too. then i happened read a post somewhere give that solution, though not perfect, but works, and i use it achieved my goal. the efficiency seems ok.
anyway, always hope a better solution.
----
the attached file is what i got.

#3 wantnon_cn   Members   -  Reputation: 115

Like
0Likes
Like

Posted 29 September 2012 - 11:43 AM

why i cannot see the attached file?
ok, you can see here: http://user.qzone.qq.com/350479720/blog/1348470101

#4 wantnon_cn   Members   -  Reputation: 115

Like
0Likes
Like

Posted 29 September 2012 - 11:46 AM

why i cannot see the attached file?
ok, you can see here: http://user.qzone.qq.com/350479720/blog/1348470101

#5 NikolajThorsen   Members   -  Reputation: 150

Like
0Likes
Like

Posted 02 October 2012 - 02:45 PM

Yes, i have used a similar solution, but this doesn't use the built-in GL_DEPTH24_STENCIL8_EXT. Having a separate color buffer just for stencil information seems very unnecessary.

What is the correct way of getting the stencil part of GL_DEPTH24_STENCIL8_EXT, if i wish to display the stencil buffer on screen? If i have omitted any important details of my implementation, please tell me and ill give more information.

Edited by NikolajThorsen, 03 October 2012 - 02:18 PM.


#6 wantnon_cn   Members   -  Reputation: 115

Like
0Likes
Like

Posted 05 October 2012 - 09:37 AM

Yes, i have used a similar solution, but this doesn't use the built-in GL_DEPTH24_STENCIL8_EXT. Having a separate color buffer just for stencil information seems very unnecessary.

What is the correct way of getting the stencil part of GL_DEPTH24_STENCIL8_EXT, if i wish to display the stencil buffer on screen? If i have omitted any important details of my implementation, please tell me and ill give more information.


so, i want to know the answer, too. hope some one can solve this.

#7 NikolajThorsen   Members   -  Reputation: 150

Like
0Likes
Like

Posted 13 October 2012 - 10:48 AM

Bump.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS