Original Post
Hi everyone, I tackled multitexturing today and got it working without any major problems. I'm now looking to do some optimizations. One thing that bothers me about my method is that every time I draw I have to tell the glsl shader which textures are which.
t_shader.SetEffectUniformInt("baseMap", 0);
t_shader.SetEffectUniformInt("layer1map", 1);
t_shader.SetEffectUniformInt("layer2map", 2);
t_shader.SetEffectUniformInt("layer3map", 3);
t_shader.SetEffectUniformInt("alphaMap", 4); Where SetEffectUniformInt is calling glUniform1i(location, value); Since these uniforms are consistently 0, 1, 2, 3, 4 is there any way to hardcode these values into the shader so I don't need to set them? Fragment Shader
uniform sampler2D baseMap;
uniform sampler2D layer1map;
uniform sampler2D layer2map;
uniform sampler2D layer3map;
uniform sampler2D alphaMap;
varying vec2 texCoord;
void main(void)
{
vec4 alphaRGB = texture2D(alphaMap, texCoord);
// layer colours
vec4 baseRGB = texture2D(baseMap, texCoord);
vec4 layer1RGB = texture2D(layer1map, texCoord);
vec4 layer2RGB = texture2D(layer2map, texCoord);
vec4 layer3RGB = texture2D(layer3map, texCoord);
// lerp between current layer and previous layer based on alpha values
vec4 layer1 = mix(baseRGB, layer1RGB, alphaRGB.r);
vec4 layer2 = mix(layer1, layer2RGB, alphaRGB.g);
vec4 layer3 = mix(layer2, layer3RGB, alphaRGB.b);
gl_FragColor = vec4(layer3.r, layer3.g, layer3.b, 1);
}
Thanks for any help, Giawa