Skip to content

Commit

Permalink
vk: treat emissive animated texture frames as polylights
Browse files Browse the repository at this point in the history
Probably not the most optimal solution, but it works.

Fixes, #458
  • Loading branch information
w23 committed Aug 31, 2023
1 parent 9c4fd15 commit 1d9b987
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ref/vk/vk_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ static void fillWaterSurfaces( const cl_entity_t *ent, vk_brush_model_t *bmodel,
R_GeometryRangeUnlock( &geom_lock );
}

static rt_light_add_polygon_t loadPolyLight(const model_t *mod, const int surface_index, const msurface_t *surf, const vec3_t emissive);

static qboolean isSurfaceAnimated( const msurface_t *s, const struct texture_s *base_override ) {
const texture_t *base = base_override ? base_override : s->texinfo->texture;

Expand Down Expand Up @@ -668,7 +670,8 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co
// Update animated textures
int updated_textures_count = 0;
for (int i = 0; i < bmodel->animated_indexes_count; ++i) {
vk_render_geometry_t *geom = bmodel->render_model.geometries + bmodel->animated_indexes[i];
const int geom_index = bmodel->animated_indexes[i];
vk_render_geometry_t *geom = bmodel->render_model.geometries + geom_index;
const int surface_index = geom->surf_deprecate - mod->surfaces;
const xvk_patch_surface_t *const patch_surface = R_VkPatchGetSurface(surface_index);

Expand All @@ -683,6 +686,17 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co
g_brush.updated_textures[updated_textures_count++] = bmodel->animated_indexes[i];
}
}

// Animated textures can be emissive
// Add them as dynamic lights for now. It would probably be better if they were static lights (for worldmodel),
// but there's no easy way to do it for now.
vec3_t *emissive = &bmodel->render_model.geometries[geom_index].emissive;
if (RT_GetEmissiveForTexture(*emissive, geom->texture)) {
rt_light_add_polygon_t polylight = loadPolyLight(mod, surface_index, geom->surf_deprecate, *emissive);
polylight.dynamic = true;
polylight.transform_row = (const matrix3x4*)&transform;
RT_LightAddPolygon(&polylight);
}
}

if (updated_textures_count > 0) {
Expand Down
6 changes: 6 additions & 0 deletions ref/vk/vk_light.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "vk_staging.h"
#include "r_speeds.h"
#include "vk_logs.h"
#include "vk_framectl.h"

#include "mod_local.h"
#include "xash3d_mathlib.h"
Expand Down Expand Up @@ -1065,6 +1066,11 @@ static void addPolygonLeafSetToClusters(const vk_light_leaf_set_t *leafs, int po
}

int RT_LightAddPolygon(const rt_light_add_polygon_t *addpoly) {
// FIXME We're adding lights directly from vk_brush.c w/o knowing whether current frame is
// ray traced. If not, this will break.
if (addpoly->dynamic && !vk_frame.rtx_enabled)
return -1;

if (g_lights_.num_polygons == MAX_SURFACE_LIGHTS) {
ERR("Max number of polygon lights %d reached", MAX_SURFACE_LIGHTS);
return -1;
Expand Down

0 comments on commit 1d9b987

Please sign in to comment.