So, I tried to lure my head around the shadow mapping in OpenGL last week, and this is not so great. So I was hoping someone here would help me. I learned about shadow matching from LearnOpenGL's shadow binding tutorial, which uses forward rendering, and from what I collect, it looks like the rendering of shadows with deferred shadows is slightly different. To start, here is my shadow map:

- , , , , . , - . , , , . , , , .
GLfloat near_plane = 1.0f;
GLfloat far_plane = 10.0f;
glm::mat4 lightProjMat = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
glm::mat4 lightPerspective = glm::lookAt(glm::vec3(-2.0f, 6.0f, -1.0f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
shadowBuf.lightSpaceMat = lightProjMat * lightPerspective;
, . , . . , , . , .
GLSL . (LSMat)
void main()
{
gl_Position = vec4(position, 1.0f);
vs_out.uv = uv;
vs_out.normal = normal;
vs_out.FragPos = vec3(model * vec4(position, 1.0f));
vs_out.FragPosLS = LSMat * vec4(vs_out.FragPos, 1.0f);
}
.
, , . (, )
, :
float shadowCalc()
{
vec4 fragPosLS = texture(gFragPosLS, uvs);
vec3 projCoords = fragPosLS.xyz / fragPosLS.w;
projCoords = projCoords * 0.5 + 0.5;
float closestDepth = texture(shadowMap, projCoords.xy).r;
float currentDepth = projCoords.z;
float shadow = currentDepth > closestDepth ? 1.0 : 0.0;
return shadow;
}
, :
float shadowValue = shadowCalc();
diffuse = diffuse * (1.0 - shadowValue);
specular = specular * (1.0 - shadowValue);
return ((diffuse * vec4(gColor, 1.0f)) + specular + ambient);
, , :

- , UV- Maya . , . , , , , shadowCalc, . 100%.
- , , . , , . , , , . , , , . , - . - , - -, .
, -, , .