this is my vertex shader :

```
#version 440
layout(location = 0) in vec3 vertexPosition;
layout(location = 3) in vec4 vertexColor;
layout(location = 2) in vec4 vertexNormal;
layout(location = 8) in vec2 vertexTexCoord;
out vec4 Color;
out vec4 Normal;
out vec4 Position;
out vec2 TexCoord;
out vec4 shadowMapCoords;
out mat3 normalMapMatrix;
uniform mat4 modelMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 normalMatrix;
uniform mat4 lightModelMatrix;
uniform mat4 lightViewMatrix;
uniform mat4 lightProjectionMatrix;
uniform vec3 ambientLight;
uniform vec3 diffuseLight;
uniform vec3 specularLight;
uniform vec3 lightPosition;
uniform float shininess;
uniform vec3 eyePosition;
vec3 surfaceToLight;
vec3 surfaceToCam;
vec3 reflectionVector;
float cosAngle;
mat4 bias = mat4(0.5, 0, 0, 0,
0, 0.5, 0, 0,
0, 0, 0.5, 0,
0.5, 0.5, 0.5, 1);
void SetNormalMapMatrix()
{
float xAngle = 1-dot( Normal.yz, vec2(1, 0) );
float zAngle = 1-dot( Normal.xy, vec2(0, 1) );
mat3 xMatrix = mat3(1, 0, 0,
0, cos(xAngle), -sin(xAngle),
0, sin(xAngle), cos(xAngle));
mat3 zMatrix = mat3(cos(zAngle), -sin(zAngle), 0,
sin(zAngle), cos(zAngle), 0,
0, 0, 1);
xMatrix = transpose(xMatrix);
zMatrix = transpose(zMatrix);
normalMapMatrix = zMatrix*xMatrix;
}
void main()
{
gl_Position = projectionMatrix*viewMatrix*modelMatrix*vec4(vertexPosition, 1);
Color = vertexColor;
Normal = normalize(normalMatrix*vertexNormal);
Position = modelViewMatrix*vec4(vertexPosition, 1);
TexCoord = vertexTexCoord;
mat4 lightSpaceMatrix = bias*lightProjectionMatrix*lightViewMatrix*lightModelMatrix;
shadowMapCoords = lightSpaceMatrix*vec4(vertexPosition, 1);
SetNormalMapMatrix();
}
//END
```

and this is my fragment shader :

```
#version 440
in vec4 Color;
in vec4 Normal;
in vec4 Position;
in vec2 TexCoord;
in vec4 shadowMapCoords;
in mat3 normalMapMatrix;
out vec4 fragmentColor;
vec3 viewVector;
uniform sampler2D Texture0;
uniform sampler2D Texture1;
uniform vec3 ambientLight;
uniform vec3 diffuseLight;
uniform vec3 specularLight;
uniform vec3 lightPosition;
uniform float shininess;
uniform vec3 eyePosition;
vec3 surfaceToLight;
vec3 surfaceToCam;
vec3 reflectionVector;
vec3 diffuseColor;
vec3 specularColor;
float cosAngle;
void Phong(vec3 position, vec3 normal)
{
normal = normalize(normal);
surfaceToLight = normalize(lightPosition.xyz-position);
surfaceToCam = normalize(eyePosition.xyz-position);
reflectionVector = normalize(reflect(-surfaceToLight, normal));
cosAngle = max(dot(reflectionVector, surfaceToCam), 0);
float specularCoefficient = pow(cosAngle, 3);
float diffuseCoefficient = max(dot(normalize(normal), normalize(surfaceToLight)), 0);
diffuseColor = diffuseColor + diffuseCoefficient*diffuseLight;
specularColor = specularColor+ specularCoefficient*specularLight;
}
void main()
{
//SetNormalMapMatrix();
vec4 tex0 = texture(Texture0, TexCoord);
vec4 tex1 = texture(Texture1, TexCoord);
vec4 shadowCoords = shadowMapCoords;
shadowCoords/=shadowCoords.w;
float shadowMapDepth = texture(Texture0, shadowCoords.xy).r;
vec3 t = vec3( tex1.rgb-vec3(0.5, 0.5, 0.5) )*2;
Phong(Position.xyz, normalMapMatrix*t.xzy);
fragmentColor = vec4(shadowCoords.zzz, 1);
}
//END
```

I have deleted the lightning and displayes the fragmentdepth in lightspace but I get a white result if I use 1-depth I get a black result.

The same thing hapens If I write the camera space coords in a vec4 and use this for displaying the depth.

But If I use the value given to gl_Position–> gl_FragCoord in the fragmentshader I get a correct result…

Maybe his helps…