rtx: collect static surface lights only once on map load, fix #122

also fix buffer overflow on >255 lights
This commit is contained in:
Ivan 'provod' Avdeev 2021-10-24 11:21:22 -07:00 committed by Ivan Avdeev
parent 452ca9de45
commit 4d78c44ed6
7 changed files with 34 additions and 10 deletions

View File

@ -1,12 +1,14 @@
## 2021-10-24 E155
- [ ] rtx: static lights
- [x] point lights
- [ ] surface lights
- [x] surface lights
- [ ] remove surface visibility cache
- [ ] rtx: remove lbsp
- [ ] rtx: rename point lights to lampochki
- [ ] rtx: move entity parsing to its own module
# Next
- [ ] rtx: rename emissive surface to surface lights
- [ ] rtx: configuration that includes texture name -> pbr params mapping, etc. Global, per-map, ...
- [ ] rtx: better light culling: normal, bsp visibility, light volumes and intensity, sort by intensity, etc
- [ ] rtx: simple convolution denoise (bilateral?)

View File

@ -249,7 +249,6 @@ vec3 computeLighting(vec3 throughput, vec3 view_dir, MaterialProperties material
const EmissiveKusok ek = lights.kusochki[index_into_emissive_kusochki];
const uint emissive_kusok_index = lights.kusochki[index_into_emissive_kusochki].kusok_index;
const Kusok ekusok = kusochki[emissive_kusok_index];
const vec3 emissive = ekusok.emissive;
// TODO streamline matrices layouts
const mat4x3 emissive_transform = mat4x3(
@ -265,7 +264,7 @@ vec3 computeLighting(vec3 throughput, vec3 view_dir, MaterialProperties material
continue;
const uint triangle_index = rand_range(ekusok.triangles);
C += sampling_light_scale * sampleSurfaceTriangle(throughput * payload.base_color * emissive, view_dir, material, emissive_transform, emissive_transform_normal, triangle_index, ekusok.index_offset, ekusok.vertex_offset);
C += sampling_light_scale * sampleSurfaceTriangle(throughput * payload.base_color * ek.emissive, view_dir, material, emissive_transform, emissive_transform_normal, triangle_index, ekusok.index_offset, ekusok.vertex_offset);
} // for all emissive kusochki
C += computePointLights(cluster_index, throughput, view_dir, material);

View File

@ -31,6 +31,7 @@ struct Kusok {
// Material
uint texture;
// TODO the color is per-model, not per-kusok
vec4 color;
vec3 emissive;
@ -50,6 +51,8 @@ struct PointLight {
struct EmissiveKusok {
uint kusok_index;
PAD(3)
vec3 emissive;
PAD(1)
vec4 tx_row_x, tx_row_y, tx_row_z;
};

View File

@ -10,9 +10,9 @@
#define MAX_BUFFER_INDICES (MAX_BUFFER_VERTICES * 3)
// indexed by uint8_t
#define MAX_SURFACE_LIGHTS 255
#define MAX_SURFACE_LIGHTS 256
// indexed by uint8_t
#define MAX_POINT_LIGHTS 255
#define MAX_POINT_LIGHTS 256
// indexed by uint8_t
#define MAX_VISIBLE_POINT_LIGHTS 31

View File

@ -866,8 +866,6 @@ void VK_LightsNewMap( void ) {
clusterBitMapInit();
prepareSurfacesLeafVisibilityCache();
VK_LightsLoadMapStaticLights();
}
void VK_LightsFrameInit( void ) {
@ -1232,6 +1230,8 @@ static void processStaticPointLights( void ) {
void VK_LightsLoadMapStaticLights( void ) {
const model_t *map = gEngine.pfnGetModelByIndex( 1 );
//debug_dump_lights.enabled = true;
// Clear static lights counts
{
g_lights.num_emissive_surfaces = g_lights.num_static.emissive_surfaces = 0;
@ -1261,7 +1261,20 @@ void VK_LightsLoadMapStaticLights( void ) {
loadRadData( map, "%.*s.rad", name_len, map->name );
}
// FIXME load static map model
// Load static map model
{
matrix3x4 xform;
Matrix3x4_LoadIdentity(xform);
const vk_brush_model_t *const bmodel = map->cache.data;
ASSERT(bmodel);
for (int i = 0; i < bmodel->render_model.num_geometries; ++i) {
const vk_render_geometry_t *geom = bmodel->render_model.geometries + i;
if (!VK_LightsAddEmissiveSurface( geom, &xform, true )) {
// TODO how to differentiate between this and non-emissive gEngine.Con_Printf(S_ERROR "Ran out of surface light slots, geom %d of %d\n", i, bmodel->render_model.num_geometries);
}
}
}
// Fix static counts
{

View File

@ -669,8 +669,12 @@ static void updateLights( void )
ASSERT(g_lights.num_emissive_surfaces <= MAX_EMISSIVE_KUSOCHKI);
lights->num_kusochki = g_lights.num_emissive_surfaces;
for (int i = 0; i < g_lights.num_emissive_surfaces; ++i) {
lights->kusochki[i].kusok_index = g_lights.emissive_surfaces[i].kusok_index;
Matrix3x4_Copy(lights->kusochki[i].tx_row_x, g_lights.emissive_surfaces[i].transform);
const vk_emissive_surface_t *const src_esurf = g_lights.emissive_surfaces + i;
struct EmissiveKusok *const dst_ekusok = lights->kusochki + i;
dst_ekusok->kusok_index = src_esurf->kusok_index;
Matrix3x4_Copy(dst_ekusok->tx_row_x, src_esurf->transform);
VectorCopy(src_esurf->emissive, dst_ekusok->emissive);
}
lights->num_point_lights = g_lights.num_point_lights;

View File

@ -142,6 +142,9 @@ void R_NewMap( void )
}
}
// After we've loaded map brush model, we can proceed with loading static surface lights
VK_LightsLoadMapStaticLights();
if (vk_core.rtx)
{
const VkSubmitInfo subinfo = {