Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 457db7c

Browse files
committed
Fixed #3 - ACES reference tonemapper broken on macOS
1 parent c763ec9 commit 457db7c

File tree

1 file changed

+6
-45
lines changed

1 file changed

+6
-45
lines changed

PostProcessing/Resources/Shaders/ACES.cginc

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -505,52 +505,13 @@ half segmented_spline_c5_fwd(half x)
505505
return pow(10.0, logy);
506506
}
507507

508-
half segmented_spline_c5_fwd_opt(half x)
509-
{
510-
const float xmin = log10(0.18 * exp2(-15.0));
511-
const float xmid = log10(0.18);
512-
const float xmax = log10(0.18 * exp2(18.0));
513-
514-
// Clamp input
515-
x = min(47185.91999999996, max(5.493164062500005e-6, x));
516-
517-
float logx = log10(x);
518-
float logy;
519-
520-
if ((logx > xmin) && (logx < xmid))
521-
{
522-
const float coefs[6] = { -4.0000000000, -4.0000000000, -3.1573765773, -0.4852499958, 1.8477324706, 1.8477324706 }; // coefs for B-spline between minPoint and midPoint (units of log luminance)
523-
const float2 maxPoint = float2(0.18 * exp2(18.0), 10000.0); // {luminance, luminance} linear extension above this
524-
float knot_coord = 3.0 * (logx - xmin) / (xmid - xmin);
525-
int j = knot_coord;
526-
float t = knot_coord - j;
527-
528-
float3 cf = float3(coefs[j], coefs[j + 1], coefs[j + 2]);
529-
float3 monomials = float3(t * t, t, 1.0);
530-
logy = dot(monomials, mul(M, cf));
531-
}
532-
else
533-
{
534-
const float coefs[6] = { -0.7185482425, 2.0810307172, 3.6681241237, 4.0000000000, 4.0000000000, 4.0000000000 }; // coefs for B-spline between midPoint and maxPoint (units of log luminance)
535-
float knot_coord = 3 * (logx - xmid) / (xmax - xmid);
536-
int j = knot_coord;
537-
float t = knot_coord - j;
538-
539-
float3 cf = float3(coefs[j], coefs[j + 1], coefs[j + 2]);
540-
float3 monomials = float3(t * t, t, 1.0);
541-
logy = dot(monomials, mul(M, cf));
542-
}
543-
544-
return pow(10.0, logy);
545-
}
546-
547508
half segmented_spline_c9_fwd(half x)
548509
{
549510
const half coefsLow[10] = { -1.6989700043, -1.6989700043, -1.4779000000, -1.2291000000, -0.8648000000, -0.4480000000, 0.0051800000, 0.4511080334, 0.9113744414, 0.9113744414 }; // coefs for B-spline between minPoint and midPoint (units of log luminance)
550511
const half coefsHigh[10] = { 0.5154386965, 0.8470437783, 1.1358000000, 1.3802000000, 1.5197000000, 1.5985000000, 1.6467000000, 1.6746091357, 1.6878733390, 1.6878733390 }; // coefs for B-spline between midPoint and maxPoint (units of log luminance)
551-
const half2 minPoint = half2(segmented_spline_c5_fwd_opt(0.18 * exp2(-6.5)), 0.02); // {luminance, luminance} linear extension below this
552-
const half2 midPoint = half2(segmented_spline_c5_fwd_opt(0.18), 4.8); // {luminance, luminance}
553-
const half2 maxPoint = half2(segmented_spline_c5_fwd_opt(0.18 * exp2(6.5)), 48.0); // {luminance, luminance} linear extension above this
512+
const half2 minPoint = half2(segmented_spline_c5_fwd(0.18 * exp2(-6.5)), 0.02); // {luminance, luminance} linear extension below this
513+
const half2 midPoint = half2(segmented_spline_c5_fwd(0.18), 4.8); // {luminance, luminance}
514+
const half2 maxPoint = half2(segmented_spline_c5_fwd(0.18 * exp2(6.5)), 48.0); // {luminance, luminance} linear extension above this
554515
const half slopeLow = 0.0; // log-log slope of low linear extension
555516
const half slopeHigh = 0.04; // log-log slope of high linear extension
556517

@@ -639,9 +600,9 @@ half3 RRT(half3 aces)
639600

640601
// --- Apply the tonescale independently in rendering-space RGB --- //
641602
half3 rgbPost;
642-
rgbPost.x = segmented_spline_c5_fwd_opt(rgbPre.x);
643-
rgbPost.y = segmented_spline_c5_fwd_opt(rgbPre.y);
644-
rgbPost.z = segmented_spline_c5_fwd_opt(rgbPre.z);
603+
rgbPost.x = segmented_spline_c5_fwd(rgbPre.x);
604+
rgbPost.y = segmented_spline_c5_fwd(rgbPre.y);
605+
rgbPost.z = segmented_spline_c5_fwd(rgbPre.z);
645606

646607
// --- RGB rendering space to OCES --- //
647608
half3 rgbOces = mul(AP1_2_AP0_MAT, rgbPost);

0 commit comments

Comments
 (0)