PDA

View Full Version : Black lines in fragment shader when normal mapping limited to distance



fredvam
09-14-2014, 02:28 PM
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\tangent 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(VertexEye.xyz), normalColor, texCoords*100); // normalized
}


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


1436

Any help on this is greatly appreciated

Firadeoclus
09-15-2014, 04:31 AM
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.

fredvam
09-15-2014, 05:37 AM
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