How do you tell OpenGL ES 2.0 to use texture as a depth buffer?

I want to render a scene with the effect of post-processing a path in OpenGL ES 2.0.

First I make all the opaque objects. Then I use a post-processing shader to detect a silhouette that uses the depth buffer as a texture. And now I want to visualize all objects using alpha blending, without writing to the depth buffer, but using in-depth testing with the values ​​from the depth buffer texture used to detect the silhouette.

If I visualized semitransparent objects before further processing, post-processing would display the contours of opaque objects above them, since they do not write to the depth buffer.

How do you tell OpenGL ES 2.0 to use texture as a depth buffer?

thanks

+4
source share
1 answer

Check out the OES_depth_texture extension. With this you can

 // generate and bind a new Framebuffer object glGenFramebuffers( ... ); glBindFramebuffer( ... ); // create a depth texture glTexImage2D(..., GL_DEPTH_COMPONENT, ...); // and attach it to the Framebuffer with glFramebufferTexture2D(..., GL_DEPTH_ATTACHMENT, ...); 

Without OpenGL extensions, there is no perfect solution. You can write depth values ​​to the color buffer, but there you will have limited accuracy.

This SO thread covers the same issue for WebGL that suffers from the same issue.
GLES2 covers Framebuffer and Renderbuffer objects, including extensions, in chapter 12.

+3
source

Source: https://habr.com/ru/post/1501179/


All Articles