new flashlight
This commit is contained in:
parent
c39e0c6031
commit
ab4d1c12c7
|
@ -63,6 +63,7 @@ GNU General Public License for more details.
|
|||
#define PARM_TEX_MEMORY 38 // returns total memory of uploaded texture in bytes
|
||||
#define PARM_DELUXEDATA 39 // nasty hack, convert int to pointer
|
||||
#define PARM_SHADOWDATA 40 // nasty hack, convert int to pointer
|
||||
#define PARM_MODERNFLASHLIGHT 41 // new dynamic flashlight, initially for Vulkan render
|
||||
|
||||
// skybox ordering
|
||||
enum
|
||||
|
|
|
@ -2696,7 +2696,21 @@ void CL_AddEntityEffects( cl_entity_t *ent )
|
|||
if( FBitSet( ent->curstate.effects, EF_BRIGHTFIELD ))
|
||||
R_EntityParticles( ent );
|
||||
|
||||
if( FBitSet( ent->curstate.effects, EF_DIMLIGHT ))
|
||||
if (REF_GET_PARM( PARM_MODERNFLASHLIGHT, 1 ) == true)
|
||||
{
|
||||
if( !ent->player ) // TODO: need testing
|
||||
{
|
||||
if ( FBitSet( ent->curstate.effects, EF_DIMLIGHT ) )
|
||||
{
|
||||
dlight_t *dl = CL_AllocDlight( ent->index );
|
||||
dl->color.r = dl->color.g = dl->color.b = 100;
|
||||
dl->radius = COM_RandomFloat( 200, 231 );
|
||||
VectorCopy( ent->origin, dl->origin );
|
||||
dl->die = cl.time + 0.001;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( FBitSet( ent->curstate.effects, EF_DIMLIGHT ))
|
||||
{
|
||||
if( ent->player && !Host_IsQuakeCompatible( ))
|
||||
{
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include <string.h>
|
||||
#include <ctype.h> // isalnum...
|
||||
|
||||
#include "camera.h"
|
||||
|
||||
#define PROFILER_SCOPES(X) \
|
||||
X(finalize , "VK_LightsFrameFinalize"); \
|
||||
X(emissive_surface, "VK_LightsAddEmissiveSurface"); \
|
||||
|
@ -808,6 +810,68 @@ static int addSpotLight( const vk_light_entity_t *le, float radius, int lightsty
|
|||
return index;
|
||||
}
|
||||
|
||||
void VK_AddFlashlight( cl_entity_t *ent, vk_global_camera_t *g_camera ) {
|
||||
vec3_t color;
|
||||
vec3_t origin;
|
||||
const int index = g_lights.num_point_lights;
|
||||
vk_point_light_t *const plight = g_lights.point_lights + index;
|
||||
*plight = (vk_point_light_t){0};
|
||||
|
||||
// parameters
|
||||
const float hack_attenuation = 0.1;
|
||||
const float radius = 2.0;
|
||||
const float _cone = 1.0;
|
||||
const float _cone2 = 30.0;
|
||||
const vec3_t light_color = {255, 255, 192};
|
||||
const float light_intensity = 200;
|
||||
|
||||
VectorCopy(light_color, color);
|
||||
|
||||
// prepare colors
|
||||
VectorScale(light_color, light_intensity / 255.0f, color);
|
||||
|
||||
// convert colors by weirdGoldsrcLightScaling
|
||||
float l1 = Q_max(color[0], Q_max(color[1], color[2]));
|
||||
l1 = l1 * l1 / 10;
|
||||
VectorScale(color, l1, color);
|
||||
|
||||
/*
|
||||
gEngine.Con_Printf("flashlight: origin=(%f %f %f) color=(%f %f %f)\n",
|
||||
origin[0], origin[1], origin[2],
|
||||
color[0], color[1], color[2]);
|
||||
*/
|
||||
|
||||
// position
|
||||
VectorCopy(ent->origin, origin);
|
||||
// TODO: relative position of the flashlight as if it were in the left hand (need modify values from g_camera->vforward, HOW?)
|
||||
//origin[0] += 20; // forward-back
|
||||
//origin[1] += -10; // left-right
|
||||
origin[2] += 30; // up-down // HACK
|
||||
VectorCopy(g_camera->vforward, plight->dir);
|
||||
//VectorSet(plight->dir, g_camera->vforward[0], g_camera->vforward[1], g_camera->vforward[2]);
|
||||
|
||||
// convert stopdots by parseStopDot
|
||||
plight->stopdot = cosf(_cone * M_PI / 180.f);
|
||||
plight->stopdot2 = cosf(_cone2 * M_PI / 180.f);
|
||||
|
||||
VectorCopy(origin, plight->origin);
|
||||
plight->radius = radius;
|
||||
|
||||
VectorScale(color, hack_attenuation, plight->base_color);
|
||||
VectorCopy(plight->base_color, plight->color);
|
||||
|
||||
/*
|
||||
gEngine.Con_Printf("flashlight: origin=(%f %f %f) color=(%f %f %f) dir=(%f %f %f)\n",
|
||||
plight->origin[0], plight->origin[1], plight->origin[2],
|
||||
plight->color[0], plight->color[1], plight->color[2],
|
||||
plight->dir[0], plight->dir[1], plight->dir[2]);
|
||||
*/
|
||||
|
||||
addPointLightToClusters( index );
|
||||
g_lights.num_point_lights++;
|
||||
}
|
||||
|
||||
|
||||
static float sphereSolidAngleFromDistDiv2Pi(float r, float d) {
|
||||
return 1. - sqrt(d*d - r*r)/d;
|
||||
}
|
||||
|
|
|
@ -228,6 +228,7 @@ static const char *getParmName(int parm)
|
|||
case PARM_TEX_MEMORY: return "PARM_TEX_MEMORY";
|
||||
case PARM_DELUXEDATA: return "PARM_DELUXEDATA";
|
||||
case PARM_SHADOWDATA: return "PARM_SHADOWDATA";
|
||||
case PARM_MODERNFLASHLIGHT: return "PARM_MODERNFLASHLIGHT";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
@ -248,6 +249,8 @@ static int VK_RefGetParm( int parm, int arg )
|
|||
case PARM_TEX_FLAGS:
|
||||
tex = findTexture(arg);
|
||||
return tex->flags;
|
||||
case PARM_MODERNFLASHLIGHT:
|
||||
return true;
|
||||
}
|
||||
|
||||
PRINT_NOT_IMPLEMENTED_ARGS("(%s(%d), %d)", getParmName(parm), parm, arg);
|
||||
|
|
|
@ -597,6 +597,8 @@ static float g_frametime = 0;
|
|||
|
||||
void VK_SceneRender( const ref_viewpass_t *rvp )
|
||||
{
|
||||
cl_entity_t *entPlayer;
|
||||
|
||||
int current_pipeline_index = kRenderNormal;
|
||||
|
||||
g_frametime = /*FIXME VK RP_NORMALPASS( )) ? */
|
||||
|
@ -660,6 +662,19 @@ void VK_SceneRender( const ref_viewpass_t *rvp )
|
|||
// Draw transparent beams
|
||||
gEngine.CL_DrawEFX( g_frametime, true );
|
||||
|
||||
// Draw flashlight // TODO: REFACTORING?
|
||||
entPlayer = gEngine.GetLocalPlayer();
|
||||
if( entPlayer->player ) { // && !Host_IsQuakeCompatible( ) ???
|
||||
if( FBitSet( entPlayer->curstate.effects, EF_DIMLIGHT )) {
|
||||
//gEngine.Con_Printf( S_WARN "FLASHLIGHT! \n");
|
||||
//dlight_t *dl = gEngine.gEfxApi.CL_AllocDlight( entPlayer->index ); // not work
|
||||
//dlight_t *dl = CL_AllocDlight( entPlayer->index ); // need copy CL_AllocDlight
|
||||
//dl->die = gpGlobals->time + 0.01f; // die on next frame
|
||||
// TODO: try allocate CL_AllocDlight from cl_tent.c but blank
|
||||
VK_AddFlashlight(entPlayer, g_camera); // FIXME: buggy with vk_rtx_freeze
|
||||
}
|
||||
}
|
||||
|
||||
VK_RenderDebugLabelEnd();
|
||||
|
||||
if (ui_infotool->value > 0)
|
||||
|
|
Loading…
Reference in New Issue