Skip to content

Commit

Permalink
vk: remove chrome material type; patch roughness manually instead
Browse files Browse the repository at this point in the history
Also, material struct is now embedded into geometry, so it can be
individually patched.
  • Loading branch information
w23 committed Sep 22, 2023
1 parent dce0598 commit 638bd16
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 46 deletions.
6 changes: 2 additions & 4 deletions ref/vk/vk_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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 );
}
Expand Down
13 changes: 2 additions & 11 deletions ref/vk/vk_materials.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
5 changes: 2 additions & 3 deletions ref/vk/vk_materials.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 );
7 changes: 1 addition & 6 deletions ref/vk/vk_ray_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion ref/vk/vk_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 2 additions & 18 deletions ref/vk/vk_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ref/vk/vk_sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
});
}

Expand Down
6 changes: 5 additions & 1 deletion ref/vk/vk_studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit 638bd16

Please sign in to comment.