I followed this tutorial:
http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=14
Though it's worth nothing that the shader provided doesn't actually work right (I think it completely omits the 2nd texture when multitexturing, as well as the 1st being too bright), but someone in the comments fixed it.
Briefly, here's how the relevant part of the fixed fragment shader looks:
void main()
{
outputColor = vec4(0.0, 0.0, 0.0, 0.0);
if (numTextures > 1)
{
vec4 vTexColor = texture2D(gSamplers[0], texCoord);
outputColor += vTexColor*fTextureContributions[0];
vTexColor = texture2D(gSamplers[1], texCoord);
outputColor += vTexColor*fTextureContributions[1];
outputColor /= 2;
}
else
{
vec4 vTexColor = texture2D(gSamplers[0], texCoord);
outputColor += vTexColor*fTextureContributions[0];
}
float fDiffuseIntensity = max(0.0, dot(normalize(vNormal), -sunLight.vDirection));
outputColor *= vColor*vec4(sunLight.vColor*(sunLight.fAmbientIntensity+fDiffuseIntensity), 1.0);
}
With the really important bit in bold.
It works and looks like it should, and when outputColor isn't divided by 2, the result is a texture that's noticeably much brighter than the original texture file.
Now, while I realize we're combining the values of 2 textures here... the fTextureContributions values are used to decide how much of each texture shows through, and I've checked that they definitely always add up to 1.0f (with a small bit of inaccuracy once it gets to 1.0f and 0.0f).
My problem/question is: I would have thought that multiplying 2 textures by numbers that add up to 1 and then adding them together would result in the correct value, but it doesn't. Dividing the result by 2 works as it should.
Why exactly is that? What have I missed? Am I looking in the wrong place perhaps? It's not something to do with the lighting afterwards is it?
I see that outputColor is having 2 values directly added to it... but I can't get my head around why that's a problem that needs to be corrected by a later division by 2 when those values are being multiplied as they are.