diff options
| author | yum <yum.food.vr@gmail.com> | 2025-06-05 19:42:36 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-06-05 19:42:36 -0700 |
| commit | 8b7ae8db808d76ddea503f94e142c7d37c1b43d3 (patch) | |
| tree | 9c60f09943b314d47bd5f8df732465831d5a566d /fog.cginc | |
| parent | 50b0b6c8b292e966a43fe56c6e0bf0a20c1d5b62 (diff) | |
more work on fog & c30
Diffstat (limited to 'fog.cginc')
| -rw-r--r-- | fog.cginc | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -21,9 +21,8 @@ struct FogParams { float density_exponent; #endif #if defined(_RAYMARCHED_FOG_HEIGHT_DENSITY) - float height_density_min; - float height_density_max; - float height_density_power; + float height_density_start; + float height_density_half_life; #endif }; @@ -40,8 +39,13 @@ FogResult raymarched_fog(v2f i, FogParams p) const float ro_epsilon = 1E-3; ro += rd * ro_epsilon; + // TODO maybe we can accelerate this? + float perspective_divide = 1.0f / i.pos.w; + float perspective_factor = length(i.eyeVec.xyz * perspective_divide); + const float2 screen_uv = (i.pos.xy + 0.5) / _ScreenParams.xy; float zDepthFromMap = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screen_uv); + float linearZ = GetLinearZFromZDepth_WorksWithMirrors(zDepthFromMap, screen_uv); linearZ = min(1E3, linearZ); @@ -75,7 +79,7 @@ FogResult raymarched_fog(v2f i, FogParams p) float3 noise_coord = (pp + _Time[0] * p.velocity) * p.density_noise_scale.xyz; - float cur_d = p.density_noise.SampleLevel(linear_repeat_s, + float cur_d = p.density_noise.SampleLevel(bilinear_repeat_s, noise_coord, 0); #if defined(_RAYMARCHED_FOG_DENSITY_EXPONENT) @@ -85,10 +89,18 @@ FogResult raymarched_fog(v2f i, FogParams p) cur_d *= p.density * step_size; #if defined(_RAYMARCHED_FOG_HEIGHT_DENSITY) - // Apply height-based density (branchless) - float t = saturate((pp.y - p.height_density_min) / - (p.height_density_max - p.height_density_min)); - cur_d *= 1.0 - t; + float height_clamped = max(pp.y - p.height_density_start, 0); + // if half_life = 2 and start = 0, then + // y=2 -> density = 1/2 + // y=4 -> density = 1/4 + // y=6 -> density = 1/8 + // if half_life = 3 and start = 0, then + // y=3 -> density = 1/2 + // y=6 -> density = 1/4 + // y=9 -> density = 1/8 + float exponent = height_clamped / p.height_density_half_life; + float factor = pow(2, -exponent); + cur_d *= factor; #endif cur_d = saturate(cur_d); |
