vk: implement r_lightmap for both traditional and RT renderers

Display lightmap plus lighting for traditional.
Display all collected lights (including bounces and simple transparency)
for RT.

Fixes #634
This commit is contained in:
Ivan Avdeev 2023-11-03 11:26:57 -04:00
parent 0ba85e3f08
commit 28eec97cbf
5 changed files with 21 additions and 6 deletions

View File

@ -13,6 +13,7 @@ struct Light {
layout(set=3,binding=0) uniform UBO {
uint num_lights;
uint debug_r_lightmap;
Light lights[max_dlights];
} ubo;
@ -38,7 +39,7 @@ void main() {
discard;
outColor.a = baseColor.a;
outColor.rgb += baseColor.rgb * texture(sLightmap, vLightmapUV).rgb;
outColor.rgb = texture(sLightmap, vLightmapUV).rgb;
for (uint i = 0; i < ubo.num_lights; ++i) {
const vec4 light_pos_r = ubo.lights[i].pos_r;
@ -47,6 +48,9 @@ void main() {
const float d2 = dot(light_dir, light_dir);
const float r2 = light_pos_r.w * light_pos_r.w;
const float attenuation = dlight_attenuation_const / (d2 + r2 * .5);
outColor.rgb += baseColor.rgb * light_color * max(0., dot(normalize(light_dir), vNormal)) * attenuation;
outColor.rgb += light_color * max(0., dot(normalize(light_dir), vNormal)) * attenuation;
}
if (ubo.debug_r_lightmap == 0)
outColor.rgb *= baseColor.rgb;
}

View File

@ -261,8 +261,10 @@ void main() {
colour = diffuse + specular;
}
const vec4 base_color_a = SRGBtoLINEAR(imageLoad(base_color_a, pix));
colour *= base_color_a.rgb;
if (ubo.ubo.debug_display_only != DEBUG_DISPLAY_LIGHTING) {
const vec4 base_color_a = SRGBtoLINEAR(imageLoad(base_color_a, pix));
colour *= base_color_a.rgb;
}
colour += imageLoad(emissive, pix).rgb;
colour = LINEARtoSRGB(colour);

View File

@ -174,6 +174,7 @@ struct PushConstants {
#define DEBUG_DISPLAY_EMISSIVE 3
#define DEBUG_DISPLAY_NSHADE 4
#define DEBUG_DISPLAY_NGEOM 5
#define DEBUG_DISPLAY_LIGHTING 6
// add more when needed
struct UniformBuffer {

View File

@ -6,6 +6,7 @@
#include "vk_staging.h"
#include "vk_const.h"
#include "vk_common.h"
#include "vk_cvar.h"
#include "vk_pipeline.h"
#include "vk_textures.h"
#include "vk_math.h"
@ -240,7 +241,9 @@ static qboolean createPipelines( void )
}
typedef struct {
uint32_t num_lights, pad[3];
uint32_t num_lights;
uint32_t debug_r_lightmap;
uint32_t padding_[2];
struct {
vec4_t pos_r;
vec4_t color;
@ -500,6 +503,7 @@ static uint32_t writeDlightsToUBO( void )
}
ubo_lights->num_lights = num_lights;
ubo_lights->debug_r_lightmap = r_lightmap->value != 0;
return ubo_lights_offset;
}

View File

@ -199,7 +199,11 @@ static void prepareUniformBuffer( const vk_ray_frame_render_args_t *args, int fr
ubo->frame_counter = frame_counter;
parseDebugDisplayValue();
ubo->debug_display_only = g_rtx.debug.rt_debug_display_only_value;
if (g_rtx.debug.rt_debug_display_only_value) {
ubo->debug_display_only = g_rtx.debug.rt_debug_display_only_value;
} else {
ubo->debug_display_only = r_lightmap->value != 0 ? DEBUG_DISPLAY_LIGHTING : DEBUG_DISPLAY_DISABLED;
}
}
typedef struct {