From cd4014766bc8d18ed965c28746e464e3d324a215 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Tue, 19 Sep 2023 13:20:04 -0400 Subject: [PATCH] vk: explicitly pass old original texture for trad renderer Fixes #571 --- ref/vk/vk_brush.c | 16 +++++++++++----- ref/vk/vk_render.c | 7 ++++--- ref/vk/vk_render.h | 4 ++++ ref/vk/vk_sprite.c | 1 + ref/vk/vk_studio.c | 1 + ref/vk/vk_triapi.c | 1 + 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ref/vk/vk_brush.c b/ref/vk/vk_brush.c index 11a1bfee..bde79110 100644 --- a/ref/vk/vk_brush.c +++ b/ref/vk/vk_brush.c @@ -279,6 +279,9 @@ static void brushComputeWaterPolys( compute_water_polys_t args ) { *args.dst_geometry = (vk_render_geometry_t){ .material = material_ref, .material_type_deprecated = kXVkMaterialRegular, + + .ye_olde_texture = tex_id, + .surf_deprecate = args.warp, .max_vertex = vertices, @@ -706,6 +709,7 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co 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 { APROF_SCOPE_DECLARE_BEGIN(brush_update_textures, "brush: update animated textures"); @@ -720,11 +724,11 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co // Optionally patch by texture_s pointer and run animations const struct texture_s *texture_override = patch_surface ? patch_surface->tex : NULL; const texture_t *t = R_TextureAnimation(ent, geom->surf_deprecate, texture_override); - const int tex_id = t->gl_texturenum; + const int new_tex_id = t->gl_texturenum; - const r_vk_material_ref_t new_material = R_VkMaterialGetForTexture(tex_id); - if (new_material.index >= 0 && new_material.index != geom->material.index) { - geom->material = new_material; + if (new_tex_id >= 0 && new_tex_id != geom->ye_olde_texture) { + geom->ye_olde_texture = new_tex_id; + geom->material = R_VkMaterialGetForTexture(new_tex_id); if (updated_textures_count < MAX_ANIMATED_TEXTURES) { g_brush.updated_textures[updated_textures_count++] = bmodel->animated_indexes[i]; } @@ -734,7 +738,7 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co // 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, tex_id)) { + if (RT_GetEmissiveForTexture(*emissive, new_tex_id)) { rt_light_add_polygon_t polylight = loadPolyLight(mod, surface_index, geom->surf_deprecate, *emissive); polylight.dynamic = true; polylight.transform_row = (const matrix3x4*)&transform; @@ -1041,6 +1045,7 @@ static qboolean fillBrushSurfaces(fill_geometries_args_t args) { const float sample_size = gEngine.Mod_SampleSizeForFace( surf ); int index_count = 0; vec3_t tangent; + const int orig_tex_id = surf->texinfo->texture->gl_texturenum; int tex_id = surf->texinfo->texture->gl_texturenum; const xvk_patch_surface_t *const psurf = R_VkPatchGetSurface(surface_index); @@ -1078,6 +1083,7 @@ static qboolean fillBrushSurfaces(fill_geometries_args_t args) { model_geometry->surf_deprecate = surf; model_geometry->material = R_VkMaterialGetForTexture(tex_id); + 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_render.c b/ref/vk/vk_render.c index ec01d265..0654d47b 100644 --- a/ref/vk/vk_render.c +++ b/ref/vk/vk_render.c @@ -723,8 +723,7 @@ static void submitToTraditionalRender( trad_submit_t args ) { for (int i = 0; i < args.geometries_count; ++i) { const vk_render_geometry_t *geom = args.geometries + i; - const r_vk_material_t *material = R_VkMaterialGet(geom->material); - const int tex = args.textures_override > 0 ? args.textures_override : material->tex_base_color; + const int tex = args.textures_override > 0 ? args.textures_override : geom->ye_olde_texture; const qboolean split = current_texture != tex || vertex_offset != geom->vertex_offset || (index_offset + element_count) != geom->index_offset; @@ -821,7 +820,9 @@ void R_RenderDrawOnce(r_draw_once_t args) { R_GeometryBufferUnlock( &buffer ); const vk_render_geometry_t geometry = { - .material = args.material, .material_type_deprecated = kXVkMaterialRegular, + .material = args.material, + .material_type_deprecated = kXVkMaterialRegular, + .ye_olde_texture = args.ye_olde_texture, .max_vertex = args.vertices_count, .vertex_offset = buffer.vertices.unit_offset, diff --git a/ref/vk/vk_render.h b/ref/vk/vk_render.h index d6eeccc1..6c23ab4a 100644 --- a/ref/vk/vk_render.h +++ b/ref/vk/vk_render.h @@ -47,6 +47,9 @@ typedef struct vk_render_geometry_s { XVkMaterialType_Deprecated material_type_deprecated; r_vk_material_ref_t material; + // Olde unpatched texture used for traditional renderer + int ye_olde_texture; + // for kXVkMaterialEmissive{,Glow} and others vec3_t emissive; } vk_render_geometry_t; @@ -157,6 +160,7 @@ typedef struct { int render_type; r_vk_material_ref_t material; + int ye_olde_texture; const vec4_t *emissive; const vec4_t *color; } r_draw_once_t; diff --git a/ref/vk/vk_sprite.c b/ref/vk/vk_sprite.c index 7df2de2e..6ad35ce9 100644 --- a/ref/vk/vk_sprite.c +++ b/ref/vk/vk_sprite.c @@ -105,6 +105,7 @@ static qboolean createQuadModel(void) { .material_type_deprecated = kXVkMaterialRegular, .material = R_VkMaterialGetForTexture(tglob.defaultTexture), + .ye_olde_texture = tglob.defaultTexture, .emissive = {1,1,1}, }; diff --git a/ref/vk/vk_studio.c b/ref/vk/vk_studio.c index 7326bcd8..afa7071f 100644 --- a/ref/vk/vk_studio.c +++ b/ref/vk/vk_studio.c @@ -1771,6 +1771,7 @@ static void buildSubmodelMeshGeometry( build_submodel_mesh_t args ) { *args.out_geometry = (vk_render_geometry_t){ .material = R_VkMaterialGetForTexture(args.texture), + .ye_olde_texture = args.texture, .material_type_deprecated = FBitSet( args.face_flags, STUDIO_NF_CHROME ) ? kXVkMaterialChrome : kXVkMaterialRegular, .vertex_offset = args.vertices_offset, diff --git a/ref/vk/vk_triapi.c b/ref/vk/vk_triapi.c index 656914ac..9d6b9fed 100644 --- a/ref/vk/vk_triapi.c +++ b/ref/vk/vk_triapi.c @@ -171,6 +171,7 @@ void TriEndEx( const vec4_t color, const char* name ) { .indices_count = num_indices, .render_type = g_triapi.render_type, .material = R_VkMaterialGetForTexture(g_triapi.texture_index), + .ye_olde_texture = g_triapi.texture_index, .emissive = (const vec4_t*)color, .color = (const vec4_t*)color, });