mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-05-31 17:21:46 +00:00
Readability improvements and minor speedup in R_AddDynamicLights.
This commit is contained in:
parent
9bd5bd4ffb
commit
4698dc0d7d
1 changed files with 29 additions and 40 deletions
|
@ -108,8 +108,7 @@ R_AddDynamicLights (msurface_t *surf)
|
||||||
{
|
{
|
||||||
int lnum;
|
int lnum;
|
||||||
int sd, td;
|
int sd, td;
|
||||||
float dist, rada, radb;
|
float dist, maxdist, radb, brightness, red, green, blue, f;
|
||||||
float red, green, blue, brightness;
|
|
||||||
vec3_t impact, local;
|
vec3_t impact, local;
|
||||||
int s, t;
|
int s, t;
|
||||||
int i;
|
int i;
|
||||||
|
@ -126,57 +125,47 @@ R_AddDynamicLights (msurface_t *surf)
|
||||||
if ( !(surf->dlightbits & (1<<lnum) ) )
|
if ( !(surf->dlightbits & (1<<lnum) ) )
|
||||||
continue; // not lit by this light
|
continue; // not lit by this light
|
||||||
|
|
||||||
dist = DotProduct (cl_dlights[lnum].origin, surf->plane->normal)
|
dist = DotProduct (cl_dlights[lnum].origin, surf->plane->normal) - surf->plane->dist;
|
||||||
- surf->plane->dist;
|
|
||||||
|
|
||||||
for (i=0 ; i<3 ; i++)
|
for (i=0 ; i<3 ; i++)
|
||||||
impact[i] = cl_dlights[lnum].origin[i] -
|
impact[i] = cl_dlights[lnum].origin[i] - surf->plane->normal[i]*dist;
|
||||||
surf->plane->normal[i]*dist;
|
|
||||||
|
|
||||||
local[0] = DotProduct (impact, tex->vecs[0]) + tex->vecs[0][3]
|
local[0] = DotProduct (impact, tex->vecs[0]) + tex->vecs[0][3] - surf->texturemins[0];
|
||||||
- surf->texturemins[0];
|
local[1] = DotProduct (impact, tex->vecs[1]) + tex->vecs[1][3] - surf->texturemins[1];
|
||||||
local[1] = DotProduct (impact, tex->vecs[1]) + tex->vecs[1][3]
|
|
||||||
- surf->texturemins[1];
|
|
||||||
|
|
||||||
s = bound (0, local[0]+0.5, (smax-1)*16);
|
|
||||||
t = bound (0, local[1]+0.5, (tmax-1)*16);
|
|
||||||
|
|
||||||
sd = local[0] - s;
|
|
||||||
td = local[1] - t;
|
|
||||||
dist *= dist;
|
dist *= dist;
|
||||||
|
|
||||||
// get brightest color's value
|
|
||||||
red = cl_dlights[lnum].color[0];
|
red = cl_dlights[lnum].color[0];
|
||||||
green = cl_dlights[lnum].color[1];
|
green = cl_dlights[lnum].color[1];
|
||||||
blue = cl_dlights[lnum].color[2];
|
blue = cl_dlights[lnum].color[2];
|
||||||
brightness = max(red, max(green, blue));
|
|
||||||
|
maxdist = cl_dlights[lnum].radius*cl_dlights[lnum].radius; // for comparisons to minimum acceptable light
|
||||||
rada = (cl_dlights[lnum].radius * cl_dlights[lnum].radius * 8) / (4.0/16.0); // comparison to min acceptable light
|
// if (cl_dlights[lnum].dark) // negate for darklight
|
||||||
if (rada*brightness >= (sd*sd + td*td + dist)) {
|
// radb = cl_dlights[lnum].radius*cl_dlights[lnum].radius*-256.0*16.0; // negate and multiply by 256 for the code below
|
||||||
radb = cl_dlights[lnum].radius
|
// else
|
||||||
* cl_dlights[lnum].radius * (256.0*4.0);
|
radb = cl_dlights[lnum].radius*cl_dlights[lnum].radius*256.0*16.0; // multiply by 256 for the code below
|
||||||
bl = blocklights;
|
bl = blocklights;
|
||||||
for (t = 0; t < tmax; t++)
|
for (t = 0 ; t<tmax ; t++)
|
||||||
|
{
|
||||||
|
td = local[1] - t*16;
|
||||||
|
td = td*td + dist;
|
||||||
|
if (td < maxdist) // make sure some part of it is visible on this line
|
||||||
{
|
{
|
||||||
td = local[1] - t*16;
|
for (s=0 ; s<smax ; s++)
|
||||||
td = td*td + dist;
|
|
||||||
if (rada >= td) // any visible this line?
|
|
||||||
{
|
{
|
||||||
for (s = 0; s < smax; s++)
|
sd = local[0] - s*16;
|
||||||
|
if ((f = sd*sd+td) < maxdist)
|
||||||
{
|
{
|
||||||
sd = local[0] - s*16;
|
brightness = radb / f;
|
||||||
if (rada >= (sd*sd+td)) // minimum light
|
*bl++ += brightness * red;
|
||||||
{
|
*bl++ += brightness * green;
|
||||||
brightness = radb / (sd*sd+td);
|
*bl++ += brightness * blue;
|
||||||
*bl++ += brightness * red;
|
|
||||||
*bl++ += brightness * green;
|
|
||||||
*bl++ += brightness * blue;
|
|
||||||
} else
|
|
||||||
bl+=3; // skip pixel
|
|
||||||
}
|
}
|
||||||
} else
|
else
|
||||||
bl+=smax*3; // skip line
|
bl += 3; // skip pixel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
bl+=smax*3; // skip line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue