123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #ifndef __TONEMAPPING__
- #define __TONEMAPPING__
- #include "ACES.cginc"
- #define TONEMAPPING_USE_FULL_ACES 0
- half3 NeutralCurve(half3 x, half a, half b, half c, half d, half e, half f)
- {
- return ((x * (a * x + c * b) + d * e) / (x * (a * x + b) + d * f)) - e / f;
- }
- half3 NeutralTonemap(half3 x, half4 params1, half4 params2)
- {
-
-
- x = max((0.0).xxx, x);
-
- half a = params1.x;
- half b = params1.y;
- half c = params1.z;
- half d = params1.w;
- half e = params2.x;
- half f = params2.y;
- half whiteLevel = params2.z;
- half whiteClip = params2.w;
- half3 whiteScale = (1.0).xxx / NeutralCurve(whiteLevel, a, b, c, d, e, f);
- x = NeutralCurve(x * whiteScale, a, b, c, d, e, f);
- x *= whiteScale;
-
- x /= whiteClip.xxx;
- return x;
- }
- half3 FilmicTonemap(half3 aces)
- {
- #if TONEMAPPING_USE_FULL_ACES
- half3 oces = RRT(aces);
- half3 odt = ODT_RGBmonitor_100nits_dim(oces);
- return odt;
- #else
-
- half saturation = rgb_2_saturation(aces);
- half ycIn = rgb_2_yc(aces);
- half s = sigmoid_shaper((saturation - 0.4) / 0.2);
- half addedGlow = 1.0 + glow_fwd(ycIn, RRT_GLOW_GAIN * s, RRT_GLOW_MID);
- aces *= addedGlow;
-
- half hue = rgb_2_hue(aces);
- half centeredHue = center_hue(hue, RRT_RED_HUE);
- half hueWeight;
- {
-
- hueWeight = Pow2(smoothstep(0.0, 1.0, 1.0 - abs(2.0 * centeredHue / RRT_RED_WIDTH)));
- }
- aces.r += hueWeight * saturation * (RRT_RED_PIVOT - aces.r) * (1.0 - RRT_RED_SCALE);
-
- half3 acescg = max(0.0, ACES_to_ACEScg(aces));
-
-
- acescg = lerp(dot(acescg, AP1_RGB2Y).xxx, acescg, RRT_SAT_FACTOR.xxx);
-
-
-
- const half a = 278.5085;
- const half b = 10.7772;
- const half c = 293.6045;
- const half d = 88.7122;
- const half e = 80.6889;
- half3 x = acescg;
- half3 rgbPost = (x * (a * x + b)) / (x * (c * x + d) + e);
-
-
-
- half3 linearCV = darkSurround_to_dimSurround(rgbPost);
-
-
- linearCV = lerp(dot(linearCV, AP1_RGB2Y).xxx, linearCV, ODT_SAT_FACTOR.xxx);
-
-
- half3 XYZ = mul(AP1_2_XYZ_MAT, linearCV);
-
- XYZ = mul(D60_2_D65_CAT, XYZ);
-
- linearCV = mul(XYZ_2_REC709_MAT, XYZ);
- return linearCV;
- #endif
- }
- #endif
|