2001-08-25 23:23:14 +00:00
|
|
|
/*
|
|
|
|
gl_dyn_lights.c
|
|
|
|
|
|
|
|
polyblended dynamic lights
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-08-25 23:23:14 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "QF/GL/qf_rlight.h"
|
2001-08-25 23:23:14 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-08-25 23:23:14 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
float gl_bubble_sintable[33], gl_bubble_costable[33];
|
2001-08-25 23:23:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_InitBubble (void)
|
2001-08-25 23:23:14 +00:00
|
|
|
{
|
|
|
|
float a;
|
|
|
|
float *bub_sin, *bub_cos;
|
2001-09-01 08:57:04 +00:00
|
|
|
int i;
|
2001-08-25 23:23:14 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
bub_sin = gl_bubble_sintable;
|
|
|
|
bub_cos = gl_bubble_costable;
|
2001-08-25 23:23:14 +00:00
|
|
|
|
|
|
|
for (i = 32; i >= 0; i--) {
|
2001-09-09 19:37:07 +00:00
|
|
|
a = i * (M_PI / 16.0);
|
2001-08-25 23:23:14 +00:00
|
|
|
*bub_sin++ = sin (a);
|
|
|
|
*bub_cos++ = cos (a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 23:23:14 +00:00
|
|
|
R_RenderDlight (dlight_t *light)
|
|
|
|
{
|
|
|
|
float rad;
|
|
|
|
float *bub_sin, *bub_cos;
|
2001-09-01 08:57:04 +00:00
|
|
|
int i, j;
|
|
|
|
vec3_t v;
|
2001-08-25 23:23:14 +00:00
|
|
|
|
2012-02-17 09:33:07 +00:00
|
|
|
bub_sin = gl_bubble_sintable;
|
|
|
|
bub_cos = gl_bubble_costable;
|
2001-08-25 23:23:14 +00:00
|
|
|
rad = light->radius * 0.35;
|
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorSubtract (r_refdef.frame.position, light->origin, v);
|
2002-08-20 02:22:40 +00:00
|
|
|
if (VectorLength (v) < rad) // view is inside the dlight
|
2001-08-25 23:23:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
qfglBegin (GL_TRIANGLE_FAN);
|
|
|
|
|
2004-05-03 06:21:39 +00:00
|
|
|
qfglColor4fv (light->color);
|
2001-08-25 23:23:14 +00:00
|
|
|
|
|
|
|
VectorNormalize (v);
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
v[i] = light->origin[i] + v[i] * rad;
|
|
|
|
|
|
|
|
qfglVertex3fv (v);
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor3ubv (color_black);
|
2001-08-25 23:23:14 +00:00
|
|
|
|
|
|
|
for (i = 16; i >= 0; i--) {
|
|
|
|
for (j = 0; j < 3; j++)
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
v[j] = light->origin[j] + (r_refdef.frame.right[j] * (*bub_cos) +
|
|
|
|
r_refdef.frame.up[j] * (*bub_sin)) * rad;
|
2001-08-25 23:23:14 +00:00
|
|
|
bub_sin += 2;
|
|
|
|
bub_cos += 2;
|
|
|
|
qfglVertex3fv (v);
|
|
|
|
}
|
|
|
|
|
|
|
|
qfglEnd ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
gl_R_RenderDlights (void)
|
2001-08-25 23:23:14 +00:00
|
|
|
{
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int i;
|
2001-08-25 23:23:14 +00:00
|
|
|
dlight_t *l;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (!gl_dlight_polyblend)
|
2001-08-25 23:23:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
qfglDepthMask (GL_FALSE);
|
|
|
|
qfglDisable (GL_TEXTURE_2D);
|
|
|
|
qfglBlendFunc (GL_ONE, GL_ONE);
|
|
|
|
qfglShadeModel (GL_SMOOTH);
|
|
|
|
|
|
|
|
l = r_dlights;
|
2001-10-09 20:35:17 +00:00
|
|
|
for (i = 0; i < r_maxdlights; i++, l++) {
|
2012-02-14 08:28:09 +00:00
|
|
|
if (l->die < vr_data.realtime || !l->radius)
|
2001-08-25 23:23:14 +00:00
|
|
|
continue;
|
|
|
|
R_RenderDlight (l);
|
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (!gl_dlight_smooth)
|
2001-08-25 23:23:14 +00:00
|
|
|
qfglShadeModel (GL_FLAT);
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2001-08-25 23:23:14 +00:00
|
|
|
qfglEnable (GL_TEXTURE_2D);
|
|
|
|
qfglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
qfglDepthMask (GL_TRUE);
|
|
|
|
}
|