Roman
Roman

Reputation: 326

GLSL PBS implementation, weird shader behaviour

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: Specular Intensity + Diffuse Intensity artifacts Diffuse lightmap looks like this: enter image description here Specular lightmap (notice artifacts on the edge of the terrain): enter image description here

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;

Resulting lightmap: Modified shaders

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

Answers (1)

Roman
Roman

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));

The final shader code

Upvotes: 2

Related Questions