From 60e1e2010ab5eaa01dfd00c30f91384f95a78aa2 Mon Sep 17 00:00:00 2001 From: yum Date: Fri, 13 Jun 2025 23:38:52 -0700 Subject: Fix how fog dithering would cause overshoot --- fog.cginc | 11 ++++++----- 1 file 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; -- cgit v1.2.3