diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 71f4121..67c7679 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -66,8 +66,12 @@ float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) { } float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) { + float nearPlane = 0.1; + 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.005; - return texture(shadowMap, vec4(lightDirection.xyz , length(lightDirection) - bias)); + return texture(shadowMap, vec4(lightDirection.xyz , compValue - bias)); } float distanceToBorder(vec2 vector) { diff --git a/level.cc b/level.cc index b89610a..5be2256 100644 --- a/level.cc +++ b/level.cc @@ -422,7 +422,7 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, glm::mat4* viewProjectionMatrix, std::vector* shadowVPs) { for(unsigned int i = 0; irender(shader, lightingPass, viewProjectionMatrix, shadowVPs); } }