I’am learning OpenGL and implementing ShadowMaps. It got a directional and spotlight working after quite some work, there is just one thing that I don’t understand.
For a spotlight I calculate a projectionMatrix:
glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, 100.0f)
And a viewMatrix:
glm::lookAt(glm::vec3(spotLightPos), glm::vec3(spotLightLightDirection), glm::vec3(0.0f, 1.0f, 0.0f)));
spotLightPos = glm::vec3(4.0f, 7.0f, 2.0f)
spotLightLightDirection = glm::vec3(0.0f, -1.0f, 0.0f)
Then I go on and calculate a modelTransformation and multiple them to a MVP and so on.
But when I generate the depthMap it keeps looking at the center, so 0.0f, 0.0f, 0.0f in worldSpace instead of straight down.
What am I missing here?
The blue cube is the spotlight, and it should look straight down on the backpack, but it is looking at the bottom wooden cube at the center of the scene.
I supsect the problem has to do with the lookAt calculation so for now I didn’t post any other code, because I am not sure if and what is needed. Please ask for any information needed. Thanks a lot.
When I try adding the position to the direction as pointed out in some tutorials:
glm::lookAt(glm::vec3(spotLightPos), glm::vec3(spotLightPos) + glm::vec3(spotLightLightDirection), glm::vec3(0.0f, 1.0f, 0.0f))
The depthMap just ends up fully white. Not sure why either…