rt: propagate emissive color patches to kusochki

Fixes #330

Also, fix incorrect patch application introduced by previous commit, it
would not read the patch color value, and could only switch the light
off.
This commit is contained in:
Ivan Avdeev 2023-03-02 23:23:31 -08:00
parent a284567002
commit 4f2eb7680b
4 changed files with 40 additions and 23 deletions

View File

@ -24,6 +24,7 @@
typedef struct vk_brush_model_s {
vk_render_model_t render_model;
int num_water_surfaces;
int *surface_to_geometry_index;
} vk_brush_model_t;
static struct {
@ -218,6 +219,9 @@ static void EmitWaterPolys( const cl_entity_t *ent, const msurface_t *warp, qboo
// Render
{
vec3_t emissive;
RT_GetEmissiveForTexture(emissive, warp->texinfo->texture->gl_texturenum);
const vk_render_geometry_t geometry = {
.texture = warp->texinfo->texture->gl_texturenum, // FIXME assert >= 0
.material = kXVkMaterialWater,
@ -228,6 +232,7 @@ static void EmitWaterPolys( const cl_entity_t *ent, const msurface_t *warp, qboo
.element_count = num_indices,
.index_offset = buffer.indices.unit_offset,
.emissive = {emissive[0], emissive[1], emissive[2]},
};
VK_RenderModelDynamicAddGeometry( &geometry );
@ -526,6 +531,8 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
if (t != tex_id)
continue;
bmodel->surface_to_geometry_index[i] = num_geometries;
++num_geometries;
//gEngine.Con_Reportf( "surface %d: numverts=%d numedges=%d\n", i, surf->polys ? surf->polys->numverts : -1, surf->numedges );
@ -537,6 +544,8 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
return false;
}
VectorClear(model_geometry->emissive);
model_geometry->surf = surf;
model_geometry->texture = tex_id;
@ -647,7 +656,8 @@ qboolean VK_BrushModelLoad( model_t *mod ) {
const model_sizes_t sizes = computeSizes( mod );
const size_t model_size =
sizeof(vk_brush_model_t) +
sizeof(vk_render_geometry_t) * sizes.num_surfaces;
sizeof(vk_render_geometry_t) * sizes.num_surfaces +
sizeof(int) * mod->nummodelsurfaces;
vk_brush_model_t *bmodel = Mem_Calloc(vk_core.pool, model_size);
mod->cache.data = bmodel;
@ -659,6 +669,7 @@ qboolean VK_BrushModelLoad( model_t *mod ) {
if (sizes.num_surfaces != 0) {
bmodel->render_model.geometries = (vk_render_geometry_t*)((char*)(bmodel + 1));
bmodel->surface_to_geometry_index = (int*)((char*)(bmodel->render_model.geometries + sizes.num_surfaces));
if (!loadBrushSurfaces(sizes, mod) || !VK_RenderModelInit(&bmodel->render_model)) {
gEngine.Con_Printf(S_ERROR "Could not load model %s\n", mod->name);
@ -733,10 +744,20 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
continue;
const int tex_id = surf->texinfo->texture->gl_texturenum; // TODO animation?
const xvk_patch_surface_t *const psurf = R_VkPatchGetSurface(surface_index);
vec3_t emissive;
if ((psurf && (psurf->flags & Patch_Surface_Emissive)) || (RT_GetEmissiveForTexture(emissive, tex_id))) {
const xvk_patch_surface_t *const psurf = R_VkPatchGetSurface(surface_index);
if (psurf && (psurf->flags & Patch_Surface_Emissive)) {
VectorCopy(psurf->emissive, emissive);
} else if (RT_GetEmissiveForTexture(emissive, tex_id)) {
// emissive
} else {
// not emissive, continue to the next
continue;
}
//gEngine.Con_Reportf("%d: i=%d surf_index=%d patch=%d(%#x) => emissive=(%f,%f,%f)\n", emissive_surfaces_count, i, surface_index, !!psurf, psurf?psurf->flags:0, emissive[0], emissive[1], emissive[2]);
if (emissive_surfaces_count == MAX_SURFACE_LIGHTS) {
gEngine.Con_Printf(S_ERROR "Too many emissive surfaces for model %s: max=%d\n", mod->name, MAX_SURFACE_LIGHTS);
break;
@ -748,7 +769,6 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
surface->surf = surf;
VectorCopy(emissive, surface->emissive);
}
}
vk_brush_model_t *const bmodel = mod->cache.data;
ASSERT(bmodel);
@ -769,6 +789,8 @@ void R_VkBrushModelCollectEmissiveSurfaces( const struct model_s *mod, qboolean
} else {
RT_LightAddPolygon(&polylight);
}
VectorCopy(polylight.emissive, bmodel->render_model.geometries[bmodel->surface_to_geometry_index[s->model_surface_index]].emissive);
}
gEngine.Con_Reportf("Loaded %d polylights for %smodel %s\n", emissive_surfaces_count, is_worldmodel ? "world" : "movable ", mod->name);

View File

@ -164,9 +164,6 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr
kusok->index_offset = geom->index_offset;
kusok->triangles = geom->element_count / 3;
/* if (!render_model->static_map) */
/* VK_LightsAddEmissiveSurface( geom, transform_row, false ); */
kusok->tex_base_color = mat->tex_base_color;
kusok->tex_roughness = mat->tex_roughness;
kusok->tex_metalness = mat->tex_metalness;
@ -200,11 +197,7 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr
Vector4Copy(gcolor, kusok->color);
}
if (geom->material == kXVkMaterialEmissive || geom->material == kXVkMaterialEmissiveGlow) {
VectorCopy(geom->emissive, kusok->emissive);
} else {
RT_GetEmissiveForTexture( kusok->emissive, geom->texture );
}
/* FIXME these should be done in a different way
if (geom->material == kXVkMaterialConveyor) {

View File

@ -55,7 +55,7 @@ typedef struct vk_render_geometry_s {
// - updating dynamic lights (TODO: can decouple from surface/brush models by providing texture_id and aabb directly here)
const struct msurface_s *surf;
// for kXVkMaterialEmissive
// for kXVkMaterialEmissive{,Glow} and others
vec3_t emissive;
} vk_render_geometry_t;

View File

@ -2021,6 +2021,8 @@ static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float
.index_offset = buffer.indices.unit_offset,
.element_count = num_indices,
.emissive = {0, 0, 0},
};
VK_RenderModelDynamicAddGeometry( &geometry );