[英]OpenGL/GLSL multiple texture binding not working
周围有很多类似问题的答案,但我找不到适合我的解决方案。
我有一个包含多个网格的场景,每个都有以下绘制调用:
shader.use();
for (unsigned int i = 0; i < textures.size(); i++)
{
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, textures[i].id);
}
for (unsigned int i = 0; i < textures.size(); i++)
{
glUniform1f(glGetUniformLocation(shader.ID, material_uniforms[i].c_str()), i);
}
glActiveTexture(GL_TEXTURE0);
// draw mesh
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
我的碎片着色器制服(除其他外)是:
uniform sampler2D texture_ambient1;
uniform sampler2D texture_diffuse1;
uniform sampler2D texture_specular1;
uniform sampler2D texture_bump1;
uniform sampler2D texture_dissolve1;
在 RenderDoc 中,虽然在资源检查器中似乎列出了所有纹理,但纹理查看器中的“输入”(FS 0[0] texture_ambient1、FS 1[0] texture_diffuse1、FS 2[0] texture_dissolve1 和 FS 3[0] texture_specular1(我不知道我的另一个“texture_bump1”去了哪里?))每个绘制调用似乎都是完全相同的纹理。
同样在“Pipeline State”和FS Stage下的RenderDoc中,Textures和Samplers每个只有一个绑定项目? 似乎与 RenderDoc 看到上述所有输入的事实相矛盾?
我在我的代码中做错了什么吗?
看起来您正在尝试使用glUniform1f
绑定纹理单元,但纹理单元索引是 integer (不是浮点数),因此您应该使用glUniform1i
来设置该统一。
glUniform1i(glGetUniformLocation(shader.ID, material_uniforms[i].c_str()), i);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.