From 8af07e1e4e867aa00817440eca730c4588a12a95 Mon Sep 17 00:00:00 2001 From: Jonathan Stone Date: Tue, 15 Oct 2024 13:07:20 -0700 Subject: [PATCH] Harmonize MSL and GLSL implementations (#2070) This changelist addresses a handful of remaining cases where our MSL and GLSL code diverged, harmonizing on shading code that works in both contexts. --- libraries/stdlib/genglsl/mx_burn_color3.glsl | 7 ++++--- libraries/stdlib/genglsl/mx_burn_color4.glsl | 9 +++++---- libraries/stdlib/genglsl/mx_dodge_color3.glsl | 7 ++++--- libraries/stdlib/genglsl/mx_dodge_color4.glsl | 9 +++++---- libraries/stdlib/genglsl/mx_normalmap.glsl | 8 ++++---- libraries/stdlib/genmsl/mx_burn_color3.metal | 9 --------- libraries/stdlib/genmsl/mx_burn_color4.metal | 10 ---------- libraries/stdlib/genmsl/mx_burn_float.metal | 9 --------- libraries/stdlib/genmsl/mx_dodge_color3.metal | 9 --------- libraries/stdlib/genmsl/mx_dodge_color4.metal | 10 ---------- libraries/stdlib/genmsl/mx_dodge_float.metal | 9 --------- libraries/stdlib/genmsl/mx_normalmap.metal | 13 ------------- .../stdlib/genmsl/mx_smoothstep_float.metal | 9 --------- libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx | 17 ----------------- 14 files changed, 22 insertions(+), 113 deletions(-) delete mode 100644 libraries/stdlib/genmsl/mx_burn_color3.metal delete mode 100644 libraries/stdlib/genmsl/mx_burn_color4.metal delete mode 100644 libraries/stdlib/genmsl/mx_burn_float.metal delete mode 100644 libraries/stdlib/genmsl/mx_dodge_color3.metal delete mode 100644 libraries/stdlib/genmsl/mx_dodge_color4.metal delete mode 100644 libraries/stdlib/genmsl/mx_dodge_float.metal delete mode 100644 libraries/stdlib/genmsl/mx_normalmap.metal delete mode 100644 libraries/stdlib/genmsl/mx_smoothstep_float.metal diff --git a/libraries/stdlib/genglsl/mx_burn_color3.glsl b/libraries/stdlib/genglsl/mx_burn_color3.glsl index 10f4008f1a..8e60f857d6 100644 --- a/libraries/stdlib/genglsl/mx_burn_color3.glsl +++ b/libraries/stdlib/genglsl/mx_burn_color3.glsl @@ -2,7 +2,8 @@ void mx_burn_color3(vec3 fg, vec3 bg, float mixval, out vec3 result) { - mx_burn_float(fg.x, bg.x, mixval, result.x); - mx_burn_float(fg.y, bg.y, mixval, result.y); - mx_burn_float(fg.z, bg.z, mixval, result.z); + float f; + mx_burn_float(fg.x, bg.x, mixval, f); result.x = f; + mx_burn_float(fg.y, bg.y, mixval, f); result.y = f; + mx_burn_float(fg.z, bg.z, mixval, f); result.z = f; } diff --git a/libraries/stdlib/genglsl/mx_burn_color4.glsl b/libraries/stdlib/genglsl/mx_burn_color4.glsl index df6802a646..a1add5a372 100644 --- a/libraries/stdlib/genglsl/mx_burn_color4.glsl +++ b/libraries/stdlib/genglsl/mx_burn_color4.glsl @@ -2,8 +2,9 @@ void mx_burn_color4(vec4 fg, vec4 bg, float mixval, out vec4 result) { - mx_burn_float(fg.x, bg.x, mixval, result.x); - mx_burn_float(fg.y, bg.y, mixval, result.y); - mx_burn_float(fg.z, bg.z, mixval, result.z); - mx_burn_float(fg.w, bg.w, mixval, result.w); + float f; + mx_burn_float(fg.x, bg.x, mixval, f); result.x = f; + mx_burn_float(fg.y, bg.y, mixval, f); result.y = f; + mx_burn_float(fg.z, bg.z, mixval, f); result.z = f; + mx_burn_float(fg.w, bg.w, mixval, f); result.w = f; } diff --git a/libraries/stdlib/genglsl/mx_dodge_color3.glsl b/libraries/stdlib/genglsl/mx_dodge_color3.glsl index a8cfd1dff7..aa9cf023a6 100644 --- a/libraries/stdlib/genglsl/mx_dodge_color3.glsl +++ b/libraries/stdlib/genglsl/mx_dodge_color3.glsl @@ -2,7 +2,8 @@ void mx_dodge_color3(vec3 fg, vec3 bg, float mixval, out vec3 result) { - mx_dodge_float(fg.x, bg.x, mixval, result.x); - mx_dodge_float(fg.y, bg.y, mixval, result.y); - mx_dodge_float(fg.z, bg.z, mixval, result.z); + float f; + mx_dodge_float(fg.x, bg.x, mixval, f); result.x = f; + mx_dodge_float(fg.y, bg.y, mixval, f); result.y = f; + mx_dodge_float(fg.z, bg.z, mixval, f); result.z = f; } diff --git a/libraries/stdlib/genglsl/mx_dodge_color4.glsl b/libraries/stdlib/genglsl/mx_dodge_color4.glsl index c492043ceb..25888219b6 100644 --- a/libraries/stdlib/genglsl/mx_dodge_color4.glsl +++ b/libraries/stdlib/genglsl/mx_dodge_color4.glsl @@ -2,8 +2,9 @@ void mx_dodge_color4(vec4 fg , vec4 bg , float mixval, out vec4 result) { - mx_dodge_float(fg.x, bg.x, mixval, result.x); - mx_dodge_float(fg.y, bg.y, mixval, result.y); - mx_dodge_float(fg.z, bg.z, mixval, result.z); - mx_dodge_float(fg.w, bg.w, mixval, result.w); + float f; + mx_dodge_float(fg.x, bg.x, mixval, f); result.x = f; + mx_dodge_float(fg.y, bg.y, mixval, f); result.y = f; + mx_dodge_float(fg.z, bg.z, mixval, f); result.z = f; + mx_dodge_float(fg.w, bg.w, mixval, f); result.w = f; } diff --git a/libraries/stdlib/genglsl/mx_normalmap.glsl b/libraries/stdlib/genglsl/mx_normalmap.glsl index 9fe8c66920..66c50f31f5 100644 --- a/libraries/stdlib/genglsl/mx_normalmap.glsl +++ b/libraries/stdlib/genglsl/mx_normalmap.glsl @@ -1,9 +1,9 @@ void mx_normalmap_vector2(vec3 value, vec2 normal_scale, vec3 N, vec3 T, vec3 B, out vec3 result) { - value = (value == vec3(0.0)) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0; - - value = T * value.x * normal_scale.x + B * value.y * normal_scale.y + N * value.z; - + value = (dot(value, value) == 0.0) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0; + value = T * value.x * normal_scale.x + + B * value.y * normal_scale.y + + N * value.z; result = normalize(value); } diff --git a/libraries/stdlib/genmsl/mx_burn_color3.metal b/libraries/stdlib/genmsl/mx_burn_color3.metal deleted file mode 100644 index 856d79c929..0000000000 --- a/libraries/stdlib/genmsl/mx_burn_color3.metal +++ /dev/null @@ -1,9 +0,0 @@ -#include "mx_burn_float.metal" - -void mx_burn_color3(vec3 fg, vec3 bg, float mixval, out vec3 result) -{ - float f; - mx_burn_float(fg.x, bg.x, mixval, f); result.x = f; - mx_burn_float(fg.y, bg.y, mixval, f); result.y = f; - mx_burn_float(fg.z, bg.z, mixval, f); result.z = f; -} diff --git a/libraries/stdlib/genmsl/mx_burn_color4.metal b/libraries/stdlib/genmsl/mx_burn_color4.metal deleted file mode 100644 index 48dc6bfa47..0000000000 --- a/libraries/stdlib/genmsl/mx_burn_color4.metal +++ /dev/null @@ -1,10 +0,0 @@ -#include "mx_burn_float.metal" - -void mx_burn_color4(vec4 fg, vec4 bg, float mixval, out vec4 result) -{ - float f; - mx_burn_float(fg.x, bg.x, mixval, f); result.x = f; - mx_burn_float(fg.y, bg.y, mixval, f); result.y = f; - mx_burn_float(fg.z, bg.z, mixval, f); result.z = f; - mx_burn_float(fg.w, bg.w, mixval, f); result.w = f; -} diff --git a/libraries/stdlib/genmsl/mx_burn_float.metal b/libraries/stdlib/genmsl/mx_burn_float.metal deleted file mode 100644 index 31d981ddb9..0000000000 --- a/libraries/stdlib/genmsl/mx_burn_float.metal +++ /dev/null @@ -1,9 +0,0 @@ -void mx_burn_float(float fg, float bg, float mixval, out float result) -{ - if (abs(fg) < M_FLOAT_EPS) - { - result = 0.0; - return; - } - result = mixval*(1.0 - ((1.0 - bg) / fg)) + ((1.0-mixval)*bg); -} diff --git a/libraries/stdlib/genmsl/mx_dodge_color3.metal b/libraries/stdlib/genmsl/mx_dodge_color3.metal deleted file mode 100644 index 864a6a2529..0000000000 --- a/libraries/stdlib/genmsl/mx_dodge_color3.metal +++ /dev/null @@ -1,9 +0,0 @@ -#include "mx_dodge_float.metal" - -void mx_dodge_color3(vec3 fg, vec3 bg, float mixval, out vec3 result) -{ - float f; - mx_dodge_float(fg.x, bg.x, mixval, f); result.x = f; - mx_dodge_float(fg.y, bg.y, mixval, f); result.y = f; - mx_dodge_float(fg.z, bg.z, mixval, f); result.z = f; -} diff --git a/libraries/stdlib/genmsl/mx_dodge_color4.metal b/libraries/stdlib/genmsl/mx_dodge_color4.metal deleted file mode 100644 index dc226b4271..0000000000 --- a/libraries/stdlib/genmsl/mx_dodge_color4.metal +++ /dev/null @@ -1,10 +0,0 @@ -#include "mx_dodge_float.metal" - -void mx_dodge_color4(vec4 fg , vec4 bg , float mixval, out vec4 result) -{ - float f; - mx_dodge_float(fg.x, bg.x, mixval, f); result.x = f; - mx_dodge_float(fg.y, bg.y, mixval, f); result.y = f; - mx_dodge_float(fg.z, bg.z, mixval, f); result.z = f; - mx_dodge_float(fg.w, bg.w, mixval, f); result.w = f; -} diff --git a/libraries/stdlib/genmsl/mx_dodge_float.metal b/libraries/stdlib/genmsl/mx_dodge_float.metal deleted file mode 100644 index f138354138..0000000000 --- a/libraries/stdlib/genmsl/mx_dodge_float.metal +++ /dev/null @@ -1,9 +0,0 @@ -void mx_dodge_float(float fg, float bg, float mixval, out float result) -{ - if (abs(1.0 - fg) < M_FLOAT_EPS) - { - result = 0.0; - return; - } - result = mixval*(bg / (1.0 - fg)) + ((1.0-mixval)*bg); -} diff --git a/libraries/stdlib/genmsl/mx_normalmap.metal b/libraries/stdlib/genmsl/mx_normalmap.metal deleted file mode 100644 index 3674756d8b..0000000000 --- a/libraries/stdlib/genmsl/mx_normalmap.metal +++ /dev/null @@ -1,13 +0,0 @@ -void mx_normalmap_vector2(vec3 value, vec2 normal_scale, vec3 N, vec3 T, vec3 B, out vec3 result) -{ - value = all(value == vec3(0.0)) ? vec3(0.0, 0.0, 1.0) : value * 2.0 - 1.0; - - value = T * value.x * normal_scale.x + B * value.y * normal_scale.y + N * value.z; - - result = normalize(value); -} - -void mx_normalmap_float(vec3 value, float normal_scale, vec3 N, vec3 T, vec3 B, out vec3 result) -{ - mx_normalmap_vector2(value, vec2(normal_scale), N, T, B, result); -} diff --git a/libraries/stdlib/genmsl/mx_smoothstep_float.metal b/libraries/stdlib/genmsl/mx_smoothstep_float.metal deleted file mode 100644 index 1bca2e4d9b..0000000000 --- a/libraries/stdlib/genmsl/mx_smoothstep_float.metal +++ /dev/null @@ -1,9 +0,0 @@ -void mx_smoothstep_float(float val, float low, float high, out float result) -{ - if (val <= low) - result = 0.0; - else if (val >= high) - result = 1.0; - else - result = smoothstep(low, high, val); -} diff --git a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx index be55f772be..1920d04b70 100644 --- a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx +++ b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx @@ -41,10 +41,6 @@ - - - - @@ -134,23 +130,10 @@ - - - - - - - - - - - - -