Skip to content

Commit

Permalink
vk: comment various material-related things
Browse files Browse the repository at this point in the history
This is in preparation for #460
  • Loading branch information
w23 committed Apr 21, 2023
1 parent e9f15ed commit e54ce9c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 18 deletions.
1 change: 1 addition & 0 deletions ref/vk/shaders/ray_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct Kusok {
float normal_scale;
uint flags;

// TODO per-model
mat4 prev_transform;
};

Expand Down
8 changes: 4 additions & 4 deletions ref/vk/vk_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,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,
.surf = warp,
.surf_deprecate = warp,

.max_vertex = num_vertices,
.vertex_offset = buffer.vertices.unit_offset,
Expand Down Expand Up @@ -407,7 +407,7 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co

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 int surface_index = geom->surf_deprecate - mod->surfaces;
const xvk_patch_surface_t *const patch_surface = R_VkPatchGetSurface(surface_index);

if (render_mode == kRenderTransColor) {
Expand All @@ -419,7 +419,7 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co
} 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);
const texture_t *t = R_TextureAnimation(ent, geom->surf_deprecate, texture_override);
if (t->gl_texturenum >= 0)
geom->texture = t->gl_texturenum;
}
Expand Down Expand Up @@ -561,7 +561,7 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {

VectorClear(model_geometry->emissive);

model_geometry->surf = surf;
model_geometry->surf_deprecate = surf;
model_geometry->texture = tex_id;

model_geometry->vertex_offset = buffer.vertices.unit_offset;
Expand Down
76 changes: 66 additions & 10 deletions ref/vk/vk_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,102 @@ void VK_RenderStateSetMatrixModel(const matrix4x4 model);
// FIXME these should be bits, not enums
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
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.
kXVkMaterialChrome,
} XVkMaterialType;

typedef struct vk_render_geometry_s {
int index_offset, vertex_offset;

// Animated textures will be dynamic and change between frames
int texture;

// If this geometry is special, it will have a material type override
XVkMaterialType material;

uint32_t element_count;

// Maximum index of vertex used for this geometry; needed for ray tracing BLAS building
uint32_t max_vertex;

// Non-null only for brush models
// Used for:
// - updating animated textures for brush models
// - updating dynamic lights (TODO: can decouple from surface/brush models by providing texture_id and aabb directly here)
const struct msurface_s *surf;
// Used for updating animated textures for brush models
// Remove: have an explicit list of surfaces with animated textures
const struct msurface_s *surf_deprecate;

// Animated textures will be dynamic and change between frames
int texture;

// If this geometry is special, it will have a material type override
XVkMaterialType material;

// for kXVkMaterialEmissive{,Glow} and others
vec3_t emissive;
} vk_render_geometry_t;

typedef enum {
kVkRenderTypeSolid, // no blending, depth RW

// Mix alpha blending with depth test and write
// Set by:
// - brush: kRenderTransColor
// - studio: kRenderTransColor, kRenderTransTexture, kRenderTransAlpha, kRenderGlow
// - sprite: kRenderTransColor, kRenderTransTexture
// - triapi: kRenderTransColor, kRenderTransTexture
kVkRenderType_A_1mA_RW, // blend: src*a + dst*(1-a), depth: RW

// Mix alpha blending with depth test only
// Set by:
// - brush: kRenderTransTexture, kRenderGlow
// - sprite: kRenderTransAlpha
// - triapi: kRenderTransAlpha
kVkRenderType_A_1mA_R, // blend: src*a + dst*(1-a), depth test

// Additive alpha blending, no depth
// Set by:
// - sprite: kRenderGlow
kVkRenderType_A_1, // blend: src*a + dst, no depth test or write

// Additive alpha blending with depth test
// Set by:
// - brush: kRenderTransAdd
// - beams: all modes except kRenderNormal and beams going through triapi
// - sprite: kRenderTransAdd
// - triapi: kRenderTransAdd, kRenderGlow
kVkRenderType_A_1_R, // blend: src*a + dst, depth test

// No blend, alpha test, depth test and write
// Set by:
// - brush: kRenderTransAlpha
kVkRenderType_AT, // no blend, depth RW, alpha test

// Additive no alpha blend, depth test only
// Set by:
// - studio: kRenderTransAdd
kVkRenderType_1_1_R, // blend: src + dst, depth test

kVkRenderType_COUNT
} vk_render_type_e;

Expand Down
16 changes: 12 additions & 4 deletions ref/vk/vk_triapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ int TriSpriteTexture( model_t *pSpriteModel, int frame )
void TriRenderMode( int render_mode ) {
switch( render_mode )
{
case kRenderTransAlpha: g_triapi.render_type = kVkRenderType_A_1mA_R; break;
case kRenderTransAlpha:
g_triapi.render_type = kVkRenderType_A_1mA_R;
break;
case kRenderTransColor:
case kRenderTransTexture: g_triapi.render_type = kVkRenderType_A_1mA_RW; break;
case kRenderTransTexture:
g_triapi.render_type = kVkRenderType_A_1mA_RW;
break;
case kRenderGlow:
case kRenderTransAdd: g_triapi.render_type = kVkRenderType_A_1_R; break;
case kRenderTransAdd:
g_triapi.render_type = kVkRenderType_A_1_R;
break;
case kRenderNormal:
default: g_triapi.render_type = kVkRenderTypeSolid; break;
default:
g_triapi.render_type = kVkRenderTypeSolid;
break;
}
}

Expand Down

0 comments on commit e54ce9c

Please sign in to comment.