ivalylo
03-29-2011, 04:25 AM
Hello everyone,
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[0].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 :p ... Is the texture2D defined when texturing is disabled, i.e.
glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);
Or is there a better way to do this?
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[0].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 :p ... Is the texture2D defined when texturing is disabled, i.e.
glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);
Or is there a better way to do this?