Skip to content

Commit

Permalink
Merge pull request #651 from w23/stream-E331
Browse files Browse the repository at this point in the history
E331: make water emissive again

- [x] Make acid water surfaces emissive again.
- [x] Update emissive color for them, fix #56
  • Loading branch information
w23 authored Nov 16, 2023
2 parents 1040a96 + b21a824 commit 5f83cb1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
8 changes: 7 additions & 1 deletion ref/vk/TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 2023-11-16 E331
- [x] Emissive waters
- [x] add emissive water surface to polygon lights
- [x] update emissive color for water surfaces
- [ ] dynamic UVs
- [ ] discuss integration test strategies

# 2023-11-14 E330
- [x] culling worldmodel waters
- [-] try simple flag culling (probably won't work)
Expand All @@ -8,7 +15,6 @@
- [x] water -- doesn't seem to have 2nd face
- [x] glpoly_t winding order is reversed when camera origin is opposite to (SURF_PLANEBACK-aware) surface normal
- [x] discuss culling transparent surfaces strategies
- [ ] discuss integration test strategies

# 2023-11-13 E329
- [-] culling -> need to cull everything except opaque and blend. Alpha-mask is culled.
Expand Down
22 changes: 17 additions & 5 deletions ref/vk/vk_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,6 @@ static qboolean fillBrushSurfaces(fill_geometries_args_t args) {
const xvk_mapent_func_any_t *const entity_patch = getModelFuncAnyPatch(args.mod);
connectVertices(args.mod, entity_patch ? entity_patch->smooth_entire_model : false);


// Load sorted by gl_texturenum
// TODO this does not make that much sense in vulkan (can sort later)
for (int t = 0; t <= args.sizes.max_texture_id; ++t) {
Expand Down Expand Up @@ -1457,6 +1456,8 @@ static qboolean createRenderModel( const model_t *mod, vk_brush_model_t *bmodel,

vk_render_geometry_t *const geometries = Mem_Malloc(vk_core.pool, sizeof(vk_render_geometry_t) * sizes.num_surfaces);
bmodel->surface_to_geometry_index = Mem_Malloc(vk_core.pool, sizeof(int) * mod->nummodelsurfaces);
for (int i = 0; i < mod->nummodelsurfaces; ++i)
bmodel->surface_to_geometry_index[i] = -1;
bmodel->animated_indexes = Mem_Malloc(vk_core.pool, sizeof(int) * sizes.animated_count);
bmodel->animated_indexes_count = sizes.animated_count;

Expand Down Expand Up @@ -1654,6 +1655,8 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
switch (getSurfaceType(surf, surface_index, is_worldmodel)) {
case BrushSurface_Regular:
case BrushSurface_Animated:
case BrushSurface_Water:
// No known cases, also needs to be dynamic case BrushSurface_WaterSide:
break;
default:
continue;
Expand Down Expand Up @@ -1687,6 +1690,7 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
}

// Clear old per-geometry emissive values. The new emissive values will be assigned by the loop below only to the relevant geoms
// This is relevant for updating lights during development
for (int i = 0; i < bmodel->render_model.num_geometries; ++i) {
vk_render_geometry_t *const geom = bmodel->render_model.geometries + i;
VectorClear(geom->emissive);
Expand All @@ -1701,6 +1705,7 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
}

// Apply all emissive surfaces found
int geom_indices_count = 0;
for (int i = 0; i < emissive_surfaces_count; ++i) {
const emissive_surface_t* const s = emissive_surfaces + i;

Expand All @@ -1726,9 +1731,16 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
}

// Assign the emissive value to the right geometry
const int geom_index = bmodel->surface_to_geometry_index[s->model_surface_index];
geom_indices[i] = geom_index;
VectorCopy(polylight.emissive, bmodel->render_model.geometries[geom_index].emissive);
if (bmodel->surface_to_geometry_index) { // Can be absent for water-only models
const int geom_index = bmodel->surface_to_geometry_index[s->model_surface_index];
if (geom_index != -1) { // can be missing for water surfaces
ASSERT(geom_index >= 0);
ASSERT(geom_index < bmodel->render_model.num_geometries);
ASSERT(geom_indices_count < COUNTOF(geom_indices));
geom_indices[geom_indices_count++] = geom_index;
VectorCopy(polylight.emissive, bmodel->render_model.geometries[geom_index].emissive);
}
}
}

if (emissive_surfaces_count > 0) {
Expand All @@ -1746,7 +1758,7 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
R_VkStagingFlushSync();
}

R_RenderModelUpdateMaterials(&bmodel->render_model, geom_indices, emissive_surfaces_count);
R_RenderModelUpdateMaterials(&bmodel->render_model, geom_indices, geom_indices_count);
INFO("Loaded %d polylights for %s model %s", emissive_surfaces_count, is_static ? "static" : "movable", mod->name);
}
}
Expand Down
15 changes: 14 additions & 1 deletion ref/vk/vk_ray_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,20 @@ void RT_ModelDestroy(struct rt_model_s* model) {
}

qboolean RT_ModelUpdate(struct rt_model_s *model, const struct vk_render_geometry_s *geometries, int geometries_count) {
return RT_BlasBuild(model->blas, geometries, geometries_count);
// TODO: It might be beneficial to be able to supply which parts of the RT model should be updated.
// E.g.:
// - A flag to update BLAS (not all model updates need BLAS updates, e.g. waveHeight=0 water updates
// only update UVs)
// - A flag to update kusochki. Not all updates update offsets and textures, e.g. studio models have
// stable textures that don't change.

// Schedule rebuilding blas
if (!RT_BlasBuild(model->blas, geometries, geometries_count))
return false;

// Also update materials
RT_KusochkiUpload(model->kusochki.offset, geometries, geometries_count, NULL, NULL);
return true;
}

qboolean RT_ModelUpdateMaterials(struct rt_model_s *model, const struct vk_render_geometry_s *geometries, int geometries_count, const int *geom_indices, int geom_indices_count) {
Expand Down

0 comments on commit 5f83cb1

Please sign in to comment.