From 7ab8cb14df5c1810973f39e92934e5eb3d4c5ef6 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 17 Jul 2002 05:29:20 +0000 Subject: [PATCH] faster static light tracing (by not doing it as often), this also means results of static light traces are cached in the entity_render_t (which is now considered semi-persistent), made light falloff in .lights file actually work (it wasn't being used by the model lighting code... oops), also made coronas twice as bright git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2046 d7cf8633-e32d-0410-b094-e92efae38249 --- client.h | 13 ++++++++++-- r_light.c | 61 +++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/client.h b/client.h index 3edc6f98..99a85af3 100644 --- a/client.h +++ b/client.h @@ -29,7 +29,10 @@ typedef struct frameblend_s } frameblend_t; -// LordHavoc: nothing in this structure is persistant, it may be overwritten by the client every frame, for persistant data use entity_lerp_t. +#define MAXENTLIGHTS 128 + +// LordHavoc: disregard the following warning, entlights stuff is semi-persistent... +// LordHavoc: nothing in this structure is persistent, it may be overwritten by the client every frame, for persistent data use entity_lerp_t. typedef struct entity_render_s { // location @@ -75,6 +78,12 @@ typedef struct entity_render_s vec3_t mins, maxs; // 4 frame numbers (-1 if not used) and their blending scalers (0-1), if interpolation is not desired, use frame instead frameblend_t frameblend[4]; + + // caching results of static light traces (this is semi-persistent) + double entlightstime; + vec3_t entlightsorigin; + int numentlights; + unsigned short entlights[MAXENTLIGHTS]; } entity_render_t; @@ -193,7 +202,7 @@ typedef enum cactive_t; // -// the client_static_t structure is persistant through an arbitrary number +// the client_static_t structure is persistent through an arbitrary number // of server connections // typedef struct diff --git a/r_light.c b/r_light.c index c4db02cc..f728de2c 100644 --- a/r_light.c +++ b/r_light.c @@ -171,7 +171,7 @@ void R_DrawCoronas(void) VectorSubtract(rd->origin, vpn, diff); if (CL_TraceLine(r_origin, diff, NULL, NULL, 0, true) == 1) { - scale = 1.0f / 262144.0f; + scale = 1.0f / 131072.0f; m.cr = rd->light[0] * scale; m.cg = rd->light[1] * scale; m.cb = rd->light[2] * scale; @@ -754,11 +754,14 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo int modeldlightbits[8]; mlight_t *sl; a = currentrenderentity->alpha; - if (currentrenderentity->effects & EF_FULLBRIGHT) + // scale of the model's coordinate space, to alter light attenuation to match + // make the mscale squared so it can scale the squared distance results + mscale = currentrenderentity->scale * currentrenderentity->scale; + if (r_fullbright.integer || r_ambient.value > 128.0f || currentrenderentity->effects & EF_FULLBRIGHT) { - basecolor[0] = colorr; - basecolor[1] = colorg; - basecolor[2] = colorb; + basecolor[0] = colorr * 2.0f; + basecolor[1] = colorg * 2.0f; + basecolor[2] = colorb * 2.0f; } else { @@ -767,17 +770,50 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo R_ModelLightPoint(basecolor, currentrenderentity->origin, modeldlightbits); nl = &nearlight[0]; - for (i = 0, sl = cl.worldmodel->lights;i < cl.worldmodel->numlights && nearlights < MAX_DLIGHTS;i++, sl++) + VectorSubtract(currentrenderentity->origin, currentrenderentity->entlightsorigin, v); + if ((realtime > currentrenderentity->entlightstime && DotProduct(v,v) >= 1.0f) || currentrenderentity->numentlights >= MAXENTLIGHTS) { - if (CL_TraceLine(currentrenderentity->origin, sl->origin, NULL, NULL, 0, false) == 1) + currentrenderentity->numentlights = 0; + currentrenderentity->entlightstime = realtime + 0.2; + VectorCopy(currentrenderentity->origin, currentrenderentity->entlightsorigin); + for (i = 0, sl = cl.worldmodel->lights;i < cl.worldmodel->numlights && nearlights < MAX_DLIGHTS;i++, sl++) { - nl->falloff = sl->falloff; + if (CL_TraceLine(currentrenderentity->origin, sl->origin, NULL, NULL, 0, false) == 1) + { + if (currentrenderentity->numentlights < MAXENTLIGHTS) + currentrenderentity->entlights[currentrenderentity->numentlights++] = i; + + // integrate mscale into falloff, for maximum speed + nl->falloff = mscale * sl->falloff; + // transform the light into the model's coordinate system + if (worldcoords) + VectorCopy(sl->origin, nl->origin); + else + softwareuntransform(sl->origin, nl->origin); + f = d_lightstylevalue[sl->style] * (1.0f / 65536.0f); + VectorScale(sl->light, f, nl->light); + //nl->cullradius2 = 99999999; + nl->lightsubtract = sl->subtract; + nl->offset = sl->distbias; + nl++; + nearlights++; + } + } + } + else + { + for (i = 0;i < currentrenderentity->numentlights && nearlights < MAX_DLIGHTS;i++) + { + sl = cl.worldmodel->lights + currentrenderentity->entlights[i]; + + // integrate mscale into falloff, for maximum speed + nl->falloff = mscale * sl->falloff; // transform the light into the model's coordinate system if (worldcoords) VectorCopy(sl->origin, nl->origin); else softwareuntransform(sl->origin, nl->origin); - f = d_lightstylevalue[sl->style] * (1.0f / 32768.0f); + f = d_lightstylevalue[sl->style] * (1.0f / 65536.0f); VectorScale(sl->light, f, nl->light); //nl->cullradius2 = 99999999; nl->lightsubtract = sl->subtract; @@ -803,6 +839,8 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo VectorCopy(r_dlight[i].origin, nl->origin); else softwareuntransform(r_dlight[i].origin, nl->origin); + // integrate mscale into falloff, for maximum speed + nl->falloff = mscale; // scale the cullradius so culling by distance is done before mscale is applied //nl->cullradius2 = r_dlight[i].cullradius2 * currentrenderentity->scale * currentrenderentity->scale; nl->light[0] = r_dlight[i].light[0] * colorr; @@ -822,9 +860,6 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo basecolor[1] *= colorg; basecolor[2] *= colorb; avc = aliasvertcolor; - // scale of the model's coordinate space, to alter light attenuation to match - // make the mscale squared so it can scale the squared distance results - mscale = currentrenderentity->scale * currentrenderentity->scale; if (nearlights) { av = aliasvert; @@ -837,7 +872,7 @@ void R_LightModel(int numverts, float colorr, float colorg, float colorb, int wo // distance attenuation VectorSubtract(nl->origin, av, v); dist2 = DotProduct(v,v); - f = (1.0f / (dist2 * mscale + nl->offset)) - nl->lightsubtract; + f = (1.0f / (dist2 * nl->falloff + nl->offset)) - nl->lightsubtract; if (f > 0) { // directional shading -- 2.39.2