From 7d69c268cb20d8264b903cfaebb3b84564e56eed Mon Sep 17 00:00:00 2001 From: yum Date: Sun, 9 Apr 2023 22:17:29 -0700 Subject: Fix cubemap glare on rough materials Switch to unlit shading when roughness == 1.0. --- Shaders/parallax/parallax_lighting.cginc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Shaders') diff --git a/Shaders/parallax/parallax_lighting.cginc b/Shaders/parallax/parallax_lighting.cginc index 2d7386f..a3a7eb1 100644 --- a/Shaders/parallax/parallax_lighting.cginc +++ b/Shaders/parallax/parallax_lighting.cginc @@ -302,8 +302,16 @@ float4 effect(inout v2f i, out float depth) const float metallic = getLayerMetallic(uv, (int) layer); const float smoothness = 1.0 - getLayerRoughness(uv, (int) layer); - bool custom_cubemap = (layer == 1); - float4 lit_color = getLitColor(i, color, pp, normal, metallic, smoothness, custom_cubemap); + bool custom_cubemap = true; + float4 lit_color; + + // Hack: Bright cubemaps cause glare on rough surfaces. To prevent this, + // switch to unlit shading when shading a perfectly rough material. + if (smoothness == 0.0) { + lit_color = color; + } else { + lit_color = getLitColor(i, color, pp, normal, metallic, smoothness, custom_cubemap); + } lit_color.rgb += color.rgb * getLayerEmission(layer); @@ -315,7 +323,6 @@ float4 effect(inout v2f i, out float depth) } } - // No ray hit: return default material float base_depth = depth; float metallic = 1.0; -- cgit v1.2.3