summaryrefslogtreecommitdiffstats
path: root/math.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-02-24 18:11:03 -0800
committeryum <yum.food.vr@gmail.com>2026-02-24 18:11:03 -0800
commitaacad28954ceb792ecc7ebd90338466b9f70d456 (patch)
tree8a9a7b793caa594728d322646d4f3417f9b532bb /math.cginc
parent142805d05c999ab1c36cdecffcc305c66dd15feb (diff)
Implement wrapped lighting (direct & IBL diffuse)
Diffstat (limited to 'math.cginc')
-rwxr-xr-xmath.cginc9
1 files changed, 5 insertions, 4 deletions
diff --git a/math.cginc b/math.cginc
index 02d0fe0..3d7e92e 100755
--- a/math.cginc
+++ b/math.cginc
@@ -32,15 +32,16 @@ float sin_noise_3d_fbm(float3 uvw, uint octaves, float k, float strength) {
return result;
}
-// Wrap a dot product. Assume it's already clamped.
+// Wrap NoL. Assume it's already clamped.
// At k=0, you get standard lambertian shading.
// At k=0.5, you get half-lambertian shading.
// At k=1.0, you get flat shading.
// k must be on [0, 1].
// Energy preserving, within some small bound.
-float wrapDotProduct(float XoY, float k) {
- float lambertian = XoY;
- float half_lambertian = pow(max(1e-4, (XoY + 0.5f) / (1.0f + 0.5f)), 2);
+float wrapNoL(float NoL, float k) {
+ float lambertian = NoL;
+ float tmp = (NoL + 0.5f) / (1.0f + 0.5f);
+ float half_lambertian = tmp * tmp;
float flat = RCP_PI;
if (k < 0.5) {