2008-07-25 07:31:37 +00:00
|
|
|
/* -------------------------------------------------------------------------------
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
----------------------------------------------------------------------------------
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This code has been altered significantly from its original form, to support
|
|
|
|
several games based on the Quake III Arena engine, in the form of "Q3Map2."
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
------------------------------------------------------------------------------- */
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* marker */
|
|
|
|
#define LIGHT_C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dependencies */
|
|
|
|
#include "q3map2.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
CreateSunLight() - ydnar
|
|
|
|
this creates a sun light
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void CreateSunLight( sun_t *sun ){
|
|
|
|
int i;
|
|
|
|
float photons, d, angle, elevation, da, de;
|
|
|
|
vec3_t direction;
|
|
|
|
light_t *light;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* dummy check */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sun == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* fixup */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sun->numSamples < 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sun->numSamples = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set photons */
|
|
|
|
photons = sun->photons / sun->numSamples;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* create the right number of suns */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < sun->numSamples; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* calculate sun direction */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorCopy( sun->direction, direction );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
sun->direction[ 0 ] = cos( angle ) * cos( elevation );
|
|
|
|
sun->direction[ 1 ] = sin( angle ) * cos( elevation );
|
|
|
|
sun->direction[ 2 ] = sin( elevation );
|
|
|
|
|
|
|
|
xz_dist = sqrt( x*x + z*z )
|
|
|
|
latitude = atan2( xz_dist, y ) * RADIANS
|
|
|
|
longitude = atan2( x, z ) * RADIANS
|
|
|
|
*/
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
d = sqrt( sun->direction[ 0 ] * sun->direction[ 0 ] + sun->direction[ 1 ] * sun->direction[ 1 ] );
|
|
|
|
angle = atan2( sun->direction[ 1 ], sun->direction[ 0 ] );
|
|
|
|
elevation = atan2( sun->direction[ 2 ], d );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* jitter the angles (loop to keep random sample within sun->deviance steridians) */
|
|
|
|
do
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
da = ( Random() * 2.0f - 1.0f ) * sun->deviance;
|
|
|
|
de = ( Random() * 2.0f - 1.0f ) * sun->deviance;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( ( da * da + de * de ) > ( sun->deviance * sun->deviance ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
angle += da;
|
|
|
|
elevation += de;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* debug code */
|
|
|
|
//% Sys_Printf( "%d: Angle: %3.4f Elevation: %3.3f\n", sun->numSamples, (angle / Q_PI * 180.0f), (elevation / Q_PI * 180.0f) );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* create new vector */
|
|
|
|
direction[ 0 ] = cos( angle ) * cos( elevation );
|
|
|
|
direction[ 1 ] = sin( angle ) * cos( elevation );
|
|
|
|
direction[ 2 ] = sin( elevation );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* create a light */
|
|
|
|
numSunLights++;
|
|
|
|
light = safe_malloc( sizeof( *light ) );
|
|
|
|
memset( light, 0, sizeof( *light ) );
|
|
|
|
light->next = lights;
|
|
|
|
lights = light;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* initialize the light */
|
|
|
|
light->flags = LIGHT_SUN_DEFAULT;
|
|
|
|
light->type = EMIT_SUN;
|
|
|
|
light->fade = 1.0f;
|
|
|
|
light->falloffTolerance = falloffTolerance;
|
|
|
|
light->filterRadius = sun->filterRadius / sun->numSamples;
|
2008-07-25 07:31:37 +00:00
|
|
|
light->style = noStyles ? LS_NORMAL : sun->style;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set the light's position out to infinity */
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorMA( vec3_origin, ( MAX_WORLD_COORD * 8.0f ), direction, light->origin ); /* MAX_WORLD_COORD * 2.0f */
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set the facing to be the inverse of the sun direction */
|
|
|
|
VectorScale( direction, -1.0, light->normal );
|
|
|
|
light->dist = DotProduct( light->origin, light->normal );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set color and photons */
|
|
|
|
VectorCopy( sun->color, light->color );
|
|
|
|
light->photons = photons * skyScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* another sun? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sun->next != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
CreateSunLight( sun->next );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
CreateSkyLights() - ydnar
|
|
|
|
simulates sky light with multiple suns
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void CreateSkyLights( vec3_t color, float value, int iterations, float filterRadius, int style ){
|
|
|
|
int i, j, numSuns;
|
|
|
|
int angleSteps, elevationSteps;
|
|
|
|
float angle, elevation;
|
|
|
|
float angleStep, elevationStep;
|
|
|
|
float step, start;
|
|
|
|
sun_t sun;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* dummy check */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value <= 0.0f || iterations < 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* calculate some stuff */
|
2012-03-17 20:01:54 +00:00
|
|
|
step = 2.0f / ( iterations - 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
start = -1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* basic sun setup */
|
|
|
|
VectorCopy( color, sun.color );
|
|
|
|
sun.deviance = 0.0f;
|
|
|
|
sun.filterRadius = filterRadius;
|
|
|
|
sun.numSamples = 1;
|
2008-07-25 07:31:37 +00:00
|
|
|
sun.style = noStyles ? LS_NORMAL : style;
|
2007-11-04 03:34:51 +00:00
|
|
|
sun.next = NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* setup */
|
|
|
|
elevationSteps = iterations - 1;
|
|
|
|
angleSteps = elevationSteps * 4;
|
|
|
|
angle = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
elevationStep = DEG2RAD( 90.0f / iterations ); /* skip elevation 0 */
|
2008-07-25 07:31:37 +00:00
|
|
|
angleStep = DEG2RAD( 360.0f / angleSteps );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* calc individual sun brightness */
|
|
|
|
numSuns = angleSteps * elevationSteps + 1;
|
|
|
|
sun.photons = value / numSuns;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* iterate elevation */
|
|
|
|
elevation = elevationStep * 0.5f;
|
|
|
|
angle = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0, elevation = elevationStep * 0.5f; i < elevationSteps; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2008-07-25 07:31:37 +00:00
|
|
|
/* iterate angle */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < angleSteps; j++ )
|
2008-07-25 07:31:37 +00:00
|
|
|
{
|
|
|
|
/* create sun */
|
|
|
|
sun.direction[ 0 ] = cos( angle ) * cos( elevation );
|
|
|
|
sun.direction[ 1 ] = sin( angle ) * cos( elevation );
|
|
|
|
sun.direction[ 2 ] = sin( elevation );
|
|
|
|
CreateSunLight( &sun );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* move */
|
|
|
|
angle += angleStep;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* move */
|
|
|
|
elevation += elevationStep;
|
|
|
|
angle += angleStep / elevationSteps;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* create vertical sun */
|
|
|
|
VectorSet( sun.direction, 0.0f, 0.0f, 1.0f );
|
|
|
|
CreateSunLight( &sun );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* short circuit */
|
|
|
|
return;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
CreateEntityLights()
|
|
|
|
creates lights from light entities
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CreateEntityLights( void ){
|
|
|
|
int i, j;
|
|
|
|
light_t *light, *light2;
|
|
|
|
entity_t *e, *e2;
|
|
|
|
const char *name;
|
|
|
|
const char *target;
|
|
|
|
vec3_t dest;
|
|
|
|
const char *_color;
|
|
|
|
float intensity, scale, deviance, filterRadius;
|
|
|
|
int spawnflags, flags, numSamples;
|
|
|
|
qboolean junior;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* go throught entity list and find lights */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numEntities; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get entity */
|
|
|
|
e = &entities[ i ];
|
|
|
|
name = ValueForKey( e, "classname" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: check for lightJunior */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Q_strncasecmp( name, "lightJunior", 11 ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
junior = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( Q_strncasecmp( name, "light", 5 ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
junior = qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* lights with target names (and therefore styles) are only parsed from BSP */
|
|
|
|
target = ValueForKey( e, "targetname" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( target[ 0 ] != '\0' && i >= numBSPEntities ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* create a light */
|
|
|
|
numPointLights++;
|
|
|
|
light = safe_malloc( sizeof( *light ) );
|
|
|
|
memset( light, 0, sizeof( *light ) );
|
|
|
|
light->next = lights;
|
|
|
|
lights = light;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle spawnflags */
|
|
|
|
spawnflags = IntForKey( e, "spawnflags" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: quake 3+ light behavior */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( wolfLight == qfalse ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set default flags */
|
|
|
|
flags = LIGHT_Q3A_DEFAULT;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* linear attenuation? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( spawnflags & 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
flags |= LIGHT_ATTEN_LINEAR;
|
|
|
|
flags &= ~LIGHT_ATTEN_ANGLE;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* no angle attenuate? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( spawnflags & 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
flags &= ~LIGHT_ATTEN_ANGLE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: wolf light behavior */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* set default flags */
|
|
|
|
flags = LIGHT_WOLF_DEFAULT;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* inverse distance squared attenuation? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( spawnflags & 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
flags &= ~LIGHT_ATTEN_LINEAR;
|
|
|
|
flags |= LIGHT_ATTEN_ANGLE;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* angle attenuate? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( spawnflags & 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
flags |= LIGHT_ATTEN_ANGLE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* other flags (borrowed from wolf) */
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* wolf dark light? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( spawnflags & 4 ) || ( spawnflags & 8 ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
flags |= LIGHT_DARK;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* nogrid? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( spawnflags & 16 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
flags &= ~LIGHT_GRID;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* junior? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( junior ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
flags |= LIGHT_GRID;
|
|
|
|
flags &= ~LIGHT_SURFACES;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* store the flags */
|
|
|
|
light->flags = flags;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: set fade key (from wolf) */
|
|
|
|
light->fade = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->flags & LIGHT_ATTEN_LINEAR ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
light->fade = FloatForKey( e, "fade" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->fade == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
light->fade = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: set angle scaling (from vlight) */
|
|
|
|
light->angleScale = FloatForKey( e, "_anglescale" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->angleScale != 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
light->flags |= LIGHT_ATTEN_ANGLE;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set origin */
|
2012-03-17 20:01:54 +00:00
|
|
|
GetVectorForKey( e, "origin", light->origin );
|
2007-11-04 03:34:51 +00:00
|
|
|
light->style = IntForKey( e, "_style" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->style == LS_NORMAL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
light->style = IntForKey( e, "style" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( light->style < LS_NORMAL || light->style >= LS_NONE ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Invalid lightstyle (%d) on entity %d", light->style, i );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( light->style != LS_NORMAL ) {
|
|
|
|
Sys_FPrintf( SYS_WRN, "WARNING: Styled light found targeting %s\n **", target );
|
2008-08-24 03:20:51 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set light intensity */
|
|
|
|
intensity = FloatForKey( e, "_light" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( intensity == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
intensity = FloatForKey( e, "light" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( intensity == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
intensity = 300.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: set light scale (sof2) */
|
|
|
|
scale = FloatForKey( e, "scale" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( scale == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
scale = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
intensity *= scale;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: get deviance and samples */
|
|
|
|
deviance = FloatForKey( e, "_deviance" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( deviance == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
deviance = FloatForKey( e, "_deviation" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( deviance == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
deviance = FloatForKey( e, "_jitter" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
numSamples = IntForKey( e, "_samples" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( deviance < 0.0f || numSamples < 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
deviance = 0.0f;
|
|
|
|
numSamples = 1;
|
|
|
|
}
|
|
|
|
intensity /= numSamples;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: get filter radius */
|
|
|
|
filterRadius = FloatForKey( e, "_filterradius" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( filterRadius == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
filterRadius = FloatForKey( e, "_filteradius" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( filterRadius == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
filterRadius = FloatForKey( e, "_filter" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( filterRadius < 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
filterRadius = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
light->filterRadius = filterRadius;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set light color */
|
|
|
|
_color = ValueForKey( e, "_color" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( _color && _color[ 0 ] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sscanf( _color, "%f %f %f", &light->color[ 0 ], &light->color[ 1 ], &light->color[ 2 ] );
|
|
|
|
ColorNormalize( light->color, light->color );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
light->color[ 0 ] = light->color[ 1 ] = light->color[ 2 ] = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
intensity = intensity * pointScale;
|
|
|
|
light->photons = intensity;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
light->type = EMIT_POINT;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set falloff threshold */
|
|
|
|
light->falloffTolerance = falloffTolerance / numSamples;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* lights with a target will be spotlights */
|
|
|
|
target = ValueForKey( e, "target" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( target[ 0 ] ) {
|
|
|
|
float radius;
|
|
|
|
float dist;
|
|
|
|
sun_t sun;
|
|
|
|
const char *_sun;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get target */
|
|
|
|
e2 = FindTargetEntity( target );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( e2 == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: light at (%i %i %i) has missing target\n",
|
2012-03-17 20:01:54 +00:00
|
|
|
(int) light->origin[ 0 ], (int) light->origin[ 1 ], (int) light->origin[ 2 ] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* not a point light */
|
|
|
|
numPointLights--;
|
|
|
|
numSpotLights++;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* make a spotlight */
|
|
|
|
GetVectorForKey( e2, "origin", dest );
|
|
|
|
VectorSubtract( dest, light->origin, light->normal );
|
|
|
|
dist = VectorNormalize( light->normal, light->normal );
|
|
|
|
radius = FloatForKey( e, "radius" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !radius ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
radius = 64;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !dist ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = 64;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
light->radiusByDist = ( radius + 16 ) / dist;
|
2007-11-04 03:34:51 +00:00
|
|
|
light->type = EMIT_SPOT;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: wolf mods: spotlights always use nonlinear + angle attenuation */
|
|
|
|
light->flags &= ~LIGHT_ATTEN_LINEAR;
|
|
|
|
light->flags |= LIGHT_ATTEN_ANGLE;
|
|
|
|
light->fade = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: is this a sun? */
|
|
|
|
_sun = ValueForKey( e, "_sun" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( _sun[ 0 ] == '1' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* not a spot light */
|
|
|
|
numSpotLights--;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* unlink this light */
|
|
|
|
lights = light->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* make a sun */
|
|
|
|
VectorScale( light->normal, -1.0f, sun.direction );
|
|
|
|
VectorCopy( light->color, sun.color );
|
2012-03-17 20:01:54 +00:00
|
|
|
sun.photons = ( intensity / pointScale );
|
2007-11-04 03:34:51 +00:00
|
|
|
sun.deviance = deviance / 180.0f * Q_PI;
|
|
|
|
sun.numSamples = numSamples;
|
2008-07-25 07:31:37 +00:00
|
|
|
sun.style = noStyles ? LS_NORMAL : light->style;
|
2007-11-04 03:34:51 +00:00
|
|
|
sun.next = NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* make a sun light */
|
|
|
|
CreateSunLight( &sun );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* free original light */
|
|
|
|
free( light );
|
|
|
|
light = NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* skip the rest of this love story */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* jitter the light */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 1; j < numSamples; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* create a light */
|
|
|
|
light2 = safe_malloc( sizeof( *light ) );
|
|
|
|
memcpy( light2, light, sizeof( *light ) );
|
|
|
|
light2->next = lights;
|
|
|
|
lights = light2;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add to counts */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->type == EMIT_SPOT ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
numSpotLights++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
numPointLights++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* jitter it */
|
2012-03-17 20:01:54 +00:00
|
|
|
light2->origin[ 0 ] = light->origin[ 0 ] + ( Random() * 2.0f - 1.0f ) * deviance;
|
|
|
|
light2->origin[ 1 ] = light->origin[ 1 ] + ( Random() * 2.0f - 1.0f ) * deviance;
|
|
|
|
light2->origin[ 2 ] = light->origin[ 2 ] + ( Random() * 2.0f - 1.0f ) * deviance;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
CreateSurfaceLights() - ydnar
|
|
|
|
this hijacks the radiosity code to generate surface lights for first pass
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define APPROX_BOUNCE 1.0f
|
|
|
|
|
|
|
|
void CreateSurfaceLights( void ){
|
|
|
|
int i;
|
|
|
|
bspDrawSurface_t *ds;
|
|
|
|
surfaceInfo_t *info;
|
|
|
|
shaderInfo_t *si;
|
|
|
|
light_t *light;
|
|
|
|
float subdivide;
|
|
|
|
vec3_t origin;
|
|
|
|
clipWork_t cw;
|
|
|
|
const char *nss;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* get sun shader supressor */
|
|
|
|
nss = ValueForKey( &entities[ 0 ], "_noshadersun" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* walk the list of surfaces */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numBSPDrawSurfaces; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get surface and other bits */
|
|
|
|
ds = &bspDrawSurfaces[ i ];
|
|
|
|
info = &surfaceInfos[ i ];
|
|
|
|
si = info->si;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* sunlight? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( si->sun != NULL && nss[ 0 ] != '1' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "Sun: %s\n", si->shader );
|
|
|
|
CreateSunLight( si->sun );
|
|
|
|
si->sun = NULL; /* FIXME: leak! */
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* sky light? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( si->skyLightValue > 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "Sky: %s\n", si->shader );
|
2008-07-25 07:31:37 +00:00
|
|
|
CreateSkyLights( si->color, si->skyLightValue, si->skyLightIterations, si->lightFilterRadius, si->lightStyle );
|
2012-03-17 20:01:54 +00:00
|
|
|
si->skyLightValue = 0.0f; /* FIXME: hack! */
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* try to early out */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( si->value <= 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* autosprite shaders become point lights */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( si->autosprite ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* create an average xyz */
|
|
|
|
VectorAdd( info->mins, info->maxs, origin );
|
|
|
|
VectorScale( origin, 0.5f, origin );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* create a light */
|
|
|
|
light = safe_malloc( sizeof( *light ) );
|
|
|
|
memset( light, 0, sizeof( *light ) );
|
|
|
|
light->next = lights;
|
|
|
|
lights = light;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set it up */
|
|
|
|
light->flags = LIGHT_Q3A_DEFAULT;
|
|
|
|
light->type = EMIT_POINT;
|
|
|
|
light->photons = si->value * pointScale;
|
|
|
|
light->fade = 1.0f;
|
|
|
|
light->si = si;
|
|
|
|
VectorCopy( origin, light->origin );
|
|
|
|
VectorCopy( si->color, light->color );
|
|
|
|
light->falloffTolerance = falloffTolerance;
|
2008-07-25 07:31:37 +00:00
|
|
|
light->style = si->lightStyle;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add to point light count and continue */
|
|
|
|
numPointLights++;
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get subdivision amount */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( si->lightSubdivide > 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
subdivide = si->lightSubdivide;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
subdivide = defaultLightSubdivide;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* switch on type */
|
2012-03-17 20:01:54 +00:00
|
|
|
switch ( ds->surfaceType )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
case MST_PLANAR:
|
|
|
|
case MST_TRIANGLE_SOUP:
|
|
|
|
RadLightForTriangles( i, 0, info->lm, si, APPROX_BOUNCE, subdivide, &cw );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MST_PATCH:
|
|
|
|
RadLightForPatch( i, 0, info->lm, si, APPROX_BOUNCE, subdivide, &cw );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SetEntityOrigins()
|
|
|
|
find the offset values for inline models
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SetEntityOrigins( void ){
|
|
|
|
int i, j, k, f;
|
|
|
|
entity_t *e;
|
|
|
|
vec3_t origin;
|
|
|
|
const char *key;
|
|
|
|
int modelnum;
|
|
|
|
bspModel_t *dm;
|
|
|
|
bspDrawSurface_t *ds;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* ydnar: copy drawverts into private storage for nefarious purposes */
|
|
|
|
yDrawVerts = safe_malloc( numBSPDrawVerts * sizeof( bspDrawVert_t ) );
|
|
|
|
memcpy( yDrawVerts, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVert_t ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set the entity origins */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numEntities; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get entity and model */
|
|
|
|
e = &entities[ i ];
|
|
|
|
key = ValueForKey( e, "model" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( key[ 0 ] != '*' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
modelnum = atoi( key + 1 );
|
|
|
|
dm = &bspModels[ modelnum ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get entity origin */
|
|
|
|
key = ValueForKey( e, "origin" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( key[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
GetVectorForKey( e, "origin", origin );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set origin for all surfaces for this model */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < dm->numBSPSurfaces; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get drawsurf */
|
|
|
|
ds = &bspDrawSurfaces[ dm->firstBSPSurface + j ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set its verts */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( k = 0; k < ds->numVerts; k++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
f = ds->firstVert + k;
|
|
|
|
VectorAdd( origin, bspDrawVerts[ f ].xyz, yDrawVerts[ f ].xyz );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
PointToPolygonFormFactor()
|
|
|
|
calculates the area over a point/normal hemisphere a winding covers
|
|
|
|
ydnar: fixme: there has to be a faster way to calculate this
|
|
|
|
without the expensive per-vert sqrts and transcendental functions
|
|
|
|
ydnar 2002-09-30: added -faster switch because only 19% deviance > 10%
|
|
|
|
between this and the approximation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ONE_OVER_2PI 0.159154942f //% (1.0f / (2.0f * 3.141592657f))
|
|
|
|
|
|
|
|
float PointToPolygonFormFactor( const vec3_t point, const vec3_t normal, const winding_t *w ){
|
|
|
|
vec3_t triVector, triNormal;
|
|
|
|
int i, j;
|
|
|
|
vec3_t dirs[ MAX_POINTS_ON_WINDING ];
|
|
|
|
float total;
|
|
|
|
float dot, angle, facing;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* this is expensive */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < w->numpoints; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
VectorSubtract( w->p[ i ], point, dirs[ i ] );
|
|
|
|
VectorNormalize( dirs[ i ], dirs[ i ] );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* duplicate first vertex to avoid mod operation */
|
|
|
|
VectorCopy( dirs[ 0 ], dirs[ i ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* calculcate relative area */
|
|
|
|
total = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < w->numpoints; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get a triangle */
|
|
|
|
j = i + 1;
|
|
|
|
dot = DotProduct( dirs[ i ], dirs[ j ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* roundoff can cause slight creep, which gives an IND from acos */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dot > 1.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dot = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( dot < -1.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dot = -1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get the angle */
|
|
|
|
angle = acos( dot );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
CrossProduct( dirs[ i ], dirs[ j ], triVector );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( VectorNormalize( triVector, triNormal ) < 0.0001f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
facing = DotProduct( normal, triNormal );
|
|
|
|
total += facing * angle;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: this was throwing too many errors with radiosity + crappy maps. ignoring it. */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( total > 6.3f || total < -6.3f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* now in the range of 0 to 1 over the entire incoming hemisphere */
|
|
|
|
//% total /= (2.0f * 3.141592657f);
|
|
|
|
total *= ONE_OVER_2PI;
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
LightContributionTosample()
|
|
|
|
determines the amount of light reaching a sample (luxel or vertex) from a given light
|
|
|
|
*/
|
|
|
|
|
|
|
|
int LightContributionToSample( trace_t *trace ){
|
|
|
|
light_t *light;
|
|
|
|
float angle;
|
|
|
|
float add;
|
|
|
|
float dist;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get light */
|
|
|
|
light = trace->light;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* clear color */
|
|
|
|
VectorClear( trace->color );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: early out */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !( light->flags & LIGHT_SURFACES ) || light->envelope <= 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* do some culling checks */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->type != EMIT_SUN ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* MrE: if the light is behind the surface */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->twoSided == qfalse ) {
|
|
|
|
if ( DotProduct( light->origin, trace->normal ) - DotProduct( trace->origin, trace->normal ) < 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: test pvs */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !ClusterVisible( trace->cluster, light->cluster ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* exact point to polygon form factor */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->type == EMIT_AREA ) {
|
|
|
|
float factor;
|
|
|
|
float d;
|
|
|
|
vec3_t pushedOrigin;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* project sample point into light plane */
|
|
|
|
d = DotProduct( trace->origin, light->normal ) - light->dist;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d < 3.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* sample point behind plane? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !( light->flags & LIGHT_TWOSIDED ) && d < -1.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* sample plane coincident? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d > -3.0f && DotProduct( trace->normal, light->normal ) > 0.9f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* nudge the point so that it is clearly forward of the light */
|
|
|
|
/* so that surfaces meeting a light emiter don't get black edges */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d > -8.0f && d < 8.0f ) {
|
|
|
|
VectorMA( trace->origin, ( 8.0f - d ), light->normal, pushedOrigin );
|
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorCopy( trace->origin, pushedOrigin );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get direction and distance */
|
|
|
|
VectorCopy( light->origin, trace->end );
|
|
|
|
dist = SetupTrace( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist >= light->envelope ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* ptpff approximation */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( faster ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
/* angle attenuation */
|
|
|
|
angle = DotProduct( trace->normal, trace->direction );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* twosided lighting */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->twoSided ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
angle = fabs( angle );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* attenuate */
|
|
|
|
angle *= -DotProduct( light->normal, trace->direction );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( angle == 0.0f ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( angle < 0.0f &&
|
|
|
|
( trace->twoSided || ( light->flags & LIGHT_TWOSIDED ) ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
angle = -angle;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
add = light->photons / ( dist * dist ) * angle;
|
2008-07-25 07:31:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* calculate the contribution */
|
|
|
|
factor = PointToPolygonFormFactor( pushedOrigin, trace->normal, light->w );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( factor == 0.0f ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( factor < 0.0f ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
/* twosided lighting */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->twoSided || ( light->flags & LIGHT_TWOSIDED ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
factor = -factor;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* push light origin to other side of the plane */
|
|
|
|
VectorMA( light->origin, -2.0f, light->normal, trace->end );
|
|
|
|
dist = SetupTrace( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist >= light->envelope ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-07-25 07:31:37 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* ydnar: moved to here */
|
|
|
|
add = factor * light->add;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* point/spot lights */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( light->type == EMIT_POINT || light->type == EMIT_SPOT ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get direction and distance */
|
|
|
|
VectorCopy( light->origin, trace->end );
|
|
|
|
dist = SetupTrace( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist >= light->envelope ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* clamp the distance to prevent super hot spots */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist < 16.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = 16.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* angle attenuation */
|
2012-03-17 20:01:54 +00:00
|
|
|
angle = ( light->flags & LIGHT_ATTEN_ANGLE ) ? DotProduct( trace->normal, trace->direction ) : 1.0f;
|
|
|
|
if ( light->angleScale != 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
angle /= light->angleScale;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( angle > 1.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
angle = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* twosided lighting */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->twoSided ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
angle = fabs( angle );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* attenuate */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->flags & LIGHT_ATTEN_LINEAR ) {
|
|
|
|
add = angle * light->photons * linearScale - ( dist * light->fade );
|
|
|
|
if ( add < 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
add = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
|
|
|
add = light->photons / ( dist * dist ) * angle;
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle spotlights */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->type == EMIT_SPOT ) {
|
|
|
|
float distByNormal, radiusAtDist, sampleRadius;
|
|
|
|
vec3_t pointAtDist, distToSample;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* do cone calculation */
|
|
|
|
distByNormal = -DotProduct( trace->displacement, light->normal );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( distByNormal < 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorMA( light->origin, distByNormal, light->normal, pointAtDist );
|
|
|
|
radiusAtDist = light->radiusByDist * distByNormal;
|
|
|
|
VectorSubtract( trace->origin, pointAtDist, distToSample );
|
|
|
|
sampleRadius = VectorLength( distToSample );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* outside the cone */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sampleRadius >= radiusAtDist ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* attenuate */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sampleRadius > ( radiusAtDist - 32.0f ) ) {
|
|
|
|
add *= ( ( radiusAtDist - sampleRadius ) / 32.0f );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: sunlight */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( light->type == EMIT_SUN ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get origin and direction */
|
|
|
|
VectorAdd( trace->origin, light->origin, trace->end );
|
|
|
|
dist = SetupTrace( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* angle attenuation */
|
2012-03-17 20:01:54 +00:00
|
|
|
angle = ( light->flags & LIGHT_ATTEN_ANGLE )
|
|
|
|
? DotProduct( trace->normal, trace->direction )
|
|
|
|
: 1.0f;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* twosided lighting */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->twoSided ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
angle = fabs( angle );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* attenuate */
|
|
|
|
add = light->photons * angle;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( add <= 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup trace */
|
|
|
|
trace->testAll = qtrue;
|
|
|
|
VectorScale( light->color, add, trace->color );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* trace to point */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->testOcclusion && !trace->forceSunlight ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* trace */
|
|
|
|
TraceLine( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !( trace->compileFlags & C_SKY ) || trace->opaque ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorClear( trace->color );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* return to sender */
|
|
|
|
return 1;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: changed to a variable number */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( add <= 0.0f || ( add <= light->falloffTolerance && ( light->flags & LIGHT_FAST_ACTUAL ) ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup trace */
|
|
|
|
trace->testAll = qfalse;
|
|
|
|
VectorScale( light->color, add, trace->color );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* raytrace */
|
|
|
|
TraceLine( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->passSolid || trace->opaque ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorClear( trace->color );
|
|
|
|
return -1;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* return to sender */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
LightingAtSample()
|
|
|
|
determines the amount of light reaching a sample (luxel or vertex)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void LightingAtSample( trace_t *trace, byte styles[ MAX_LIGHTMAPS ], vec3_t colors[ MAX_LIGHTMAPS ] ){
|
|
|
|
int i, lightmapNum;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* clear colors */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorClear( colors[ lightmapNum ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: normalmap */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( normalmap ) {
|
|
|
|
colors[ 0 ][ 0 ] = ( trace->normal[ 0 ] + 1.0f ) * 127.5f;
|
|
|
|
colors[ 0 ][ 1 ] = ( trace->normal[ 1 ] + 1.0f ) * 127.5f;
|
|
|
|
colors[ 0 ][ 2 ] = ( trace->normal[ 2 ] + 1.0f ) * 127.5f;
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: don't bounce ambient all the time */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !bouncing ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorCopy( ambientColor, colors[ 0 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: trace to all the list of lights pre-stored in tw */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < trace->numLights && trace->lights[ i ] != NULL; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* set light */
|
|
|
|
trace->light = trace->lights[ i ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* style check */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( lightmapNum = 0; lightmapNum < MAX_LIGHTMAPS; lightmapNum++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( styles[ lightmapNum ] == trace->light->style ||
|
|
|
|
styles[ lightmapNum ] == LS_NONE ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* max of MAX_LIGHTMAPS (4) styles allowed to hit a sample */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( lightmapNum >= MAX_LIGHTMAPS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* sample light */
|
|
|
|
LightContributionToSample( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->color[ 0 ] == 0.0f && trace->color[ 1 ] == 0.0f && trace->color[ 2 ] == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle negative light */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->light->flags & LIGHT_NEGATIVE ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorScale( trace->color, -1.0f, trace->color );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set style */
|
|
|
|
styles[ lightmapNum ] = trace->light->style;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add it */
|
|
|
|
VectorAdd( colors[ lightmapNum ], trace->color, colors[ lightmapNum ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* cheap mode */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( cheap &&
|
|
|
|
colors[ 0 ][ 0 ] >= 255.0f &&
|
|
|
|
colors[ 0 ][ 1 ] >= 255.0f &&
|
|
|
|
colors[ 0 ][ 2 ] >= 255.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
LightContributionToPoint()
|
|
|
|
for a given light, how much light/color reaches a given point in space (with no facing)
|
|
|
|
note: this is similar to LightContributionToSample() but optimized for omnidirectional sampling
|
|
|
|
*/
|
|
|
|
|
|
|
|
int LightContributionToPoint( trace_t *trace ){
|
|
|
|
light_t *light;
|
|
|
|
float add, dist;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* get light */
|
|
|
|
light = trace->light;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* clear color */
|
|
|
|
VectorClear( trace->color );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: early out */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !( light->flags & LIGHT_GRID ) || light->envelope <= 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* is this a sun? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->type != EMIT_SUN ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* sun only? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sunOnly ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* test pvs */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !ClusterVisible( trace->cluster, light->cluster ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: check origin against light's pvs envelope */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->origin[ 0 ] > light->maxs[ 0 ] || trace->origin[ 0 ] < light->mins[ 0 ] ||
|
|
|
|
trace->origin[ 1 ] > light->maxs[ 1 ] || trace->origin[ 1 ] < light->mins[ 1 ] ||
|
|
|
|
trace->origin[ 2 ] > light->maxs[ 2 ] || trace->origin[ 2 ] < light->mins[ 2 ] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
gridBoundsCulled++;
|
|
|
|
return qfalse;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set light origin */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->type == EMIT_SUN ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorAdd( trace->origin, light->origin, trace->end );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorCopy( light->origin, trace->end );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set direction */
|
|
|
|
dist = SetupTrace( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* test envelope */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist > light->envelope ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
gridEnvelopeCulled++;
|
|
|
|
return qfalse;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ptpff approximation */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->type == EMIT_AREA && faster ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* clamp the distance to prevent super hot spots */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist < 16.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = 16.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* attenuate */
|
2012-03-17 20:01:54 +00:00
|
|
|
add = light->photons / ( dist * dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* exact point to polygon form factor */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( light->type == EMIT_AREA ) {
|
|
|
|
float factor, d;
|
|
|
|
vec3_t pushedOrigin;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* see if the point is behind the light */
|
|
|
|
d = DotProduct( trace->origin, light->normal ) - light->dist;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !( light->flags & LIGHT_TWOSIDED ) && d < -1.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* nudge the point so that it is clearly forward of the light */
|
|
|
|
/* so that surfaces meeting a light emiter don't get black edges */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d > -8.0f && d < 8.0f ) {
|
|
|
|
VectorMA( trace->origin, ( 8.0f - d ), light->normal, pushedOrigin );
|
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorCopy( trace->origin, pushedOrigin );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* calculate the contribution (ydnar 2002-10-21: [bug 642] bad normal calc) */
|
|
|
|
factor = PointToPolygonFormFactor( pushedOrigin, trace->direction, light->w );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( factor == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( factor < 0.0f ) {
|
|
|
|
if ( light->flags & LIGHT_TWOSIDED ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
factor = -factor;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: moved to here */
|
|
|
|
add = factor * light->add;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* point/spot lights */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( light->type == EMIT_POINT || light->type == EMIT_SPOT ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* clamp the distance to prevent super hot spots */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dist < 16.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = 16.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* attenuate */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->flags & LIGHT_ATTEN_LINEAR ) {
|
|
|
|
add = light->photons * linearScale - ( dist * light->fade );
|
|
|
|
if ( add < 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
add = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
|
|
|
add = light->photons / ( dist * dist );
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle spotlights */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( light->type == EMIT_SPOT ) {
|
|
|
|
float distByNormal, radiusAtDist, sampleRadius;
|
|
|
|
vec3_t pointAtDist, distToSample;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* do cone calculation */
|
|
|
|
distByNormal = -DotProduct( trace->displacement, light->normal );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( distByNormal < 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorMA( light->origin, distByNormal, light->normal, pointAtDist );
|
|
|
|
radiusAtDist = light->radiusByDist * distByNormal;
|
|
|
|
VectorSubtract( trace->origin, pointAtDist, distToSample );
|
|
|
|
sampleRadius = VectorLength( distToSample );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* outside the cone */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sampleRadius >= radiusAtDist ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* attenuate */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sampleRadius > ( radiusAtDist - 32.0f ) ) {
|
|
|
|
add *= ( ( radiusAtDist - sampleRadius ) / 32.0f );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: sunlight */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( light->type == EMIT_SUN ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* attenuate */
|
|
|
|
add = light->photons;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( add <= 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup trace */
|
|
|
|
trace->testAll = qtrue;
|
|
|
|
VectorScale( light->color, add, trace->color );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* trace to point */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->testOcclusion && !trace->forceSunlight ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* trace */
|
|
|
|
TraceLine( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !( trace->compileFlags & C_SKY ) || trace->opaque ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorClear( trace->color );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* return to sender */
|
|
|
|
return qtrue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* unknown light type */
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: changed to a variable number */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( add <= 0.0f || ( add <= light->falloffTolerance && ( light->flags & LIGHT_FAST_ACTUAL ) ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup trace */
|
|
|
|
trace->testAll = qfalse;
|
|
|
|
VectorScale( light->color, add, trace->color );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* trace */
|
|
|
|
TraceLine( trace );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace->passSolid ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorClear( trace->color );
|
|
|
|
return qfalse;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* we have a valid sample */
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
TraceGrid()
|
|
|
|
grid samples are for quickly determining the lighting
|
|
|
|
of dynamically placed entities in the world
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define MAX_CONTRIBUTIONS 1024
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t dir;
|
|
|
|
vec3_t color;
|
|
|
|
int style;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
contribution_t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void TraceGrid( int num ){
|
|
|
|
int i, j, x, y, z, mod, step, numCon, numStyles;
|
|
|
|
float d;
|
|
|
|
vec3_t baseOrigin, cheapColor, color;
|
|
|
|
rawGridPoint_t *gp;
|
|
|
|
bspGridPoint_t *bgp;
|
|
|
|
contribution_t contributions[ MAX_CONTRIBUTIONS ];
|
|
|
|
trace_t trace;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get grid points */
|
|
|
|
gp = &rawGridPoints[ num ];
|
|
|
|
bgp = &bspGridPoints[ num ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get grid origin */
|
|
|
|
mod = num;
|
2012-03-17 20:01:54 +00:00
|
|
|
z = mod / ( gridBounds[ 0 ] * gridBounds[ 1 ] );
|
|
|
|
mod -= z * ( gridBounds[ 0 ] * gridBounds[ 1 ] );
|
2007-11-04 03:34:51 +00:00
|
|
|
y = mod / gridBounds[ 0 ];
|
|
|
|
mod -= y * gridBounds[ 0 ];
|
|
|
|
x = mod;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.origin[ 0 ] = gridMins[ 0 ] + x * gridSize[ 0 ];
|
|
|
|
trace.origin[ 1 ] = gridMins[ 1 ] + y * gridSize[ 1 ];
|
|
|
|
trace.origin[ 2 ] = gridMins[ 2 ] + z * gridSize[ 2 ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set inhibit sphere */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( gridSize[ 0 ] > gridSize[ 1 ] && gridSize[ 0 ] > gridSize[ 2 ] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.inhibitRadius = gridSize[ 0 ] * 0.5f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( gridSize[ 1 ] > gridSize[ 0 ] && gridSize[ 1 ] > gridSize[ 2 ] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.inhibitRadius = gridSize[ 1 ] * 0.5f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.inhibitRadius = gridSize[ 2 ] * 0.5f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* find point cluster */
|
|
|
|
trace.cluster = ClusterForPointExt( trace.origin, GRID_EPSILON );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace.cluster < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* try to nudge the origin around to find a valid point */
|
|
|
|
VectorCopy( trace.origin, baseOrigin );
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( step = 9; step <= 18; step += 9 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < 8; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
VectorCopy( baseOrigin, trace.origin );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i & 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.origin[ 0 ] += step;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.origin[ 0 ] -= step;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( i & 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.origin[ 1 ] += step;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.origin[ 1 ] -= step;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( i & 4 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.origin[ 2 ] += step;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
trace.origin[ 2 ] -= step;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: changed to find cluster num */
|
|
|
|
trace.cluster = ClusterForPointExt( trace.origin, VERTEX_EPSILON );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace.cluster >= 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( i != 8 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* can't find a valid point at all */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( step > 18 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup trace */
|
|
|
|
trace.testOcclusion = !noTrace;
|
|
|
|
trace.forceSunlight = qfalse;
|
|
|
|
trace.recvShadows = WORLDSPAWN_RECV_SHADOWS;
|
|
|
|
trace.numSurfaces = 0;
|
|
|
|
trace.surfaces = NULL;
|
|
|
|
trace.numLights = 0;
|
|
|
|
trace.lights = NULL;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* clear */
|
|
|
|
numCon = 0;
|
|
|
|
VectorClear( cheapColor );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* trace to all the lights, find the major light direction, and divide the
|
|
|
|
total light between that along the direction and the remaining in the ambient */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( trace.light = lights; trace.light != NULL; trace.light = trace.light->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
float addSize;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* sample light */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !LightContributionToPoint( &trace ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle negative light */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trace.light->flags & LIGHT_NEGATIVE ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorScale( trace.color, -1.0f, trace.color );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add a contribution */
|
|
|
|
VectorCopy( trace.color, contributions[ numCon ].color );
|
|
|
|
VectorCopy( trace.direction, contributions[ numCon ].dir );
|
|
|
|
contributions[ numCon ].style = trace.light->style;
|
|
|
|
numCon++;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* push average direction around */
|
|
|
|
addSize = VectorLength( trace.color );
|
|
|
|
VectorMA( gp->dir, addSize, trace.direction, gp->dir );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* stop after a while */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numCon >= ( MAX_CONTRIBUTIONS - 1 ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: cheap mode */
|
|
|
|
VectorAdd( cheapColor, trace.color, cheapColor );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( cheapgrid && cheapColor[ 0 ] >= 255.0f && cheapColor[ 1 ] >= 255.0f && cheapColor[ 2 ] >= 255.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* normalize to get primary light direction */
|
|
|
|
VectorNormalize( gp->dir, gp->dir );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* now that we have identified the primary light direction,
|
|
|
|
go back and separate all the light into directed and ambient */
|
|
|
|
numStyles = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numCon; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get relative directed strength */
|
|
|
|
d = DotProduct( contributions[ i ].dir, gp->dir );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d < 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
d = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* find appropriate style */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < numStyles; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( gp->styles[ j ] == contributions[ i ].style ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* style not found? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( j >= numStyles ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add a new style */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numStyles < MAX_LIGHTMAPS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
gp->styles[ numStyles ] = contributions[ i ].style;
|
|
|
|
bgp->styles[ numStyles ] = contributions[ i ].style;
|
|
|
|
numStyles++;
|
|
|
|
//% Sys_Printf( "(%d, %d) ", num, contributions[ i ].style );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* fallback */
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
j = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add the directed color */
|
|
|
|
VectorMA( gp->directed[ j ], d, contributions[ i ].color, gp->directed[ j ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ambient light will be at 1/4 the value of directed light */
|
|
|
|
/* (ydnar: nuke this in favor of more dramatic lighting?) */
|
2012-03-17 20:01:54 +00:00
|
|
|
d = 0.25f * ( 1.0f - d );
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorMA( gp->ambient[ j ], d, contributions[ i ].color, gp->ambient[ j ] );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* store off sample */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < MAX_LIGHTMAPS; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* do some fudging to keep the ambient from being too low (2003-07-05: 0.25 -> 0.125) */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !bouncing ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorMA( gp->ambient[ i ], 0.125f, gp->directed[ i ], gp->ambient[ i ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set minimum light and copy off to bytes */
|
|
|
|
VectorCopy( gp->ambient[ i ], color );
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < 3; j++ )
|
|
|
|
if ( color[ j ] < minGridLight[ j ] ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
color[ j ] = minGridLight[ j ];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
ColorToBytes( color, bgp->ambient[ i ], 1.0f );
|
|
|
|
ColorToBytes( gp->directed[ i ], bgp->directed[ i ], 1.0f );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* debug code */
|
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
//% Sys_FPrintf( SYS_VRB, "%10d %10d %10d ", &gp->ambient[ 0 ][ 0 ], &gp->ambient[ 0 ][ 1 ], &gp->ambient[ 0 ][ 2 ] );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d Amb: (%03.1f %03.1f %03.1f) Dir: (%03.1f %03.1f %03.1f)\n",
|
|
|
|
num,
|
|
|
|
gp->ambient[ 0 ][ 0 ], gp->ambient[ 0 ][ 1 ], gp->ambient[ 0 ][ 2 ],
|
|
|
|
gp->directed[ 0 ][ 0 ], gp->directed[ 0 ][ 1 ], gp->directed[ 0 ][ 2 ] );
|
2007-11-04 03:34:51 +00:00
|
|
|
#endif
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* store direction */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !bouncing ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
NormalToLatLong( gp->dir, bgp->latLong );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SetupGrid()
|
|
|
|
calculates the size of the lightgrid and allocates memory
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SetupGrid( void ){
|
|
|
|
int i, j;
|
|
|
|
vec3_t maxs, oldGridSize;
|
|
|
|
const char *value;
|
|
|
|
char temp[ 64 ];
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* don't do this if not grid lighting */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( noGridLighting ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: set grid size */
|
|
|
|
value = ValueForKey( &entities[ 0 ], "gridsize" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sscanf( value, "%f %f %f", &gridSize[ 0 ], &gridSize[ 1 ], &gridSize[ 2 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* quantize it */
|
|
|
|
VectorCopy( gridSize, oldGridSize );
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < 3; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
gridSize[ i ] = gridSize[ i ] >= 8.0f ? floor( gridSize[ i ] ) : 8.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: increase gridSize until grid count is smaller than max allowed */
|
|
|
|
numRawGridPoints = MAX_MAP_LIGHTGRID + 1;
|
|
|
|
j = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( numRawGridPoints > MAX_MAP_LIGHTGRID )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get world bounds */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < 3; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
gridMins[ i ] = gridSize[ i ] * ceil( bspModels[ 0 ].mins[ i ] / gridSize[ i ] );
|
|
|
|
maxs[ i ] = gridSize[ i ] * floor( bspModels[ 0 ].maxs[ i ] / gridSize[ i ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
gridBounds[ i ] = ( maxs[ i ] - gridMins[ i ] ) / gridSize[ i ] + 1;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set grid size */
|
|
|
|
numRawGridPoints = gridBounds[ 0 ] * gridBounds[ 1 ] * gridBounds[ 2 ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* increase grid size a bit */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numRawGridPoints > MAX_MAP_LIGHTGRID ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
gridSize[ j++ % 3 ] += 16.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* print it */
|
|
|
|
Sys_Printf( "Grid size = { %1.0f, %1.0f, %1.0f }\n", gridSize[ 0 ], gridSize[ 1 ], gridSize[ 2 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* different? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !VectorCompare( gridSize, oldGridSize ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sprintf( temp, "%.0f %.0f %.0f", gridSize[ 0 ], gridSize[ 1 ], gridSize[ 2 ] );
|
|
|
|
SetKeyValue( &entities[ 0 ], "gridsize", (const char*) temp );
|
|
|
|
Sys_FPrintf( SYS_VRB, "Storing adjusted grid size\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* 2nd variable. fixme: is this silly? */
|
|
|
|
numBSPGridPoints = numRawGridPoints;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* allocate lightgrid */
|
|
|
|
rawGridPoints = safe_malloc( numRawGridPoints * sizeof( *rawGridPoints ) );
|
|
|
|
memset( rawGridPoints, 0, numRawGridPoints * sizeof( *rawGridPoints ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( bspGridPoints != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
free( bspGridPoints );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
bspGridPoints = safe_malloc( numBSPGridPoints * sizeof( *bspGridPoints ) );
|
|
|
|
memset( bspGridPoints, 0, numBSPGridPoints * sizeof( *bspGridPoints ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* clear lightgrid */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numRawGridPoints; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
VectorCopy( ambientColor, rawGridPoints[ i ].ambient[ j ] );
|
|
|
|
rawGridPoints[ i ].styles[ 0 ] = LS_NORMAL;
|
|
|
|
bspGridPoints[ i ].styles[ 0 ] = LS_NORMAL;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 1; j < MAX_LIGHTMAPS; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
rawGridPoints[ i ].styles[ j ] = LS_NONE;
|
|
|
|
bspGridPoints[ i ].styles[ j ] = LS_NONE;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* note it */
|
|
|
|
Sys_Printf( "%9d grid points\n", numRawGridPoints );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
LightWorld()
|
|
|
|
does what it says...
|
|
|
|
*/
|
|
|
|
|
|
|
|
void LightWorld( void ){
|
|
|
|
vec3_t color;
|
|
|
|
float f;
|
|
|
|
int b, bt;
|
|
|
|
qboolean minVertex, minGrid;
|
|
|
|
const char *value;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ydnar: smooth normals */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( shade ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "--- SmoothNormals ---\n" );
|
|
|
|
SmoothNormals();
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* determine the number of grid points */
|
|
|
|
Sys_Printf( "--- SetupGrid ---\n" );
|
|
|
|
SetupGrid();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* find the optional minimum lighting values */
|
|
|
|
GetVectorForKey( &entities[ 0 ], "_color", color );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( VectorLength( color ) == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorSet( color, 1.0, 1.0, 1.0 );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ambient */
|
|
|
|
f = FloatForKey( &entities[ 0 ], "_ambient" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( f == 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
f = FloatForKey( &entities[ 0 ], "ambient" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorScale( color, f, ambientColor );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* minvertexlight */
|
|
|
|
minVertex = qfalse;
|
|
|
|
value = ValueForKey( &entities[ 0 ], "_minvertexlight" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
minVertex = qtrue;
|
|
|
|
f = atof( value );
|
|
|
|
VectorScale( color, f, minVertexLight );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* mingridlight */
|
|
|
|
minGrid = qfalse;
|
|
|
|
value = ValueForKey( &entities[ 0 ], "_mingridlight" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
minGrid = qtrue;
|
|
|
|
f = atof( value );
|
|
|
|
VectorScale( color, f, minGridLight );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* minlight */
|
|
|
|
value = ValueForKey( &entities[ 0 ], "_minlight" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
f = atof( value );
|
|
|
|
VectorScale( color, f, minLight );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( minVertex == qfalse ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorScale( color, f, minVertexLight );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( minGrid == qfalse ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
VectorScale( color, f, minGridLight );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* create world lights */
|
|
|
|
Sys_FPrintf( SYS_VRB, "--- CreateLights ---\n" );
|
|
|
|
CreateEntityLights();
|
|
|
|
CreateSurfaceLights();
|
|
|
|
Sys_Printf( "%9d point lights\n", numPointLights );
|
|
|
|
Sys_Printf( "%9d spotlights\n", numSpotLights );
|
|
|
|
Sys_Printf( "%9d diffuse (area) lights\n", numDiffuseLights );
|
|
|
|
Sys_Printf( "%9d sun/sky lights\n", numSunLights );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* calculate lightgrid */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !noGridLighting ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: set up light envelopes */
|
|
|
|
SetupEnvelopes( qtrue, fastgrid );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "--- TraceGrid ---\n" );
|
|
|
|
RunThreadsOnIndividual( numRawGridPoints, qtrue, TraceGrid );
|
|
|
|
Sys_Printf( "%d x %d x %d = %d grid\n",
|
2012-03-17 20:01:54 +00:00
|
|
|
gridBounds[ 0 ], gridBounds[ 1 ], gridBounds[ 2 ], numBSPGridPoints );
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: emit statistics on light culling */
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d grid points envelope culled\n", gridEnvelopeCulled );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d grid points bounds culled\n", gridBoundsCulled );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* slight optimization to remove a sqrt */
|
|
|
|
subdivideThreshold *= subdivideThreshold;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* map the world luxels */
|
|
|
|
Sys_Printf( "--- MapRawLightmap ---\n" );
|
|
|
|
RunThreadsOnIndividual( numRawLightmaps, qtrue, MapRawLightmap );
|
|
|
|
Sys_Printf( "%9d luxels\n", numLuxels );
|
|
|
|
Sys_Printf( "%9d luxels mapped\n", numLuxelsMapped );
|
|
|
|
Sys_Printf( "%9d luxels occluded\n", numLuxelsOccluded );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* dirty them up */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dirty ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
Sys_Printf( "--- DirtyRawLightmap ---\n" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RunThreadsOnIndividual( numRawLightmaps, qtrue, DirtyRawLightmap );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* ydnar: set up light envelopes */
|
|
|
|
SetupEnvelopes( qfalse, fast );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* light up my world */
|
|
|
|
lightsPlaneCulled = 0;
|
|
|
|
lightsEnvelopeCulled = 0;
|
|
|
|
lightsBoundsCulled = 0;
|
|
|
|
lightsClusterCulled = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "--- IlluminateRawLightmap ---\n" );
|
|
|
|
RunThreadsOnIndividual( numRawLightmaps, qtrue, IlluminateRawLightmap );
|
|
|
|
Sys_Printf( "%9d luxels illuminated\n", numLuxelsIlluminated );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
StitchSurfaceLightmaps();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "--- IlluminateVertexes ---\n" );
|
|
|
|
RunThreadsOnIndividual( numBSPDrawSurfaces, qtrue, IlluminateVertexes );
|
|
|
|
Sys_Printf( "%9d vertexes illuminated\n", numVertsIlluminated );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: emit statistics on light culling */
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d lights plane culled\n", lightsPlaneCulled );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d lights envelope culled\n", lightsEnvelopeCulled );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d lights bounds culled\n", lightsBoundsCulled );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d lights cluster culled\n", lightsClusterCulled );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* radiosity */
|
|
|
|
b = 1;
|
|
|
|
bt = bounce;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( bounce > 0 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* store off the bsp between bounces */
|
|
|
|
StoreSurfaceLightmaps();
|
|
|
|
Sys_Printf( "Writing %s\n", source );
|
|
|
|
WriteBSPFile( source );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* note it */
|
|
|
|
Sys_Printf( "\n--- Radiosity (bounce %d of %d) ---\n", b, bt );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* flag bouncing */
|
|
|
|
bouncing = qtrue;
|
|
|
|
VectorClear( ambientColor );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* generate diffuse lights */
|
|
|
|
RadFreeLights();
|
|
|
|
RadCreateDiffuseLights();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup light envelopes */
|
|
|
|
SetupEnvelopes( qfalse, fastbounce );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numLights == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "No diffuse light to calculate, ending radiosity.\n" );
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add to lightgrid */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bouncegrid ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
gridEnvelopeCulled = 0;
|
|
|
|
gridBoundsCulled = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "--- BounceGrid ---\n" );
|
|
|
|
RunThreadsOnIndividual( numRawGridPoints, qtrue, TraceGrid );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d grid points envelope culled\n", gridEnvelopeCulled );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d grid points bounds culled\n", gridBoundsCulled );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* light up my world */
|
|
|
|
lightsPlaneCulled = 0;
|
|
|
|
lightsEnvelopeCulled = 0;
|
|
|
|
lightsBoundsCulled = 0;
|
|
|
|
lightsClusterCulled = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "--- IlluminateRawLightmap ---\n" );
|
|
|
|
RunThreadsOnIndividual( numRawLightmaps, qtrue, IlluminateRawLightmap );
|
|
|
|
Sys_Printf( "%9d luxels illuminated\n", numLuxelsIlluminated );
|
|
|
|
Sys_Printf( "%9d vertexes illuminated\n", numVertsIlluminated );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
StitchSurfaceLightmaps();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "--- IlluminateVertexes ---\n" );
|
|
|
|
RunThreadsOnIndividual( numBSPDrawSurfaces, qtrue, IlluminateVertexes );
|
|
|
|
Sys_Printf( "%9d vertexes illuminated\n", numVertsIlluminated );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: emit statistics on light culling */
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d lights plane culled\n", lightsPlaneCulled );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d lights envelope culled\n", lightsEnvelopeCulled );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d lights bounds culled\n", lightsBoundsCulled );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d lights cluster culled\n", lightsClusterCulled );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* interate */
|
|
|
|
bounce--;
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
LightMain()
|
|
|
|
main routine for light processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
int LightMain( int argc, char **argv ){
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
char mapSource[ 1024 ];
|
|
|
|
const char *value;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* note it */
|
|
|
|
Sys_Printf( "--- Light ---\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* set standard game flags */
|
|
|
|
wolfLight = game->wolfLight;
|
|
|
|
lmCustomSize = game->lightmapSize;
|
|
|
|
lightmapGamma = game->lightmapGamma;
|
|
|
|
lightmapCompensate = game->lightmapCompensate;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* process commandline arguments */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1; i < ( argc - 1 ); i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* lightsource scaling */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( argv[ i ], "-point" ) || !strcmp( argv[ i ], "-pointscale" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
f = atof( argv[ i + 1 ] );
|
|
|
|
pointScale *= f;
|
|
|
|
Sys_Printf( "Point (entity) light scaled by %f to %f\n", f, pointScale );
|
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-area" ) || !strcmp( argv[ i ], "-areascale" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
f = atof( argv[ i + 1 ] );
|
|
|
|
areaScale *= f;
|
|
|
|
Sys_Printf( "Area (shader) light scaled by %f to %f\n", f, areaScale );
|
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-sky" ) || !strcmp( argv[ i ], "-skyscale" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
f = atof( argv[ i + 1 ] );
|
|
|
|
skyScale *= f;
|
|
|
|
Sys_Printf( "Sky/sun light scaled by %f to %f\n", f, skyScale );
|
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-bouncescale" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
f = atof( argv[ i + 1 ] );
|
|
|
|
bounceScale *= f;
|
|
|
|
Sys_Printf( "Bounce (radiosity) light scaled by %f to %f\n", f, bounceScale );
|
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-scale" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
f = atof( argv[ i + 1 ] );
|
|
|
|
pointScale *= f;
|
|
|
|
areaScale *= f;
|
|
|
|
skyScale *= f;
|
|
|
|
bounceScale *= f;
|
|
|
|
Sys_Printf( "All light scaled by %f\n", f );
|
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-gamma" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
f = atof( argv[ i + 1 ] );
|
|
|
|
lightmapGamma = f;
|
|
|
|
Sys_Printf( "Lighting gamma set to %f\n", lightmapGamma );
|
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-compensate" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
f = atof( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( f <= 0.0f ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
f = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-07-25 07:31:37 +00:00
|
|
|
lightmapCompensate = f;
|
|
|
|
Sys_Printf( "Lighting compensation set to 1/%f\n", lightmapCompensate );
|
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar switches */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-bounce" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bounce = atoi( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bounce < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bounce = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( bounce > 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Radiosity enabled with %d bounce(s)\n", bounce );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-supersample" ) || !strcmp( argv[ i ], "-super" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
superSample = atoi( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( superSample < 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
superSample = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( superSample > 1 ) {
|
|
|
|
Sys_Printf( "Ordered-grid supersampling enabled with %d sample(s) per lightmap texel\n", ( superSample * superSample ) );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-samples" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
lightSamples = atoi( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( lightSamples < 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
lightSamples = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( lightSamples > 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Adaptive supersampling enabled with %d sample(s) per lightmap texel\n", lightSamples );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-filter" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
filter = qtrue;
|
|
|
|
Sys_Printf( "Lightmap filtering enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-dark" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dark = qtrue;
|
|
|
|
Sys_Printf( "Dark lightmap seams enabled\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-shadeangle" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
shadeAngleDegrees = atof( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( shadeAngleDegrees < 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
shadeAngleDegrees = 0.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( shadeAngleDegrees > 0.0f ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
shade = qtrue;
|
|
|
|
Sys_Printf( "Phong shading enabled with a breaking angle of %f degrees\n", shadeAngleDegrees );
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-thresh" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
subdivideThreshold = atof( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( subdivideThreshold < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
subdivideThreshold = DEFAULT_SUBDIVIDE_THRESHOLD;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Subdivision threshold set at %.3f\n", subdivideThreshold );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-approx" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
approximateTolerance = atoi( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( approximateTolerance < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
approximateTolerance = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( approximateTolerance > 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Approximating lightmaps within a byte tolerance of %d\n", approximateTolerance );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
i++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-deluxe" ) || !strcmp( argv[ i ], "-deluxemap" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
deluxemap = qtrue;
|
|
|
|
Sys_Printf( "Generating deluxemaps for average light direction\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-external" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
externalLightmaps = qtrue;
|
|
|
|
Sys_Printf( "Storing all lightmaps externally\n" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-lightmapsize" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
lmCustomSize = atoi( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* must be a power of 2 and greater than 2 */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( ( lmCustomSize - 1 ) & lmCustomSize ) || lmCustomSize < 2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: Lightmap size must be a power of 2, greater or equal to 2 pixels.\n" );
|
2008-07-25 07:31:37 +00:00
|
|
|
lmCustomSize = game->lightmapSize;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
Sys_Printf( "Default lightmap size set to %d x %d pixels\n", lmCustomSize, lmCustomSize );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* enable external lightmaps */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( lmCustomSize != game->lightmapSize ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
externalLightmaps = qtrue;
|
|
|
|
Sys_Printf( "Storing all lightmaps externally\n" );
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: add this to suppress warnings */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-custinfoparms" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Custom info parms enabled\n" );
|
|
|
|
useCustomInfoParms = qtrue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-wolf" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* -game should already be set */
|
2008-07-25 07:31:37 +00:00
|
|
|
wolfLight = qtrue;
|
|
|
|
Sys_Printf( "Enabling Wolf lighting model (linear default)\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-q3" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
/* -game should already be set */
|
|
|
|
wolfLight = qfalse;
|
|
|
|
Sys_Printf( "Enabling Quake 3 lighting model (nonlinear default)\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-sunonly" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sunOnly = qtrue;
|
|
|
|
Sys_Printf( "Only computing sunlight\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-bounceonly" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bounceOnly = qtrue;
|
|
|
|
Sys_Printf( "Storing bounced light (radiosity) only\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-nocollapse" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
noCollapse = qtrue;
|
|
|
|
Sys_Printf( "Identical lightmap collapsing disabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-shade" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
shade = qtrue;
|
|
|
|
Sys_Printf( "Phong shading enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-bouncegrid" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bouncegrid = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( bounce > 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Grid lighting with radiosity enabled\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-smooth" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
lightSamples = EXTRA_SCALE;
|
|
|
|
Sys_Printf( "The -smooth argument is deprecated, use \"-samples 2\" instead\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-fast" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
fast = qtrue;
|
|
|
|
fastgrid = qtrue;
|
|
|
|
fastbounce = qtrue;
|
|
|
|
Sys_Printf( "Fast mode enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-faster" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
faster = qtrue;
|
|
|
|
fast = qtrue;
|
|
|
|
fastgrid = qtrue;
|
|
|
|
fastbounce = qtrue;
|
|
|
|
Sys_Printf( "Faster mode enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-fastgrid" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
fastgrid = qtrue;
|
|
|
|
Sys_Printf( "Fast grid lighting enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-fastbounce" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
fastbounce = qtrue;
|
|
|
|
Sys_Printf( "Fast bounce mode enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-cheap" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
cheap = qtrue;
|
|
|
|
cheapgrid = qtrue;
|
|
|
|
Sys_Printf( "Cheap mode enabled\n" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-cheapgrid" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
cheapgrid = qtrue;
|
|
|
|
Sys_Printf( "Cheap grid mode enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-normalmap" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
normalmap = qtrue;
|
|
|
|
Sys_Printf( "Storing normal map instead of lightmap\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-trisoup" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
trisoup = qtrue;
|
|
|
|
Sys_Printf( "Converting brush faces to triangle soup\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-debug" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
debug = qtrue;
|
|
|
|
Sys_Printf( "Lightmap debugging enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-debugsurfaces" ) || !strcmp( argv[ i ], "-debugsurface" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
debugSurfaces = qtrue;
|
|
|
|
Sys_Printf( "Lightmap surface debugging enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-debugunused" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
debugUnused = qtrue;
|
|
|
|
Sys_Printf( "Unused luxel debugging enabled\n" );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-debugaxis" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
debugAxis = qtrue;
|
|
|
|
Sys_Printf( "Lightmap axis debugging enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-debugcluster" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
debugCluster = qtrue;
|
|
|
|
Sys_Printf( "Luxel cluster debugging enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-debugorigin" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
debugOrigin = qtrue;
|
|
|
|
Sys_Printf( "Luxel origin debugging enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-debugdeluxe" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
deluxemap = qtrue;
|
|
|
|
debugDeluxemap = qtrue;
|
|
|
|
Sys_Printf( "Deluxemap debugging enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-export" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
exportLightmaps = qtrue;
|
|
|
|
Sys_Printf( "Exporting lightmaps\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
else if ( !strcmp( argv[ i ], "-notrace" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
noTrace = qtrue;
|
|
|
|
Sys_Printf( "Shadow occlusion disabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-patchshadows" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
patchShadows = qtrue;
|
|
|
|
Sys_Printf( "Patch shadow casting enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-extra" ) ) {
|
|
|
|
superSample = EXTRA_SCALE; /* ydnar */
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "The -extra argument is deprecated, use \"-super 2\" instead\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-extrawide" ) ) {
|
|
|
|
superSample = EXTRAWIDE_SCALE; /* ydnar */
|
|
|
|
filter = qtrue; /* ydnar */
|
|
|
|
Sys_Printf( "The -extrawide argument is deprecated, use \"-filter [-super 2]\" instead\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-samplesize" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sampleSize = atoi( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( sampleSize < 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sampleSize = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
i++;
|
|
|
|
Sys_Printf( "Default lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-novertex" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
noVertexLighting = qtrue;
|
|
|
|
Sys_Printf( "Disabling vertex lighting\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-nogrid" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
noGridLighting = qtrue;
|
|
|
|
Sys_Printf( "Disabling grid lighting\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-border" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
lightmapBorder = qtrue;
|
|
|
|
Sys_Printf( "Adding debug border to lightmaps\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-nosurf" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
noSurfaces = qtrue;
|
|
|
|
Sys_Printf( "Not tracing against surfaces\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-dump" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dump = qtrue;
|
|
|
|
Sys_Printf( "Dumping radiosity lights into numbered prefabs\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-lomem" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
loMem = qtrue;
|
|
|
|
Sys_Printf( "Enabling low-memory (potentially slower) lighting mode\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-nostyle" ) || !strcmp( argv[ i ], "-nostyles" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
noStyles = qtrue;
|
|
|
|
Sys_Printf( "Disabling lightstyles\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-cpma" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
cpmaHack = qtrue;
|
|
|
|
Sys_Printf( "Enabling Challenge Pro Mode Asstacular Vertex Lighting Mode (tm)\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* r7: dirtmapping */
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-dirty" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirty = qtrue;
|
|
|
|
Sys_Printf( "Dirtmapping enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-dirtdebug" ) || !strcmp( argv[ i ], "-debugdirt" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtDebug = qtrue;
|
|
|
|
Sys_Printf( "Dirtmap debugging enabled\n" );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-dirtmode" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtMode = atoi( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dirtMode != 0 && dirtMode != 1 ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtMode = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( dirtMode == 1 ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
Sys_Printf( "Enabling randomized dirtmapping\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2008-07-25 07:31:37 +00:00
|
|
|
Sys_Printf( "Enabling ordered dir mapping\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-07-25 07:31:37 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-dirtdepth" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtDepth = atof( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dirtDepth <= 0.0f ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtDepth = 128.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-07-25 07:31:37 +00:00
|
|
|
Sys_Printf( "Dirtmapping depth set to %.1f\n", dirtDepth );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-dirtscale" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtScale = atof( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dirtScale <= 0.0f ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtScale = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-07-25 07:31:37 +00:00
|
|
|
Sys_Printf( "Dirtmapping scale set to %.1f\n", dirtScale );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( !strcmp( argv[ i ], "-dirtgain" ) ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtGain = atof( argv[ i + 1 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dirtGain <= 0.0f ) {
|
2008-07-25 07:31:37 +00:00
|
|
|
dirtGain = 1.0f;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-07-25 07:31:37 +00:00
|
|
|
Sys_Printf( "Dirtmapping gain set to %.1f\n", dirtGain );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2008-07-25 07:31:37 +00:00
|
|
|
/* unhandled args */
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2008-07-25 07:31:37 +00:00
|
|
|
Sys_Printf( "WARNING: Unknown argument \"%s\"\n", argv[ i ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2008-07-25 07:31:37 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* clean up map name */
|
|
|
|
strcpy( source, ExpandArg( argv[ i ] ) );
|
|
|
|
StripExtension( source );
|
|
|
|
DefaultExtension( source, ".bsp" );
|
|
|
|
strcpy( mapSource, ExpandArg( argv[ i ] ) );
|
|
|
|
StripExtension( mapSource );
|
|
|
|
DefaultExtension( mapSource, ".map" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: set default sample size */
|
|
|
|
SetDefaultSampleSize( sampleSize );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: handle shaders */
|
|
|
|
BeginMapShaderFile( source );
|
|
|
|
LoadShaderInfo();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* note loading */
|
|
|
|
Sys_Printf( "Loading %s\n", source );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: load surface file */
|
|
|
|
LoadSurfaceExtraFile( source );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* load bsp file */
|
|
|
|
LoadBSPFile( source );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* parse bsp entities */
|
|
|
|
ParseEntities();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* load map file */
|
|
|
|
value = ValueForKey( &entities[ 0 ], "_keepLights" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] != '1' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
LoadMapFile( mapSource, qtrue );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set the entity/model origins and init yDrawVerts */
|
|
|
|
SetEntityOrigins();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: set up optimization */
|
|
|
|
SetupBrushes();
|
2008-07-25 07:31:37 +00:00
|
|
|
SetupDirt();
|
2007-11-04 03:34:51 +00:00
|
|
|
SetupSurfaceLightmaps();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* initialize the surface facet tracing */
|
|
|
|
SetupTraceNodes();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* light the world */
|
|
|
|
LightWorld();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: store off lightmaps */
|
|
|
|
StoreSurfaceLightmaps();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* write out the bsp */
|
|
|
|
UnparseEntities();
|
|
|
|
Sys_Printf( "Writing %s\n", source );
|
|
|
|
WriteBSPFile( source );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: export lightmaps */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( exportLightmaps && !externalLightmaps ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
ExportLightmaps();
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* return to sender */
|
|
|
|
return 0;
|
|
|
|
}
|