Skip to content

Commit

Permalink
Fix roughness artifacts in specularBRDF()
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzBrueckner committed Feb 10, 2023
1 parent 175eebd commit b3619eb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Shaders/deferred_light/deferred_light.frag.glsl
Expand Up @@ -335,9 +335,9 @@ void main() {

#ifdef _Sun
vec3 sh = normalize(v + sunDir);
float sdotNH = dot(n, sh);
float sdotVH = dot(v, sh);
float sdotNL = dot(n, sunDir);
float sdotNH = max(0.0, dot(n, sh));
float sdotVH = max(0.0, dot(v, sh));
float sdotNL = max(0.0, dot(n, sunDir));
float svisibility = 1.0;
vec3 sdirect = lambertDiffuseBRDF(albedo, sdotNL) +
specularBRDF(f0, roughness, sdotNL, sdotNH, dotNV, sdotVH) * occspec.y;
Expand Down
6 changes: 3 additions & 3 deletions Shaders/deferred_light_mobile/deferred_light.frag.glsl
Expand Up @@ -185,9 +185,9 @@ void main() {

#ifdef _Sun
vec3 sh = normalize(v + sunDir);
float sdotNH = dot(n, sh);
float sdotVH = dot(v, sh);
float sdotNL = dot(n, sunDir);
float sdotNH = max(0.0, dot(n, sh));
float sdotVH = max(0.0, dot(v, sh));
float sdotNL = max(0.0, dot(n, sunDir));
float svisibility = 1.0;
vec3 sdirect = lambertDiffuseBRDF(albedo, sdotNL) +
specularBRDF(f0, roughness, sdotNL, sdotNH, dotNV, sdotVH) * occspec.y;
Expand Down
2 changes: 1 addition & 1 deletion Shaders/std/brdf.glsl
Expand Up @@ -77,7 +77,7 @@ vec3 orenNayarDiffuseBRDF(const vec3 albedo, const float roughness, const float
}

vec3 lambertDiffuseBRDF(const vec3 albedo, const float nl) {
return albedo * max(0.0, nl);
return albedo * nl;
}

vec3 surfaceAlbedo(const vec3 baseColor, const float metalness) {
Expand Down
6 changes: 3 additions & 3 deletions Shaders/std/light.glsl
Expand Up @@ -104,9 +104,9 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
vec3 ld = lp - p;
vec3 l = normalize(ld);
vec3 h = normalize(v + l);
float dotNH = dot(n, h);
float dotVH = dot(v, h);
float dotNL = dot(n, l);
float dotNH = max(0.0, dot(n, h));
float dotVH = max(0.0, dot(v, h));
float dotNL = max(0.0, dot(n, l));

#ifdef _LTC
float theta = acos(dotNV);
Expand Down
8 changes: 4 additions & 4 deletions Shaders/std/light_mobile.glsl
Expand Up @@ -57,11 +57,11 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
vec3 ld = lp - p;
vec3 l = normalize(ld);
vec3 h = normalize(v + l);
float dotNH = dot(n, h);
float dotVH = dot(v, h);
float dotNL = dot(n, l);
float dotNH = max(0.0, dot(n, h));
float dotVH = max(0.0, dot(v, h));
float dotNL = max(0.0, dot(n, l));

vec3 direct = albedo * max(dotNL, 0.0) +
vec3 direct = lambertDiffuseBRDF(albedo, dotNL) +
specularBRDF(f0, rough, dotNL, dotNH, dotNV, dotVH) * spec;

direct *= lightCol;
Expand Down

0 comments on commit b3619eb

Please sign in to comment.