summaryrefslogtreecommitdiffstats
path: root/fog.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-06-13 23:38:52 -0700
committeryum <yum.food.vr@gmail.com>2025-06-13 23:38:55 -0700
commit60e1e2010ab5eaa01dfd00c30f91384f95a78aa2 (patch)
treefd609dd3aa90937cd3f8f88d467fc3fdc167d0e3 /fog.cginc
parent86ff834cec5a75f6e0a2636de03cf5f79050d7ae (diff)
Fix how fog dithering would cause overshoot
Diffstat (limited to 'fog.cginc')
-rw-r--r--fog.cginc11
1 files changed, 6 insertions, 5 deletions
diff --git a/fog.cginc b/fog.cginc
index 6057f36..adef303 100644
--- a/fog.cginc
+++ b/fog.cginc
@@ -127,12 +127,13 @@ FogResult raymarched_fog(v2f i, FogParams p)
[loop]
for (uint ii = 0; ii < p.steps && traveled < max_dist; ++ii)
{
- // Clamp step size to avoid missing dense features
- float current_step = min(step_size, 2.0 * p.mean_free_path);
-
// Apply dithering to this step
- float dithered_step = current_step * (1.0 - dither + dither * 2.0);
-
+ float cur_dither = frac(dither + (ii + 1) * PHI);
+ float dithered_step = step_size * (cur_dither + 0.5);
+ float remaining = max_dist - traveled;
+ remaining = max(remaining, 0.1);
+ dithered_step = min(dithered_step, remaining);
+
// Advance position
pp += dithered_step * rd;
traveled += dithered_step;