【发布时间】:2016-05-28 14:52:13
【问题描述】:
我正在尝试制作多纹理地形。 但是当我尝试绑定 3 个纹理时,只显示了一个纹理。 c#代码在这里:
GL.UseProgram(program);
//Active textures, glId - is texture id, generated by GL.GenTexture()
GL.BindTextures(0,3,new int[3]{grass.glId,grass_normal.glId,stone.glId});
//Set shaders uniform, diffuse is a shader class
diffuse.SetUniform("mainTexture",grass.glId);
diffuse.SetUniform("gNormalMap",grass_normal.glId);
diffuse.SetUniform("stoneTexture",stone.glId);
//Just some render code, for example
GL.BindVertexArray(mesh.vao);
GL.DrawElements(PrimitiveType.Triangles,
mesh.triangles.Count,DrawElementsType.UnsignedInt, IntPtr.Zero);
//Unbind all
GL.UseProgram(0);
GL.BindVertexArray(0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.BindBuffer(BufferTarget.ElementArrayBuffer,0);
GL.BindTextures(0,3,new int[3]{0,0,0});
有shader片段程序:
#version 140
uniform sampler2D mainTexture;//grass
uniform sampler2D gNormalMap;//grass normal
uniform sampler2D stoneTexture;//stone
out vec4 FragColor;
//hide other uniforms and inputs
void main (void){
//Some light code
vec4 x = texture2D(stoneTexture, fract(vTexCoord.st * texSize));
vec4 y = texture2D(mainTexture, fract(vTexCoord.st * texSize));
vec4 tex = x;//display stone, but i want to mix textures later
//I don't know why, but there is no difference,
//if i use stone - 'tex = x', or grass - 'tex = y'
//in both cases, only grass is displayed
FragColor = color*tex*(diffuse+ambient);//Color
}
我尝试先绑定石头再绑定草,显示的是没有草的石头。我的意思是这样的:
GL.BindTextures(0,3,new int[3]{stone.glId,grass_normal.glId,grass.glId});
没有效果,只显示一个纹理。
【问题讨论】:
-
我只是想确保我理解。你在问为什么会这样,对吧?
-
是的,但现在我修复了它(阅读下一篇文章)