mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 15:21:44 +00:00
gl1: Prepare to share R_LightPoint
This commit is contained in:
parent
8f5a40710b
commit
7fd23f07db
8 changed files with 103 additions and 92 deletions
|
@ -132,6 +132,12 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
|
||||||
int sidebit;
|
int sidebit;
|
||||||
float dist;
|
float dist;
|
||||||
|
|
||||||
|
if (surf->dlightframe != r_dlightframecount)
|
||||||
|
{
|
||||||
|
surf->dlightbits = 0;
|
||||||
|
surf->dlightframe = r_dlightframecount;
|
||||||
|
}
|
||||||
|
|
||||||
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
|
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
|
||||||
|
|
||||||
if (dist >= 0)
|
if (dist >= 0)
|
||||||
|
@ -148,12 +154,6 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surf->dlightframe != r_dlightframecount)
|
|
||||||
{
|
|
||||||
surf->dlightbits = 0;
|
|
||||||
surf->dlightframe = r_dlightframecount;
|
|
||||||
}
|
|
||||||
|
|
||||||
surf->dlightbits |= bit;
|
surf->dlightbits |= bit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,8 +161,8 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
|
||||||
void
|
void
|
||||||
R_PushDlights(void)
|
R_PushDlights(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
dlight_t *l;
|
dlight_t *l;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (gl1_flashblend->value)
|
if (gl1_flashblend->value)
|
||||||
{
|
{
|
||||||
|
@ -182,15 +182,15 @@ R_PushDlights(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
|
R_LightPoint(const entity_t *currententity, refdef_t *refdef, const msurface_t *surfaces,
|
||||||
|
const mnode_t *nodes, vec3_t p, vec3_t color, float modulate, vec3_t lightspot)
|
||||||
{
|
{
|
||||||
vec3_t end;
|
vec3_t end, dist;
|
||||||
float r;
|
float r;
|
||||||
int lnum;
|
int lnum;
|
||||||
dlight_t *dl;
|
dlight_t *dl;
|
||||||
vec3_t dist;
|
|
||||||
|
|
||||||
if (!r_worldmodel || !r_worldmodel->lightdata || !currententity)
|
if (!currententity)
|
||||||
{
|
{
|
||||||
color[0] = color[1] = color[2] = 1.0;
|
color[0] = color[1] = color[2] = 1.0;
|
||||||
return;
|
return;
|
||||||
|
@ -200,8 +200,8 @@ R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
|
||||||
end[1] = p[1];
|
end[1] = p[1];
|
||||||
end[2] = p[2] - 2048;
|
end[2] = p[2] - 2048;
|
||||||
|
|
||||||
r = R_RecursiveLightPoint(r_worldmodel->surfaces, r_worldmodel->nodes,
|
r = R_RecursiveLightPoint(surfaces, nodes, refdef->lightstyles,
|
||||||
r_newrefdef.lightstyles, p, end, pointcolor, lightspot, r_modulate->value);
|
p, end, pointcolor, lightspot, modulate);
|
||||||
|
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
{
|
{
|
||||||
|
@ -213,16 +213,16 @@ R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add dynamic lights */
|
/* add dynamic lights */
|
||||||
dl = r_newrefdef.dlights;
|
dl = refdef->dlights;
|
||||||
|
|
||||||
for (lnum = 0; lnum < r_newrefdef.num_dlights; lnum++, dl++)
|
for (lnum = 0; lnum < refdef->num_dlights; lnum++, dl++)
|
||||||
{
|
{
|
||||||
float add;
|
float add;
|
||||||
|
|
||||||
VectorSubtract(currententity->origin,
|
VectorSubtract(currententity->origin,
|
||||||
dl->origin, dist);
|
dl->origin, dist);
|
||||||
add = dl->intensity - VectorLength(dist);
|
add = dl->intensity - VectorLength(dist);
|
||||||
add *= (1.0 / 256);
|
add *= (1.0f / 256.0f);
|
||||||
|
|
||||||
if (add > 0)
|
if (add > 0)
|
||||||
{
|
{
|
||||||
|
@ -230,7 +230,7 @@ R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VectorScale(color, r_modulate->value, color);
|
VectorScale(color, modulate, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -478,7 +478,7 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||||
}
|
}
|
||||||
|
|
||||||
store:
|
store:
|
||||||
|
/* put into texture format */
|
||||||
stride -= (smax << 2);
|
stride -= (smax << 2);
|
||||||
bl = s_blocklights;
|
bl = s_blocklights;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ viddef_t vid;
|
||||||
model_t *r_worldmodel;
|
model_t *r_worldmodel;
|
||||||
|
|
||||||
float gldepthmin, gldepthmax;
|
float gldepthmin, gldepthmax;
|
||||||
|
extern vec3_t lightspot;
|
||||||
|
|
||||||
glconfig_t gl_config;
|
glconfig_t gl_config;
|
||||||
glstate_t gl_state;
|
glstate_t gl_state;
|
||||||
|
@ -250,13 +251,15 @@ R_DrawNullModel(entity_t *currententity)
|
||||||
{
|
{
|
||||||
vec3_t shadelight;
|
vec3_t shadelight;
|
||||||
|
|
||||||
if (currententity->flags & RF_FULLBRIGHT)
|
if (currententity->flags & RF_FULLBRIGHT || !r_worldmodel || !r_worldmodel->lightdata)
|
||||||
{
|
{
|
||||||
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
|
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
R_LightPoint(currententity, currententity->origin, shadelight);
|
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
|
||||||
|
r_worldmodel->nodes, currententity->origin, shadelight,
|
||||||
|
r_modulate->value, lightspot);
|
||||||
}
|
}
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -1122,7 +1125,9 @@ R_SetLightLevel(entity_t *currententity)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save off light value for server to look at */
|
/* save off light value for server to look at */
|
||||||
R_LightPoint(currententity, r_newrefdef.vieworg, shadelight);
|
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
|
||||||
|
r_worldmodel->nodes, r_newrefdef.vieworg, shadelight,
|
||||||
|
r_modulate->value, lightspot);
|
||||||
|
|
||||||
/* pick the greatest component, which should be the
|
/* pick the greatest component, which should be the
|
||||||
* same as the mono value returned by software */
|
* same as the mono value returned by software */
|
||||||
|
|
|
@ -678,7 +678,16 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
R_LightPoint(currententity, currententity->origin, shadelight);
|
if (!r_worldmodel || !r_worldmodel->lightdata)
|
||||||
|
{
|
||||||
|
shadelight[0] = shadelight[1] = shadelight[2] = 1.0F;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
R_LightPoint(currententity, &r_newrefdef, r_worldmodel->surfaces,
|
||||||
|
r_worldmodel->nodes, currententity->origin, shadelight,
|
||||||
|
r_modulate->value, lightspot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* player lighting hack for communication back to server */
|
/* player lighting hack for communication back to server */
|
||||||
|
|
|
@ -249,7 +249,8 @@ void R_Bind(int texnum);
|
||||||
|
|
||||||
void R_TexEnv(GLenum value);
|
void R_TexEnv(GLenum value);
|
||||||
|
|
||||||
void R_LightPoint(entity_t *currententity, vec3_t p, vec3_t color);
|
void R_LightPoint(const entity_t *currententity, refdef_t *refdef, const msurface_t *surfaces,
|
||||||
|
const mnode_t *nodes, vec3_t p, vec3_t color, float modulate, vec3_t lightspot);
|
||||||
void R_PushDlights(void);
|
void R_PushDlights(void);
|
||||||
|
|
||||||
extern model_t *r_worldmodel;
|
extern model_t *r_worldmodel;
|
||||||
|
|
|
@ -76,8 +76,8 @@ GL3_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframe
|
||||||
void
|
void
|
||||||
GL3_PushDlights(void)
|
GL3_PushDlights(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
dlight_t *l;
|
dlight_t *l;
|
||||||
|
int i;
|
||||||
|
|
||||||
/* because the count hasn't advanced yet for this frame */
|
/* because the count hasn't advanced yet for this frame */
|
||||||
r_dlightframecount = gl3_framecount + 1;
|
r_dlightframecount = gl3_framecount + 1;
|
||||||
|
@ -109,12 +109,10 @@ GL3_PushDlights(void)
|
||||||
void
|
void
|
||||||
GL3_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
|
GL3_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
|
||||||
{
|
{
|
||||||
vec3_t end;
|
vec3_t end, dist;
|
||||||
float r;
|
float r;
|
||||||
int lnum;
|
int lnum;
|
||||||
dlight_t *dl;
|
dlight_t *dl;
|
||||||
vec3_t dist;
|
|
||||||
float add;
|
|
||||||
|
|
||||||
if (!gl3_worldmodel->lightdata || !currententity)
|
if (!gl3_worldmodel->lightdata || !currententity)
|
||||||
{
|
{
|
||||||
|
@ -145,6 +143,8 @@ GL3_LightPoint(entity_t *currententity, vec3_t p, vec3_t color)
|
||||||
|
|
||||||
for (lnum = 0; lnum < gl3_newrefdef.num_dlights; lnum++, dl++)
|
for (lnum = 0; lnum < gl3_newrefdef.num_dlights; lnum++, dl++)
|
||||||
{
|
{
|
||||||
|
float add;
|
||||||
|
|
||||||
VectorSubtract(currententity->origin,
|
VectorSubtract(currententity->origin,
|
||||||
dl->origin, dist);
|
dl->origin, dist);
|
||||||
add = dl->intensity - VectorLength(dist);
|
add = dl->intensity - VectorLength(dist);
|
||||||
|
|
|
@ -1045,7 +1045,7 @@ R_BuildPolygonFromSurface(const entity_t *currententity, const model_t *currentm
|
||||||
|
|
||||||
r_polydesc.nump = 0;
|
r_polydesc.nump = 0;
|
||||||
|
|
||||||
// reconstruct the polygon
|
/* reconstruct the polygon */
|
||||||
pedges = currentmodel->edges;
|
pedges = currentmodel->edges;
|
||||||
lnumverts = fa->numedges;
|
lnumverts = fa->numedges;
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,12 @@
|
||||||
* Lightmaps and dynamic lighting
|
* Lightmaps and dynamic lighting
|
||||||
*
|
*
|
||||||
* =======================================================================
|
* =======================================================================
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "header/local.h"
|
#include "header/local.h"
|
||||||
|
|
||||||
int r_dlightframecount;
|
int r_dlightframecount;
|
||||||
|
vec3_t lightspot;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
R_RenderDlight(dlight_t *light)
|
R_RenderDlight(dlight_t *light)
|
||||||
|
@ -83,11 +83,6 @@ R_RenderDlight(dlight_t *light)
|
||||||
vkCmdDrawIndexed(vk_activeCmdbuffer, 48, 1, 0, 0, 0);
|
vkCmdDrawIndexed(vk_activeCmdbuffer, 48, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
=============
|
|
||||||
R_RenderDlights
|
|
||||||
=============
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
R_RenderDlights(void)
|
R_RenderDlights(void)
|
||||||
{
|
{
|
||||||
|
@ -99,24 +94,17 @@ R_RenderDlights(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r_dlightframecount = r_framecount + 1; // because the count hasn't
|
/* because the count hasn't advanced yet for this frame */
|
||||||
// advanced yet for this frame
|
r_dlightframecount = r_framecount + 1;
|
||||||
|
|
||||||
l = r_newrefdef.dlights;
|
l = r_newrefdef.dlights;
|
||||||
|
|
||||||
for (i = 0; i < r_newrefdef.num_dlights; i++, l++)
|
for (i = 0; i < r_newrefdef.num_dlights; i++, l++)
|
||||||
{
|
{
|
||||||
R_RenderDlight(l);
|
R_RenderDlight(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
=============================================================================
|
|
||||||
|
|
||||||
DYNAMIC LIGHTS
|
|
||||||
|
|
||||||
=============================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
void
|
||||||
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
|
R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount)
|
||||||
{
|
{
|
||||||
|
@ -128,6 +116,25 @@ R_MarkSurfaceLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframeco
|
||||||
|
|
||||||
for (i = 0; i < node->numsurfaces; i++, surf++)
|
for (i = 0; i < node->numsurfaces; i++, surf++)
|
||||||
{
|
{
|
||||||
|
int sidebit;
|
||||||
|
float dist;
|
||||||
|
|
||||||
|
dist = DotProduct(light->origin, surf->plane->normal) - surf->plane->dist;
|
||||||
|
|
||||||
|
if (dist >= 0)
|
||||||
|
{
|
||||||
|
sidebit = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sidebit = SURF_PLANEBACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((surf->flags & SURF_PLANEBACK) != sidebit)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (surf->dlightframe != r_dlightframecount)
|
if (surf->dlightframe != r_dlightframecount)
|
||||||
{
|
{
|
||||||
surf->dlightbits = 0;
|
surf->dlightbits = 0;
|
||||||
|
@ -161,18 +168,6 @@ R_PushDlights(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
=============================================================================
|
|
||||||
|
|
||||||
LIGHT SAMPLING
|
|
||||||
|
|
||||||
=============================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
vec3_t lightspot;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity)
|
R_LightPoint(vec3_t p, vec3_t color, entity_t *currententity)
|
||||||
{
|
{
|
||||||
|
@ -270,12 +265,13 @@ R_AddDynamicLights(msurface_t *surf)
|
||||||
surf->plane->normal[i] * fdist;
|
surf->plane->normal[i] * fdist;
|
||||||
}
|
}
|
||||||
|
|
||||||
local[0] = DotProduct(impact,
|
local[0] = DotProduct(impact, surf->lmvecs[0]) +
|
||||||
surf->lmvecs[0]) + surf->lmvecs[0][3] - surf->texturemins[0];
|
surf->lmvecs[0][3] - surf->texturemins[0];
|
||||||
local[1] = DotProduct(impact,
|
local[1] = DotProduct(impact, surf->lmvecs[1]) +
|
||||||
surf->lmvecs[1]) + surf->lmvecs[1][3] - surf->texturemins[1];
|
surf->lmvecs[1][3] - surf->texturemins[1];
|
||||||
|
|
||||||
plightdest = s_blocklights;
|
plightdest = s_blocklights;
|
||||||
|
|
||||||
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += (1 << surf->lmshift))
|
for (t = 0, ftacc = 0; t < tmax; t++, ftacc += (1 << surf->lmshift))
|
||||||
{
|
{
|
||||||
td = local[1] - ftacc;
|
td = local[1] - ftacc;
|
||||||
|
@ -346,7 +342,7 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||||
int i, j, size;
|
int i, j, size;
|
||||||
byte *lightmap;
|
byte *lightmap;
|
||||||
float scale[4];
|
float scale[4];
|
||||||
int mapscount;
|
int nummaps;
|
||||||
float *bl;
|
float *bl;
|
||||||
|
|
||||||
if (surf->texinfo->flags &
|
if (surf->texinfo->flags &
|
||||||
|
@ -394,15 +390,15 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count the # of maps */
|
/* count the # of maps */
|
||||||
for (mapscount = 0; mapscount < MAXLIGHTMAPS && surf->styles[mapscount] != 255 ;
|
for (nummaps = 0; nummaps < MAXLIGHTMAPS && surf->styles[nummaps] != 255;
|
||||||
mapscount++)
|
nummaps++)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
lightmap = surf->samples;
|
lightmap = surf->samples;
|
||||||
|
|
||||||
/* add all the lightmaps */
|
/* add all the lightmaps */
|
||||||
if (mapscount == 1)
|
if (nummaps == 1)
|
||||||
{
|
{
|
||||||
int maps;
|
int maps;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue