summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-11-02 18:42:25 -0700
committeryum <yum.food.vr@gmail.com>2024-11-02 18:42:25 -0700
commit03c6eff81b3a9034f2a8e8caaad84cdc29b29f23 (patch)
tree0a6f9bb41e84914d42fe9ed0b789c6bf7449232c
parentd16350ccfa8f59cbb919ffc208f481958e6371fe (diff)
hack: Apply interleaved gradient noise to direct light
This minimizes color banding due to dim direct lighting
-rw-r--r--pbr.cginc15
1 files changed, 15 insertions, 0 deletions
diff --git a/pbr.cginc b/pbr.cginc
index d795267..e4e5ff1 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -347,6 +347,21 @@ float4 getLitColor(
screenPos = float4(i.screenPos, 0, i.pos.w);
#endif
+// TODO optimize this
+// Break up color banding by adding some dithering to direct light.
+{
+ float2 screen_uv;
+ {
+ float3 full_vec_eye_to_geometry = i.worldPos - _WorldSpaceCameraPos;
+ float3 world_dir = normalize(i.worldPos - _WorldSpaceCameraPos);
+ float perspective_divide = 1.0 / i.pos.w;
+ float perspective_factor = length(full_vec_eye_to_geometry * perspective_divide);
+ screen_uv = i.screenPos.xy * perspective_divide;
+ }
+ uint2 screen_uv_round = floor(screen_uv * _ScreenParams.xy);
+ direct_light.color += ign(screen_uv_round) * 0.00390625;
+}
+
#if 1
float reflection_strength = _ReflectionStrength;
#if defined(_REFLECTION_STRENGTH_TEX)