# Shadow Mapping, why does my shadow change size and position when I rotate my light?

I have looked far and wide for this and have not found any issue like this, so far. Basically, when my light is at a certain angle my shadows seem to be correctly positioned and scaled, yet if I rotate the light about itself, both of these things change.

It should be about that size and position but it is rotated incorrectly here.

In this image, it is completely incorrect.

Now for my code.

1st, the code run on the CPU concerning the shadow map:

In the load, I create my shadow map based on the width and height of the screen.

shadow = shadow_map(renderer::get_screen_width(), renderer::get_screen_height());


And I set up my shaders, no need to show it, that bit's working. In the update method I give my shadow map the properties of the light used to create the shadow like so:

shadow.light_dir = normalize(spot.get_direction());


Then in my render method I do this:

renderer::set_render_target(shadow);
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
for (auto &e : meshes)
{
auto m = e.second;
auto M = m.get_transform().get_transform_matrix();
//glm::lookAt(light_position, light_position + light_dir, glm::vec3(0.0f, 1.0f, 0.0f));
auto P = cam.get_projection();
auto MVP = biasMatrix * (P * V * M);
renderer::render(m);
}

glCullFace(GL_BACK);
//set render target back to screen
renderer::set_render_target();

//...

auto lM = m.get_transform().get_transform_matrix();
auto lP = cam.get_projection();
auto lMVP = (lP * lV * lM);

glUniformMatrix4fv(main_eff.get_uniform_location("lightMVP"), 1, GL_FALSE, value_ptr(lMVP));



It is worth noting that my bias matrix looks like this:

0.5, 0.0, 0.0, 0.5,
0.0, 0.5, 0.0, 0.5,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0


void main()
{
// **********************
// **********************
// ************************
// Calculate view direction
// ************************
vec3 view_dir = normalize(eye_pos - position);
// **************
// Sample texture
// **************
vec4 tex_colour = texture(tex, tex_coord);
// ********************
// Calculate spot light
// ********************
colour = calculate_spot(spot, mat, position, normal, view_dir, tex_colour);
// *********************
// *********************

colour.a = 1.0;
}


float calculate_shadow(in sampler2D shadow_map, in vec4 light_space_pos)
{
vec3 light_dir = normalize(spot.position - position);

vec3 proj_coords = light_space_pos.xyz / light_space_pos.w;

proj_coords = proj_coords * 0.5 + 0.5;

float current_depth = proj_coords.z;

float bias = max(0.05 * (1.0 - dot(normal, light_dir)), 0.005);

float shadow = current_depth - bias > closest_depth ? 0.0 : 1.0;

vertex_light = (lightMVP * vec4(vertex_position, 1.0));