summaryrefslogtreecommitdiffstats
path: root/fog.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-11-18 17:51:12 -0800
committeryum <yum.food.vr@gmail.com>2024-11-18 17:51:12 -0800
commit5fdbeddf4b0002ae292c6f4081a0c9baeda919bf (patch)
treebe0ca6381b12adc4abfe79b4d81d64069b828696 /fog.cginc
parent43df9fc828a0103ebac98194dbf3f19b88ebed75 (diff)
Refactor tonemapping curves into their own headers
Also add iq's "almost identity" curve.
Diffstat (limited to 'fog.cginc')
-rw-r--r--fog.cginc44
1 files changed, 3 insertions, 41 deletions
diff --git a/fog.cginc b/fog.cginc
index 8fbe7de..3a0f5e9 100644
--- a/fog.cginc
+++ b/fog.cginc
@@ -9,6 +9,7 @@
#include "oklab.cginc"
#include "pbr.cginc"
#include "poi.cginc"
+#include "tone.cginc"
#ifndef __FOG_INC
#define __FOG_INC
@@ -209,45 +210,6 @@ float fog00_map_dr(
}
#endif
-// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
-// cc0
-float3 AcesFilmic(float3 x) {
- float a = 2.51f;
- float b = 0.03f;
- float c = 2.43f;
- float d = 0.59f;
- float e = 0.14f;
- return saturate((x*(a*x+b))/(x*(c*x+d)+e));
-}
-
-// Clamp x to [0, k].
-// Assumes that x is already on [0, 1].
-float3 SmoothClamp(float3 x, float k) {
- // Derivation of `b` from `k`:
- // f(x, b) = b * x / (x + b)
- // We want f(1, b) = k.
- // In other words, we want the max value the function can take on [0, 1] to
- // be k.
- // k = f(1, b)
- // = b / (1 + b)
- // b = k * (1 + b)
- // = k + kb
- // 1 = k/b + k
- // 1 - k = k/b
- // 1/(1-k) = b/k
- // b = k/(1-k)
- float e = 1E-4;
- k = min(1-e, k);
- float b = k/(1-k);
- return b * x / (x + b);
-}
-float SmoothClamp(float x, float k) {
- float e = 1E-4;
- k = min(1-e, k);
- float b = k/(1-k);
- return b * x / (x + b);
-}
-
Fog00PBR getFog00(v2f i, ToonerData tdata) {
float3 cam_pos = _WorldSpaceCameraPos;
float3 obj_pos = i.worldPos;
@@ -415,11 +377,11 @@ Fog00PBR getFog00(v2f i, ToonerData tdata) {
//pbr.albedo.rgb += ign(tdata.screen_uv_round) * .00390625;
// Remap onto [0, 1]
- pbr.albedo.rgb = AcesFilmic(pbr.albedo.rgb);
+ pbr.albedo.rgb = aces_filmic(pbr.albedo.rgb);
// Clamp so max brightness is comfortable. Do it in perceptually uniform
// space to avoid affecting saturation.
pbr.albedo.rgb = LRGBtoOKLAB(pbr.albedo.rgb);
- pbr.albedo.x = SmoothClamp(pbr.albedo.x, _Gimmick_Fog_00_Max_Brightness);
+ pbr.albedo.x = smooth_clamp(pbr.albedo.x, _Gimmick_Fog_00_Max_Brightness);
pbr.albedo.rgb = OKLABtoLRGB(pbr.albedo.rgb);
float4 clip_pos = mul(UNITY_MATRIX_VP, float4(ro, 1.0));