I have a shader that has something like a dozen color/texture pairs. All the textures are optional. I am trying to figure out, how to implement this, without the need to recompile the shader. So I have:
uniform sampler2D diffuseTex;
uniform vec3 diffuseColor;
uniform float diffuseAmount;
vec3 diff = diffuseColor;
diff += texture2D(diffuseTex, gl_TexCoord.st).rgb*diffuseAmount;
I don't want to use #ifdefs for the texture2D lookup. So when there is a texture, I set the diffuseColor to black. I'm wondering, if the opposite variant is working properly - to disable texturing and expect texture2D to return black. Sometimes I get weird results, but can't tell if this is the cause of the problem or I've messed something else ... Is the texture2D defined when texturing is disabled, i.e.
Or is there a better way to do this?