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
This commit is contained in:
Ivan Avdeev 2021-11-19 10:20:53 -08:00 committed by Ivan Avdeev
parent 10c48e86b3
commit 10dab2f021
3 changed files with 12 additions and 4 deletions

View File

@ -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" );

View File

@ -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 );

View File

@ -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;
}