quakeforge/libs/video/renderer/vulkan/shader/lighting_cascade.frag
Bill Currie 140fe93a9c [vulkan] Add some debug to the cascade shadows
It turns out what I thought was a cascade selection bug was just very
bad choice of cascade steps: factors of 8 just don't work nicely. I'm
not sure that simple factors work all that well, either. I need to make
the cascade system configurable and probably support more cascades.
2024-02-01 18:57:25 +09:00

35 lines
847 B
GLSL

#version 450
#extension GL_GOOGLE_include_directive : enable
#include "lighting.h"
layout (set = 3, binding = 0) uniform sampler2DArrayShadow shadow_map[32];
float
shadow (uint map_id, uint layer, uint mat_id, vec4 pos, vec3 lpos)
{
float fd = pos.w;
uint ind = fd > CascadeDepths[1]
? fd > CascadeDepths[0] ? 0 : 1
: fd > CascadeDepths[2] ? 2 : 3;
vec4 p = shadow_mats[mat_id + ind] * vec4 (pos.xyz, 1);
p = p / p.w;
float depth = p.z;
vec2 uv = (p.xy + vec2(1)) / 2;
return texture (shadow_map[map_id], vec4 (uv, layer + ind, depth));
}
vec4
debug_shadow (vec4 pos)
{
float fd = pos.w;
uint ind = fd > CascadeDepths[1]
? fd > CascadeDepths[0] ? 0 : 1
: fd > CascadeDepths[2] ? 2 : 3;
ind += 1;
return vec4 (ind & 1, ind & 2, ind & 4, 1);
}
//#define DEBUG_SHADOW(p) debug_shadow(p)
#include "lighting_main.finc"