From e4b856805ed1cf7ef751ddcdb0c7fa18b2138595 Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Tue, 17 Apr 2012 09:12:57 +0200 Subject: [PATCH] Make the number of shadow cascades and the range of each configurable --- Effects/sunlight.eff | 2 ++ Shaders/sunlight.frag | 14 +++++++++----- preferences.xml | 5 +++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Effects/sunlight.eff b/Effects/sunlight.eff index 9905237ca..638c83dfc 100644 --- a/Effects/sunlight.eff +++ b/Effects/sunlight.eff @@ -77,6 +77,8 @@ - fg_ViewMatrixInverse - fg_ViewMatrix - fg_Planes + - fg_ShadowNumber + - fg_ShadowDistances --> diff --git a/Shaders/sunlight.frag b/Shaders/sunlight.frag index 4c616819c..6d453c6ec 100644 --- a/Shaders/sunlight.frag +++ b/Shaders/sunlight.frag @@ -8,6 +8,8 @@ uniform vec4 fg_SunDiffuseColor; uniform vec4 fg_SunSpecularColor; uniform vec3 fg_SunDirection; uniform vec3 fg_Planes; +uniform int fg_ShadowNumber; +uniform vec4 fg_ShadowDistances; varying vec3 ray; vec3 position( vec3 viewdir, float depth ); @@ -18,18 +20,20 @@ vec4 DynamicShadow( in vec4 ecPosition, out vec4 tint ) vec4 coords; vec2 shift = vec2( 0.0 ); int index = 4; - if (ecPosition.z > -5.0) { + float factor = 0.5; + if (ecPosition.z > -fg_ShadowDistances.x) { index = 1; + factor = 1.0; tint = vec4(0.0,1.0,0.0,1.0); - } else if (ecPosition.z > -50.0) { + } else if (ecPosition.z > -fg_ShadowDistances.y && fg_ShadowNumber > 1) { index = 2; shift = vec2( 0.0, 0.5 ); tint = vec4(0.0,0.0,1.0,1.0); - } else if (ecPosition.z > -512.0) { + } else if (ecPosition.z > -fg_ShadowDistances.z && fg_ShadowNumber > 2) { index = 3; shift = vec2( 0.5, 0.0 ); tint = vec4(1.0,1.0,0.0,1.0); - } else if (ecPosition.z > -10000.0) { + } else if (ecPosition.z > -fg_ShadowDistances.w && fg_ShadowNumber > 3) { shift = vec2( 0.5, 0.5 ); tint = vec4(1.0,0.0,0.0,1.0); } else { @@ -39,7 +43,7 @@ vec4 DynamicShadow( in vec4 ecPosition, out vec4 tint ) coords.t = dot( ecPosition, gl_EyePlaneT[index] ); coords.p = dot( ecPosition, gl_EyePlaneR[index] ); coords.q = dot( ecPosition, gl_EyePlaneQ[index] ); - coords.st *= .5; + coords.st *= factor; coords.st += shift; return coords; } diff --git a/preferences.xml b/preferences.xml index e3cfde94d..766f57388 100644 --- a/preferences.xml +++ b/preferences.xml @@ -182,6 +182,11 @@ Started September 2000 by David Megginson, david@megginson.com false 4096 + 4 + 5.0 + 50.0 + 500.0 + 5000.0 false