Skip to content

Commit

Permalink
Fix missing basis orthogonalizations in GLSL backend (#1177)
Browse files Browse the repository at this point in the history
I've encountered shading artifacts in normal mapped MaterialX materials, and upon closer inspection I believe that these are caused by the missing basis orthogonalizations @Tellusim brought to attention in PR #1049.

However, instead of using a second normalize(cross(..)) call, I've applied the Gram-Schmidt algorithm.
  • Loading branch information
pablode authored Jan 4, 2023
1 parent f66296b commit fefce08
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libraries/pbrlib/genglsl/lib/mx_environment_fis.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ float mx_latlong_compute_lod(vec3 dir, float pdf, float maxMipLevel, int envSamp
vec3 mx_environment_radiance(vec3 N, vec3 V, vec3 X, vec2 alpha, int distribution, FresnelData fd)
{
// Generate tangent frame.
vec3 Y = normalize(cross(N, X));
X = cross(Y, N);
X = normalize(X - dot(X, N) * N);
vec3 Y = cross(N, X);
mat3 tangentToWorld = mat3(X, Y, N);

// Transform the view vector to tangent space.
Expand Down
3 changes: 2 additions & 1 deletion libraries/pbrlib/genglsl/mx_conductor_bsdf.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ void mx_conductor_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlusion, float

N = mx_forward_facing_normal(N, V);

vec3 Y = normalize(cross(N, X));
X = normalize(X - dot(X, N) * N);
vec3 Y = cross(N, X);
vec3 H = normalize(L + V);

float NdotL = clamp(dot(N, L), M_FLOAT_EPS, 1.0);
Expand Down
3 changes: 2 additions & 1 deletion libraries/pbrlib/genglsl/mx_dielectric_bsdf.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ void mx_dielectric_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlusion, floa

N = mx_forward_facing_normal(N, V);

vec3 Y = normalize(cross(N, X));
X = normalize(X - dot(X, N) * N);
vec3 Y = cross(N, X);
vec3 H = normalize(L + V);

float NdotL = clamp(dot(N, L), M_FLOAT_EPS, 1.0);
Expand Down
3 changes: 2 additions & 1 deletion libraries/pbrlib/genglsl/mx_generalized_schlick_bsdf.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ void mx_generalized_schlick_bsdf_reflection(vec3 L, vec3 V, vec3 P, float occlus

N = mx_forward_facing_normal(N, V);

vec3 Y = normalize(cross(N, X));
X = normalize(X - dot(X, N) * N);
vec3 Y = cross(N, X);
vec3 H = normalize(L + V);

float NdotL = clamp(dot(N, L), M_FLOAT_EPS, 1.0);
Expand Down

0 comments on commit fefce08

Please sign in to comment.