From 2dfd6322587eb095a5a4f7b22d70e1abcc14d5e3 Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 31 Mar 2025 21:50:39 -0700 Subject: Overhaul wrapped lighting Now: * k=0 -> lambertian * k=0.5 -> half lambertian * k=1.0 -> flat All three points should be energy conserving, but I haven't done the actual analysis yet. --- math.cginc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'math.cginc') diff --git a/math.cginc b/math.cginc index 8d404d9..bccb206 100644 --- a/math.cginc +++ b/math.cginc @@ -15,9 +15,24 @@ float pow5(float x) return (tmp * tmp) * x; } -float wrapNoL(float NoL, float factor) { +float wrapNoL(float NoL, float k) { +#if 0 // https://www.iro.umontreal.ca/~derek/files/jgt_wrap_final.pdf - return pow(max(1E-4, (NoL + factor) / (1 + factor)), 1 + factor); + return pow(max(1E-4, (NoL + k) / (1 + k)), 1 + k); +#else + float k_sq = k * k; + float b = max(0, lerp(NoL, 1.0, k)); + float p = -6.0 * k_sq + 5.0 * k + 1.0; + // Using the formula + float F = pow(b, p); + + // Approximate integral of NoL with respect to theta + float I = 0.7856 * k_sq - 0.2148 * k + 1.0; + + float G = F / max(I, 1E-6); + + return G; +#endif } float halfLambertianNoL(float NoL) { -- cgit v1.2.3