【发布时间】:2014-11-01 08:34:45
【问题描述】:
我正在尝试将 FBO 的深度纹理和颜色纹理链接到 GLSL 着色器(4.0 版)
问题是,同时只有一个链接,很奇怪,因为其他纹理很好地链接在一起(例如:漫反射贴图、法线贴图和高光贴图)
这是我的绑定 RT 代码:
void RenderTexture::BindRead(GLuint locationColor,GLuint locationDepth,unsigned int unit,unsigned int dUnit)
{
colorUnit = unit;
this->depthUnit = dUnit;
assert(unit >= 0 && unit <= 31);
glActiveTexture(GL_TEXTURE0 + unit);
glBindTexture(GL_TEXTURE_2D,m_rt);
if (hasDepth)
{
assert(depthUnit >= 0 && depthUnit <= 31);
glActiveTexture(GL_TEXTURE0 + dUnit);
glBindTexture(GL_TEXTURE_2D,m_depth);
glUniform1i(locationDepth,dUnit);
}
glUniform1i(locationColor,unit);
}
我真的不知道这里出了什么问题......
【问题讨论】:
-
你怎么知道将纹理绑定到着色器不起作用?你有错误吗?
-
不,我没有收到错误,两个 sampler2Ds 返回相同的值,(如果我先设置深度,那么它们都会有深度纹理)
-
你能显示着色器吗?
-
#version 400 layout(location=0) out vec3 FragColor; in vec2 UV; uniform sampler2D rt0; uniform sampler2D d0; void main() { vec3 tex = texture(rt0,UV).xyz; vec3 depth = texture(d0,UV).xyz; FragColor = tex + depth; }