From abca7c9f1e82b22f10b75f35ff84de6b26ec601e Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 8 Mar 2015 14:56:18 +0100 Subject: [PATCH] Disabled directional light if its below the map. --- data/shader/phong.fsh | 48 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/data/shader/phong.fsh b/data/shader/phong.fsh index 2ead53b..707fe32 100644 --- a/data/shader/phong.fsh +++ b/data/shader/phong.fsh @@ -114,34 +114,36 @@ void main() // direction lighting if(length(directionalLightVector)>0.0f) { vec3 directionalVector = normalize(directionalLightVector); - float directionalVisibility = 1.0f; - if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) { - if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.2) { - directionalVisibility = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001); + if (dot(vec3(0.0, 1.0, 0.0), directionalVector) > 0.0) { + float directionalVisibility = 1.0f; + if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) { + if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.2) { + directionalVisibility = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001); + } + else if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.0) { + float directionalVisibility0 = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001); + float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002); + directionalVisibility = mix(directionalVisibility0, directionalVisibility1, distanceToBorder(shadowCoord0.xy) * 5); + } + else { + directionalVisibility = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002); + } } - else if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.0) { - float directionalVisibility0 = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001); - float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002); - directionalVisibility = mix(directionalVisibility0, directionalVisibility1, distanceToBorder(shadowCoord0.xy) * 5); + else if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.0) { + float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.01); + float directionalVisibility2 = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01); + directionalVisibility = mix(directionalVisibility1, directionalVisibility2, distanceToBorder(shadowCoord1.xy) * 5); } else { - directionalVisibility = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002); + directionalVisibility = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01); } + diffuseColor += clamp(dot(normalize(vNormal), directionalVector) + *diffuseFactor*directionalIntensity*directionalColor, 0.0, 1.0)*directionalVisibility; + vec3 cameraVector = normalize(camera - vec3(fragPosition)); + specularColor += clamp(pow((dot((cameraVector+directionalVector),normalize(vNormal))/ + (length(cameraVector+directionalVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) + *specularFactor*directionalIntensity*directionalColor*directionalVisibility; } - else if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.0) { - float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.01); - float directionalVisibility2 = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01); - directionalVisibility = mix(directionalVisibility1, directionalVisibility2, distanceToBorder(shadowCoord1.xy) * 5); - } - else { - directionalVisibility = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01); - } - diffuseColor += clamp(dot(normalize(vNormal), directionalVector) - *diffuseFactor*directionalIntensity*directionalColor, 0.0, 1.0)*directionalVisibility; - vec3 cameraVector = normalize(camera - vec3(fragPosition)); - specularColor += clamp(pow((dot((cameraVector+directionalVector),normalize(vNormal))/ - (length(cameraVector+directionalVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) - *specularFactor*directionalIntensity*directionalColor*directionalVisibility; } // point lights