[vulkan] Get point light shadows working

Other than the rather bad shadow acne, this is actually quake itself
working nicely. Still need to get directional lights working for
community maps, and all sorts of other little things (hide view model,
show player, fix brush backfaces, etc).
This commit is contained in:
Bill Currie 2023-08-03 00:05:41 +09:00
parent 1fe0f5ffd5
commit 2fbe44a72e
6 changed files with 25 additions and 10 deletions

View file

@ -4,7 +4,7 @@
layout (set = 3, binding = 0) uniform sampler2DArrayShadow shadow_map[32];
float
shadow (uint map_id, uint layer, uint mat_id, vec3 pos)
shadow (uint map_id, uint layer, uint mat_id, vec3 pos, vec3 lpos)
{
return 1;
}

View file

@ -7,11 +7,24 @@ layout (set = 0, binding = 0) buffer ShadowMatrices {
layout (set = 3, binding = 0) uniform samplerCubeArrayShadow shadow_map[32];
float
shadow (uint map_id, uint layer, uint mat_id, vec3 pos)
shadow (uint map_id, uint layer, uint mat_id, vec3 pos, vec3 lpos)
{
vec4 p = shadow_mats[mat_id] * vec4 (pos, 1);
float depth = (p / p.w).z;
return texture (shadow_map[map_id], vec4 (p.xyz, layer), depth);
vec3 dir = pos - lpos;
vec3 adir = abs(dir);
adir = max (adir.yzx, adir.zxy);
uint ind = dir.x <= -adir.x ? 5
: dir.x >= adir.x ? 4
: dir.y <= -adir.y ? 0
: dir.y >= adir.y ? 1
: dir.z <= -adir.z ? 3
: dir.z >= adir.z ? 2 : 0;
vec4 p = shadow_mats[mat_id + ind] * vec4 (pos, 1);
p = p / (p.w - 0.5); //FIXME hard-coded bias
float depth = p.z;
dir = mat3(vec3( 0, 0, 1),
vec3(-1, 0, 0),
vec3( 0, 1, 0)) * dir;
return texture (shadow_map[map_id], vec4 (dir, layer), depth);
}
#include "lighting_main.finc"

View file

@ -54,7 +54,7 @@ main (void)
uint map_id = bitfieldExtract (id_data, 13, 5);
uint layer = bitfieldExtract (id_data, 18, 11);
I *= shadow (map_id, layer, mat_id, p);
I *= shadow (map_id, layer, mat_id, p, l.position.xyz);
float namb = dot(l.direction.xyz, l.direction.xyz);
I *= spot_cone (l, incoming) * diffuse (incoming, n);

View file

@ -2,7 +2,7 @@
#extension GL_GOOGLE_include_directive : enable
float
shadow (uint mapid, uint layer, uint mat_id, vec3 pos)
shadow (uint mapid, uint layer, uint mat_id, vec3 pos, vec3 lpos)
{
return 1;
}

View file

@ -7,7 +7,7 @@ layout (set = 0, binding = 0) buffer ShadowMatrices {
layout (set = 3, binding = 0) uniform sampler2DArrayShadow shadow_map[32];
float
shadow (uint map_id, uint layer, uint mat_id, vec3 pos)
shadow (uint map_id, uint layer, uint mat_id, vec3 pos, vec3 lpos)
{
vec4 p = shadow_mats[mat_id] * vec4 (pos, 1);
p = p / (p.w - 0.5); //FIXME hard-coded bias

View file

@ -349,7 +349,6 @@ lighting_update_lights (const exprval_t **params, exprval_t *result,
//.id_data = make_id(r->matrix_id, r->map_index, r->layer,
//r->mode),
.id_data = 0x80000000, // no style
.style = 11,
};
}
dlight_offset = sizeof (qfv_light_render_t[lctx->dynamic_base]);
@ -1157,7 +1156,7 @@ create_light_matrices (lightingctx_t *lctx)
mmulf (side_view, qfv_z_up, side_view);
mmulf (lm[j], proj, side_view);
}
r->matrix_id = r->matrix_base + BOX_FRONT;
r->matrix_id = r->matrix_base;
break;
case ST_CASCADE:
// dependent on view fustrum and cascade level
@ -1197,6 +1196,9 @@ static uint32_t
make_id (uint32_t matrix_index, uint32_t map_index, uint32_t layer,
uint32_t type)
{
if (type == ST_CUBE) {
layer /= 6;
}
return ((matrix_index & 0x1fff) << 0)
| ((map_index & 0x1f) << 13)
| ((layer & 0x7ff) << 18)