|
|
|
@@ -123,6 +123,7 @@ R_SetupEntityLightingGrid
|
|
|
|
|
|
|
|
|
|
=================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void R_SetupEntityLightingGrid( trRefEntity_t *ent ) {
|
|
|
|
|
vec3_t lightOrigin;
|
|
|
|
|
int pos[3];
|
|
|
|
@@ -252,484 +253,6 @@ static void R_SetupEntityLightingGrid( trRefEntity_t *ent ) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void R_SetupEntityLightingGrid_crazy( trRefEntity_t *ent ) {
|
|
|
|
|
vec3_t lightOrigin;
|
|
|
|
|
int pos[3];
|
|
|
|
|
int i, j;
|
|
|
|
|
byte *gridData;
|
|
|
|
|
float frac[3];
|
|
|
|
|
int gridStep[3];
|
|
|
|
|
vec3_t direction;
|
|
|
|
|
float totalFactor;
|
|
|
|
|
|
|
|
|
|
// Light 2 stuff
|
|
|
|
|
vec3_t lightOriginA;
|
|
|
|
|
float lightdist = r_leidebug->value;
|
|
|
|
|
int posA[3];
|
|
|
|
|
vec3_t directionA;
|
|
|
|
|
|
|
|
|
|
if ( ent->e.renderfx & RF_LIGHTING_ORIGIN ) {
|
|
|
|
|
// seperate lightOrigins are needed so an object that is
|
|
|
|
|
// sinking into the ground can still be lit, and so
|
|
|
|
|
// multi-part models can be lit identically
|
|
|
|
|
VectorCopy( ent->e.lightingOrigin, lightOrigin );
|
|
|
|
|
} else {
|
|
|
|
|
VectorCopy( ent->e.origin, lightOrigin );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VectorSubtract( lightOrigin, tr.world->lightGridOrigin, lightOrigin );
|
|
|
|
|
|
|
|
|
|
// Light 1
|
|
|
|
|
for ( i = 0 ; i < 3 ; i++ ) {
|
|
|
|
|
float v;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v = lightOrigin[i]*tr.world->lightGridInverseSize[i];
|
|
|
|
|
pos[i] = floor( v );
|
|
|
|
|
frac[i] = v - pos[i];
|
|
|
|
|
if ( pos[i] < 0 ) {
|
|
|
|
|
pos[i] = 0;
|
|
|
|
|
} else if ( pos[i] >= tr.world->lightGridBounds[i] - 1 ) {
|
|
|
|
|
pos[i] = tr.world->lightGridBounds[i] - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VectorClear( ent->ambientLight );
|
|
|
|
|
VectorClear( ent->directedLight );
|
|
|
|
|
VectorClear( ent->dynamicLight );
|
|
|
|
|
VectorClear( direction );
|
|
|
|
|
|
|
|
|
|
assert( tr.world->lightGridData ); // NULL with -nolight maps
|
|
|
|
|
|
|
|
|
|
// trilerp the light value
|
|
|
|
|
gridStep[0] = 8;
|
|
|
|
|
gridStep[1] = 8 * tr.world->lightGridBounds[0];
|
|
|
|
|
gridStep[2] = 8 * tr.world->lightGridBounds[0] * tr.world->lightGridBounds[1];
|
|
|
|
|
gridData = tr.world->lightGridData + pos[0] * gridStep[0]
|
|
|
|
|
+ pos[1] * gridStep[1] + pos[2] * gridStep[2];
|
|
|
|
|
|
|
|
|
|
totalFactor = 0;
|
|
|
|
|
for ( i = 0 ; i < 8 ; i++ ) {
|
|
|
|
|
float factor;
|
|
|
|
|
byte *data;
|
|
|
|
|
int lat, lng;
|
|
|
|
|
vec3_t normal;
|
|
|
|
|
#if idppc
|
|
|
|
|
float d0, d1, d2, d3, d4, d5;
|
|
|
|
|
#endif
|
|
|
|
|
factor = 1.0;
|
|
|
|
|
data = gridData;
|
|
|
|
|
for ( j = 0 ; j < 3 ; j++ ) {
|
|
|
|
|
if ( i & (1<<j) ) {
|
|
|
|
|
factor *= frac[j];
|
|
|
|
|
data += gridStep[j];
|
|
|
|
|
} else {
|
|
|
|
|
factor *= (1.0f - frac[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !(data[0]+data[1]+data[2]) ) {
|
|
|
|
|
continue; // ignore samples in walls
|
|
|
|
|
}
|
|
|
|
|
totalFactor += factor;
|
|
|
|
|
#if idppc
|
|
|
|
|
d0 = data[0]; d1 = data[1]; d2 = data[2];
|
|
|
|
|
d3 = data[3]; d4 = data[4]; d5 = data[5];
|
|
|
|
|
|
|
|
|
|
ent->ambientLight[0] += factor * d0;
|
|
|
|
|
ent->ambientLight[1] += factor * d1;
|
|
|
|
|
ent->ambientLight[2] += factor * d2;
|
|
|
|
|
|
|
|
|
|
ent->directedLight[0] += factor * d3;
|
|
|
|
|
ent->directedLight[1] += factor * d4;
|
|
|
|
|
ent->directedLight[2] += factor * d5;
|
|
|
|
|
#else
|
|
|
|
|
ent->ambientLight[0] += factor * data[0];
|
|
|
|
|
ent->ambientLight[1] += factor * data[1];
|
|
|
|
|
ent->ambientLight[2] += factor * data[2];
|
|
|
|
|
|
|
|
|
|
ent->directedLight[0] += factor * data[3];
|
|
|
|
|
ent->directedLight[1] += factor * data[4];
|
|
|
|
|
ent->directedLight[2] += factor * data[5];
|
|
|
|
|
#endif
|
|
|
|
|
lat = data[7];
|
|
|
|
|
lng = data[6];
|
|
|
|
|
lat *= (FUNCTABLE_SIZE/256);
|
|
|
|
|
lng *= (FUNCTABLE_SIZE/256);
|
|
|
|
|
|
|
|
|
|
// decode X as cos( lat ) * sin( long )
|
|
|
|
|
// decode Y as sin( lat ) * sin( long )
|
|
|
|
|
// decode Z as cos( long )
|
|
|
|
|
|
|
|
|
|
normal[0] = tr.sinTable[(lat+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK] * tr.sinTable[lng];
|
|
|
|
|
normal[1] = tr.sinTable[lat] * tr.sinTable[lng];
|
|
|
|
|
normal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
|
|
|
|
|
|
|
|
|
|
VectorMA( direction, factor, normal, direction );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( totalFactor > 0 && totalFactor < 0.99 ) {
|
|
|
|
|
totalFactor = 1.0f / totalFactor;
|
|
|
|
|
VectorScale( ent->ambientLight, totalFactor, ent->ambientLight );
|
|
|
|
|
VectorScale( ent->directedLight, totalFactor, ent->directedLight );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VectorScale( ent->ambientLight, r_ambientScale->value, ent->ambientLight );
|
|
|
|
|
VectorScale( ent->directedLight, r_directedScale->value, ent->directedLight );
|
|
|
|
|
|
|
|
|
|
VectorNormalize2( direction, ent->lightDir );
|
|
|
|
|
|
|
|
|
|
// Light 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// leilei - lighting hack
|
|
|
|
|
//
|
|
|
|
|
// Try to sample the lightgrid from four different positions
|
|
|
|
|
// so we can add in four more lights to the model
|
|
|
|
|
|
|
|
|
|
vec3_t dirr;
|
|
|
|
|
VectorSubtract( lightOrigin, backEnd.viewParms.or.origin, dirr );
|
|
|
|
|
//VectorCopy(backEnd.viewParms.or.orign, dirr);
|
|
|
|
|
VectorNormalize( dirr );
|
|
|
|
|
// VectorMA( lightOrigin, lightdist, dirr, lightOriginA );
|
|
|
|
|
// Reverse the light direction to check
|
|
|
|
|
|
|
|
|
|
VectorSubtract( ent->lightDir, lightOrigin, dirr );
|
|
|
|
|
VectorNormalize( dirr );
|
|
|
|
|
|
|
|
|
|
lightOriginA[0] = lightOrigin[0] - (dirr[0] * lightdist);
|
|
|
|
|
lightOriginA[1] = lightOrigin[1] - (dirr[1] * lightdist);
|
|
|
|
|
lightOriginA[2] = lightOrigin[2] - (dirr[2] * lightdist);
|
|
|
|
|
// VectorSubtract( lightOriginA, tr.world->lightGridOrigin, lightOriginA );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ( i = 0 ; i < 3 ; i++ ) {
|
|
|
|
|
float v;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v = lightOriginA[i]*tr.world->lightGridInverseSize[i];
|
|
|
|
|
posA[i] = floor( v );
|
|
|
|
|
frac[i] = v - posA[i];
|
|
|
|
|
if ( posA[i] < 0 ) {
|
|
|
|
|
posA[i] = 0;
|
|
|
|
|
} else if ( posA[i] >= tr.world->lightGridBounds[i] - 1 ) {
|
|
|
|
|
posA[i] = tr.world->lightGridBounds[i] - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VectorClear( ent->directedLightA );
|
|
|
|
|
VectorClear( directionA );
|
|
|
|
|
|
|
|
|
|
assert( tr.world->lightGridData ); // NULL with -nolight maps
|
|
|
|
|
|
|
|
|
|
// trilerp the light value
|
|
|
|
|
gridStep[0] = 8;
|
|
|
|
|
gridStep[1] = 8 * tr.world->lightGridBounds[0];
|
|
|
|
|
gridStep[2] = 8 * tr.world->lightGridBounds[0] * tr.world->lightGridBounds[1];
|
|
|
|
|
gridData = tr.world->lightGridData + posA[0] * gridStep[0]
|
|
|
|
|
+ posA[1] * gridStep[1] + posA[2] * gridStep[2];
|
|
|
|
|
|
|
|
|
|
totalFactor = 0;
|
|
|
|
|
for ( i = 0 ; i < 8 ; i++ ) {
|
|
|
|
|
float factor;
|
|
|
|
|
byte *data;
|
|
|
|
|
int lat, lng;
|
|
|
|
|
vec3_t normal;
|
|
|
|
|
#if idppc
|
|
|
|
|
float d0, d1, d2, d3, d4, d5;
|
|
|
|
|
#endif
|
|
|
|
|
factor = 1.0;
|
|
|
|
|
data = gridData;
|
|
|
|
|
for ( j = 0 ; j < 3 ; j++ ) {
|
|
|
|
|
if ( i & (1<<j) ) {
|
|
|
|
|
factor *= frac[j];
|
|
|
|
|
data += gridStep[j];
|
|
|
|
|
} else {
|
|
|
|
|
factor *= (1.0f - frac[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !(data[0]+data[1]+data[2]) ) {
|
|
|
|
|
continue; // ignore samples in walls
|
|
|
|
|
}
|
|
|
|
|
totalFactor += factor;
|
|
|
|
|
#if idppc
|
|
|
|
|
d0 = data[0]; d1 = data[1]; d2 = data[2];
|
|
|
|
|
d3 = data[3]; d4 = data[4]; d5 = data[5];
|
|
|
|
|
|
|
|
|
|
ent->directedLightA[0] += factor * d3;
|
|
|
|
|
ent->directedLightA[1] += factor * d4;
|
|
|
|
|
ent->directedLightA[2] += factor * d5;
|
|
|
|
|
#else
|
|
|
|
|
ent->directedLightA[0] += factor * data[3];
|
|
|
|
|
ent->directedLightA[1] += factor * data[4];
|
|
|
|
|
ent->directedLightA[2] += factor * data[5];
|
|
|
|
|
#endif
|
|
|
|
|
lat = data[7];
|
|
|
|
|
lng = data[6];
|
|
|
|
|
lat *= (FUNCTABLE_SIZE/256);
|
|
|
|
|
lng *= (FUNCTABLE_SIZE/256);
|
|
|
|
|
|
|
|
|
|
// decode X as cos( lat ) * sin( long )
|
|
|
|
|
// decode Y as sin( lat ) * sin( long )
|
|
|
|
|
// decode Z as cos( long )
|
|
|
|
|
|
|
|
|
|
normal[0] = tr.sinTable[(lat+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK] * tr.sinTable[lng];
|
|
|
|
|
normal[1] = tr.sinTable[lat] * tr.sinTable[lng];
|
|
|
|
|
normal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
|
|
|
|
|
|
|
|
|
|
VectorMA( direction, factor, normal, direction );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( totalFactor > 0 && totalFactor < 0.99 ) {
|
|
|
|
|
totalFactor = 1.0f / totalFactor;
|
|
|
|
|
VectorScale( ent->directedLightA, totalFactor, ent->directedLightA );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VectorScale( ent->directedLightA, r_directedScale->value, ent->directedLightA );
|
|
|
|
|
|
|
|
|
|
VectorNormalize2( direction, ent->lightDir );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void R_SetupEntityLightingGrid_crazyed( trRefEntity_t *ent ) {
|
|
|
|
|
vec3_t lightOrigin;
|
|
|
|
|
int pos[3];
|
|
|
|
|
int i, j;
|
|
|
|
|
byte *gridData;
|
|
|
|
|
float frac[3];
|
|
|
|
|
int gridStep[3];
|
|
|
|
|
vec3_t direction;
|
|
|
|
|
float totalFactor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte *gridDataA;
|
|
|
|
|
|
|
|
|
|
float fracA[3];
|
|
|
|
|
int posA[3];
|
|
|
|
|
|
|
|
|
|
vec3_t failed;
|
|
|
|
|
|
|
|
|
|
int lightdist = 128;
|
|
|
|
|
|
|
|
|
|
lightdist = r_leidebug->integer;
|
|
|
|
|
|
|
|
|
|
failed[0] = 666;
|
|
|
|
|
failed[1] = 666;
|
|
|
|
|
failed[2] = 666;
|
|
|
|
|
|
|
|
|
|
int failA = 0;
|
|
|
|
|
vec3_t lightOriginA;
|
|
|
|
|
vec3_t directionA;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// leilei - lighting hack
|
|
|
|
|
//
|
|
|
|
|
// Try to sample the lightgrid from four different positions
|
|
|
|
|
// so we can add in four more lights to the model
|
|
|
|
|
|
|
|
|
|
vec3_t dirr;
|
|
|
|
|
VectorSubtract( lightOrigin, backEnd.viewParms.or.origin, dirr );
|
|
|
|
|
//VectorCopy(backEnd.viewParms.or.orign, dirr);
|
|
|
|
|
VectorNormalize( dirr );
|
|
|
|
|
// VectorMA( lightOrigin, lightdist, dirr, lightOriginA );
|
|
|
|
|
// lightOriginA[0] = dirr[0] * lightdist;
|
|
|
|
|
// lightOriginA[1] = dirr[1] * lightdist;
|
|
|
|
|
// lightOriginA[2] = dirr[2] * lightdist;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( ent->e.renderfx & RF_LIGHTING_ORIGIN ) {
|
|
|
|
|
// seperate lightOrigins are needed so an object that is
|
|
|
|
|
// sinking into the ground can still be lit, and so
|
|
|
|
|
// multi-part models can be lit identically
|
|
|
|
|
VectorCopy( ent->e.lightingOrigin, lightOrigin );
|
|
|
|
|
} else {
|
|
|
|
|
VectorCopy( ent->e.origin, lightOrigin );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reverse the light direction to check
|
|
|
|
|
|
|
|
|
|
VectorSubtract( ent->lightDir, lightOrigin, dirr );
|
|
|
|
|
VectorNormalize( dirr );
|
|
|
|
|
|
|
|
|
|
lightOriginA[0] = lightOrigin[0] - (dirr[0] * lightdist);
|
|
|
|
|
lightOriginA[1] = lightOrigin[1] - (dirr[1] * lightdist);
|
|
|
|
|
lightOriginA[2] = lightOrigin[2] - (dirr[2] * lightdist);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VectorSubtract( lightOrigin, tr.world->lightGridOrigin, lightOrigin );
|
|
|
|
|
|
|
|
|
|
VectorSubtract( lightOriginA, tr.world->lightGridOrigin, lightOriginA );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//VectorAdd( lightOrigin, lightOriginA, lightOriginA );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ( i = 0 ; i < 3 ; i++ ) {
|
|
|
|
|
float v;
|
|
|
|
|
float vA;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v = lightOrigin[i]*tr.world->lightGridInverseSize[i];
|
|
|
|
|
pos[i] = floor( v );
|
|
|
|
|
frac[i] = v - pos[i];
|
|
|
|
|
if ( pos[i] < 0 ) {
|
|
|
|
|
pos[i] = 0;
|
|
|
|
|
} else if ( pos[i] >= tr.world->lightGridBounds[i] - 1 ) {
|
|
|
|
|
pos[i] = tr.world->lightGridBounds[i] - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vA = lightOriginA[i]*tr.world->lightGridInverseSize[i];
|
|
|
|
|
posA[i] = ceil( vA );
|
|
|
|
|
fracA[i] = vA - posA[i];
|
|
|
|
|
if ( posA[i] < 0 ) {
|
|
|
|
|
posA[i] = 0;
|
|
|
|
|
} else if ( posA[i] <= tr.world->lightGridBounds[i] - 1 ) {
|
|
|
|
|
posA[i] = tr.world->lightGridBounds[i] - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VectorClear( ent->ambientLight );
|
|
|
|
|
VectorClear( ent->directedLight );
|
|
|
|
|
VectorClear( ent->dynamicLight );
|
|
|
|
|
VectorClear( direction );
|
|
|
|
|
|
|
|
|
|
// leilei - lighting hack
|
|
|
|
|
|
|
|
|
|
VectorClear( directionA );
|
|
|
|
|
VectorClear( ent->directedLightA );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert( tr.world->lightGridData ); // NULL with -nolight maps
|
|
|
|
|
|
|
|
|
|
// trilerp the light value
|
|
|
|
|
gridStep[0] = 8;
|
|
|
|
|
gridStep[1] = 8 * tr.world->lightGridBounds[0];
|
|
|
|
|
gridStep[2] = 8 * tr.world->lightGridBounds[0] * tr.world->lightGridBounds[1];
|
|
|
|
|
gridData = tr.world->lightGridData + pos[0] * gridStep[0]
|
|
|
|
|
+ pos[1] * gridStep[1] + pos[2] * gridStep[2];
|
|
|
|
|
|
|
|
|
|
gridDataA = tr.world->lightGridData + posA[0] * gridStep[0]
|
|
|
|
|
+ posA[1] * gridStep[1] + posA[2] * gridStep[2];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
totalFactor = 0;
|
|
|
|
|
for ( i = 0 ; i < 8 ; i++ ) {
|
|
|
|
|
float factor;
|
|
|
|
|
float factorA;
|
|
|
|
|
byte *data;
|
|
|
|
|
|
|
|
|
|
byte *dataA;
|
|
|
|
|
int lat, lng;
|
|
|
|
|
vec3_t normal;
|
|
|
|
|
#if idppc
|
|
|
|
|
float d0, d1, d2, d3, d4, d5;
|
|
|
|
|
#endif
|
|
|
|
|
factor = 1.0;
|
|
|
|
|
factorA = 1.0;
|
|
|
|
|
data = gridData;
|
|
|
|
|
|
|
|
|
|
dataA = gridDataA;
|
|
|
|
|
for ( j = 0 ; j < 3 ; j++ ) {
|
|
|
|
|
if ( i & (1<<j) ) {
|
|
|
|
|
factor *= frac[j];
|
|
|
|
|
factorA *= fracA[j];
|
|
|
|
|
data += gridStep[j];
|
|
|
|
|
dataA += gridStep[j];
|
|
|
|
|
} else {
|
|
|
|
|
factor *= (1.0f - frac[j]);
|
|
|
|
|
factorA *= (1.0f - fracA[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !(dataA[0]+dataA[1]+dataA[2]) ) {
|
|
|
|
|
failA = 1; // try to fallback on an actual light we have
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !(data[0]+data[1]+data[2]) ) {
|
|
|
|
|
continue; // ignore samples in walls
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalFactor += factor;
|
|
|
|
|
// idpcc stripped out for now as i can't test that.
|
|
|
|
|
ent->ambientLight[0] += factor * data[0];
|
|
|
|
|
ent->ambientLight[1] += factor * data[1];
|
|
|
|
|
ent->ambientLight[2] += factor * data[2];
|
|
|
|
|
|
|
|
|
|
ent->directedLight[0] += factor * data[3];
|
|
|
|
|
ent->directedLight[1] += factor * data[4];
|
|
|
|
|
ent->directedLight[2] += factor * data[5];
|
|
|
|
|
|
|
|
|
|
ent->directedLightA[0] += factorA * dataA[3];
|
|
|
|
|
ent->directedLightA[1] += factorA * dataA[4];
|
|
|
|
|
ent->directedLightA[2] += factorA * dataA[5];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lat = data[7];
|
|
|
|
|
lng = data[6];
|
|
|
|
|
lat *= (FUNCTABLE_SIZE/256);
|
|
|
|
|
lng *= (FUNCTABLE_SIZE/256);
|
|
|
|
|
|
|
|
|
|
// decode X as cos( lat ) * sin( long )
|
|
|
|
|
// decode Y as sin( lat ) * sin( long )
|
|
|
|
|
// decode Z as cos( long )
|
|
|
|
|
|
|
|
|
|
normal[0] = tr.sinTable[(lat+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK] * tr.sinTable[lng];
|
|
|
|
|
normal[1] = tr.sinTable[lat] * tr.sinTable[lng];
|
|
|
|
|
normal[2] = tr.sinTable[(lng+(FUNCTABLE_SIZE/4))&FUNCTABLE_MASK];
|
|
|
|
|
|
|
|
|
|
VectorMA( direction, factor, normal, direction );
|
|
|
|
|
VectorMA( directionA, factorA, normal, directionA );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( totalFactor > 0 && totalFactor < 0.99 ) {
|
|
|
|
|
totalFactor = 1.0f / totalFactor;
|
|
|
|
|
VectorScale( ent->ambientLight, totalFactor, ent->ambientLight );
|
|
|
|
|
VectorScale( ent->directedLight, totalFactor, ent->directedLight );
|
|
|
|
|
|
|
|
|
|
VectorScale( ent->directedLightA, totalFactor, ent->directedLightA );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VectorScale( ent->ambientLight, r_ambientScale->value, ent->ambientLight );
|
|
|
|
|
VectorScale( ent->directedLight, r_directedScale->value, ent->directedLight );
|
|
|
|
|
VectorScale( ent->directedLightA, r_directedScale->value, ent->directedLightA );
|
|
|
|
|
|
|
|
|
|
VectorNormalize2( direction, ent->lightDir );
|
|
|
|
|
VectorNormalize2( directionA, ent->lightDirA );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if (failA){
|
|
|
|
|
VectorCopy(failed, ent->lightDirA);
|
|
|
|
|
VectorCopy(failed, ent->directedLightA);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
===============
|
|
|
|
@@ -782,14 +305,11 @@ void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent ) {
|
|
|
|
|
float d;
|
|
|
|
|
vec3_t lightDir;
|
|
|
|
|
vec3_t lightOrigin;
|
|
|
|
|
qboolean crazy;
|
|
|
|
|
// lighting calculations
|
|
|
|
|
if ( ent->lightingCalculated ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (r_shadeMode->integer == 6)
|
|
|
|
|
crazy =qtrue;
|
|
|
|
|
ent->lightingCalculated = qtrue;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@@ -807,9 +327,6 @@ void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent ) {
|
|
|
|
|
// if NOWORLDMODEL, only use dynamic lights (menu system, etc)
|
|
|
|
|
if ( !(refdef->rdflags & RDF_NOWORLDMODEL )
|
|
|
|
|
&& tr.world->lightGridData ) {
|
|
|
|
|
if (crazy)
|
|
|
|
|
R_SetupEntityLightingGrid_crazy( ent );
|
|
|
|
|
else
|
|
|
|
|
R_SetupEntityLightingGrid( ent );
|
|
|
|
|
} else {
|
|
|
|
|
ent->ambientLight[0] = ent->ambientLight[1] =
|
|
|
|
|