summaryrefslogtreecommitdiffstats
path: root/math.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-03-31 21:50:39 -0700
committeryum <yum.food.vr@gmail.com>2025-03-31 21:50:39 -0700
commit2dfd6322587eb095a5a4f7b22d70e1abcc14d5e3 (patch)
tree76b6f84628e07c722b74ce58b34e70d672e9541d /math.cginc
parent3f1915bbd0e6176e625c484cf24a460cc88bfeac (diff)
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.
Diffstat (limited to 'math.cginc')
-rw-r--r--math.cginc19
1 files changed, 17 insertions, 2 deletions
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) {