From a914c586b2b01dc2d103551365a9025326e77e3e Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 2 Oct 2020 17:29:20 -0700 Subject: [PATCH] experiment with color banding --- Effects/Deferred_ToonEffect.cs | 8 ------- Effects/FXB/Deferred_ToonEffect.fxb | 4 ++-- Effects/HLSL/Deferred_ToonEffect.fx | 33 ++++++++++++++++++----------- Renderer.cs | 2 -- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Effects/Deferred_ToonEffect.cs b/Effects/Deferred_ToonEffect.cs index a55b678..f5d2bfe 100644 --- a/Effects/Deferred_ToonEffect.cs +++ b/Effects/Deferred_ToonEffect.cs @@ -18,8 +18,6 @@ namespace Kav EffectParameter directionalLightDirectionParam; EffectParameter directionalLightColorParam; - EffectParameter softnessParam; - EffectParameter cascadeFarPlanesParam; EffectParameter shadowMapSizeParam; @@ -43,8 +41,6 @@ namespace Kav public Vector3 DirectionalLightDirection { get; set; } public Vector3 DirectionalLightColor { get; set; } - public float Softness { get; set; } - public float[] CascadeFarPlanes { get; } public float ShadowMapSize { get; set; } @@ -76,8 +72,6 @@ namespace Kav directionalLightDirectionParam.SetValue(DirectionalLightDirection); directionalLightColorParam.SetValue(DirectionalLightColor); - softnessParam.SetValue(Softness); - cascadeFarPlanesParam.SetValue(CascadeFarPlanes); shadowMapSizeParam.SetValue(ShadowMapSize); @@ -104,8 +98,6 @@ namespace Kav directionalLightDirectionParam = Parameters["DirectionalLightDirection"]; directionalLightColorParam = Parameters["DirectionalLightColor"]; - softnessParam = Parameters["Softness"]; - cascadeFarPlanesParam = Parameters["CascadeFarPlanes"]; shadowMapSizeParam = Parameters["ShadowMapSize"]; diff --git a/Effects/FXB/Deferred_ToonEffect.fxb b/Effects/FXB/Deferred_ToonEffect.fxb index f40c541..bcd420f 100644 --- a/Effects/FXB/Deferred_ToonEffect.fxb +++ b/Effects/FXB/Deferred_ToonEffect.fxb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6f1008f0dd9ab943b47e548d9f61d122e44785f7fbb9ea47b7d73448af681016 -size 21180 +oid sha256:725d85ea8bb4ad3016dadae76f6da73792b3f46f99facdd5fe91a5666cc3a13a +size 21072 diff --git a/Effects/HLSL/Deferred_ToonEffect.fx b/Effects/HLSL/Deferred_ToonEffect.fx index 9da8035..6806710 100644 --- a/Effects/HLSL/Deferred_ToonEffect.fx +++ b/Effects/HLSL/Deferred_ToonEffect.fx @@ -18,8 +18,6 @@ float3 EyePosition _ps(c0) _cb(c0); float3 DirectionalLightDirection _ps(c1) _cb(c1); float3 DirectionalLightColor _ps(c2) _cb(c2); -float Softness _ps(c3) _cb(c3); - float CascadeFarPlanes[NUM_SHADOW_CASCADES] _ps(c4) _cb(c4); float ShadowMapSize _ps(c8) _cb(c8); @@ -138,6 +136,26 @@ float ComputeShadow(float3 positionWorldSpace, float3 N, float3 L) } } +float IntensityBanding(float NdotL) +{ + if (NdotL > 0.5) + { + return 1.0; + } + else if (NdotL > 0.25) + { + return 0.5; + } + else if (NdotL > 0.0) + { + return 0.25; + } + else + { + return 0.0; + } +} + // FIXME: organize this float4 main_ps(PixelInput input) : SV_TARGET0 { @@ -153,16 +171,7 @@ float4 main_ps(PixelInput input) : SV_TARGET0 float NdotL = dot(N, L); float NdotH = max(dot(N, H), 0.0); - float lightIntensity; - if (Softness > 0.0) - { - lightIntensity = smoothstep(0, Softness, NdotL); - } - else - { - lightIntensity = (NdotL > 0.0) ? 1.0 : 0.0; - } - + float lightIntensity = IntensityBanding(NdotL); float3 light = lightIntensity * DirectionalLightColor; float specularIntensity = pow(NdotH * lightIntensity, 32 * 32); diff --git a/Renderer.cs b/Renderer.cs index a67e3b8..e8b2bf8 100644 --- a/Renderer.cs +++ b/Renderer.cs @@ -352,8 +352,6 @@ namespace Kav Deferred_ToonEffect.DirectionalLightColor = directionalLight.Color.ToVector3() * directionalLight.Intensity; - Deferred_ToonEffect.Softness = 0.01f; - Deferred_ToonEffect.ShadowMapOne = ShadowRenderTargets[0]; if (NumShadowCascades > 1) {