From d6aef2a24458fe095466f82e8a9c976db8a8ad4b Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 15 Mar 2015 17:15:15 +0100 Subject: [PATCH] Optimized shadows of the torches. --- data/levels/Compositions.xml | 2 +- data/shader/phong.fsh | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/data/levels/Compositions.xml b/data/levels/Compositions.xml index 8193e65..57cd8b5 100644 --- a/data/levels/Compositions.xml +++ b/data/levels/Compositions.xml @@ -74,7 +74,7 @@ 1.0 0.9 0.3 - 10.0 + 8.0 -0.5 1.0 1.0 diff --git a/data/shader/phong.fsh b/data/shader/phong.fsh index e4415ae..16cd455 100644 --- a/data/shader/phong.fsh +++ b/data/shader/phong.fsh @@ -146,8 +146,9 @@ float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) { float A = -(farPlane+nearPlane)/(farPlane-nearPlane); float B = -2*(farPlane*nearPlane)/(farPlane - nearPlane); float compValue = 0.5*(-A*length(lightDirection) + B)/length(lightDirection) + 0.5; - float bias = 0.001*tan(acos(clamp(dot(vNormal, lightDirection), 0.0, 1.0))); - bias = clamp(bias, 0.0, 0.0005); + float bias = 0.001*tan(acos(clamp(dot(vNormal, normalize(lightDirection)), 0.0, 1.0))); + bias = clamp(bias, 0.0, 0.001); + bias *= 1/length(lightDirection)*8; return texture(shadowMap, vec4(lightDirection , compValue - bias)); } @@ -248,11 +249,11 @@ void main() intensity = clamp(exp(-(1/lightIntensities[i])*distance), 0.0, 1.0); } diffuseColor += clamp(dot(normalize(vNormal), lightVector) - *diffuseFactor*intensity*lightColors[i], 0.0, 1.0)*pointVisibility; + *diffuseFactor*intensity*lightColors[i]*pointVisibility, 0.0, 1.0); vec3 cameraVector = normalize(camera - vec3(fragPosition)); specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/ - (length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) - *specularFactor*intensity*lightColors[i]*pointVisibility; + (length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess)*pointVisibility, 0.0, 1.0) + *specularFactor*intensity*lightColors[i]; } }