Fix shadow acne
This commit is contained in:
parent
0254b81882
commit
6510f720cb
@ -211,9 +211,10 @@ public:
|
||||
for (const RenderObject &obj : renderObjects) {
|
||||
obj.render(shadowShader);
|
||||
}
|
||||
for (const RenderObject &obj : transparentRenderObjects) {
|
||||
// Don't render transparent objects -- we just assume they don't cast any shadow
|
||||
/* for (const RenderObject &obj : transparentRenderObjects) {
|
||||
obj.render(shadowShader);
|
||||
}
|
||||
} */
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// reset viewport
|
||||
@ -261,8 +262,8 @@ public:
|
||||
int screen_width = 1280;
|
||||
int screen_height = 720;
|
||||
|
||||
int shadow_width = 1024;
|
||||
int shadow_height = 1024;
|
||||
int shadow_width = 2048;
|
||||
int shadow_height = 2048;
|
||||
|
||||
unsigned int depthMap;
|
||||
unsigned int depthMapFBO;
|
||||
|
@ -17,6 +17,9 @@ uniform mediump float specularStrength;
|
||||
|
||||
mediump float ShadowCalculation(vec4 fragPosLightSpace)
|
||||
{
|
||||
// The bias varies depending on the angle to the light (the steeper the angle, the bigger the bias needs to be)
|
||||
mediump float bias = max(0.005 * (1.0 - dot(Normal, lightDirection)), 0.0005);
|
||||
|
||||
// perform perspective divide
|
||||
mediump vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
|
||||
// transform to [0,1] range
|
||||
@ -30,7 +33,7 @@ mediump float ShadowCalculation(vec4 fragPosLightSpace)
|
||||
// get depth of current fragment from light's perspective
|
||||
mediump float currentDepth = projCoords.z;
|
||||
// check whether current frag pos is in shadow
|
||||
mediump float shadow = currentDepth > closestDepth ? 1.0 : 0.0;
|
||||
mediump float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user