#Pointlight shadows render, but aren't "positioned" correctly

5 messages · Page 1 of 1 (latest)

daring zinc
#

okay, the title might sound confusing, but basically I've been following LearnOpenGL to get pointlight shadows to work. I've gotten spotlight and directional shadows to work, but I messed up point light. I've narrowed it down to something on the mathematical side of things in C++, 90% sure it isn't the shaders, framebuffer, cubemap etc., but I could be wrong. I've added some photos about what I am describing. I'm only going to provide my code if requested (shaders specifically) but here is the main math part of it. Also rendering to the framebuffer cubemap is correct. ```void OpenGLRenderer::SetupPointLightMatrix() {
float aspect = (float)2048 / (float)2048; //resolution of the shadow map, adjust as needed
float near = 0.1f;
float far = 25.0f;
glm::mat4 shadowProj = glm::perspective(glm::radians(90.0f), aspect, near, far);

shadowTransforms.clear();

shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(1, 0, 0), glm::vec3(0, -1, 0))); // +X
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(-1, 0, 0), glm::vec3(0, -1, 0))); // -X
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(0, 1, 0), glm::vec3(0, 0, 1))); // +Y
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(0, -1, 0), glm::vec3(0, 0, -1))); // -Y
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(0, 0, 1), glm::vec3(0, -1, 0))); // +Z
shadowTransforms.push_back(shadowProj * glm::lookAt(lightPos, lightPos + glm::vec3(0, 0, -1), glm::vec3(0, -1, 0))); // -Z

}
that and potentially shader issues is the only thing I can think of. Also here is the main shadow point light calculation float PointShadowCalc(vec3 fragPos, samplerCube map)
{
// get vector between fragment position and light position
vec3 fragToLight = fragPos - lightPos;
// use the light to fragment vector to sample from the depth map
closestDepth = texture(map, fragToLight).r;
// it is currently in linear range between [0,1]. Re-transform back to original value
closestDepth *= light_far_plane;
// now get current linear depth as the length between the fragment and light position
float currentDepth = length(fragToLight);
// now test for shadows
float bias = 0.01 + 0.05 * (currentDepth / light_far_plane);
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;

return shadow;

} ```

#

also here is my geo shader to "condense" 6 passes into 1 pass for rendering ```#version 460 core
layout (triangles) in;
layout (triangle_strip, max_vertices=18) out;

uniform mat4 shadowMatrices[6];

out vec4 FragPos; // FragPos from GS (output per emitvertex)

void main()
{
for(int face = 0; face < 6; ++face)
{
gl_Layer = face; // built-in variable that specifies to which face we render.
for(int i = 0; i < 3; ++i) // for each triangle vertex
{
FragPos = gl_in[i].gl_Position;
gl_Position = shadowMatrices[face] * FragPos;
EmitVertex();
}
EndPrimitive();
}
} ``` sry if this is vague, if oyu need more info, I would be more than happy to provide it. Thank you

#

renderdoc doesn't really give a lot of useful info, the most useful thing was see the depth map itself, but I can easily visualize it with some shader changes

daring zinc
#

btw the black cube pos in the photos is 0, 0.55, 0 -- the light source (white cube) is at 0, 2, 2

#

also when the cube was grounded/touching the plain exact, teh shadow did touch it, but didnt seem natural, it was a very skinny shadow, then got wider