Added debug display for light source depth maps and shadow toggle

This commit is contained in:
saschawillems 2016-07-17 18:34:52 +02:00
parent 1e4e233f81
commit 7f687570d4
9 changed files with 59 additions and 87 deletions

View file

@ -14,30 +14,16 @@ layout (location = 0) out vec4 outFragColor;
float LinearizeDepth(float depth)
{
float n = 1.0; // camera z near
float f = 96.0; // camera z far
float n = 0.1; // camera z near
float f = 64.0; // camera z far
float z = depth;
return (2.0 * n) / (f + n - z * (f - n));
}
void main()
{
vec3 components[3];
components[0] = texture(samplerPosition, inUV.st).rgb;
components[1] = texture(samplerNormal, inUV.st).rgb;
//components[2] = texture(samplerDepth, inUV.st).rgb;
// Uncomment to display specular component
//components[2] = vec3(texture(samplerAlbedo, inUV.st).a);
// Select component depending on z coordinate of quad
highp int index = int(inUV.z);
if (index == 2)
{
float depth = texture(samplerDepth, vec3(inUV.st, 2.0)).r;
outFragColor = vec4(vec3(1.0-LinearizeDepth(depth)), 1.0);
}
else
{
outFragColor.rgb = components[index];
}
// Display depth from light's point-of-view
// inUV.w = number of light source
float depth = texture(samplerDepth, vec3(inUV)).r;
outFragColor = vec4(vec3(1.0 - LinearizeDepth(depth)), 0.0);
}

View file

@ -5,12 +5,11 @@
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec2 inUV;
layout (location = 3) in vec3 inNormal;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
mat4 modelview;
} ubo;
layout (location = 0) out vec3 outUV;
@ -22,6 +21,9 @@ out gl_PerVertex
void main()
{
outUV = vec3(inUV.st, inNormal.z);
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
outUV = vec3(inUV.st, gl_InstanceIndex);
vec4 tmpPos = vec4(inPos, 1.0);
tmpPos.y += gl_InstanceIndex;
tmpPos.xy *= vec2(1.0/4.0, 1.0/3.0);
gl_Position = ubo.projection * ubo.modelview * tmpPos;
}

View file

@ -31,6 +31,7 @@ layout (binding = 4) uniform UBO
{
vec4 viewPos;
Light lights[LIGHT_COUNT];
int useShadows;
} ubo;
float textureProj(vec4 P, float layer, vec2 offset)
@ -124,18 +125,21 @@ void main()
}
// Shadow calculations in a separate pass
for(int i = 0; i < LIGHT_COUNT; ++i)
if (ubo.useShadows > 0)
{
vec4 shadowClip = ubo.lights[i].viewMatrix * vec4(fragPos, 1.0);
for(int i = 0; i < LIGHT_COUNT; ++i)
{
vec4 shadowClip = ubo.lights[i].viewMatrix * vec4(fragPos, 1.0);
float shadowFactor;
#ifdef USE_PCF
shadowFactor= filterPCF(shadowClip, i);
#else
shadowFactor = textureProj(shadowClip, i, vec2(0.0));
#endif
float shadowFactor;
#ifdef USE_PCF
shadowFactor= filterPCF(shadowClip, i);
#else
shadowFactor = textureProj(shadowClip, i, vec2(0.0));
#endif
fragcolor *= shadowFactor;
fragcolor *= shadowFactor;
}
}
outFragColor.rgb = fragcolor;

View file

@ -10,7 +10,6 @@ layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 modelview;
mat4 lightMVP;
} ubo;
layout (location = 0) out vec2 outUV;