# I want to render some surfaces in GLSL with normal maps, and some without

I have normal mapping working in my game, but I want to only use normal mapping for some surfaces, and not others.

Right now, as far as I can tell, my shader is applying an incorrect normal of (0, 0, 0) in tangent space to my non normal mapped surfaces, since no textures are bound to the sampler.

Is there a suitable way of detecting that nothing is bound to a sampler in GLSL and then using a flat normal instead? I've also found old posts around the web recommending the following:

1. Using a dummy 1x1 texture with the color (128, 128, 255) - this will lose Phong interpolation.
2. Switching shader programs for normal mapped and non-normal mapped surfaces - I get the feeling that I'd end up duplicating a lot of code this way, especially when I start implementing specular maps, parallax displacement maps, etc.

Are either of these still recommended or is there a new feature to query the sampler that I could make use of? Should I be doing it one way over another for performance reasons?

#version 330 core

in vec2 UV;
in vec3 tangentSpaceLightDir;
out vec4 outColor;
uniform sampler2D diffuseMap, normalMap;

void main (void)
{
vec4 texel = texture(diffuseMap, UV);
vec4 ntexel = texture(normalMap, UV);

// I want to use vertex normal here, if nothing is bound.
vec3 N = normalize(ntexel.xyz * 2.0 - 1.0);

vec3 L = normalize(tangentSpaceLightDir);

float lambertTerm = dot(N, -L);

vec4 finalColor = vec4(0.0);
if (lambertTerm > 0.0)
{
finalColor += vec4(lambertTerm, 1.0);
}

outColor = finalColor * texel;
}


• Go ahead and make a conditional like you're saying, either by sampling the texture or by creating a separate uniform for this purpose. As you probably know, adding branching on a shader is almost never a good idea, and much less so in the fragment shader: You usually don't want to do this
• Add a uniform float that determines whether or not you use normals. Set it to 0 to disable and to 1 to enable. After calculating the normals, multiply the result by this value. If you set it to 0, the result will be 0. However, the program won't be faster when you want to disable normals. You would usually prefer this approach