#version 330 core
precision highp float;

in vec3 position;
in vec4 color0;
in vec4 normal;

uniform mat4 Model;
uniform mat4 Projection;
uniform mat4 light_space_matrix; // New uniform for the light's view-projection matrix
uniform vec3 light_position;

out vec4 v_normal;
out vec4 color;
out vec3 light_direction;
out vec4 v_light_space_position; // New: Output for shadow calculation

void main() {
        vec4 world_poisition = Model * vec4(position, 1.0);
        vec3 direction_to_light = light_position - world_poisition.xyz;

        // Transform the fragment position into the light's clip space
        v_light_space_position = light_space_matrix * world_poisition;

        // Original lighting setup
        light_direction = normalize(direction_to_light);

        color = color0;
        v_normal = Model * normal;
        gl_Position = Projection * Model * vec4(position, 1.0);
}
