rtx: add lightstyles support, fix #138
This commit is contained in:
parent
54a777f0fd
commit
4f903bd1d6
|
@ -2,6 +2,7 @@
|
|||
#include "vk_mapents.h"
|
||||
#include "vk_textures.h"
|
||||
#include "vk_brush.h"
|
||||
#include "vk_lightmap.h"
|
||||
#include "vk_cvar.h"
|
||||
#include "vk_common.h"
|
||||
#include "profiler.h"
|
||||
|
@ -770,7 +771,7 @@ static void addPointLightToAllClusters( int index ) {
|
|||
}
|
||||
}
|
||||
|
||||
static int addPointLight( const vec3_t origin, const vec3_t color, float radius, float hack_attenuation ) {
|
||||
static int addPointLight( const vec3_t origin, const vec3_t color, float radius, int lightstyle, float hack_attenuation ) {
|
||||
const int index = g_lights.num_point_lights;
|
||||
vk_point_light_t *const plight = g_lights.point_lights + index;
|
||||
|
||||
|
@ -789,7 +790,9 @@ static int addPointLight( const vec3_t origin, const vec3_t color, float radius,
|
|||
VectorCopy(origin, plight->origin);
|
||||
plight->radius = radius;
|
||||
|
||||
VectorScale(color, hack_attenuation, plight->color);
|
||||
VectorScale(color, hack_attenuation, plight->base_color);
|
||||
VectorCopy(plight->base_color, plight->color);
|
||||
plight->lightstyle = lightstyle;
|
||||
|
||||
// Omnidirectional light
|
||||
plight->stopdot = plight->stopdot2 = -1.f;
|
||||
|
@ -800,7 +803,7 @@ static int addPointLight( const vec3_t origin, const vec3_t color, float radius,
|
|||
return index;
|
||||
}
|
||||
|
||||
static int addSpotLight( const vk_light_entity_t *le, float radius, float hack_attenuation, qboolean all_clusters ) {
|
||||
static int addSpotLight( const vk_light_entity_t *le, float radius, int lightstyle, float hack_attenuation, qboolean all_clusters ) {
|
||||
const int index = g_lights.num_point_lights;
|
||||
vk_point_light_t *const plight = g_lights.point_lights + index;
|
||||
|
||||
|
@ -821,7 +824,9 @@ static int addSpotLight( const vk_light_entity_t *le, float radius, float hack_a
|
|||
VectorCopy(le->origin, plight->origin);
|
||||
plight->radius = radius;
|
||||
|
||||
VectorScale(le->color, hack_attenuation, plight->color);
|
||||
VectorScale(le->color, hack_attenuation, plight->base_color);
|
||||
VectorCopy(plight->base_color, plight->color);
|
||||
plight->lightstyle = lightstyle;
|
||||
|
||||
VectorCopy(le->dir, plight->dir);
|
||||
plight->stopdot = le->stopdot;
|
||||
|
@ -853,7 +858,7 @@ static void addDlight( const dlight_t *dlight ) {
|
|||
dlight->color.g * scaler,
|
||||
dlight->color.b * scaler);
|
||||
|
||||
index = addPointLight(dlight->origin, color, dlight->radius, 1e5f);
|
||||
index = addPointLight(dlight->origin, color, dlight->radius, -1, 1e5f);
|
||||
if (index < 0)
|
||||
return;
|
||||
|
||||
|
@ -875,12 +880,12 @@ static void processStaticPointLights( void ) {
|
|||
|
||||
switch (le->type) {
|
||||
case LightTypePoint:
|
||||
index = addPointLight(le->origin, le->color, default_radius, hack_attenuation);
|
||||
index = addPointLight(le->origin, le->color, default_radius, le->style, hack_attenuation);
|
||||
break;
|
||||
|
||||
case LightTypeSpot:
|
||||
case LightTypeEnvironment:
|
||||
index = addSpotLight(le, default_radius, hack_attenuation_spot, i == g_map_entities.single_environment_index);
|
||||
index = addSpotLight(le, default_radius, le->style, hack_attenuation_spot, i == g_map_entities.single_environment_index);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -971,6 +976,17 @@ void VK_LightsFrameFinalize( void ) {
|
|||
/* } */
|
||||
/* } */
|
||||
|
||||
for (int i = 0; i < g_lights.num_point_lights; ++i) {
|
||||
vk_point_light_t *const light = g_lights.point_lights + i;
|
||||
if (light->lightstyle < 0 || light->lightstyle >= MAX_LIGHTSTYLES)
|
||||
continue;
|
||||
|
||||
{
|
||||
const float scale = g_lightmap.lightstylevalue[light->lightstyle] / 255.f;
|
||||
VectorScale(light->base_color, scale, light->color);
|
||||
}
|
||||
}
|
||||
|
||||
APROF_SCOPE_BEGIN(dlights);
|
||||
for (int i = 0; i < MAX_DLIGHTS; ++i) {
|
||||
const dlight_t *dlight = gEngine.GetDynamicLight(i);
|
||||
|
|
|
@ -41,6 +41,9 @@ typedef struct {
|
|||
float stopdot, stopdot2;
|
||||
float radius;
|
||||
int flags;
|
||||
|
||||
int lightstyle;
|
||||
vec3_t base_color;
|
||||
} vk_point_light_t;
|
||||
|
||||
// TODO spotlight
|
||||
|
|
|
@ -16,12 +16,12 @@ 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;
|
||||
|
||||
xvk_lightmap_state_t g_lightmap;
|
||||
|
||||
// TODO this doesn't really need to be this huge
|
||||
static uint r_blocklights[BLOCK_SIZE_MAX*BLOCK_SIZE_MAX*3]; // This is just a temp HDR-ish buffer for lightmap generation
|
||||
|
||||
|
@ -150,7 +150,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++ )
|
||||
{
|
||||
const uint scale = gl_lms.lightstylevalue[surf->styles[map]];
|
||||
const uint scale = g_lightmap.lightstylevalue[surf->styles[map]];
|
||||
for( i = 0, bl = r_blocklights; i < size; i++, bl += 3, lm++ )
|
||||
{
|
||||
bl[0] += gEngine.LightToTexGamma( lm->r ) * scale;
|
||||
|
@ -253,7 +253,7 @@ void VK_RunLightStyles( void )
|
|||
ls = gEngine.GetLightStyle( i );
|
||||
if( !world->lightdata )
|
||||
{
|
||||
gl_lms.lightstylevalue[i] = 256 * 256;
|
||||
g_lightmap.lightstylevalue[i] = 256 * 256;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -267,18 +267,18 @@ void VK_RunLightStyles( void )
|
|||
|
||||
if( !ls->length )
|
||||
{
|
||||
gl_lms.lightstylevalue[i] = 256 * scale;
|
||||
g_lightmap.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;
|
||||
g_lightmap.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;
|
||||
g_lightmap.lightstylevalue[i] = ls->map[flight%ls->length] * 22 * scale;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -291,6 +291,6 @@ void VK_RunLightStyles( void )
|
|||
k = ls->map[clight % ls->length];
|
||||
l += (float)( k * 22.0f ) * lerpfrac;
|
||||
|
||||
gl_lms.lightstylevalue[i] = (int)l * scale;
|
||||
g_lightmap.lightstylevalue[i] = (int)l * scale;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,17 @@
|
|||
|
||||
#include "const.h"
|
||||
#include "com_model.h"
|
||||
#include "protocol.h"
|
||||
|
||||
#define BLOCK_SIZE_MAX 1024
|
||||
#define BLOCK_SIZE BLOCK_SIZE_MAX
|
||||
|
||||
typedef struct {
|
||||
int lightstylevalue[MAX_LIGHTSTYLES]; // value 0 - 65536
|
||||
} xvk_lightmap_state_t;
|
||||
|
||||
extern xvk_lightmap_state_t g_lightmap;
|
||||
|
||||
void VK_ClearLightmap( void );
|
||||
void VK_CreateSurfaceLightmap( msurface_t *surf, const model_t *loadmodel );
|
||||
void VK_UploadLightmap( void );
|
||||
|
|
|
@ -205,16 +205,23 @@ static void addLightEntity( const entity_props_t *props, unsigned have_fields )
|
|||
VectorCopy(props->_light, le->color);
|
||||
}
|
||||
|
||||
if ( (have_fields & Field_style) != 0) {
|
||||
le->style = props->style;
|
||||
}
|
||||
|
||||
if (le->type != LightEnvironment) {
|
||||
//gEngine.Con_Reportf("Pre scaling: %f %f %f ", values._light[0], values._light[1], values._light[2]);
|
||||
weirdGoldsrcLightScaling(le->color);
|
||||
//gEngine.Con_Reportf("post scaling: %f %f %f\n", values._light[0], values._light[1], values._light[2]);
|
||||
}
|
||||
|
||||
gEngine.Con_Reportf("Added light %d: %s color=(%f %f %f) origin=(%f %f %f) dir=(%f %f %f) stopdot=(%f %f)\n", g_map_entities.num_lights,
|
||||
gEngine.Con_Reportf("Added light %d: %s targetname=%s color=(%f %f %f) origin=(%f %f %f) style=%d dir=(%f %f %f) stopdot=(%f %f)\n",
|
||||
g_map_entities.num_lights,
|
||||
le->type == LightTypeEnvironment ? "environment" : le->type == LightTypeSpot ? "spot" : "point",
|
||||
props->targetname,
|
||||
le->color[0], le->color[1], le->color[2],
|
||||
le->origin[0], le->origin[1], le->origin[2],
|
||||
le->style,
|
||||
le->dir[0], le->dir[1], le->dir[2],
|
||||
le->stopdot, le->stopdot2);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
X(9, string, wad, WadList) \
|
||||
X(10, string, targetname, String) \
|
||||
X(11, string, target, String) \
|
||||
X(12, int, style, Int) \
|
||||
|
||||
typedef enum {
|
||||
Unknown = 0,
|
||||
|
@ -46,11 +47,8 @@ typedef struct {
|
|||
vec3_t color;
|
||||
vec3_t dir;
|
||||
|
||||
//int style;
|
||||
int flags;
|
||||
int style;
|
||||
float stopdot, stopdot2;
|
||||
//char pattern[64];
|
||||
//int dark;
|
||||
|
||||
string target_entity;
|
||||
} vk_light_entity_t;
|
||||
|
|
Loading…
Reference in New Issue