     float k = (r*r) / 8.0;
 
     float nom = NdotV;
+
     float denom = NdotV * (1.0 - k) + k;
+    denom = max(0.0001, denom);
 
     return nom / denom;
 }

    uniform sampler2D u_roughness;
#endif

varying vec2 v_texCoord;
varying vec3 v_position;
varying vec3 v_normal;

vec3 fresnelSchlick(float cosTheta, vec3 F0) {
    return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);


            kD *= 1.0 - metalness;

            float NdotL = max(dot(N, L), 0.0) * light.intensity;
            Lo += (kD * albedo / M_PI + brdf) * radiance * NdotL * lightAttenuation;
        }
    #endif

    vec3 ambient = vec3(0.03) * albedo;
    vec3 color = ambient + Lo;

    #ifdef defGammaCorrection
        color = color / (color + vec3(1.0));
        color = pow(color, vec3(1.0 / 2.2));
    #endif

    gl_FragColor = vec4(color, 0.8);
}
