shadowMap.fs
#version 330 core
layout(location = 0) in vec3 aPos;
//layout(location = 1) in vec2 vertexTexCoord;
//layout(location = 2) in vec3 vertexNormal;
uniform mat4 matrixMVP;
uniform mat4 matrixView;
uniform float far_plane;
//out vec2 depth;
out float depth;
void main()
{
vec4 posP = matrixMVP * vec4(aPos, 1.0);
gl_Position = posP;
//用线性的深度值避免浮点误差
vec4 posV = matrixView * vec4(aPos, 1.0f);
float L = length(posV.xyz);
depth = L / (far_plane);
/*gl_Position = pos4;*/
}
shadowMap.vs
#version 330 core
in float depth;
//int location;
//#define VPL_ILLUMINATION_RADIOSITY_128
void main()
{
//这里影响目前结果图的边界,剔除掉了 pos4.z 小于0的情况
//gl_FragDepth = gl_FragCoord.z;
//gl_FragDepth = pow(gl_FragCoord.z, 20.0); //为了可见
gl_FragDepth = depth;
}