将DepthBuffer和TextureBuffer发送到同一片段OpenGL3
Send Depthbuffer and TextureBuffer to same Fragment OpenGL3
这可能是愚蠢的,而且一个琐碎的问题着色器。
我的FBO使用1个纹理缓冲区和1个深度缓冲区生成
glGenTextures(1, &texture_color);
glBindTexture(GL_TEXTURE_2D, texture_color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glGenTextures(1, &texture_depth);
glBindTexture(GL_TEXTURE_2D, texture_depth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
我想在我的片段缓冲区中具有
uniform sampler2D colorTexture;
uniform sampler2D depthTexture;
要填充颜色和深度纹理...
我只能将一个或另一个带有glbindTexture(并且效果很好),但是我不成功地同时发送2次。有人知道该怎么做吗?
谢谢!
好吧,我可能不是巨人,因为解决方案很容易,我只是做错了。
我试图使用glactiveTexture(gl_depth),然后对我的纹理进行绑定:( glbindTexture(gl_texture_2d,vistibilityfbo.getDepthTexture());)认为使用GL_DEPTH。
。但是我错了,它使用以下方式工作:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, visibilityFBO.getColorTexture());
glUniform1i(glGetUniformLocation(visibilityPassShader.Program, "positionTexture"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, visibilityFBO.getDepthTexture());
glUniform1i(glGetUniformLocation(visibilityPassShader.Program, "depthTexture"), 1);
与以前相同,但是深度被考虑为纹理,因为我使用glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
来产生深度纹理。因此,我只需要调用下一个纹理并将其绑定才能使用它。
在片段中仍然是:
uniform sampler2D positionTexture;
uniform sampler2D depthTexture;
按良好的顺序。
使用OpenGl> = 4,您可以在片段着色器
中使用layout (binding = 0) uniform sampler2D positionTexture;
layout (binding = 1) uniform sampler2D depthTexture;
并原谅源代码中有关gluuniform1i的部分。
希望它可以帮助某人!
相关文章:
- 这个带有模板<类 Vector 的C++代码片段有什么问题>
- Opengl 3.1 GLSL 140 在 C++ 年输出白色在片段着色器中
- 这两个代码片段相似,但显示的结果不同
- 如何替换此示例代码片段中已弃用的handler_type_t或 boost::asio::handler_type?
- 我需要解释给定片段的输出
- 如果我在下面的代码片段中添加"delete[] d;",为什么我得到零?
- 我遇到了这个代码片段,不明白. 它递归检查 C++ 字符串中是否存在大写字符
- 任何人都可以解释一下我是否需要 & 在第一个代码片段中
- OpenGL 片段着色器未在英特尔 HD 4000 显卡上编译
- 帧缓冲纹理变为白色(片段着色器不会影响它)
- 如何在 c++ 中检查连续片段中数字被 11 整除
- 提取狮身人面像文档中的C++代码片段
- 为什么此代码片段有效?如何取消引用空点?
- 将顶点位置从顶点传递到片段着色器 - 仅在使用 Nsight 进行调试时有效
- 无法在这个基本的Qt代码片段中找到错误,但我被告知它肯定存在?
- 使用片段着色器写入 1D 纹理后从 1D 纹理读回不起作用
- 如何在顶点着色器中使用VBO数据作为位置数据,在片段着色器中使用统一数据作为颜色数据
- 这个代码片段中会发生死锁吗?为什么
- 同时与两个片段着色器发生碰撞
- 将DepthBuffer和TextureBuffer发送到同一片段OpenGL3