summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2013-03-19 03:39:02 +0400
committerAndrey Nazarov <skuller@skuller.net>2013-03-20 22:04:53 +0400
commit14bcd3eba8d12e1f4fea1b27390d7af5a5238ff0 (patch)
treea6a792a8b04d2ed28434d1c87dad037c4f6fcb5a /src
parent72166e9cddee2b882b423b6b6299f164e45f3ae5 (diff)
Fix radius of dynamic lights in GL mode.
Fall off from the same highest intensity on plane no matter what value ‘gl_dlight_falloff’ is set to. Subtract DLIGHT_CUTOFF from entity lighting intensity.
Diffstat (limited to 'src')
-rw-r--r--src/refresh/gl/surf.c65
-rw-r--r--src/refresh/gl/world.c4
2 files changed, 32 insertions, 37 deletions
diff --git a/src/refresh/gl/surf.c b/src/refresh/gl/surf.c
index 9714e19..10d42fa 100644
--- a/src/refresh/gl/surf.c
+++ b/src/refresh/gl/surf.c
@@ -114,40 +114,40 @@ static float blocklights[MAX_BLOCKLIGHTS * 3];
#if USE_DLIGHTS
static void add_dynamic_lights(mface_t *surf)
{
- dlight_t *light;
- mtexinfo_t *texinfo;
- cplane_t *plane;
- vec3_t point;
- int local[2];
- vec_t dist, radius, scale, f;
- float *bl;
- int smax, tmax, s, t, sd, td;
- int i, j, k;
+ dlight_t *light;
+ mtexinfo_t *tex;
+ vec3_t point;
+ int local[2];
+ vec_t dist, rad, minlight, scale, frac;
+ float *bl;
+ int i, smax, tmax, s, t, sd, td;
smax = S_MAX(surf);
tmax = T_MAX(surf);
-
- k = !!gl_dlight_falloff->integer;
- scale = 1 + 0.1f * k;
+ tex = surf->texinfo;
for (i = 0; i < glr.fd.num_dlights; i++) {
- if (!(surf->dlightbits & (1 << i))) {
+ if (!(surf->dlightbits & (1 << i)))
continue;
- }
light = &glr.fd.dlights[i];
- plane = surf->plane;
- dist = PlaneDiffFast(light->transformed, plane);
- radius = light->intensity * scale - fabs(dist);
- if (radius < DLIGHT_CUTOFF) {
+ dist = PlaneDiffFast(light->transformed, surf->plane);
+ rad = light->intensity - fabs(dist);
+ if (rad < DLIGHT_CUTOFF)
continue;
+
+ if (gl_dlight_falloff->integer) {
+ minlight = rad - DLIGHT_CUTOFF * 0.8f;
+ scale = rad / minlight; // fall off from rad to 0
+ } else {
+ minlight = rad - DLIGHT_CUTOFF;
+ scale = 1; // fall off from rad to minlight
}
- VectorMA(light->transformed, -dist, plane->normal, point);
+ VectorMA(light->transformed, -dist, surf->plane->normal, point);
- texinfo = surf->texinfo;
- local[0] = DotProduct(point, texinfo->axis[0]) + texinfo->offset[0];
- local[1] = DotProduct(point, texinfo->axis[1]) + texinfo->offset[1];
+ local[0] = DotProduct(point, tex->axis[0]) + tex->offset[0];
+ local[1] = DotProduct(point, tex->axis[1]) + tex->offset[1];
local[0] -= surf->texturemins[0];
local[1] -= surf->texturemins[1];
@@ -157,19 +157,16 @@ static void add_dynamic_lights(mface_t *surf)
td = abs(local[1] - (t << 4));
for (s = 0; s < smax; s++) {
sd = abs(local[0] - (s << 4));
- if (sd > td) {
- j = sd + (td >> 1);
- } else {
- j = td + (sd >> 1);
- }
-
- if (j + DLIGHT_CUTOFF < radius) {
- f = radius - (j + DLIGHT_CUTOFF * k);
- bl[0] += light->color[0] * f;
- bl[1] += light->color[1] * f;
- bl[2] += light->color[2] * f;
+ if (sd > td)
+ dist = sd + (td >> 1);
+ else
+ dist = td + (sd >> 1);
+ if (dist < minlight) {
+ frac = rad - dist * scale;
+ bl[0] += light->color[0] * frac;
+ bl[1] += light->color[1] * frac;
+ bl[2] += light->color[2] * frac;
}
-
bl += 3;
}
}
diff --git a/src/refresh/gl/world.c b/src/refresh/gl/world.c
index e7d3091..5bcf8fc 100644
--- a/src/refresh/gl/world.c
+++ b/src/refresh/gl/world.c
@@ -213,13 +213,11 @@ static void GL_TransformLights(mmodel_t *model)
static void GL_AddLights(vec3_t origin, vec3_t color)
{
dlight_t *light;
- vec3_t dir;
vec_t f;
int i;
for (i = 0, light = glr.fd.dlights; i < glr.fd.num_dlights; i++, light++) {
- VectorSubtract(light->origin, origin, dir);
- f = light->intensity - VectorLength(dir);
+ f = light->intensity - DLIGHT_CUTOFF - Distance(light->origin, origin);
if (f > 0) {
f *= (1.0f / 255);
VectorMA(color, f, light->color, color);