From 2b4469a4a9b8c75cd450135aecb8e9290579b705 Mon Sep 17 00:00:00 2001 From: jpark37 Date: Sun, 10 Nov 2024 19:28:41 -0800 Subject: [PATCH] libobs: plugins: Use MAD for sRGB functions Also fix stray comment about pow behavior. --- libobs/data/color.effect | 4 ++-- plugins/nv-filters/data/color.effect | 2 +- plugins/obs-filters/data/color.effect | 2 +- plugins/obs-transitions/data/fade_to_color_transition.effect | 2 +- plugins/obs-transitions/data/fade_transition.effect | 2 +- plugins/obs-transitions/data/stinger_matte_transition.effect | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libobs/data/color.effect b/libobs/data/color.effect index 065c5ae86b13a4..7cdcf6222de53b 100644 --- a/libobs/data/color.effect +++ b/libobs/data/color.effect @@ -10,7 +10,7 @@ float3 srgb_linear_to_nonlinear(float3 v) float srgb_nonlinear_to_linear_channel(float u) { - return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4); + return (u <= 0.04045) ? (u / 12.92) : pow(mad(u, 1. / 1.055, .055 / 1.055), 2.4); } float3 srgb_nonlinear_to_linear(float3 v) @@ -148,7 +148,7 @@ float3 linear_to_hlg(float3 rgb, float Lw) float Yd = dot(rgb, float3(0.2627, 0.678, 0.0593)); - // pow(0., exponent) can lead to NaN, use smallest positive normal number + // avoid inf from pow(0., negative) by using smallest positive normal number Yd = max(6.10352e-5, Yd); rgb *= pow(Yd, -1. / 6.); diff --git a/plugins/nv-filters/data/color.effect b/plugins/nv-filters/data/color.effect index 5de529424a6e41..5d7e3a1d0a9df0 100644 --- a/plugins/nv-filters/data/color.effect +++ b/plugins/nv-filters/data/color.effect @@ -10,7 +10,7 @@ float3 srgb_linear_to_nonlinear(float3 v) float srgb_nonlinear_to_linear_channel(float u) { - return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4); + return (u <= 0.04045) ? (u / 12.92) : pow(mad(u, 1. / 1.055, .055 / 1.055), 2.4); } float3 srgb_nonlinear_to_linear(float3 v) diff --git a/plugins/obs-filters/data/color.effect b/plugins/obs-filters/data/color.effect index 5de529424a6e41..5d7e3a1d0a9df0 100644 --- a/plugins/obs-filters/data/color.effect +++ b/plugins/obs-filters/data/color.effect @@ -10,7 +10,7 @@ float3 srgb_linear_to_nonlinear(float3 v) float srgb_nonlinear_to_linear_channel(float u) { - return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4); + return (u <= 0.04045) ? (u / 12.92) : pow(mad(u, 1. / 1.055, .055 / 1.055), 2.4); } float3 srgb_nonlinear_to_linear(float3 v) diff --git a/plugins/obs-transitions/data/fade_to_color_transition.effect b/plugins/obs-transitions/data/fade_to_color_transition.effect index ec3fdf8b698683..36fd8d568abecb 100644 --- a/plugins/obs-transitions/data/fade_to_color_transition.effect +++ b/plugins/obs-transitions/data/fade_to_color_transition.effect @@ -24,7 +24,7 @@ VertData VSDefault(VertData v_in) float srgb_nonlinear_to_linear_channel(float u) { - return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4); + return (u <= 0.04045) ? (u / 12.92) : pow(mad(u, 1. / 1.055, .055 / 1.055), 2.4); } float3 srgb_nonlinear_to_linear(float3 v) diff --git a/plugins/obs-transitions/data/fade_transition.effect b/plugins/obs-transitions/data/fade_transition.effect index f0ca0cbc0f11ed..40d7e1b19904c4 100644 --- a/plugins/obs-transitions/data/fade_transition.effect +++ b/plugins/obs-transitions/data/fade_transition.effect @@ -28,7 +28,7 @@ VertData VSDefault(VertData v_in) float srgb_nonlinear_to_linear_channel(float u) { - return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4); + return (u <= 0.04045) ? (u / 12.92) : pow(mad(u, 1. / 1.055, .055 / 1.055), 2.4); } float3 srgb_nonlinear_to_linear(float3 v) diff --git a/plugins/obs-transitions/data/stinger_matte_transition.effect b/plugins/obs-transitions/data/stinger_matte_transition.effect index 65e43f1e2b8082..c7fb7fbfd92b1d 100644 --- a/plugins/obs-transitions/data/stinger_matte_transition.effect +++ b/plugins/obs-transitions/data/stinger_matte_transition.effect @@ -25,7 +25,7 @@ VertData VSDefault(VertData v_in) float srgb_nonlinear_to_linear_channel(float u) { - return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4); + return (u <= 0.04045) ? (u / 12.92) : pow(mad(u, 1. / 1.055, .055 / 1.055), 2.4); } float3 srgb_nonlinear_to_linear(float3 v)