Jump to content

5947ee5c462d7_ScreenShot2017-06-19at11_26_45PM.png.8145945815b24303af7d90be294f980b.png

As you can see the shadow positions are wrong.

lightSpace =  lightSpaceMatrix * model * vec4(position, 1.0);

LightSpace in vertex shader.

vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
projCoords = projCoords * 0.5 + 0.5;

Perspective divide and make sure range is between [0, 1] in fragment shader.

glm::vec3 lightPos(20.0, 20.00, 20.0);
glm::vec3 lightColor(1000.0, 1000.0, 1000.0);
glm::mat4 lightProjection, lightView;
glm::mat4 lightSpaceMatrix;
lightProjection = glm::frustum(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 100000.0f);
lightView = glm::lookAt(lightPos, glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0));
lightSpaceMatrix = lightProjection * lightView;

Lighting matrix setup in main.

Depth map is 4096 * 4096, I have checked that it is correct, and I have used glViewport to change the render window.

What am I doing wrong here?

Link to comment
https://linustechtips.com/topic/795527-wrong-shadow-positions-shadow-mapping-opengl/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×