Skip to content

Commit

Permalink
rt: remove a bunch of extra material flags
Browse files Browse the repository at this point in the history
These are either unused, or their meaning can be recovered through other
means.
  • Loading branch information
w23 committed Apr 22, 2023
1 parent 41b033e commit 935c2e7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 87 deletions.
2 changes: 1 addition & 1 deletion ref/vk/vk_beams.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f
{
const vk_render_geometry_t geometry = {
.texture = texture,
.material = kXVkMaterialEmissive,
.material = kXVkMaterialRegular,

.max_vertex = total_vertices,
.vertex_offset = buffer.vertices.unit_offset,
Expand Down
5 changes: 3 additions & 2 deletions ref/vk/vk_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static void EmitWaterPolys( const cl_entity_t *ent, const msurface_t *warp, qboo

const vk_render_geometry_t geometry = {
.texture = warp->texinfo->texture->gl_texturenum, // FIXME assert >= 0
.material = kXVkMaterialWater,
.material = kXVkMaterialRegular,
.surf_deprecate = warp,

.max_vertex = num_vertices,
Expand Down Expand Up @@ -570,6 +570,7 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
model_geometry->index_offset = index_offset;

if( FBitSet( surf->flags, SURF_DRAWSKY )) {
//gEngine.Con_Printf("SURF_SKY: tex_id=%d\n", tex_id);
model_geometry->material = kXVkMaterialSky;
} else {
model_geometry->material = kXVkMaterialRegular;
Expand All @@ -579,7 +580,7 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
}

if (FBitSet( surf->flags, SURF_CONVEYOR )) {
model_geometry->material = kXVkMaterialConveyor;
// FIXME make an explicit list of dynamic-uv geometries
}

VectorCopy(surf->texinfo->vecs[0], tangent);
Expand Down
44 changes: 1 addition & 43 deletions ref/vk/vk_ray_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,6 @@ vk_ray_model_t* VK_RayModelCreate( vk_ray_model_init_t args ) {

/* gEngine.Con_Reportf("Loading model %s, geoms: %d\n", args.model->debug_name, args.model->num_geometries); */

qboolean HACK_additive_emissive = false;

switch (args.model->render_type) {
case kVkRenderType_A_1mA_RW: // blend: scr*a + dst*(1-a), depth: RW
case kVkRenderType_A_1mA_R: // blend: scr*a + dst*(1-a), depth test
HACK_additive_emissive = true;
break;
case kVkRenderType_A_1: // blend: scr*a + dst, no depth test or write
case kVkRenderType_A_1_R: // blend: scr*a + dst, depth test
case kVkRenderType_1_1_R: // blend: scr + dst, depth test
HACK_additive_emissive = true;
break;
case kVkRenderTypeSolid:
case kVkRenderType_AT:
break;
case kVkRenderType_COUNT:
ASSERT(!"Invalid model render_type");
break;
}

for (int i = 0; i < args.model->num_geometries; ++i) {
vk_render_geometry_t *mg = args.model->geometries + i;
const uint32_t prim_count = mg->element_count / 3;
Expand All @@ -290,33 +270,12 @@ vk_ray_model_t* VK_RayModelCreate( vk_ray_model_init_t args ) {
},
};

#if 0
gEngine.Con_Reportf(" g%d: v(%#x %d %#x) V%d i(%#x %d %#x) I%d\n", i,
vertex_offset*sizeof(vk_vertex_t), mg->vertex_count * sizeof(vk_vertex_t), (vertex_offset + mg->vertex_count) * sizeof(vk_vertex_t), mg->vertex_count,
index_offset*sizeof(uint16_t), mg->element_count * sizeof(uint16_t), (index_offset + mg->element_count) * sizeof(uint16_t), mg->element_count);
#endif

geom_build_ranges[i] = (VkAccelerationStructureBuildRangeInfoKHR) {
.primitiveCount = prim_count,
.primitiveOffset = mg->index_offset * sizeof(uint16_t),
.firstVertex = mg->vertex_offset,
};

/* { */
/* const uint32_t index_offset = mg->index_offset * sizeof(uint16_t); */
/* gEngine.Con_Reportf(" g%d: vertices:[%08x, %08x) indices:[%08x, %08x)\n", */
/* i, */
/* mg->vertex_offset * sizeof(vk_vertex_t), (mg->vertex_offset + mg->max_vertex) * sizeof(vk_vertex_t), */
/* index_offset, index_offset + mg->element_count * sizeof(uint16_t) */
/* ); */
/* } */


if (HACK_additive_emissive && mg->material != kXVkMaterialEmissive && mg->material != kXVkMaterialEmissiveGlow) {
mg->material = kXVkMaterialEmissive;
VectorCopy(args.model->color, mg->emissive);
}

applyMaterialToKusok(kusochki + i, mg, args.model->color, false);
Matrix4x4_LoadIdentity(kusochki[i].prev_transform);
}
Expand Down Expand Up @@ -510,8 +469,7 @@ void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render
vk_render_geometry_t *geom = render_model->geometries + i;

// FIXME an impedance mismatch: render_type is per-model, while materials and emissive color are per-geom
if (HACK_additive_emissive && geom->material != kXVkMaterialEmissive && geom->material != kXVkMaterialEmissiveGlow) {
geom->material = kXVkMaterialEmissive;
if (HACK_additive_emissive) {
VectorCopy(render_model->color, geom->emissive);
}

Expand Down
27 changes: 4 additions & 23 deletions ref/vk/vk_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,20 @@ void VK_RenderStateSetMatrixModel(const matrix4x4 model);
// 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, etc.
// For some things we don't even have that. E.g. water and sky surfaces are weird.
// Lets just assigne water and sky materials to those geometries (and probably completely
// disregard render_mode, as it should be irrelevant).
// FIXME these should be bits, not enums
// figure out what it is given heuristics like render_mode, texture name, surface flags, source entity type, etc.
typedef enum {
kXVkMaterialRegular = 0,

// Set for dynamic water surface in vk_brush.c. Used to
// TYno NOT USED, REMOVE NOW.
// Remove: No prerequisites. Water material should be decided based on texture, not whether it's being drawn as dynamic water surface.
kXVkMaterialWater,

// Set for SURF_DRAWSKY surfaces in vk_brush.c.
// Used: for setting KUSOK_MATERIAL_FLAG_SKYBOX for skybox texture sampling and environment shadows.
// Remove: pass it as a special texture/material index (e.g. -2).
kXVkMaterialSky,

// Set by beams and sprites.
// Used: as a negative flag for setting model color from emissive color. A bit tricky, don't really follow.
// Remove: ???
kXVkMaterialEmissive,

// Set by sprites.
// Used: glow means no depth test. Allows for slight ray overshoot (KUSOK_MATERIAL_FLAG_FIXME_GLOW). Desired effect: literally glow.
// Remove: should be able to extract this info from kRenderType
// Set by glow sprites only.
// Used: glow means no depth test. Allows for slight ray overshoot (KUSOK_MATERIAL_FLAG_FIXME_GLOW). Special exclusive case for sprites. Desired effect: "bloom" from bright light sources.
// Remove: in favor of "real" pbr hdr, tonemapping and bloop.
kXVkMaterialEmissiveGlow,

// Set for brush surfaces with dynamic UVs.
// Used: currently unused, conveyors are drawn incorrectly.
// Remove: it's more efficient to solve this via explicit list of dynamic-uv geometries.
kXVkMaterialConveyor,

// 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.
Expand Down
2 changes: 1 addition & 1 deletion ref/vk/vk_sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ static void R_DrawSpriteQuad( const char *debug_name, mspriteframe_t *frame, vec
{
const vk_render_geometry_t geometry = {
.texture = texture,
.material = render_mode == kRenderGlow ? kXVkMaterialEmissiveGlow : kXVkMaterialEmissive,
.material = render_mode == kRenderGlow ? kXVkMaterialEmissiveGlow : kXVkMaterialRegular,

.max_vertex = 4,
.vertex_offset = buffer.vertices.unit_offset,
Expand Down
4 changes: 1 addition & 3 deletions ref/vk/vk_textures.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ static vk_texture_t *Common_AllocTexture( const char *name, texFlags_t flags )

// copy initial params
Q_strncpy( tex->name, name, sizeof( tex->name ));
if( FBitSet( flags, TF_SKYSIDE ))
tex->texnum = tglob.skyboxbasenum++;
else tex->texnum = i; // texnum is used for fast acess into vk_textures array too
tex->texnum = i; // texnum is used for fast acess into vk_textures array too
tex->flags = flags;

// add to hash table
Expand Down
23 changes: 10 additions & 13 deletions ref/vk/vk_textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@ typedef struct vk_texture_s

typedef struct vk_textures_global_s
{
int defaultTexture; // use for bad textures
int particleTexture;
int whiteTexture;
int grayTexture;
int blackTexture;
int solidskyTexture; // quake1 solid-sky layer
int alphaskyTexture; // quake1 alpha-sky layer
int lightmapTextures[MAX_LIGHTMAPS];
int dlightTexture; // custom dlight texture
int cinTexture; // cinematic texture

int skytexturenum; // this not a gl_texturenum!
int skyboxbasenum; // start with 5800 FIXME remove this, lewa says this is a GL1 hack
int defaultTexture; // use for bad textures
int particleTexture;
int whiteTexture;
int grayTexture;
int blackTexture;
int solidskyTexture; // quake1 solid-sky layer
int alphaskyTexture; // quake1 alpha-sky layer
int lightmapTextures[MAX_LIGHTMAPS];
int dlightTexture; // custom dlight texture
int cinTexture; // cinematic texture

qboolean fCustomSkybox; // TODO do we need this for anything?

Expand Down
2 changes: 1 addition & 1 deletion ref/vk/vk_triapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void emitDynamicGeometry(int num_indices, const vec4_t color, const char*
{
const vk_render_geometry_t geometry = {
.texture = g_triapi.texture_index,
.material = (g_triapi.render_type == kVkRenderTypeSolid) ? kXVkMaterialRegular : kXVkMaterialEmissive,
.material = kXVkMaterialRegular,

.max_vertex = g_triapi.num_vertices,
.vertex_offset = buffer.vertices.unit_offset,
Expand Down

0 comments on commit 935c2e7

Please sign in to comment.