Reputation: 326
I'am using Cook-Torrance specular BRDF + Disney's diffuse BRDF light models, which work fine if applied separately. Unfortunately if I try to combine them something weird happens:
Diffuse lightmap looks like this:
Specular lightmap (notice artifacts on the edge of the terrain):
Resulting lightmap is being calculated like this:
float result = Fr + Fd;
Where Fd is a diffuse BRDF component, Fr is a specular BRDF component.
Why does it give such artifacts on the resulting lightmap?
I was thinking that resulting light-intensity exceeds the range [0;1], to check that I modified the code as follows:
return result <= 1.0 ? result : 1.0;
As you can see, all the artifacts now have an intensity of 1.0 (they obviously exceed [0;1] range), but why does that keep happening if specular map contains zeroes?
Full shader code: Pastebin
Upvotes: 1
Views: 567
Reputation: 326
As @Columbo mentioned, it was NaN exception (throwed cause of division by zero), which lead to weird shader behaviour. I modified the code slightly:
float F_Schlick (in float f0, in float f90, in float u)
{
return f0 + ( f90 - f0 ) * pow(clamp(1.0 - u, 0.0, 1.0), 5.0); //line 34
}
Dot product should be greater than zero:
float dotNV = abs(dot(N, V));
float dotNL = abs(dot(N, L));
Upvotes: 2