4

我想在 OpenGL ES 2.0 中渲染一个带有轮廓后处理效果的场景。

首先我渲染所有不透明的对象。然后我使用后处理着色器进行轮廓检测,将深度缓冲区用作纹理。现在我想使用 alpha 混合渲染所有对象,而不是写入深度缓冲区,而是使用深度缓冲区纹理中用于轮廓检测的值进行深度测试。

如果我在后期处理之前渲染半透明对象,则后期处理会在它们上面渲染不透明对象的轮廓,因为它们不写入深度缓冲区。

你如何告诉 OpenGL ES 2.0 使用纹理作为深度缓冲区?

谢谢

4

2 回答 2

3

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 into the color buffer, but you will have limited precision there.

This SO thread covers the same question for WebGL which suffers from the same problem.
The GLES2 book covers Framebuffer Objects and Renderbuffer Objects, including extensions, in chapter 12.

于 2013-09-08T20:56:48.153 回答
0

onDrawFrame(){ ...

            ////attach texture for SSAO
            GLES20.glActiveTexture(GLES30.GL_TEXTURE2);
            GLES20.glBindTexture(GLES30.GL_TEXTURE_2D, TextureXYZ);
            GLES20.glUniform1i(rs.u_textureXYZ, 2);
            GLES20.glActiveTexture(GLES30.GL_TEXTURE3);
            GLES20.glBindTexture(GLES30.GL_TEXTURE_2D, TextureAO_Norm);//нормали
            GLES20.glUniform1i(rs.u_textureAO_norm, 3);
            GLES20.glActiveTexture(GLES30.GL_TEXTURE4);
            GLES20.glBindTexture(GLES30.GL_TEXTURE_2D, Texture_depth);//Depth
            GLES20.glUniform1i(rs.u_textureDepth, 4);

片段着色器...

uniform sampler2D u_textureXYZ;
uniform sampler2D u_textureAO_norm;
uniform sampler2D u_textureDepth;
于 2021-04-14T04:53:18.703 回答