From 1291d0cc93a68dc1a0f0320960778dd0e7e6ba9b Mon Sep 17 00:00:00 2001 From: vlj Date: Sun, 20 Apr 2014 00:21:30 +0200 Subject: [PATCH] Increase shadow fidelity. --- data/shaders/sunlightshadow.frag | 20 ++++++++++---------- src/graphics/render.cpp | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index f51ca667c..d970def0b 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -53,7 +53,7 @@ float getShadowFactor(vec3 pos, float bias, int index) float sum = 0.; for (int i = 0; i < 4; i++) { - sum += texture(shadowtex, vec4(shadowtexcoord + 0.0005 * shadowoffset[i], float(index), 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); + sum += texture(shadowtex, vec4(shadowtexcoord + shadowoffset[i] / 2048., float(index), 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); } return sum / 4.; } @@ -91,26 +91,26 @@ void main() { float bias = 0.002 * tan(acos(NdotL)); // According to the slope bias = clamp(bias, 0.001, 0.014); float factor; - if (xpos.z < 20.) + if (xpos.z < 5.) factor = getShadowFactor(xpos.xyz, bias, 0); - else if (xpos.z < 25.) + else if (xpos.z < 6.) { float a = getShadowFactor(xpos.xyz, bias, 0), b = getShadowFactor(xpos.xyz, bias, 1); - factor = mix(a, b, (xpos.z - 20.) / 5.); + factor = mix(a, b, (xpos.z - 5.)); } - else if (xpos.z < 50.) + else if (xpos.z < 20.) factor = getShadowFactor(xpos.xyz, bias, 1); - else if (xpos.z < 60.) + else if (xpos.z < 30.) { float a = getShadowFactor(xpos.xyz, bias, 1), b = getShadowFactor(xpos.xyz, bias, 2); - factor = mix(a, b, (xpos.z - 50.) / 10.); + factor = mix(a, b, (xpos.z - 20.) / 10.); } - else if (xpos.z < 100.) + else if (xpos.z < 50.) factor = getShadowFactor(xpos.xyz, bias, 2); - else if (xpos.z < 120.) + else if (xpos.z < 70.) { float a = getShadowFactor(xpos.xyz, bias, 2), b = getShadowFactor(xpos.xyz, bias, 3); - factor = mix(a, b, (xpos.z - 100.) / 20.); + factor = mix(a, b, (xpos.z - 50.) / 20.); } else factor = getShadowFactor(xpos.xyz, bias, 3); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index d5932b937..9ff0fc1b5 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -558,17 +558,17 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, const float oldnear = camnode->getNearValue(); float FarValues[] = { - 20., - 50., - 100., + 6., + 30., + 70., oldfar, }; float NearValues[] = { oldnear, + 5., 20., 50., - 100., }; const core::matrix4 &SunCamViewMatrix = m_suncam->getViewMatrix();