From 10dab2f0218f2dc42cde20d79fa629b24b925550 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Fri, 19 Nov 2021 10:20:53 -0800 Subject: [PATCH] fix materials application to studio models, fix #216 1. make sure that it can find studio textures by name exactly (no wad or other weird prefixes necessary) 2. do not apply HACK_reflective to chrome that already has a patched material --- ref_vk/vk_materials.c | 11 ++++++++--- ref_vk/vk_materials.h | 3 +++ ref_vk/vk_ray_model.c | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ref_vk/vk_materials.c b/ref_vk/vk_materials.c index 426ff33a..f471003d 100644 --- a/ref_vk/vk_materials.c +++ b/ref_vk/vk_materials.c @@ -12,10 +12,13 @@ static struct { static int findTextureNamedLike( const char *texture_name ) { const model_t *map = gEngine.pfnGetModelByIndex( 1 ); string texname; - int tex_id; - // Try bsp texture first - tex_id = XVK_TextureLookupF("#%s:%s.mip", map->name, texture_name); + // Try texture name as-is first + int tex_id = XVK_TextureLookupF("%s", texture_name); + + // Try bsp name + if (!tex_id) + tex_id = XVK_TextureLookupF("#%s:%s.mip", map->name, texture_name); if (!tex_id) { const char *wad = g_map_entities.wadlist; @@ -90,6 +93,7 @@ static void loadMaterialsFromFile( const char *filename ) { if (current_material.base_color == -1) current_material.base_color = current_material_index; g_materials.materials[current_material_index] = current_material; + g_materials.materials[current_material_index].set = true; } continue; } @@ -141,6 +145,7 @@ void XVK_ReloadMaterials( void ) { mat->metalness = tglob.blackTexture; mat->roughness = tglob.whiteTexture; mat->normalmap = 0; + mat->set = false; } loadMaterialsFromFile( "pbr/materials.mat" ); diff --git a/ref_vk/vk_materials.h b/ref_vk/vk_materials.h index 0b729704..b6624850 100644 --- a/ref_vk/vk_materials.h +++ b/ref_vk/vk_materials.h @@ -1,10 +1,13 @@ #pragma once +#include "xash3d_types.h" + typedef struct { int base_color; int roughness; int metalness; int normalmap; + qboolean set; } xvk_material_t; void XVK_ReloadMaterials( void ); diff --git a/ref_vk/vk_ray_model.c b/ref_vk/vk_ray_model.c index 5389a767..210606d6 100644 --- a/ref_vk/vk_ray_model.c +++ b/ref_vk/vk_ray_model.c @@ -375,7 +375,7 @@ void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render // FIXME also this erases previous roughness unconditionally if (HACK_reflective) { kusok->tex_roughness = tglob.blackTexture; - } else if (geom->material == kXVkMaterialChrome) { + } else if (!mat->set && geom->material == kXVkMaterialChrome) { kusok->tex_roughness = tglob.grayTexture; }