From 6bfa4c90fac80ce8a56b47e491f6cd07530a2804 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Mon, 2 Oct 2023 11:39:00 -0400 Subject: [PATCH] vk: brush: assign white texture for kRenderTransColor kRenderTransColor mode strips geometry of its texture and makes it solid color. Previously we were noticing this rendermode late, and failed to update the textures. Now we depend on reading this rendermode from map entities, and pre-assigning correct (white) textures on load. Assumes that rendermode doesn't change at runtime for brush models. Fixes #528 --- ref/vk/vk_brush.c | 24 +++++++++++------------- ref/vk/vk_materials.c | 23 ++++++++++++++--------- ref/vk/vk_materials.h | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/ref/vk/vk_brush.c b/ref/vk/vk_brush.c index 1f3bec6a..82fc9a9e 100644 --- a/ref/vk/vk_brush.c +++ b/ref/vk/vk_brush.c @@ -730,16 +730,8 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co if (bmodel->render_model.num_geometries == 0) return; - // TransColor means ignore textures and draw just color - if (render_mode == kRenderTransColor) { - // TODO cache previous render_mode. - // TODO also it will break switching render type from TransColor to anyting else -- textures will be stuck at white - for (int i = 0; i < bmodel->render_model.num_geometries; ++i) { - vk_render_geometry_t *geom = bmodel->render_model.geometries + i; - geom->material = R_VkMaterialGetForTexture(tglob.whiteTexture); - geom->ye_olde_texture = tglob.whiteTexture; - } - } else { + // Animate textures + { APROF_SCOPE_DECLARE_BEGIN(brush_update_textures, "brush: update animated textures"); // Update animated textures int updated_textures_count = 0; @@ -1121,6 +1113,8 @@ static qboolean fillBrushSurfaces(fill_geometries_args_t args) { return false; } + model_geometry->ye_olde_texture = orig_tex_id; + qboolean material_assigned = false; if (entity_patch) { for (int i = 0; i < entity_patch->matmap_count; ++i) { @@ -1132,8 +1126,13 @@ static qboolean fillBrushSurfaces(fill_geometries_args_t args) { } if (!material_assigned && entity_patch->rendermode > 0) { - model_geometry->material = R_VkMaterialGetEx(tex_id, entity_patch->rendermode); - material_assigned = true; + material_assigned = R_VkMaterialGetEx(tex_id, entity_patch->rendermode, &model_geometry->material); + if (!material_assigned && entity_patch->rendermode == kRenderTransColor) { + // TransColor means ignore textures and draw just color + model_geometry->material = R_VkMaterialGetForTexture(tglob.whiteTexture); + model_geometry->ye_olde_texture = tglob.whiteTexture; + material_assigned = true; + } } } @@ -1145,7 +1144,6 @@ static qboolean fillBrushSurfaces(fill_geometries_args_t args) { VectorClear(model_geometry->emissive); model_geometry->surf_deprecate = surf; - model_geometry->ye_olde_texture = orig_tex_id; model_geometry->vertex_offset = args.base_vertex_offset; model_geometry->max_vertex = vertex_offset + surf->numedges; diff --git a/ref/vk/vk_materials.c b/ref/vk/vk_materials.c index 13daeca7..252107cf 100644 --- a/ref/vk/vk_materials.c +++ b/ref/vk/vk_materials.c @@ -361,18 +361,23 @@ r_vk_material_t R_VkMaterialGetForRef( r_vk_material_ref_t ref ) { return g_materials.materials[ref.index]; } -r_vk_material_t R_VkMaterialGetEx( int tex_id, int rendermode ) { +qboolean R_VkMaterialGetEx( int tex_id, int rendermode, r_vk_material_t *out_material ) { DEBUG("Getting material for tex_id=%d rendermode=%d", tex_id, rendermode); - if (rendermode > 0) { - ASSERT(rendermode < COUNTOF(g_materials.rendermode)); - const r_vk_material_per_mode_t* const mode = &g_materials.rendermode[rendermode]; - for (int i = 0; i < mode->count; ++i) { - if (mode->materials[i].tex_id == tex_id) - return mode->materials[i].mat; + if (rendermode == 0) { + WARN("rendermode==0: fallback to regular tex_id=%d", tex_id); + *out_material = R_VkMaterialGetForTexture(tex_id); + return true; + } + + ASSERT(rendermode < COUNTOF(g_materials.rendermode)); + const r_vk_material_per_mode_t* const mode = &g_materials.rendermode[rendermode]; + for (int i = 0; i < mode->count; ++i) { + if (mode->materials[i].tex_id == tex_id) { + *out_material = mode->materials[i].mat; + return true; } } - DEBUG("Fallback to regular tex_id=%d", tex_id); - return R_VkMaterialGetForTexture(tex_id); + return false; } diff --git a/ref/vk/vk_materials.h b/ref/vk/vk_materials.h index 16844902..b7c8626d 100644 --- a/ref/vk/vk_materials.h +++ b/ref/vk/vk_materials.h @@ -28,7 +28,7 @@ void R_VkMaterialsLoadForModel( const struct model_s* mod ); r_vk_material_t R_VkMaterialGetForTexture( int tex_id ); -r_vk_material_t R_VkMaterialGetEx( int tex_id, int rendermode ); +qboolean R_VkMaterialGetEx( int tex_id, int rendermode, r_vk_material_t *out_material ); r_vk_material_ref_t R_VkMaterialGetForName( const char *name ); r_vk_material_t R_VkMaterialGetForRef( r_vk_material_ref_t ref );