rtx: create new materials referenceable by "for" key, #291
This commit is contained in:
parent
f02e0a8b3a
commit
86b13716bf
|
@ -347,12 +347,18 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode )
|
|||
for (int i = 0; i < bmodel->render_model.num_geometries; ++i) {
|
||||
vk_render_geometry_t *geom = bmodel->render_model.geometries + i;
|
||||
const int surface_index = geom->surf - mod->surfaces;
|
||||
const struct texture_s *override = g_map_entities.patch.surfaces ? g_map_entities.patch.surfaces[surface_index].tex : NULL;
|
||||
const texture_t *t = R_TextureAnimation(ent, geom->surf, override);
|
||||
if (t->gl_texturenum < 0)
|
||||
continue;
|
||||
const xvk_patch_surface_t *patch_surface = g_map_entities.patch.surfaces ? g_map_entities.patch.surfaces+surface_index : NULL;
|
||||
|
||||
geom->texture = t->gl_texturenum;
|
||||
// Patch by constant texture index first, if it exists
|
||||
if (patch_surface && patch_surface->tex_id >= 0) {
|
||||
geom->texture = patch_surface->tex_id;
|
||||
} else {
|
||||
// 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, texture_override);
|
||||
if (t->gl_texturenum >= 0)
|
||||
geom->texture = t->gl_texturenum;
|
||||
}
|
||||
}
|
||||
|
||||
bmodel->render_model.render_mode = render_mode;
|
||||
|
@ -471,9 +477,6 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
|
|||
if (!renderableSurface(surf, surface_index))
|
||||
continue;
|
||||
|
||||
if (psurf && psurf->flags & Patch_Surface_Texture)
|
||||
tex_id = psurf->tex_id;
|
||||
|
||||
if (t != tex_id)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -348,6 +348,7 @@ static void addPatchSurface( const entity_props_t *props, uint32_t have_fields )
|
|||
const texture_t* const tex = map->textures[i];
|
||||
if (tex->gl_texturenum == tex_id) {
|
||||
psurf->tex = tex;
|
||||
psurf->tex_id = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,8 +83,13 @@ struct texture_s;
|
|||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
|
||||
// Static texture index in case there's no texture_s pointer
|
||||
int tex_id;
|
||||
|
||||
// Pointer to texture_s data (which also may include animation)
|
||||
const struct texture_s *tex;
|
||||
|
||||
vec3_t emissive;
|
||||
} xvk_patch_surface_t;
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ static void loadMaterialsFromFile( const char *filename ) {
|
|||
};
|
||||
int current_material_index = -1;
|
||||
qboolean force_reload = false;
|
||||
string current_for_name;
|
||||
|
||||
gEngine.Con_Reportf("Loading materials from %s\n", filename);
|
||||
|
||||
|
@ -65,6 +66,7 @@ static void loadMaterialsFromFile( const char *filename ) {
|
|||
if (key[0] == '{') {
|
||||
current_material = k_default_material;
|
||||
current_material_index = -1;
|
||||
current_for_name[0] = '\0';
|
||||
force_reload = false;
|
||||
continue;
|
||||
}
|
||||
|
@ -72,17 +74,17 @@ static void loadMaterialsFromFile( const char *filename ) {
|
|||
if (key[0] == '}') {
|
||||
qboolean create = false;
|
||||
if (current_material_index < 0) {
|
||||
if (current_material.tex_base_color < 0)
|
||||
if (Q_strlen(current_for_name) == 0)
|
||||
continue; // No basecolor_map value, cannot use it as a primary slot for this material
|
||||
|
||||
current_material_index = current_material.tex_base_color;
|
||||
current_material_index = XVK_CreateDummyTexture( current_for_name );
|
||||
create = true;
|
||||
} else {
|
||||
// If there's no explicit basecolor_map value, use the "for" target texture
|
||||
if (current_material.tex_base_color == -1)
|
||||
current_material.tex_base_color = current_material_index;
|
||||
}
|
||||
|
||||
// If there's no explicit basecolor_map value, use the "for" target texture
|
||||
if (current_material.tex_base_color == -1)
|
||||
current_material.tex_base_color = current_material_index;
|
||||
|
||||
gEngine.Con_Reportf("Creating%s material for texture %s(%d)\n", create?" new":"",
|
||||
findTexture(current_material_index)->name, current_material_index);
|
||||
|
||||
|
@ -97,6 +99,9 @@ static void loadMaterialsFromFile( const char *filename ) {
|
|||
|
||||
if (Q_stricmp(key, "for") == 0) {
|
||||
current_material_index = XVK_FindTextureNamedLike(value);
|
||||
if (current_material_index < 0) {
|
||||
Q_strncpy(current_for_name, value, sizeof(current_for_name));
|
||||
}
|
||||
} else if (Q_stricmp(key, "force_reload") == 0) {
|
||||
force_reload = Q_atoi(value) != 0;
|
||||
} else {
|
||||
|
|
|
@ -1044,3 +1044,20 @@ int XVK_FindTextureNamedLike( const char *texture_name ) {
|
|||
|
||||
return tex_id ? tex_id : -1;
|
||||
}
|
||||
|
||||
int XVK_CreateDummyTexture( const char *name ) {
|
||||
// emo-texture from quake1
|
||||
rgbdata_t *pic = Common_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR );
|
||||
|
||||
for( int y = 0; y < 16; y++ )
|
||||
{
|
||||
for( int x = 0; x < 16; x++ )
|
||||
{
|
||||
if(( y < 8 ) ^ ( x < 8 ))
|
||||
((uint *)pic->buffer)[y*16+x] = 0xFFFF00FF;
|
||||
else ((uint *)pic->buffer)[y*16+x] = 0xFF000000;
|
||||
}
|
||||
}
|
||||
|
||||
return VK_LoadTextureInternal(name, pic, TF_NOMIPMAP);
|
||||
}
|
||||
|
|
|
@ -78,3 +78,5 @@ void XVK_SetupSky( const char *skyboxname );
|
|||
// Full names depend on map name, wad name, etc. This function tries them all.
|
||||
// Returns -1 if not found
|
||||
int XVK_FindTextureNamedLike( const char *texture_name );
|
||||
|
||||
int XVK_CreateDummyTexture( const char *name );
|
||||
|
|
Loading…
Reference in New Issue