diff --git a/include/QF/Vulkan/qf_lighting.h b/include/QF/Vulkan/qf_lighting.h index d0e32fb68..e8f2eaac5 100644 --- a/include/QF/Vulkan/qf_lighting.h +++ b/include/QF/Vulkan/qf_lighting.h @@ -49,6 +49,12 @@ typedef struct qfv_lightmatset_s DARRAY_TYPE (mat4f_t) qfv_lightmatset_t; #define ST_CASCADE 2 // cascaded shadow maps #define ST_CUBE 3 // cubemap (omni, large spotlight) +enum { + lighting_main, + lighting_shadow, + lighting_debug, +}; + typedef struct qfv_light_render_s { // mat_id (13) map_id (5) layer (11) type (2) uint32_t id_data; @@ -80,9 +86,6 @@ typedef struct lightingframe_s { VkBuffer style_buffer; VkBuffer id_buffer; light_queue_t light_queue[4]; - uint32_t ico_count; - uint32_t cone_count; - uint32_t flat_count; qfv_imageviewset_t views; qfv_framebufferset_t framebuffers; diff --git a/libs/video/renderer/vulkan/rp_main_def.plist b/libs/video/renderer/vulkan/rp_main_def.plist index a7a34fdf3..a31e3d459 100644 --- a/libs/video/renderer/vulkan/rp_main_def.plist +++ b/libs/video/renderer/vulkan/rp_main_def.plist @@ -1576,9 +1576,9 @@ renderpasses = { color = $color.lights; tasks = ( { func = lighting_bind_descriptors; - params = (none); }, + params = (main, none); }, { func = lighting_draw_lights; - params = (none); }, + params = (main, none); }, ); stages = ( @@ -1593,9 +1593,9 @@ renderpasses = { color = $color.lights; tasks = ( { func = lighting_bind_descriptors; - params = (plane); }, + params = (main, plane); }, { func = lighting_draw_lights; - params = (plane); }, + params = (main, plane); }, ); stages = ( @@ -1610,9 +1610,9 @@ renderpasses = { color = $color.lights; tasks = ( { func = lighting_bind_descriptors; - params = (cascade); }, + params = (main, cascade); }, { func = lighting_draw_lights; - params = (cascade); }, + params = (main, cascade); }, ); stages = ( @@ -1627,9 +1627,9 @@ renderpasses = { color = $color.lights; tasks = ( { func = lighting_bind_descriptors; - params = (cube); }, + params = (main, cube); }, { func = lighting_draw_lights; - params = (cube); }, + params = (main, cube); }, ); stages = ( @@ -1715,7 +1715,8 @@ renderpasses = { color = $color.lights; tasks = ( - { func = lighting_bind_descriptors; }, + { func = lighting_bind_descriptors; + params = (debug, none); }, { func = lighting_draw_splats; }, ); diff --git a/libs/video/renderer/vulkan/shader/light_splat.vert b/libs/video/renderer/vulkan/shader/light_splat.vert index 77ae25491..408bbd8db 100644 --- a/libs/video/renderer/vulkan/shader/light_splat.vert +++ b/libs/video/renderer/vulkan/shader/light_splat.vert @@ -33,7 +33,7 @@ void main (void) { LightData l = lights[light_index]; - float sz = 1 / l.attenuation.w; + float sz = l.attenuation.w > 0 ? 1 / l.attenuation.w : sqrt(abs(l.color.w)); float c = l.direction.w; float sxy = sz * (c < 0 ? sqrt (c*c * (1 - c*c)) / (0.5 - c) : 1); vec3 scale = vec3 (sxy, sxy, sz); diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index 541af81c1..ea8a34b46 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -357,9 +357,6 @@ lighting_update_lights (const exprval_t **params, exprval_t *result, auto lframe = &lctx->frames.a[ctx->curFrame]; - lframe->ico_count = 0; - lframe->cone_count = 0; - lframe->flat_count = 0; memset (lframe->light_queue, 0, sizeof (lframe->light_queue)); if (!lctx->scene || !lctx->scene->lights) { return; @@ -550,29 +547,38 @@ lighting_bind_descriptors (const exprval_t **params, exprval_t *result, auto lframe = &lctx->frames.a[ctx->curFrame]; auto shadow_type = *(int *) params[0]->value; + auto stage = *(int *) params[1]->value; + + if (stage == lighting_debug) { + VkDescriptorSet sets[] = { + Vulkan_Matrix_Descriptors (ctx, ctx->curFrame), + lframe->lights_set, + }; + dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, + layout, 0, 2, sets, 0, 0); - VkDescriptorSet sets[] = { - lframe->shadowmat_set, - lframe->lights_set, - lframe->attach_set, - (VkDescriptorSet[]) { - lctx->shadow_2d_set, - lctx->shadow_2d_set, - lctx->shadow_2d_set, - lctx->shadow_cube_set - }[shadow_type], - }; - dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, - layout, 0, 4, sets, 0, 0); - if (1) { VkBuffer buffers[] = { lframe->id_buffer, lctx->splat_verts, }; - VkDeviceSize offsets[] = { sizeof (uint32_t), 0 }; + VkDeviceSize offsets[] = { 0, 0 }; dfunc->vkCmdBindVertexBuffers (cmd, 0, 2, buffers, offsets); dfunc->vkCmdBindIndexBuffer (cmd, lctx->splat_inds, 0, VK_INDEX_TYPE_UINT32); + } else { + VkDescriptorSet sets[] = { + lframe->shadowmat_set, + lframe->lights_set, + lframe->attach_set, + (VkDescriptorSet[]) { + lctx->shadow_2d_set, + lctx->shadow_2d_set, + lctx->shadow_2d_set, + lctx->shadow_cube_set + }[shadow_type], + }; + dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, + layout, 0, 4, sets, 0, 0); } } @@ -588,35 +594,17 @@ lighting_draw_splats (const exprval_t **params, exprval_t *result, auto cmd = taskctx->cmd; auto lframe = &lctx->frames.a[ctx->curFrame]; - if (lframe->ico_count) { - dfunc->vkCmdDrawIndexed (cmd, num_ico_inds, lframe->ico_count, 0, 0, 0); + if (lframe->light_queue[ST_CUBE].count) { + auto q = lframe->light_queue[ST_CUBE]; + dfunc->vkCmdDrawIndexed (cmd, num_ico_inds, q.count, 0, 0, q.start); } - if (lframe->cone_count) { - dfunc->vkCmdDrawIndexed (cmd, num_cone_inds, lframe->cone_count, - num_ico_inds, 12, lframe->ico_count); + if (lframe->light_queue[ST_PLANE].count) { + auto q = lframe->light_queue[ST_PLANE]; + dfunc->vkCmdDrawIndexed (cmd, num_cone_inds, q.count, + num_ico_inds, 12, q.start); } } -static void -lighting_draw_flats (const exprval_t **params, exprval_t *result, - exprctx_t *ectx) -{ - auto taskctx = (qfv_taskctx_t *) ectx; - auto ctx = taskctx->ctx; - auto device = ctx->device; - auto dfunc = device->funcs; - auto lctx = ctx->lighting_context; - auto cmd = taskctx->cmd; - - auto lframe = &lctx->frames.a[ctx->curFrame]; - if (!lframe->flat_count) { - return; - } - - uint32_t splat_count = lframe->ico_count + lframe->cone_count; - dfunc->vkCmdDraw (cmd, 3, lframe->flat_count, 0, splat_count); -} - static void lighting_draw_lights (const exprval_t **params, exprval_t *result, exprctx_t *ectx) @@ -645,6 +633,30 @@ lighting_draw_lights (const exprval_t **params, exprval_t *result, dfunc->vkCmdDraw (cmd, 3, 1, 0, 0); } +static exprenum_t lighting_stage_enum; +static exprtype_t lighting_stage_type = { + .name = "lighting_stage", + .size = sizeof (int), + .get_string = cexpr_enum_get_string, + .data = &lighting_stage_enum, +}; +static int lighting_stage_values[] = { + lighting_main, + lighting_shadow, + lighting_debug, +}; +static exprsym_t lighting_stage_symbols[] = { + {"main", &lighting_stage_type, lighting_stage_values + 0}, + {"shadow", &lighting_stage_type, lighting_stage_values + 1}, + {"debug", &lighting_stage_type, lighting_stage_values + 2}, + {} +}; +static exprtab_t lighting_stage_symtab = { .symbols = lighting_stage_symbols }; +static exprenum_t lighting_stage_enum = { + &lighting_stage_type, + &lighting_stage_symtab, +}; + static exprenum_t shadow_type_enum; static exprtype_t shadow_type_type = { .name = "shadow_type", @@ -668,6 +680,7 @@ static exprenum_t shadow_type_enum = { static exprtype_t *shadow_type_param[] = { &shadow_type_type, + &lighting_stage_type, }; static exprtype_t *stepref_param[] = { @@ -684,7 +697,7 @@ static exprfunc_t lighting_update_descriptors_func[] = { {} }; static exprfunc_t lighting_bind_descriptors_func[] = { - { .func = lighting_bind_descriptors, .num_params = 1, + { .func = lighting_bind_descriptors, .num_params = 2, .param_types = shadow_type_param }, {} }; @@ -692,12 +705,8 @@ static exprfunc_t lighting_draw_splats_func[] = { { .func = lighting_draw_splats }, {} }; -static exprfunc_t lighting_draw_flats_func[] = { - { .func = lighting_draw_flats }, - {} -}; static exprfunc_t lighting_draw_lights_func[] = { - { .func = lighting_draw_lights, .num_params = 1, + { .func = lighting_draw_lights, .num_params = 2, .param_types = shadow_type_param }, {} }; @@ -717,7 +726,6 @@ static exprsym_t lighting_task_syms[] = { { "lighting_bind_descriptors", &cexpr_function, lighting_bind_descriptors_func }, { "lighting_draw_splats", &cexpr_function, lighting_draw_splats_func }, - { "lighting_draw_flats", &cexpr_function, lighting_draw_flats_func }, { "lighting_draw_lights", &cexpr_function, lighting_draw_lights_func }, { "lighting_setup_aux", &cexpr_function, lighting_setup_aux_func }, { "lighting_draw_shadow_maps", &cexpr_function,