rtx: allow patching emissive color for brush surfaces, #117

This commit is contained in:
Ivan Avdeev 2021-11-28 11:15:02 -08:00
parent c4c97b2822
commit 5a7cb651ca
7 changed files with 65 additions and 36 deletions

View File

@ -390,9 +390,10 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f
.element_count = total_indices,
.index_offset = index_buffer.buffer.unit.offset,
.emissive = { color[0], color[1], color[2] },
};
// FIXME .emissive = { color[0], color[1], color[2] },
VK_RenderModelDynamicBegin( render_mode, "beam" /* TODO its name */ );
VK_RenderModelDynamicAddGeometry( &geometry );

View File

@ -378,7 +378,7 @@ static qboolean renderableSurface( const msurface_t *surf, int i ) {
// gEngine.Con_Reportf("\n");
// }
//
if (g_map_entities.patch.surfaces && g_map_entities.patch.surfaces[i].tex_id == Patch_Surface_Delete)
if (g_map_entities.patch.surfaces && g_map_entities.patch.surfaces[i].flags & Patch_Surface_Delete)
return false;
//if( surf->flags & ( SURF_DRAWSKY | SURF_DRAWTURB | SURF_CONVEYOR | SURF_DRAWTURB_QUADS ) ) {
@ -465,15 +465,13 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
int index_count = 0;
vec3_t tangent;
int tex_id = surf->texinfo->texture->gl_texturenum;
const xvk_patch_surface_t *const psurf = g_map_entities.patch.surfaces ? g_map_entities.patch.surfaces + surface_index : NULL;
if (!renderableSurface(surf, -1))
continue;
if (g_map_entities.patch.surfaces) {
const int patch = g_map_entities.patch.surfaces[surface_index].tex_id;
if (patch != Patch_Surface_NoPatch)
tex_id = patch;
}
if (psurf && psurf->flags & Patch_Surface_Texture)
tex_id = psurf->tex_id;
if (t != tex_id)
continue;
@ -510,6 +508,12 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
model_geometry->material = kXVkMaterialConveyor;
}
// FIXME material should be flags
if (psurf && psurf->flags & Patch_Surface_Emissive) {
model_geometry->material = kXVkMaterialEmissive;
VectorCopy(psurf->emissive, model_geometry->emissive);
}
VectorCopy(surf->texinfo->vecs[0], tangent);
VectorNormalize(tangent);

View File

