diff --git a/ref/vk/vk_brush.c b/ref/vk/vk_brush.c index 75c2c6650..cd84eb665 100644 --- a/ref/vk/vk_brush.c +++ b/ref/vk/vk_brush.c @@ -275,10 +275,9 @@ static void brushComputeWaterPolys( compute_water_polys_t args ) { // Render const int tex_id = args.warp->texinfo->texture->gl_texturenum; - const r_vk_material_ref_t material_ref = R_VkMaterialGetForTexture(tex_id); + const r_vk_material_t material = R_VkMaterialGetForTexture(tex_id); *args.dst_geometry = (vk_render_geometry_t){ - .material = material_ref, - .material_type_deprecated = kXVkMaterialRegular, + .material = material, .ye_olde_texture = tex_id, @@ -1091,7 +1090,6 @@ static qboolean fillBrushSurfaces(fill_geometries_args_t args) { model_geometry->index_offset = index_offset; { - model_geometry->material_type_deprecated = kXVkMaterialRegular; ASSERT(!FBitSet( surf->flags, SURF_DRAWTILED )); VK_CreateSurfaceLightmap( surf, args.mod ); } diff --git a/ref/vk/vk_materials.c b/ref/vk/vk_materials.c index f3de6d1e8..fd3e6d09d 100644 --- a/ref/vk/vk_materials.c +++ b/ref/vk/vk_materials.c @@ -264,18 +264,9 @@ void R_VkMaterialsReload( void ) { } } -r_vk_material_ref_t R_VkMaterialGetForTexture( int tex_index ) { +r_vk_material_t R_VkMaterialGetForTexture( int tex_index ) { ASSERT(tex_index >= 0); ASSERT(tex_index < MAX_TEXTURES); - // TODO add versioning to detect reloads? - return (r_vk_material_ref_t){ .index = tex_index, }; -} - -const r_vk_material_t* R_VkMaterialGet( r_vk_material_ref_t ref ) { - ASSERT(ref.index >= 0); - ASSERT(ref.index < MAX_TEXTURES); - - // TODO verify version ? - return g_materials.materials + ref.index; + return g_materials.materials[tex_index]; } diff --git a/ref/vk/vk_materials.h b/ref/vk/vk_materials.h index 294c60106..bf7cfec17 100644 --- a/ref/vk/vk_materials.h +++ b/ref/vk/vk_materials.h @@ -13,6 +13,7 @@ typedef struct r_vk_material_s { float metalness; float normal_scale; + // TODO this should be internal qboolean set; } r_vk_material_t; @@ -22,6 +23,4 @@ typedef struct { int index; } r_vk_material_ref_t; // TODO: track "version" in high bits? void R_VkMaterialsReload( void ); -r_vk_material_ref_t R_VkMaterialGetForTexture( int tex_id ); - -const r_vk_material_t* R_VkMaterialGet( r_vk_material_ref_t ref ); +r_vk_material_t R_VkMaterialGetForTexture( int tex_id ); diff --git a/ref/vk/vk_ray_model.c b/ref/vk/vk_ray_model.c index 9543c03d5..26bf3173e 100644 --- a/ref/vk/vk_ray_model.c +++ b/ref/vk/vk_ray_model.c @@ -26,7 +26,7 @@ typedef struct rt_model_s { } rt_model_t; static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometry_t *geom, const r_vk_material_t *override_material, const vec4_t override_color) { - const r_vk_material_t *const mat = override_material ? override_material : R_VkMaterialGet(geom->material); + const r_vk_material_t *const mat = override_material ? override_material : &geom->material; ASSERT(mat); // TODO split kusochki into static geometry data and potentially dynamic material data @@ -56,11 +56,6 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr kusok->material.base_color[2] *= override_color[2]; kusok->material.base_color[3] *= override_color[3]; } - - // TODO should be patched by the Chrome material source itself to generate a static chrome material - const qboolean HACK_chrome = geom->material_type_deprecated == kXVkMaterialChrome; - if (!mat->set && HACK_chrome) - kusok->material.tex_roughness = tglob.grayTexture; } // TODO utilize uploadKusochki([1]) to avoid 2 copies of staging code diff --git a/ref/vk/vk_render.c b/ref/vk/vk_render.c index 0654d47b5..6980a8f67 100644 --- a/ref/vk/vk_render.c +++ b/ref/vk/vk_render.c @@ -821,7 +821,6 @@ void R_RenderDrawOnce(r_draw_once_t args) { const vk_render_geometry_t geometry = { .material = args.material, - .material_type_deprecated = kXVkMaterialRegular, .ye_olde_texture = args.ye_olde_texture, .max_vertex = args.vertices_count, diff --git a/ref/vk/vk_render.h b/ref/vk/vk_render.h index 3e9a2dc29..1803a3aad 100644 --- a/ref/vk/vk_render.h +++ b/ref/vk/vk_render.h @@ -10,21 +10,6 @@ void VK_RenderShutdown( void ); struct ref_viewpass_s; void VK_RenderSetupCamera( const struct ref_viewpass_s *rvp ); -// Quirk for passing surface type to the renderer -// xash3d does not really have a notion of materials. Instead there are custom code paths -// for different things. There's also render_mode for entities which determine blending mode -// and stuff. -// For ray tracing we do need to assing a material to each rendered surface, so we need to -// figure out what it is given heuristics like render_mode, texture name, surface flags, source entity type, etc. -typedef enum { - kXVkMaterialRegular = 0, - - // Set for chrome studio submodels. - // Used: ray tracing sets gray roughness texture to get smooth surface look. - // Remove: Have an explicit material for chrome surfaces. - kXVkMaterialChrome, -} XVkMaterialType_Deprecated; - typedef struct vk_render_geometry_s { int index_offset, vertex_offset; @@ -39,8 +24,7 @@ typedef struct vk_render_geometry_s { const struct msurface_s *surf_deprecate; // If this geometry is special, it will have a material type override - XVkMaterialType_Deprecated material_type_deprecated; - r_vk_material_ref_t material; + r_vk_material_t material; // Olde unpatched texture used for traditional renderer int ye_olde_texture; @@ -154,7 +138,7 @@ typedef struct { int vertices_count, indices_count; int render_type; - r_vk_material_ref_t material; + r_vk_material_t material; int ye_olde_texture; const vec4_t *emissive; const vec4_t *color; diff --git a/ref/vk/vk_sprite.c b/ref/vk/vk_sprite.c index 6ad35ce98..d593464a4 100644 --- a/ref/vk/vk_sprite.c +++ b/ref/vk/vk_sprite.c @@ -103,7 +103,6 @@ static qboolean createQuadModel(void) { .element_count = 6, .index_offset = g_sprite.quad.geom.indices.unit_offset, - .material_type_deprecated = kXVkMaterialRegular, .material = R_VkMaterialGetForTexture(tglob.defaultTexture), .ye_olde_texture = tglob.defaultTexture, .emissive = {1,1,1}, @@ -799,13 +798,14 @@ static void R_DrawSpriteQuad( const char *debug_name, const mspriteframe_t *fram Matrix4x4_CreateFromVectors(transform, right, up, v_normal, org); const vk_render_type_e render_type = spriteRenderModeToRenderType(render_mode); + const r_vk_material_t material_override = R_VkMaterialGetForTexture(texture); R_RenderModelDraw(&g_sprite.quad.model, (r_model_draw_t){ .render_type = render_type, .color = (const vec4_t*)color, .transform = &transform, .prev_transform = &transform, - .material_override = R_VkMaterialGet(R_VkMaterialGetForTexture(texture)), + .material_override = &material_override, }); } diff --git a/ref/vk/vk_studio.c b/ref/vk/vk_studio.c index afa7071f9..ace22623f 100644 --- a/ref/vk/vk_studio.c +++ b/ref/vk/vk_studio.c @@ -1772,7 +1772,6 @@ 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, .max_vertex = num_vertices, @@ -1783,6 +1782,11 @@ static void buildSubmodelMeshGeometry( build_submodel_mesh_t args ) { .emissive = {0, 0, 0}, }; + if (!args.out_geometry->material.set && FBitSet( args.face_flags, STUDIO_NF_CHROME )) { + // TODO configurable + args.out_geometry->material.roughness = tglob.grayTexture; + } + *args.out_vertices_count += num_vertices; *args.out_indices_count += num_indices; }