2021-02-01 20:05:04 +01:00
|
|
|
#include "vk_scene.h"
|
|
|
|
#include "vk_brush.h"
|
2022-05-04 18:23:37 +02:00
|
|
|
#include "vk_staging.h"
|
2021-02-08 19:57:27 +01:00
|
|
|
#include "vk_studio.h"
|
2021-02-01 20:05:04 +01:00
|
|
|
#include "vk_lightmap.h"
|
|
|
|
#include "vk_const.h"
|
2021-02-08 19:57:27 +01:00
|
|
|
#include "vk_render.h"
|
2022-07-09 21:47:16 +02:00
|
|
|
#include "vk_geometry.h"
|
2021-02-08 19:57:27 +01:00
|
|
|
#include "vk_math.h"
|
2021-02-01 20:05:04 +01:00
|
|
|
#include "vk_common.h"
|
2021-02-08 19:57:27 +01:00
|
|
|
#include "vk_core.h"
|
2021-02-15 21:20:25 +01:00
|
|
|
#include "vk_sprite.h"
|
2021-02-17 22:26:09 +01:00
|
|
|
#include "vk_beams.h"
|
2021-03-28 22:52:25 +02:00
|
|
|
#include "vk_light.h"
|
2021-04-12 20:07:41 +02:00
|
|
|
#include "vk_rtx.h"
|
2023-10-20 17:18:55 +02:00
|
|
|
#include "r_textures.h"
|
2021-11-03 18:15:12 +01:00
|
|
|
#include "vk_cvar.h"
|
2021-11-14 22:53:50 +01:00
|
|
|
#include "vk_materials.h"
|
2021-09-29 18:34:46 +02:00
|
|
|
#include "camera.h"
|
2021-11-27 08:59:48 +01:00
|
|
|
#include "vk_mapents.h"
|
2022-02-22 08:46:50 +01:00
|
|
|
#include "profiler.h"
|
2023-08-28 17:58:38 +02:00
|
|
|
#include "vk_entity_data.h"
|
2023-08-29 18:31:57 +02:00
|
|
|
#include "vk_logs.h"
|
2021-02-01 20:05:04 +01:00
|
|
|
|
|
|
|
#include "com_strings.h"
|
|
|
|
#include "ref_params.h"
|
|
|
|
#include "eiface.h"
|
2021-11-19 20:31:45 +01:00
|
|
|
#include "pm_movevars.h"
|
2021-02-01 20:05:04 +01:00
|
|
|
|
2021-02-08 19:57:27 +01:00
|
|
|
#include <stdlib.h> // qsort
|
|
|
|
#include <memory.h>
|
|
|
|
|
2023-08-29 19:12:35 +02:00
|
|
|
#define LOG_MODULE LogModule_Misc
|
|
|
|
|
2022-02-22 08:46:50 +01:00
|
|
|
#define PROFILER_SCOPES(X) \
|
|
|
|
X(scene_render, "VK_SceneRender"); \
|
|
|
|
X(draw_viewmodel, "draw viewmodel"); \
|
|
|
|
X(draw_worldbrush, "draw worldbrush"); \
|
|
|
|
X(draw_opaques, "draw opaque entities"); \
|
|
|
|
X(draw_opaque_beams, "draw opaque beams"); \
|
|
|
|
X(draw_translucent, "draw translucent entities"); \
|
|
|
|
X(draw_transparent_beams, "draw transparent beams"); \
|
|
|
|
|
|
|
|
#define SCOPE_DECLARE(scope, name) APROF_SCOPE_DECLARE(scope)
|
|
|
|
PROFILER_SCOPES(SCOPE_DECLARE)
|
|
|
|
#undef SCOPE_DECLARE
|
|
|
|
|
2021-11-19 20:31:45 +01:00
|
|
|
typedef struct vk_trans_entity_s {
|
|
|
|
struct cl_entity_s *entity;
|
|
|
|
int render_mode;
|
|
|
|
} vk_trans_entity_t;
|
|
|
|
|
2021-02-17 22:26:09 +01:00
|
|
|
typedef struct draw_list_s {
|
|
|
|
struct cl_entity_s *solid_entities[MAX_SCENE_ENTITIES]; // opaque moving or alpha brushes
|
|
|
|
vk_trans_entity_t trans_entities[MAX_SCENE_ENTITIES]; // translucent brushes or studio models kek
|
|
|
|
struct cl_entity_s *beam_entities[MAX_SCENE_ENTITIES];
|
|
|
|
uint num_solid_entities;
|
|
|
|
uint num_trans_entities;
|
|
|
|
uint num_beam_entities;
|
|
|
|
} draw_list_t;
|
|
|
|
|
2021-02-01 20:05:04 +01:00
|
|
|
static struct {
|
|
|
|
draw_list_t draw_stack[MAX_SCENE_STACK];
|
|
|
|
int draw_stack_pos;
|
|
|
|
draw_list_t *draw_list;
|
|
|
|
} g_lists;
|
|
|
|
|
2023-03-03 07:32:08 +01:00
|
|
|
static void loadLights( const model_t *const map ) {
|
|
|
|
RT_LightsLoadBegin(map);
|
2021-12-22 08:30:48 +01:00
|
|
|
|
2023-03-03 07:32:08 +01:00
|
|
|
const int num_models = gEngine.EngineGetParm( PARM_NUMMODELS, 0 );
|
|
|
|
for( int i = 0; i < num_models; i++ ) {
|
|
|
|
const model_t *const mod = gEngine.pfnGetModelByIndex( i + 1 );
|
2021-12-22 08:30:48 +01:00
|
|
|
|
2023-03-03 07:32:08 +01:00
|
|
|
if (!mod)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( mod->type != mod_brush )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const qboolean is_worldmodel = i == 0;
|
|
|
|
R_VkBrushModelCollectEmissiveSurfaces(mod, is_worldmodel);
|
|
|
|
}
|
2022-01-15 08:48:57 +01:00
|
|
|
|
2023-03-03 07:32:08 +01:00
|
|
|
// Load static map lights
|
|
|
|
// Reads surfaces from loaded brush models (must happen after all brushes are loaded)
|
|
|
|
RT_LightsLoadEnd();
|
2021-12-22 08:30:48 +01:00
|
|
|
}
|
|
|
|
|
2023-04-13 18:48:28 +02:00
|
|
|
// Clears all old map data
|
|
|
|
static void mapLoadBegin( const model_t *const map ) {
|
2023-09-29 19:02:51 +02:00
|
|
|
VK_EntityDataClear();
|
|
|
|
|
|
|
|
// Depends on VK_EntityDataClear()
|
2023-06-02 20:49:02 +02:00
|
|
|
R_StudioCacheClear();
|
2023-04-13 18:48:28 +02:00
|
|
|
R_GeometryBuffer_MapClear();
|
|
|
|
|
|
|
|
VK_ClearLightmap();
|
|
|
|
|
|
|
|
// This is to ensure that we have computed lightstyles properly
|
|
|
|
VK_RunLightStyles();
|
|
|
|
|
|
|
|
if (vk_core.rtx)
|
|
|
|
VK_RayNewMap();
|
|
|
|
|
|
|
|
RT_LightsNewMap(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mapLoadEnd(const model_t *const map) {
|
|
|
|
// TODO should we do something like VK_BrushEndLoad?
|
|
|
|
VK_UploadLightmap();
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:13:08 +02:00
|
|
|
static void preloadModels( void ) {
|
2023-04-13 18:48:28 +02:00
|
|
|
const int num_models = gEngine.EngineGetParm( PARM_NUMMODELS, 0 );
|
|
|
|
|
|
|
|
// Load all models at once
|
2023-08-29 19:12:35 +02:00
|
|
|
DEBUG( "Num models: %d:", num_models );
|
2023-04-13 18:48:28 +02:00
|
|
|
for( int i = 0; i < num_models; i++ )
|
|
|
|
{
|
|
|
|
model_t *m;
|
|
|
|
if(( m = gEngine.pfnGetModelByIndex( i + 1 )) == NULL )
|
|
|
|
continue;
|
|
|
|
|
2023-08-29 19:12:35 +02:00
|
|
|
DEBUG( " %d: name=%s, type=%d, submodels=%d, nodes=%d, surfaces=%d, nummodelsurfaces=%d", i, m->name, m->type, m->numsubmodels, m->numnodes, m->numsurfaces, m->nummodelsurfaces);
|
2023-04-13 18:48:28 +02:00
|
|
|
|
2023-09-26 18:27:24 +02:00
|
|
|
R_VkMaterialsLoadForModel(m);
|
|
|
|
|
2023-06-20 19:13:08 +02:00
|
|
|
switch (m->type) {
|
|
|
|
case mod_brush:
|
|
|
|
if (!VK_BrushModelLoad(m))
|
|
|
|
gEngine.Host_Error( "Couldn't load brush model %s\n", m->name );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mod_studio:
|
|
|
|
if (!R_StudioModelPreload(m))
|
|
|
|
gEngine.Host_Error( "Couldn't preload studio model %s\n", m->name );
|
|
|
|
break;
|
2023-04-13 18:48:28 +02:00
|
|
|
|
2023-06-20 19:13:08 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2023-04-13 18:48:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-13 19:05:13 +02:00
|
|
|
static void loadMap(const model_t* const map) {
|
2023-04-13 18:48:28 +02:00
|
|
|
mapLoadBegin(map);
|
|
|
|
|
2023-05-31 19:15:27 +02:00
|
|
|
R_SpriteNewMapFIXME();
|
|
|
|
|
2023-04-13 19:05:13 +02:00
|
|
|
// Load light entities and patch data prior to loading map brush model
|
2021-12-22 08:30:48 +01:00
|
|
|
XVK_ParseMapEntities();
|
2023-04-13 19:05:13 +02:00
|
|
|
|
|
|
|
// Load PBR materials (depends on wadlist from parsed map entities)
|
2023-09-19 19:05:12 +02:00
|
|
|
R_VkMaterialsReload();
|
2023-04-13 19:05:13 +02:00
|
|
|
|
|
|
|
// Parse patch data
|
|
|
|
// Depends on loaded materials. Must preceed loading brush models.
|
2021-12-22 08:30:48 +01:00
|
|
|
XVK_ParseMapPatches();
|
2021-12-21 20:37:45 +01:00
|
|
|
|
2023-06-20 19:13:08 +02:00
|
|
|
preloadModels();
|
2021-12-22 08:30:48 +01:00
|
|
|
|
2023-03-03 07:32:08 +01:00
|
|
|
loadLights(map);
|
2023-04-13 18:48:28 +02:00
|
|
|
mapLoadEnd(map);
|
2023-03-03 07:32:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void reloadPatches( void ) {
|
2023-08-29 19:12:35 +02:00
|
|
|
INFO("Reloading patches and materials");
|
2023-04-13 19:05:13 +02:00
|
|
|
|
|
|
|
R_VkStagingFlushSync();
|
|
|
|
|
|
|
|
XVK_CHECK(vkDeviceWaitIdle( vk_core.device ));
|
2023-03-03 07:32:08 +01:00
|
|
|
|
2023-05-26 19:45:44 +02:00
|
|
|
VK_BrushModelDestroyAll();
|
2023-03-03 07:32:08 +01:00
|
|
|
|
|
|
|
const model_t *const map = gEngine.pfnGetModelByIndex( 1 );
|
2023-04-13 19:05:13 +02:00
|
|
|
loadMap(map);
|
|
|
|
|
|
|
|
R_VkStagingFlushSync();
|
2021-12-21 20:37:45 +01:00
|
|
|
}
|
|
|
|
|
2021-02-01 20:05:04 +01:00
|
|
|
void VK_SceneInit( void )
|
|
|
|
{
|
2022-02-22 08:46:50 +01:00
|
|
|
PROFILER_SCOPES(APROF_SCOPE_INIT);
|
|
|
|
|
2021-02-01 20:05:04 +01:00
|
|
|
g_lists.draw_list = g_lists.draw_stack;
|
|
|
|
g_lists.draw_stack_pos = 0;
|
2023-03-03 07:32:08 +01:00
|
|
|
|
2021-12-05 14:55:11 +01:00
|
|
|
if (vk_core.rtx) {
|
2023-11-03 18:15:11 +01:00
|
|
|
gEngine.Cmd_AddCommand("rt_debug_reload_patches", reloadPatches, "Reload patched entities, lights and extra PBR materials");
|
2021-12-05 14:55:11 +01:00
|
|
|
}
|
2021-02-01 20:05:04 +01:00
|
|
|
}
|
|
|
|
|
2021-02-03 21:24:04 +01:00
|
|
|
#define R_ModelOpaque( rm ) ( rm == kRenderNormal )
|
|
|
|
int R_FIXME_GetEntityRenderMode( cl_entity_t *ent )
|
|
|
|
{
|
|
|
|
//int i, opaque, trans;
|
|
|
|
//mstudiotexture_t *ptexture;
|
|
|
|
model_t *model;
|
|
|
|
//studiohdr_t *phdr;
|
|
|
|
|
|
|
|
/* TODO
|
|
|
|
if( ent->player ) // check it for real playermodel
|
|
|
|
model = R_StudioSetupPlayerModel( ent->curstate.number - 1 );
|
|
|
|
else */ model = ent->model;
|
|
|
|
|
|
|
|
if( R_ModelOpaque( ent->curstate.rendermode ))
|
|
|
|
{
|
|
|
|
if(( model && model->type == mod_brush ) && FBitSet( model->flags, MODEL_TRANSPARENT ))
|
|
|
|
return kRenderTransAlpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO studio models hack
|
|
|
|
ptexture = (mstudiotexture_t *)((byte *)phdr + phdr->textureindex);
|
|
|
|
|
|
|
|
for( opaque = trans = i = 0; i < phdr->numtextures; i++, ptexture++ )
|
|
|
|
{
|
|
|
|
// ignore chrome & additive it's just a specular-like effect
|
|
|
|
if( FBitSet( ptexture->flags, STUDIO_NF_ADDITIVE ) && !FBitSet( ptexture->flags, STUDIO_NF_CHROME ))
|
|
|
|
trans++;
|
|
|
|
else opaque++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if model is more additive than opaque
|
|
|
|
if( trans > opaque )
|
|
|
|
return kRenderTransAdd;
|
|
|
|
*/
|
|
|
|
return ent->curstate.rendermode;
|
|
|
|
}
|
|
|
|
|
2023-05-26 19:45:44 +02:00
|
|
|
void R_SceneMapDestroy( void ) {
|
2023-10-09 18:48:38 +02:00
|
|
|
// Make sure no rendering is happening
|
|
|
|
XVK_CHECK(vkDeviceWaitIdle( vk_core.device ));
|
|
|
|
|
2023-05-26 19:45:44 +02:00
|
|
|
VK_BrushModelDestroyAll();
|
|
|
|
}
|
|
|
|
|
2021-02-01 20:05:04 +01:00
|
|
|
// tell the renderer what new map is started
|
2022-01-15 08:48:57 +01:00
|
|
|
void R_NewMap( void ) {
|
|
|
|
const model_t *const map = gEngine.pfnGetModelByIndex( 1 );
|
2021-02-01 20:05:04 +01:00
|
|
|
|
2021-04-09 23:59:04 +02:00
|
|
|
// Existence of cache.data for the world means that we've already have loaded this map
|
|
|
|
// and this R_NewMap call is from within loading of a saved game.
|
|
|
|
const qboolean is_save_load = !!gEngine.pfnGetModelByIndex( 1 )->cache.data;
|
|
|
|
|
2023-08-29 19:12:35 +02:00
|
|
|
INFO( "R_NewMap, loading save: %d", is_save_load );
|
2021-04-09 23:59:04 +02:00
|
|
|
|
2023-09-14 19:48:39 +02:00
|
|
|
// New map causes entites to be reallocated regardless of whether it was save-load.
|
|
|
|
// This realloc invalidates all previous entity data and pointers.
|
|
|
|
// Make sure that EntityData doesn't accidentally reference old pointers.
|
|
|
|
VK_EntityDataClear();
|
|
|
|
|
2021-04-09 23:59:04 +02:00
|
|
|
// Skip clearing already loaded data if the map hasn't changed.
|
|
|
|
if (is_save_load)
|
|
|
|
return;
|
2021-02-01 20:05:04 +01:00
|
|
|
|
2023-04-25 00:22:46 +02:00
|
|
|
// Make sure that we're not rendering anything before starting to mess with GPU objects
|
|
|
|
XVK_CHECK(vkDeviceWaitIdle(vk_core.device));
|
2023-10-20 17:18:55 +02:00
|
|
|
R_TextureSetupSky( gEngine.pfnGetMoveVars()->skyName );
|
2021-11-19 20:31:45 +01:00
|
|
|
|
2023-04-13 19:05:13 +02:00
|
|
|
loadMap(map);
|
2023-08-22 20:23:20 +02:00
|
|
|
|
|
|
|
R_StudioResetPlayerModels();
|
2021-02-01 20:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qboolean R_AddEntity( struct cl_entity_s *clent, int type )
|
|
|
|
{
|
|
|
|
/* if( !r_drawentities->value ) */
|
|
|
|
/* return false; // not allow to drawing */
|
2021-02-03 21:24:04 +01:00
|
|
|
int render_mode;
|
2021-02-01 20:05:04 +01:00
|
|
|
|
|
|
|
if( !clent || !clent->model )
|
|
|
|
return false; // if set to invisible, skip
|
|
|
|
|
|
|
|
if( FBitSet( clent->curstate.effects, EF_NODRAW ))
|
|
|
|
return false; // done
|
|
|
|
|
2021-02-03 21:24:04 +01:00
|
|
|
render_mode = R_FIXME_GetEntityRenderMode( clent );
|
|
|
|
|
2021-02-01 20:05:04 +01:00
|
|
|
/* TODO
|
|
|
|
if( !R_ModelOpaque( clent->curstate.rendermode ) && CL_FxBlend( clent ) <= 0 )
|
|
|
|
return true; // invisible
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case ET_FRAGMENTED:
|
|
|
|
r_stats.c_client_ents++;
|
|
|
|
break;
|
|
|
|
case ET_TEMPENTITY:
|
|
|
|
r_stats.c_active_tents_count++;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2021-02-03 21:24:04 +01:00
|
|
|
if( render_mode == kRenderNormal )
|
2021-02-01 20:05:04 +01:00
|
|
|
{
|
2021-02-03 21:24:04 +01:00
|
|
|
if( g_lists.draw_list->num_solid_entities >= ARRAYSIZE(g_lists.draw_list->solid_entities) )
|
2021-02-01 20:05:04 +01:00
|
|
|
return false;
|
|
|
|
|
2021-02-03 21:24:04 +01:00
|
|
|
g_lists.draw_list->solid_entities[g_lists.draw_list->num_solid_entities] = clent;
|
|
|
|
g_lists.draw_list->num_solid_entities++;
|
2021-02-01 20:05:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-03 21:24:04 +01:00
|
|
|
if( g_lists.draw_list->num_trans_entities >= ARRAYSIZE(g_lists.draw_list->trans_entities) )
|
2021-02-01 20:05:04 +01:00
|
|
|
return false;
|
|
|
|
|
2021-02-03 21:24:04 +01:00
|
|
|
g_lists.draw_list->trans_entities[g_lists.draw_list->num_trans_entities] = (vk_trans_entity_t){ clent, render_mode };
|
|
|
|
g_lists.draw_list->num_trans_entities++;
|
2021-02-01 20:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_ProcessEntData( qboolean allocate )
|
|
|
|
{
|
|
|
|
if( !allocate )
|
|
|
|
{
|
|
|
|
g_lists.draw_list->num_solid_entities = 0;
|
2021-02-03 21:24:04 +01:00
|
|
|
g_lists.draw_list->num_trans_entities = 0;
|
2021-02-17 22:48:41 +01:00
|
|
|
g_lists.draw_list->num_beam_entities = 0;
|
2021-02-01 20:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if( gEngine.drawFuncs->R_ProcessEntData )
|
|
|
|
gEngine.drawFuncs->R_ProcessEntData( allocate );
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_ClearScreen( void )
|
|
|
|
{
|
|
|
|
g_lists.draw_list->num_solid_entities = 0;
|
2021-02-03 21:24:04 +01:00
|
|
|
g_lists.draw_list->num_trans_entities = 0;
|
2021-02-17 22:48:41 +01:00
|
|
|
g_lists.draw_list->num_beam_entities = 0;
|
2021-02-01 20:05:04 +01:00
|
|
|
|
|
|
|
// clear the scene befor start new frame
|
|
|
|
if( gEngine.drawFuncs->R_ClearScene != NULL )
|
|
|
|
gEngine.drawFuncs->R_ClearScene();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_PushScene( void )
|
|
|
|
{
|
|
|
|
if( ++g_lists.draw_stack_pos >= MAX_SCENE_STACK )
|
|
|
|
gEngine.Host_Error( "draw stack overflow\n" );
|
|
|
|
g_lists.draw_list = &g_lists.draw_stack[g_lists.draw_stack_pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_PopScene( void )
|
|
|
|
{
|
|
|
|
if( --g_lists.draw_stack_pos < 0 )
|
|
|
|
gEngine.Host_Error( "draw stack underflow\n" );
|
|
|
|
g_lists.draw_list = &g_lists.draw_stack[g_lists.draw_stack_pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear the render entities before each frame
|
|
|
|
void R_ClearScene( void )
|
|
|
|
{
|
|
|
|
g_lists.draw_list->num_solid_entities = 0;
|
2021-02-03 21:24:04 +01:00
|
|
|
g_lists.draw_list->num_trans_entities = 0;
|
2021-02-17 22:48:41 +01:00
|
|
|
g_lists.draw_list->num_beam_entities = 0;
|
2021-02-01 20:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void R_RenderScene( void )
|
|
|
|
{
|
2021-02-08 19:57:27 +01:00
|
|
|
PRINT_NOT_IMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void R_RotateForEntity( matrix4x4 out, const cl_entity_t *e )
|
|
|
|
{
|
|
|
|
float scale = 1.0f;
|
|
|
|
|
2023-05-04 19:30:13 +02:00
|
|
|
// TODO we should be able to remove this, as worldmodel is draw in a separate code path
|
2021-02-08 19:57:27 +01:00
|
|
|
if( e == gEngine.GetEntityByIndex( 0 ) )
|
|
|
|
{
|
|
|
|
Matrix4x4_LoadIdentity(out);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( e->model->type != mod_brush && e->curstate.scale > 0.0f )
|
|
|
|
scale = e->curstate.scale;
|
|
|
|
|
|
|
|
Matrix4x4_CreateFromEntity( out, e->angles, e->origin, scale );
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME find a better place for this function
|
|
|
|
static int R_RankForRenderMode( int rendermode )
|
|
|
|
{
|
|
|
|
switch( rendermode )
|
|
|
|
{
|
|
|
|
case kRenderTransTexture:
|
|
|
|
return 1; // draw second
|
|
|
|
case kRenderTransAdd:
|
|
|
|
return 2; // draw third
|
|
|
|
case kRenderGlow:
|
|
|
|
return 3; // must be last!
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_TransEntityCompare
|
|
|
|
|
|
|
|
Sorting translucent entities by rendermode then by distance
|
|
|
|
|
|
|
|
FIXME find a better place for this function
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static int R_TransEntityCompare( const void *a, const void *b)
|
|
|
|
{
|
|
|
|
vk_trans_entity_t *tent1, *tent2;
|
|
|
|
cl_entity_t *ent1, *ent2;
|
|
|
|
vec3_t vecLen, org;
|
|
|
|
float dist1, dist2;
|
|
|
|
int rendermode1;
|
|
|
|
int rendermode2;
|
|
|
|
|
|
|
|
tent1 = (vk_trans_entity_t*)a;
|
|
|
|
tent2 = (vk_trans_entity_t*)b;
|
|
|
|
|
|
|
|
ent1 = tent1->entity;
|
|
|
|
ent2 = tent2->entity;
|
|
|
|
|
|
|
|
rendermode1 = tent1->render_mode;
|
|
|
|
rendermode2 = tent2->render_mode;
|
|
|
|
|
|
|
|
// sort by distance
|
|
|
|
if( ent1->model->type != mod_brush || rendermode1 != kRenderTransAlpha )
|
|
|
|
{
|
|
|
|
VectorAverage( ent1->model->mins, ent1->model->maxs, org );
|
|
|
|
VectorAdd( ent1->origin, org, org );
|
2021-02-20 23:54:57 +01:00
|
|
|
VectorSubtract( g_camera.vieworg, org, vecLen );
|
2021-02-08 19:57:27 +01:00
|
|
|
dist1 = DotProduct( vecLen, vecLen );
|
|
|
|
}
|
|
|
|
else dist1 = 1000000000;
|
|
|
|
|
|
|
|
if( ent2->model->type != mod_brush || rendermode2 != kRenderTransAlpha )
|
|
|
|
{
|
|
|
|
VectorAverage( ent2->model->mins, ent2->model->maxs, org );
|
|
|
|
VectorAdd( ent2->origin, org, org );
|
2021-02-20 23:54:57 +01:00
|
|
|
VectorSubtract( g_camera.vieworg, org, vecLen );
|
2021-02-08 19:57:27 +01:00
|
|
|
dist2 = DotProduct( vecLen, vecLen );
|
|
|
|
}
|
|
|
|
else dist2 = 1000000000;
|
|
|
|
|
|
|
|
if( dist1 > dist2 )
|
|
|
|
return -1;
|
|
|
|
if( dist1 < dist2 )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// then sort by rendermode
|
|
|
|
if( R_RankForRenderMode( rendermode1 ) > R_RankForRenderMode( rendermode2 ))
|
|
|
|
return 1;
|
|
|
|
if( R_RankForRenderMode( rendermode1 ) < R_RankForRenderMode( rendermode2 ))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME where should this function be
|
|
|
|
#define RP_NORMALPASS() true // FIXME ???
|
2021-02-17 22:26:09 +01:00
|
|
|
int CL_FxBlend( cl_entity_t *e ) // FIXME do R_SetupFrustum: , vec3_t vforward )
|
2021-02-08 19:57:27 +01:00
|
|
|
{
|
|
|
|
int blend = 0;
|
|
|
|
float offset, dist;
|
|
|
|
vec3_t tmp;
|
|
|
|
|
|
|
|
offset = ((int)e->index ) * 363.0f; // Use ent index to de-sync these fx
|
|
|
|
|
|
|
|
switch( e->curstate.renderfx )
|
|
|
|
{
|
|
|
|
case kRenderFxPulseSlowWide:
|
|
|
|
blend = e->curstate.renderamt + 0x40 * sin( gpGlobals->time * 2 + offset );
|
|
|
|
break;
|
|
|
|
case kRenderFxPulseFastWide:
|
|
|
|
blend = e->curstate.renderamt + 0x40 * sin( gpGlobals->time * 8 + offset );
|
|
|
|
break;
|
|
|
|
case kRenderFxPulseSlow:
|
|
|
|
blend = e->curstate.renderamt + 0x10 * sin( gpGlobals->time * 2 + offset );
|
|
|
|
break;
|
|
|
|
case kRenderFxPulseFast:
|
|
|
|
blend = e->curstate.renderamt + 0x10 * sin( gpGlobals->time * 8 + offset );
|
|
|
|
break;
|
|
|
|
case kRenderFxFadeSlow:
|
|
|
|
if( RP_NORMALPASS( ))
|
|
|
|
{
|
|
|
|
if( e->curstate.renderamt > 0 )
|
|
|
|
e->curstate.renderamt -= 1;
|
|
|
|
else e->curstate.renderamt = 0;
|
|
|
|
}
|
|
|
|
blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxFadeFast:
|
|
|
|
if( RP_NORMALPASS( ))
|
|
|
|
{
|
|
|
|
if( e->curstate.renderamt > 3 )
|
|
|
|
e->curstate.renderamt -= 4;
|
|
|
|
else e->curstate.renderamt = 0;
|
|
|
|
}
|
|
|
|
blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxSolidSlow:
|
|
|
|
if( RP_NORMALPASS( ))
|
|
|
|
{
|
|
|
|
if( e->curstate.renderamt < 255 )
|
|
|
|
e->curstate.renderamt += 1;
|
|
|
|
else e->curstate.renderamt = 255;
|
|
|
|
}
|
|
|
|
blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxSolidFast:
|
|
|
|
if( RP_NORMALPASS( ))
|
|
|
|
{
|
|
|
|
if( e->curstate.renderamt < 252 )
|
|
|
|
e->curstate.renderamt += 4;
|
|
|
|
else e->curstate.renderamt = 255;
|
|
|
|
}
|
|
|
|
blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxStrobeSlow:
|
|
|
|
blend = 20 * sin( gpGlobals->time * 4 + offset );
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxStrobeFast:
|
|
|
|
blend = 20 * sin( gpGlobals->time * 16 + offset );
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxStrobeFaster:
|
|
|
|
blend = 20 * sin( gpGlobals->time * 36 + offset );
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxFlickerSlow:
|
|
|
|
blend = 20 * (sin( gpGlobals->time * 2 ) + sin( gpGlobals->time * 17 + offset ));
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxFlickerFast:
|
|
|
|
blend = 20 * (sin( gpGlobals->time * 16 ) + sin( gpGlobals->time * 23 + offset ));
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxHologram:
|
|
|
|
case kRenderFxDistort:
|
|
|
|
VectorCopy( e->origin, tmp );
|
2021-02-17 22:26:09 +01:00
|
|
|
VectorSubtract( tmp, g_camera.vieworg, tmp );
|
|
|
|
dist = DotProduct( tmp, g_camera.vforward );
|
2021-02-08 19:57:27 +01:00
|
|
|
|
|
|
|
// turn off distance fade
|
|
|
|
if( e->curstate.renderfx == kRenderFxDistort )
|
|
|
|
dist = 1;
|
|
|
|
|
|
|
|
if( dist <= 0 )
|
|
|
|
{
|
|
|
|
blend = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->curstate.renderamt = 180;
|
|
|
|
if( dist <= 100 ) blend = e->curstate.renderamt;
|
|
|
|
else blend = (int) ((1.0f - ( dist - 100 ) * ( 1.0f / 400.0f )) * e->curstate.renderamt );
|
|
|
|
blend += gEngine.COM_RandomLong( -32, 31 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
blend = bound( 0, blend, 255 );
|
|
|
|
|
|
|
|
return blend;
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:35:50 +01:00
|
|
|
static void drawEntity( cl_entity_t *ent, int render_mode )
|
2021-02-08 19:57:27 +01:00
|
|
|
{
|
|
|
|
const model_t *mod = ent->model;
|
2021-03-13 22:35:50 +01:00
|
|
|
matrix4x4 model;
|
2021-02-08 19:57:27 +01:00
|
|
|
|
|
|
|
if (!mod)
|
2021-02-17 22:26:09 +01:00
|
|
|
return;
|
2021-02-08 19:57:27 +01:00
|
|
|
|
|
|
|
// handle studiomodels with custom rendermodes on texture
|
2023-02-25 02:43:07 +01:00
|
|
|
const float blend = render_mode == kRenderNormal ? 1.f : CL_FxBlend( ent ) / 255.0f;
|
2021-02-08 19:57:27 +01:00
|
|
|
|
2021-02-20 21:00:31 +01:00
|
|
|
// TODO ref_gl does this earlier (when adding entity), can we too?
|
2023-02-25 02:43:07 +01:00
|
|
|
if( blend <= 0.0f )
|
2021-02-17 22:26:09 +01:00
|
|
|
return;
|
|
|
|
|
2021-02-14 02:19:59 +01:00
|
|
|
switch (mod->type)
|
|
|
|
{
|
|
|
|
case mod_brush:
|
2021-02-15 21:20:25 +01:00
|
|
|
R_RotateForEntity( model, ent );
|
2023-04-18 21:18:27 +02:00
|
|
|
|
2023-09-29 18:48:32 +02:00
|
|
|
// If this is potentially a func_any model
|
2023-04-19 20:47:55 +02:00
|
|
|
if (ent->model->name[0] == '*') {
|
2023-09-29 18:48:32 +02:00
|
|
|
for (int i = 0; i < g_map_entities.func_any_count; ++i) {
|
|
|
|
xvk_mapent_func_any_t *const fw = g_map_entities.func_any + i;
|
|
|
|
if (Q_strcmp(ent->model->name, fw->model) == 0 && fw->origin_patched) {
|
2023-08-29 19:12:35 +02:00
|
|
|
/* DEBUG("ent->index=%d (%s) mapent:%d off=%f %f %f", */
|
2023-04-19 20:47:55 +02:00
|
|
|
/* ent->index, ent->model->name, fw->entity_index, */
|
|
|
|
/* fw->origin[0], fw->origin[1], fw->origin[2]); */
|
2023-04-19 20:40:08 +02:00
|
|
|
Matrix3x4_LoadIdentity(model);
|
2023-04-19 20:47:55 +02:00
|
|
|
Matrix4x4_SetOrigin(model, fw->origin[0], fw->origin[1], fw->origin[2]);
|
|
|
|
break;
|
2023-04-19 20:40:08 +02:00
|
|
|
}
|
2023-04-18 21:18:27 +02:00
|
|
|
}
|
|
|
|
}
|
2023-04-19 20:40:08 +02:00
|
|
|
|
2023-02-25 07:48:26 +01:00
|
|
|
VK_BrushModelDraw( ent, render_mode, blend, model );
|
2021-02-14 02:19:59 +01:00
|
|
|
break;
|
|
|
|
|
2021-02-15 21:20:25 +01:00
|
|
|
case mod_studio:
|
2023-05-04 19:30:13 +02:00
|
|
|
// TODO R_RotateForEntity ?
|
2023-02-25 08:57:49 +01:00
|
|
|
VK_StudioDrawModel( ent, render_mode, blend );
|
2021-02-14 02:19:59 +01:00
|
|
|
break;
|
2021-02-15 21:20:25 +01:00
|
|
|
|
|
|
|
case mod_sprite:
|
2023-02-25 02:43:07 +01:00
|
|
|
R_VkSpriteDrawModel( ent, blend );
|
2021-02-20 21:00:31 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case mod_alias:
|
|
|
|
case mod_bad:
|
|
|
|
PRINT_NOT_IMPLEMENTED();
|
2021-02-15 21:20:25 +01:00
|
|
|
break;
|
2021-02-14 02:19:59 +01:00
|
|
|
}
|
2021-02-01 20:05:04 +01:00
|
|
|
}
|
|
|
|
|
2021-02-17 22:26:09 +01:00
|
|
|
static float g_frametime = 0;
|
2021-11-03 18:15:12 +01:00
|
|
|
|
2021-12-27 08:12:50 +01:00
|
|
|
void VK_SceneRender( const ref_viewpass_t *rvp ) {
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_BEGIN_EARLY(scene_render);
|
2021-12-30 04:27:46 +01:00
|
|
|
const cl_entity_t* const local_player = gEngine.GetLocalPlayer();
|
2021-02-17 22:26:09 +01:00
|
|
|
|
|
|
|
g_frametime = /*FIXME VK RP_NORMALPASS( )) ? */
|
2021-09-29 18:34:46 +02:00
|
|
|
gpGlobals->time - gpGlobals->oldtime
|
2021-02-17 22:26:09 +01:00
|
|
|
/* FIXME VK : 0.f */;
|
2021-02-08 19:57:27 +01:00
|
|
|
|
2023-05-04 19:30:13 +02:00
|
|
|
VK_RenderSetupCamera( rvp );
|
2021-03-03 20:58:40 +01:00
|
|
|
|
2021-02-20 21:35:04 +01:00
|
|
|
VK_RenderDebugLabelBegin( "opaque" );
|
|
|
|
|
2021-02-15 18:55:42 +01:00
|
|
|
// Draw view model
|
|
|
|
{
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_BEGIN(draw_viewmodel);
|
2021-02-15 18:55:42 +01:00
|
|
|
R_RunViewmodelEvents();
|
2021-02-20 21:00:31 +01:00
|
|
|
R_DrawViewModel();
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_END(draw_viewmodel);
|
2021-02-15 18:55:42 +01:00
|
|
|
}
|
|
|
|
|
2021-02-14 02:19:59 +01:00
|
|
|
// Draw world brush
|
2021-02-08 19:57:27 +01:00
|
|
|
{
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_BEGIN(draw_worldbrush);
|
2021-02-10 01:42:08 +01:00
|
|
|
cl_entity_t *world = gEngine.GetEntityByIndex( 0 );
|
|
|
|
if( world && world->model )
|
2021-02-08 19:57:27 +01:00
|
|
|
{
|
2023-02-25 07:48:26 +01:00
|
|
|
const float blend = 1.f;
|
|
|
|
VK_BrushModelDraw( world, kRenderNormal, blend, NULL );
|
2021-02-08 19:57:27 +01:00
|
|
|
}
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_END(draw_worldbrush);
|
2021-02-08 19:57:27 +01:00
|
|
|
}
|
|
|
|
|
2021-12-30 04:27:46 +01:00
|
|
|
{
|
|
|
|
// Draw flashlight for local player
|
|
|
|
if( FBitSet( local_player->curstate.effects, EF_DIMLIGHT )) {
|
2022-07-30 20:37:06 +02:00
|
|
|
RT_LightAddFlashlight(local_player, true);
|
2021-12-30 04:27:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_BEGIN(draw_opaques);
|
2021-02-08 19:57:27 +01:00
|
|
|
// Draw opaque entities
|
|
|
|
for (int i = 0; i < g_lists.draw_list->num_solid_entities; ++i)
|
|
|
|
{
|
|
|
|
cl_entity_t *ent = g_lists.draw_list->solid_entities[i];
|
2021-03-13 22:35:50 +01:00
|
|
|
drawEntity(ent, kRenderNormal);
|
2021-12-30 04:27:46 +01:00
|
|
|
|
2021-12-28 13:09:29 +01:00
|
|
|
// Draw flashlight for other players
|
2021-12-30 04:27:46 +01:00
|
|
|
if( FBitSet( ent->curstate.effects, EF_DIMLIGHT ) && ent != local_player) {
|
2022-07-30 20:37:06 +02:00
|
|
|
RT_LightAddFlashlight(ent, false);
|
2021-12-28 13:09:29 +01:00
|
|
|
}
|
2021-02-08 19:57:27 +01:00
|
|
|
}
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_END(draw_opaques);
|
2021-02-08 19:57:27 +01:00
|
|
|
|
2021-02-17 22:26:09 +01:00
|
|
|
// Draw opaque beams
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_BEGIN(draw_opaque_beams);
|
2021-02-17 22:26:09 +01:00
|
|
|
gEngine.CL_DrawEFX( g_frametime, false );
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_END(draw_opaque_beams);
|
2021-02-17 22:26:09 +01:00
|
|
|
|
2021-02-20 21:35:04 +01:00
|
|
|
VK_RenderDebugLabelEnd();
|
2021-02-08 19:57:27 +01:00
|
|
|
|
2021-02-20 21:35:04 +01:00
|
|
|
VK_RenderDebugLabelBegin( "tranparent" );
|
|
|
|
|
|
|
|
{
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_BEGIN(draw_translucent);
|
2021-02-08 19:57:27 +01:00
|
|
|
// sort translucents entities by rendermode and distance
|
|
|
|
qsort( g_lists.draw_list->trans_entities, g_lists.draw_list->num_trans_entities, sizeof( vk_trans_entity_t ), R_TransEntityCompare );
|
|
|
|
|
|
|
|
// Draw transparent ents
|
|
|
|
for (int i = 0; i < g_lists.draw_list->num_trans_entities; ++i)
|
|
|
|
{
|
|
|
|
const vk_trans_entity_t *ent = g_lists.draw_list->trans_entities + i;
|
2021-03-13 22:35:50 +01:00
|
|
|
drawEntity(ent->entity, ent->render_mode);
|
2021-02-08 19:57:27 +01:00
|
|
|
}
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_END(draw_translucent);
|
2021-02-08 19:57:27 +01:00
|
|
|
}
|
2021-02-14 02:19:59 +01:00
|
|
|
|
2021-02-17 22:26:09 +01:00
|
|
|
// Draw transparent beams
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_BEGIN(draw_transparent_beams);
|
2021-02-17 22:26:09 +01:00
|
|
|
gEngine.CL_DrawEFX( g_frametime, true );
|
2022-02-22 08:46:50 +01:00
|
|
|
APROF_SCOPE_END(draw_transparent_beams);
|
2021-02-17 22:26:09 +01:00
|
|
|
|
2021-02-20 21:35:04 +01:00
|
|
|
VK_RenderDebugLabelEnd();
|
2021-11-03 18:15:12 +01:00
|
|
|
|
2023-11-03 18:15:11 +01:00
|
|
|
if (r_infotool->value > 0)
|
2021-11-03 18:15:12 +01:00
|
|
|
XVK_CameraDebugPrintCenterEntity();
|
2022-02-22 08:46:50 +01:00
|
|
|
|
|
|
|
APROF_SCOPE_END(scene_render);
|
2021-02-01 20:05:04 +01:00
|
|
|
}
|
2021-02-15 21:20:25 +01:00
|
|
|
|
2021-02-17 22:26:09 +01:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
CL_AddCustomBeam
|
|
|
|
|
|
|
|
Add the beam that encoded as custom entity
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void CL_AddCustomBeam( cl_entity_t *pEnvBeam )
|
|
|
|
{
|
|
|
|
if( g_lists.draw_list->num_beam_entities >= ARRAYSIZE(g_lists.draw_list->beam_entities) )
|
|
|
|
{
|
2023-08-29 19:12:35 +02:00
|
|
|
ERR("Too many beams %d!", g_lists.draw_list->num_beam_entities );
|
2021-02-17 22:26:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pEnvBeam )
|
|
|
|
{
|
|
|
|
g_lists.draw_list->beam_entities[g_lists.draw_list->num_beam_entities] = pEnvBeam;
|
|
|
|
g_lists.draw_list->num_beam_entities++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CL_DrawBeams( int fTrans, BEAM *active_beams )
|
|
|
|
{
|
|
|
|
BEAM *pBeam;
|
|
|
|
int i, flags;
|
|
|
|
|
|
|
|
// FIXME VK pglDepthMask( fTrans ? GL_FALSE : GL_TRUE );
|
|
|
|
|
|
|
|
// server beams don't allocate beam chains
|
|
|
|
// all params are stored in cl_entity_t
|
|
|
|
for( i = 0; i < g_lists.draw_list->num_beam_entities; i++ )
|
|
|
|
{
|
|
|
|
cl_entity_t *currentbeam = g_lists.draw_list->beam_entities[i];
|
|
|
|
flags = currentbeam->curstate.rendermode & 0xF0;
|
|
|
|
|
|
|
|
if( fTrans && FBitSet( flags, FBEAM_SOLID ))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !fTrans && !FBitSet( flags, FBEAM_SOLID ))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
R_BeamDrawCustomEntity( currentbeam, g_frametime );
|
|
|
|
// FIXME VK r_stats.c_view_beams_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw temporary entity beams
|
|
|
|
for( pBeam = active_beams; pBeam; pBeam = pBeam->next )
|
|
|
|
{
|
|
|
|
if( fTrans && FBitSet( pBeam->flags, FBEAM_SOLID ))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !fTrans && !FBitSet( pBeam->flags, FBEAM_SOLID ))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
R_BeamDraw( pBeam, g_frametime );
|
|
|
|
}
|
|
|
|
}
|