Skip to content

Commit

Permalink
Fix Metal
Browse files Browse the repository at this point in the history
  • Loading branch information
JGamache-autodesk committed Oct 22, 2024
1 parent 7fde534 commit 9787137
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libraries/pbrlib/genglsl/lib/mx39_microfacet_sheen.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#include "mx39_microfacet.glsl"
#include "mx_microfacet_sheen.glsl"

float mx_inversesqrt(float x)
{
#ifdef __METAL_VERSION__
return ::rsqrt(x);
#else
return inversesqrt(x);
#endif
}

// The following functions are adapted from https://github.com/tizian/ltc-sheen.
// "Practical Multiple-Scattering Sheen Using Linearly Transformed Cosines", Zeltner et al.

Expand Down Expand Up @@ -33,7 +42,7 @@ mat3 mx39_orthonormal_basis_ltc(vec3 V, vec3 N, float NdotV)
float lenSqr = dot(X, X);
if (lenSqr > 0.0)
{
X *= inversesqrt(lenSqr);
X *= mx_inversesqrt(lenSqr);
vec3 Y = cross(N, X);
return mat3(X, Y, N);
}
Expand Down Expand Up @@ -83,7 +92,7 @@ vec3 mx39_zeltner_sheen_importance_sample(vec2 Xi, vec3 V, vec3 N, float roughne
vec3 w = vec3(wo.x/aInv - wo.z*bInv/aInv, wo.y / aInv, wo.z);

float lenSqr = dot(w, w);
w *= inversesqrt(lenSqr);
w *= mx_inversesqrt(lenSqr);

// D(w) = Do(wo) . ||M.wo||^3 / |M|
// = Do(wo / ||M.wo||) . ||M.wo||^4 / |M|
Expand Down

0 comments on commit 9787137

Please sign in to comment.