add flashlight for classic render (workaround)

This commit is contained in:
NightFox 2021-12-26 04:06:19 +03:00
parent 74a9809b08
commit 6dbaf76b6c
1 changed files with 65 additions and 13 deletions

View File

@ -14,6 +14,10 @@
#include "xash3d_mathlib.h"
#include "protocol.h" // MAX_DLIGHTS
#include "camera.h"
#include "pm_defs.h"
#include "pmtrace.h"
#include <memory.h>
#define MAX_UNIFORM_SLOTS (MAX_SCENE_ENTITIES * 2 /* solid + trans */ + 1)
@ -547,22 +551,70 @@ static uint32_t writeDlightsToUBO( void )
// TODO this should not be here (where? vk_scene?)
for (int i = 0; i < MAX_DLIGHTS && num_lights < ARRAYSIZE(ubo_lights->light); ++i) {
const dlight_t *l = gEngine.GetDynamicLight(i);
dlight_t *l = gEngine.GetDynamicLight(i);
if( !l || l->die < gpGlobals->time || !l->radius )
continue;
Vector4Set(
ubo_lights->light[num_lights].color,
l->color.r / 255.f,
l->color.g / 255.f,
l->color.b / 255.f,
1.f);
Vector4Set(
ubo_lights->light[num_lights].pos_r,
l->origin[0],
l->origin[1],
l->origin[2],
l->radius);
// Draw flashlight (workaround)
cl_entity_t *entPlayer;
entPlayer = gEngine.GetLocalPlayer();
if( FBitSet( entPlayer->curstate.effects, EF_DIMLIGHT )) {
#define FLASHLIGHT_DISTANCE 2000 // in units
pmtrace_t *trace;
vec3_t forward, view_ofs;
vec3_t vecSrc, vecEnd;
float falloff;
trace = gEngine.EV_VisTraceLine( vecSrc, vecEnd, PM_STUDIO_BOX );
// compute falloff
falloff = trace->fraction * FLASHLIGHT_DISTANCE;
if( falloff < 500.0f ) falloff = 1.0f;
else falloff = 500.0f / falloff;
falloff *= falloff;
AngleVectors( g_camera.viewangles, forward, NULL, NULL );
view_ofs[0] = view_ofs[1] = 0.0f;
if( entPlayer->curstate.usehull == 1 ) {
view_ofs[2] = 12.0f; // VEC_DUCK_VIEW;
} else {
view_ofs[2] = 28.0f; // DEFAULT_VIEWHEIGHT
}
VectorAdd( entPlayer->origin, view_ofs, vecSrc );
VectorMA( vecSrc, FLASHLIGHT_DISTANCE, forward, vecEnd );
trace = gEngine.EV_VisTraceLine( vecSrc, vecEnd, PM_STUDIO_BOX );
VectorMA( trace->endpos, -30, forward, l->origin );
// apply brigthness to dlight
l->color.r = bound( 0, falloff * 255, 255 );
l->color.g = bound( 0, falloff * 255, 255 );
l->color.b = bound( 0, falloff * 255, 255 );
l->radius = 60;
Vector4Set(
ubo_lights->light[num_lights].color,
l->color.r / 255.f,
l->color.g / 255.f,
l->color.b / 255.f,
1.f);
Vector4Set(
ubo_lights->light[num_lights].pos_r,
l->origin[0],
l->origin[1],
l->origin[2],
l->radius);
} else {
Vector4Set(
ubo_lights->light[num_lights].color,
l->color.r / 255.f,
l->color.g / 255.f,
l->color.b / 255.f,
1.f);
Vector4Set(
ubo_lights->light[num_lights].pos_r,
l->origin[0],
l->origin[1],
l->origin[2],
l->radius);
}
num_lights++;
}