mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-14 04:59:58 +01:00
apply proper lightstyles on map load
Lightstyles remain fixed for the entire map duration. Need to implement either texture reupload in VK, or devise some other scheme of updating ligtmaps w/o texture reupload (lightstylevalues uniform buffers?).
This commit is contained in:
parent
8870650466
commit
fc9eedbd9d
@ -7,6 +7,7 @@
|
||||
#include "vk_framectl.h"
|
||||
#include "vk_brush.h"
|
||||
#include "vk_scene.h"
|
||||
#include "vk_cvar.h"
|
||||
|
||||
#include "xash3d_types.h"
|
||||
#include "cvardef.h"
|
||||
@ -572,6 +573,8 @@ qboolean R_VkInit( void )
|
||||
if (!initDescriptorPool())
|
||||
return false;
|
||||
|
||||
VK_LoadCvars();
|
||||
|
||||
VK_SceneInit();
|
||||
|
||||
initTextures();
|
||||
|
12
ref_vk/vk_cvar.c
Normal file
12
ref_vk/vk_cvar.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include "vk_cvar.h"
|
||||
#include "vk_common.h"
|
||||
|
||||
#define NONEXTERN_CVAR(cvar) cvar_t *cvar;
|
||||
DECLARE_CVAR(NONEXTERN_CVAR)
|
||||
#undef NONEXTERN_CVAR
|
||||
|
||||
void VK_LoadCvars( void )
|
||||
{
|
||||
r_lighting_modulate = gEngine.Cvar_Get( "r_lighting_modulate", "0.6", FCVAR_ARCHIVE, "lightstyles modulate scale" );
|
||||
cl_lightstyle_lerping = gEngine.pfnGetCvarPointer( "cl_lightstyle_lerping", 0 );
|
||||
}
|
15
ref_vk/vk_cvar.h
Normal file
15
ref_vk/vk_cvar.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "cvardef.h"
|
||||
|
||||
#define CVAR_TO_BOOL( x ) ((x) && ((x)->value != 0.0f) ? true : false )
|
||||
|
||||
void VK_LoadCvars( void );
|
||||
|
||||
#define DECLARE_CVAR(X) \
|
||||
X(r_lighting_modulate) \
|
||||
X(cl_lightstyle_lerping) \
|
||||
|
||||
#define EXTERN_CVAR(cvar) extern cvar_t *cvar;
|
||||
DECLARE_CVAR(EXTERN_CVAR)
|
||||
#undef EXTERN_CVAR
|
@ -1,9 +1,11 @@
|
||||
#include "vk_lightmap.h"
|
||||
#include "vk_common.h"
|
||||
#include "vk_textures.h"
|
||||
#include "vk_cvar.h"
|
||||
|
||||
#include "com_strings.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
#include "protocol.h"
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
@ -14,6 +16,8 @@ typedef struct
|
||||
//msurface_t *dynamic_surfaces;
|
||||
//msurface_t *lightmap_surfaces[MAX_LIGHTMAPS];
|
||||
byte lightmap_buffer[BLOCK_SIZE_MAX*BLOCK_SIZE_MAX*4];
|
||||
|
||||
int lightstylevalue[MAX_LIGHTSTYLES]; // value 0 - 65536
|
||||
} gllightmapstate_t;
|
||||
|
||||
static gllightmapstate_t gl_lms;
|
||||
@ -89,7 +93,7 @@ static void LM_UploadBlock( qboolean dynamic )
|
||||
}
|
||||
|
||||
gEngine.Con_Printf(S_ERROR "VK NOT IMPLEMENTED %s dynamic \n", __FUNCTION__);
|
||||
/* GL_Bind( XASH_TEXTURE0, tr.dlightTexture ); */
|
||||
/* GL_Bind( XASH_TEXTURE0, gl_lms.dlightTexture ); */
|
||||
/* pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, BLOCK_SIZE, height, GL_RGBA, GL_UNSIGNED_BYTE, gl_lms.lightmap_buffer ); */
|
||||
}
|
||||
else
|
||||
@ -127,7 +131,7 @@ format in r_blocklights
|
||||
static void R_BuildLightMap( msurface_t *surf, byte *dest, int stride, qboolean dynamic )
|
||||
{
|
||||
int smax, tmax;
|
||||
uint *bl, scale;
|
||||
uint *bl;
|
||||
int i, map, size, s, t;
|
||||
int sample_size;
|
||||
mextrasurf_t *info = surf->info;
|
||||
@ -144,9 +148,7 @@ static void R_BuildLightMap( msurface_t *surf, byte *dest, int stride, qboolean
|
||||
// add all the lightmaps
|
||||
for( map = 0; map < MAXLIGHTMAPS && surf->styles[map] != 255 && lm; map++ )
|
||||
{
|
||||
// FIXME we need to CL_RunLightStyles first to do this scale = tr.lightstylevalue[surf->styles[map]];
|
||||
const int scale = 256;
|
||||
|
||||
const uint scale = gl_lms.lightstylevalue[surf->styles[map]];
|
||||
for( i = 0, bl = r_blocklights; i < size; i++, bl += 3, lm++ )
|
||||
{
|
||||
bl[0] += gEngine.LightToTexGamma( lm->r ) * scale;
|
||||
@ -157,7 +159,7 @@ static void R_BuildLightMap( msurface_t *surf, byte *dest, int stride, qboolean
|
||||
|
||||
/* TODO
|
||||
// add all the dynamic lights
|
||||
if( surf->dlightframe == tr.framecount && dynamic )
|
||||
if( surf->dlightframe == gl_lms.framecount && dynamic )
|
||||
R_AddDynamicLights( surf );
|
||||
*/
|
||||
|
||||
@ -226,3 +228,65 @@ void VK_ClearLightmap( void )
|
||||
VK_FreeTexture(tglob.lightmapTextures[i]);
|
||||
gl_lms.current_lightmap_texture = 0;
|
||||
}
|
||||
|
||||
void VK_RunLightStyles( void )
|
||||
{
|
||||
int i, k, flight, clight;
|
||||
float l, lerpfrac, backlerp;
|
||||
float frametime = (gpGlobals->time - gpGlobals->oldtime);
|
||||
float scale;
|
||||
lightstyle_t *ls;
|
||||
const model_t *world = gEngine.pfnGetModelByIndex( 1 );
|
||||
|
||||
if( !world ) return;
|
||||
|
||||
scale = r_lighting_modulate->value;
|
||||
|
||||
// light animations
|
||||
// 'm' is normal light, 'a' is no light, 'z' is double bright
|
||||
for( i = 0; i < MAX_LIGHTSTYLES; i++ )
|
||||
{
|
||||
ls = gEngine.GetLightStyle( i );
|
||||
if( !world->lightdata )
|
||||
{
|
||||
gl_lms.lightstylevalue[i] = 256 * 256;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( !gEngine.EngineGetParm( PARAM_GAMEPAUSED, 0 ) && frametime <= 0.1f )
|
||||
ls->time += frametime; // evaluate local time
|
||||
|
||||
flight = (int)Q_floor( ls->time * 10 );
|
||||
clight = (int)Q_ceil( ls->time * 10 );
|
||||
lerpfrac = ( ls->time * 10 ) - flight;
|
||||
backlerp = 1.0f - lerpfrac;
|
||||
|
||||
if( !ls->length )
|
||||
{
|
||||
gl_lms.lightstylevalue[i] = 256 * scale;
|
||||
continue;
|
||||
}
|
||||
else if( ls->length == 1 )
|
||||
{
|
||||
// single length style so don't bother interpolating
|
||||
gl_lms.lightstylevalue[i] = ls->map[0] * 22 * scale;
|
||||
continue;
|
||||
}
|
||||
else if( !ls->interp || !CVAR_TO_BOOL( cl_lightstyle_lerping ))
|
||||
{
|
||||
gl_lms.lightstylevalue[i] = ls->map[flight%ls->length] * 22 * scale;
|
||||
continue;
|
||||
}
|
||||
|
||||
// interpolate animating light
|
||||
// frame just gone
|
||||
k = ls->map[flight % ls->length];
|
||||
l = (float)( k * 22.0f ) * backlerp;
|
||||
|
||||
// upcoming frame
|
||||
k = ls->map[clight % ls->length];
|
||||
l += (float)( k * 22.0f ) * lerpfrac;
|
||||
|
||||
gl_lms.lightstylevalue[i] = (int)l * scale;
|
||||
}
|
||||
}
|
||||
|
@ -9,3 +9,4 @@
|
||||
void VK_ClearLightmap( void );
|
||||
void VK_CreateSurfaceLightmap( msurface_t *surf, const model_t *loadmodel );
|
||||
void VK_UploadLightmap( void );
|
||||
void VK_RunLightStyles( void );
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "vk_2d.h"
|
||||
#include "vk_scene.h"
|
||||
#include "vk_framectl.h"
|
||||
#include "vk_lightmap.h"
|
||||
|
||||
#include "xash3d_types.h"
|
||||
#include "com_strings.h"
|
||||
@ -137,11 +138,6 @@ static void R_InitSkyClouds( struct mip_s *mt, struct texture_s *tx, qboolean cu
|
||||
|
||||
extern void GL_SubdivideSurface( msurface_t *fa );
|
||||
|
||||
static void CL_RunLightStyles( void )
|
||||
{
|
||||
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
// sprites
|
||||
static void R_GetSpriteParms( int *frameWidth, int *frameHeight, int *numFrames, int currentFrame, const model_t *pSprite )
|
||||
{
|
||||
@ -605,7 +601,7 @@ ref_interface_t gReffuncs =
|
||||
|
||||
R_InitSkyClouds,
|
||||
GL_SubdivideSurface,
|
||||
CL_RunLightStyles,
|
||||
VK_RunLightStyles,
|
||||
|
||||
R_GetSpriteParms,
|
||||
R_GetSpriteTexture,
|
||||
|
@ -29,6 +29,9 @@ void R_NewMap( void )
|
||||
|
||||
VK_ClearLightmap();
|
||||
|
||||
// This is to ensure that we have computed lightstyles properly
|
||||
VK_RunLightStyles();
|
||||
|
||||
// TODO should we do something like VK_BrushBeginLoad?
|
||||
VK_BrushClear();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user