Tweaked shadow map to follow camera movement

simple_math_single_header
Martin Felis 2018-06-25 21:53:43 +02:00
parent 24516b592e
commit 75677a5b70
2 changed files with 6 additions and 1 deletions

View File

@ -28,10 +28,14 @@ float ShadowCalculationPCF(vec4 frag_pos_light_space, vec3 frag_normal_light_spa
vec3 projected_coordinates = frag_pos_light_space.xyz / frag_pos_light_space.w;
projected_coordinates = projected_coordinates * 0.5 + 0.5;
if (abs(projected_coordinates.z) > 1.0 ) {
return 1.0;
}
float current_depth = projected_coordinates.z;
float bias = 0.00;
bias = max(0.01 * (1.0 - dot(frag_normal_light_space, uLightDirection)), uShadowBias);
bias = max(0.001 * (1.0 - dot(frag_normal_light_space, uLightDirection)), uShadowBias);
float shadow = 0.0;
vec2 texel_size = 1.0 / textureSize(uShadowMap, 0);

View File

@ -510,6 +510,7 @@ void Renderer::RenderGl() {
// Shadow Map
mLight.mShadowMapTarget.Bind();
mLight.mPosition = mCamera.mEye;
glViewport(0, 0, mLight.mShadowMapSize, mLight.mShadowMapSize);
mLight.UpdateMatrices();
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);