@ -604,7 +604,7 @@ void VK_LightsAddEmissiveSurface( const struct vk_render_geometry_s *geom, const
if (!geom->surf)
goto fin; // TODO break? no surface means that model is not brush
if (/* geom->material != kXVkMaterialSky && */geom->material != kXVkMaterialEmissive && !g_lights.map.emissive_textures[texture_num].set)
if (geom->material != kXVkMaterialEmissive && !g_lights.map.emissive_textures[texture_num].set)
goto fin;
if (g_lights.num_emissive_surfaces >= 256)
@ -634,11 +634,10 @@ void VK_LightsAddEmissiveSurface( const struct vk_render_geometry_s *geom, const
// Insert into emissive surfaces
esurf->kusok_index = geom->kusok_index;
if (/* geom->material != kXVkMaterialSky && */geom->material != kXVkMaterialEmissive) {
if (geom->material != kXVkMaterialEmissive) {
VectorCopy(g_lights.map.emissive_textures[texture_num].emissive, esurf->emissive);
} else {
// TODO see #227
VectorSet(esurf->emissive, 0.f, 0.f, 0.f);
VectorCopy(geom->emissive, esurf->emissive);
}
Matrix3x4_Copy(esurf->transform, *transform_row);

View File

@ -251,9 +251,10 @@ static void readWorldspawn( const entity_props_t *props ) {
Q_strcpy(g_map_entities.wadlist, props->wad);
}
static void addPatchSurface( const entity_props_t *props ) {
static void addPatchSurface( const entity_props_t *props, uint32_t have_fields ) {
const model_t* const map = gEngine.pfnGetModelByIndex( 1 );
const int num_surfaces = map->numsurfaces;
xvk_patch_surface_t *psurf = NULL;
if (props->_xvk_surface_id < 0 || props->_xvk_surface_id >= num_surfaces) {
gEngine.Con_Printf(S_ERROR "Incorrect patch for surface_index %d where numsurfaces=%d\n", props->_xvk_surface_id, num_surfaces);
return;
@ -262,31 +263,46 @@ static void addPatchSurface( const entity_props_t *props ) {
if (!g_map_entities.patch.surfaces) {
g_map_entities.patch.surfaces = Mem_Malloc(vk_core.pool, num_surfaces * sizeof(xvk_patch_surface_t));
for (int i = 0; i < num_surfaces; ++i) {
g_map_entities.patch.surfaces[i].tex_id = Patch_Surface_NoPatch;
g_map_entities.patch.surfaces[i].flags = Patch_Surface_NoPatch;
g_map_entities.patch.surfaces[i].tex_id = -1;
g_map_entities.patch.surfaces[i].tex = NULL;
}
}
if (props->_xvk_texture[0] != '\0') {
const int tex_id = VK_FindTexture( props->_xvk_texture );
gEngine.Con_Printf(S_WARN "Patch for surface %d with texture \"%s\" -> %d\n", props->_xvk_surface_id, props->_xvk_texture, tex_id);
g_map_entities.patch.surfaces[props->_xvk_surface_id].tex_id = tex_id;
psurf = g_map_entities.patch.surfaces + props->_xvk_surface_id;
// Find texture_t for this index
for (int i = 0; i < map->numtextures; ++i) {
const texture_t* const tex = map->textures[i];
if (tex->gl_texturenum == tex_id) {
g_map_entities.patch.surfaces[props->_xvk_surface_id].tex = tex;
break;
if (have_fields & Field__xvk_texture) {
if (props->_xvk_texture[0] == '\0') {
gEngine.Con_Reportf("Patch: surface %d removed\n", props->_xvk_surface_id);
psurf->flags = Patch_Surface_Delete;
return;
} else {
const int tex_id = VK_FindTexture( props->_xvk_texture );
gEngine.Con_Reportf("Patch for surface %d with texture \"%s\" -> %d\n", props->_xvk_surface_id, props->_xvk_texture, tex_id);
psurf->tex_id = tex_id;
// Find texture_t for this index
for (int i = 0; i < map->numtextures; ++i) {
const texture_t* const tex = map->textures[i];
if (tex->gl_texturenum == tex_id) {
psurf->tex = tex;
break;
}
}
}
return;
psurf->flags |= Patch_Surface_Texture;
}
}
gEngine.Con_Reportf("Patch: surface %d removed\n", props->_xvk_surface_id);
g_map_entities.patch.surfaces[props->_xvk_surface_id].tex_id = Patch_Surface_Delete;
g_map_entities.patch.surfaces[props->_xvk_surface_id].tex = NULL;
if (have_fields & Field__light) {
VectorCopy(props->_light, psurf->emissive);
psurf->flags |= Patch_Surface_Emissive;
gEngine.Con_Reportf("Patch for surface %d: assign emissive %f %f %f\n", props->_xvk_surface_id,
psurf->emissive[0],
psurf->emissive[1],
psurf->emissive[2]
);
}
}
static void parseEntities( char *string ) {
@ -323,8 +339,8 @@ static void parseEntities( char *string ) {
break;
case Unknown:
if (have_fields & Field__xvk_surface_id && have_fields & Field__xvk_texture) {
addPatchSurface( &values );
if (have_fields & Field__xvk_surface_id) {
addPatchSurface( &values, have_fields );
}
break;
case Ignored:

View File

@ -63,15 +63,19 @@ typedef struct {
} xvk_mapent_target_t;
enum {
Patch_Surface_NoPatch = -1,
Patch_Surface_Delete = -2,
Patch_Surface_NoPatch = 0,
Patch_Surface_Delete = 0x01,
Patch_Surface_Texture = 0x02,
Patch_Surface_Emissive = 0x04,
};
struct texture_s;
typedef struct {
uint32_t flags;
int tex_id;
const struct texture_s *tex;
vec3_t emissive;
} xvk_patch_surface_t;
typedef struct {

View File

@ -100,6 +100,9 @@ typedef struct vk_render_geometry_s {
// Index into kusochki buffer for current frame
uint32_t kusok_index;
// for kXVkMaterialEmissive
vec3_t emissive;
} vk_render_geometry_t;
struct vk_ray_model_s;

View File

@ -644,7 +644,7 @@ qboolean R_SpriteOccluded( cl_entity_t *e, vec3_t origin, float *pscale )
return false;
}
static void R_DrawSpriteQuad( const char *debug_name, mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale, int texture, int render_mode )
static void R_DrawSpriteQuad( const char *debug_name, mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale, int texture, int render_mode, vec3_t color )
{
vec3_t point;
xvk_render_buffer_allocation_t vertex_buffer, index_buffer;
@ -710,6 +710,8 @@ static void R_DrawSpriteQuad( const char *debug_name, mspriteframe_t *frame, vec
.element_count = 6,
.index_offset = index_buffer.buffer.unit.offset,
.emissive = {color[0], color[1], color[2]},
};
VK_RenderModelDynamicBegin( render_mode, "%s", debug_name );
@ -937,7 +939,7 @@ void VK_SpriteDrawModel( cl_entity_t *e )
ubo->color[3] = tr.blend;
*/
VK_RenderStateSetColor( color[0], color[1], color[2], .5f ); // FIXME VK: tr.blend
R_DrawSpriteQuad( model->name, frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode );
R_DrawSpriteQuad( model->name, frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode, color );
}
else
{
@ -949,14 +951,14 @@ void VK_SpriteDrawModel( cl_entity_t *e )
{
// FIXME VK make sure we end up with the same values as gl
VK_RenderStateSetColor( color[0], color[1], color[2], 1.f * ilerp );
R_DrawSpriteQuad( model->name, oldframe, origin, v_right, v_up, scale, oldframe->gl_texturenum, e->curstate.rendermode );
R_DrawSpriteQuad( model->name, oldframe, origin, v_right, v_up, scale, oldframe->gl_texturenum, e->curstate.rendermode, color );
}
if( lerp != 0.0f )
{
// FIXME VK make sure we end up with the same values as gl
VK_RenderStateSetColor( color[0], color[1], color[2], 1.f * lerp );
R_DrawSpriteQuad( model->name, frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode );
R_DrawSpriteQuad( model->name, frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode, color );
}
}