Black lines in fragment shader when normal mapping limited to distance

I am rendering terrain and compute normals and tangents on the fly, to save resources want to limit
the calculations to only nearby pixels.

I can create this effect by doing a mix(), this was what i started out with just to see if i could tell the boarder between
normal mapping and regular mapping, the result was fine, but the expensive normal angent calculation was part of the mixer.

So when I split the code into diffuse or diffuse with normal maps, I get a black line, I even try to smoothstep but there are zero
cases where the fragment shader should get zero normal data.

I also have a directional light with ambient light that does not use normals, even this light is black on those pixels, its as if “discard” was called

Get black lines!

vec3 normal = normalize(worldNormal);
if (dist <= 50.0f) {
 vec3 normalColor = shadeTexturedAndLitNormalFast().rgb;
  normal = perturb_normal(normalize(worldNormal), normalize(, normalColor, texCoords*100); // normalized

if the two normals above are mixed by smothstep or just distance, works fine…


Any help on this is greatly appreciated

Looks like a gradient issue. If you have texture lookups in non-uniform control flow you may have to provide explicit gradients or LOD (i.e., use textureGrad or textureLod), or place the texture lookups outside the if.

Yes that makes perfect sense. I always call the diffuse sampler, and with the first test I did i also always call the normal map sampler.

Thanks, will give this a try

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.