Skip to content

Commit

Permalink
libobs: plugins: Use MAD for sRGB functions
Browse files Browse the repository at this point in the history
Also fix stray comment about pow behavior.
  • Loading branch information
jpark37 authored and RytoEX committed Jan 29, 2025
1 parent 3461576 commit 689c009
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libobs/data/color.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.);
Expand Down
2 changes: 1 addition & 1 deletion plugins/nv-filters/data/color.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugins/obs-filters/data/color.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugins/obs-transitions/data/fade_transition.effect
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 689c009

Please sign in to comment.