forked from DaemonEngine/Daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtr_light.cpp
More file actions
94 lines (74 loc) · 3.02 KB
/
tr_light.cpp
File metadata and controls
94 lines (74 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2006-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
This file is part of Daemon source code.
Daemon source code 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.
Daemon source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Daemon source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// tr_light.c
#include "tr_local.h"
/*
=============================================================================
LIGHT SAMPLING
=============================================================================
*/
void R_InterpolateLightGrid( world_t *w, int from[3], int to[3], float *factors[3],
vec3_t lightColor, vec3_t lightDir )
{
float totalFactor = 0.0f, factor;
float *xFactor, *yFactor, *zFactor;
int gridStep[ 3 ];
int x, y, z;
bspGridPoint1_t *gp1;
bspGridPoint2_t *gp2;
VectorClear( lightColor );
VectorClear( lightDir );
gridStep[ 0 ] = 1;
gridStep[ 1 ] = w->lightGridBounds[ 0 ];
gridStep[ 2 ] = gridStep[ 1 ] * w->lightGridBounds[ 1 ];
for( x = from[ 0 ], xFactor = factors[ 0 ]; x <= to[ 0 ];
x++, xFactor++ ) {
if( x < 0 || x >= w->lightGridBounds[ 0 ] )
continue;
for( y = from[ 1 ], yFactor = factors[ 1 ]; y <= to[ 1 ];
y++, yFactor++ ) {
if( y < 0 || y >= w->lightGridBounds[ 1 ] )
continue;
for( z = from[ 2 ], zFactor = factors[ 2 ]; z <= to[ 2 ];
z++, zFactor++ ) {
if( z < 0 || z >= w->lightGridBounds[ 2 ] )
continue;
gp1 = w->lightGridData1 + x * gridStep[ 0 ] + y * gridStep[ 1 ] + z * gridStep[ 2 ];
gp2 = w->lightGridData2 + x * gridStep[ 0 ] + y * gridStep[ 1 ] + z * gridStep[ 2 ];
if ( !gp2->isSet )
{
continue; // ignore samples in walls
}
factor = *xFactor * *yFactor * *zFactor;
totalFactor += factor;
lightDir[ 0 ] += factor * snorm8ToFloat( gp2->direction[ 0 ] - 128 );
lightDir[ 1 ] += factor * snorm8ToFloat( gp2->direction[ 1 ] - 128 );
lightDir[ 2 ] += factor * snorm8ToFloat( gp2->direction[ 2 ] - 128 );
lightColor[ 0 ] += factor * unorm8ToFloat( gp1->color[ 0 ] );
lightColor[ 1 ] += factor * unorm8ToFloat( gp1->color[ 1 ] );
lightColor[ 2 ] += factor * unorm8ToFloat( gp1->color[ 2 ] );
}
}
}
if ( totalFactor > 0.0f )
{
VectorScale( lightDir, 1.0f / totalFactor, lightDir );
VectorScale( lightColor, 1.0f / totalFactor, lightColor );
}
}