I am attempting to implement shadow maps.
I am first going to implement spotlights over directional lights (I am aware this is harder).
Since I was already rendering the geometry, my attempt was to recycle my old shaders and modify them to make shaders to create the depth maps.
This created the following vertex shader:
#version 450
layout(location = 0) in vec3 position; //(x,y,z) coordinates of a vertex
layout(std430, binding = 3) buffer data_buffer
{
vec4 cubes_info[];//first 3 values are position of object
};
uniform mat4 view = mat4(1); //Camera orientation and position
uniform mat4 proj = mat4(1); //The projection parameters (FOV, viewport dimensions)
void main()
{
gl_Position = proj*view*(vec4(position, 1.0) + vec4(vec3(cubes_info[gl_InstanceID]),0));
}
And fragment shader:
#version 450
layout(location = 0) out float fragmentdepth;
void main()
{
fragmentdepth = gl_FragCoord.z;
}
As you can see, both shaders are pretty basic, they are a little more complex than they would otherwise be since they are using instancing, but overall they are simple.
However the output of these shaders is:
Where the original image is:
As you can see, the depth is being lost.
I think this is because my perspective, projection and model matrices are identical for both shaders.
In other words, I think that the camera I use for rendering the second image does not store the depth information. I wanted to know how can you generate a similar projection matrix to store the depth?