Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

Light.c File Reference

#include <Assert.h>
#include <Windows.h>
#include <Math.h>
#include "BaseType.h"
#include "Ram.h"
#include "System.h"
#include "Vec3d.h"
#include "Light.h"
#include "Surface.h"
#include "GBSPFile.h"
#include "Plane.h"
#include "World.h"
#include "Trace.h"

Go to the source code of this file.

Defines

#define LIGHT_FRACT   8
#define MOST_SIG_OFFSET   1
#define SQRT_TAB_SIZE   16384
#define MANT_SHIFTS   7
#define FastSqrtFloat   double
#define EXP_BIAS   1023
#define EXP_SHIFTS   20
#define EXP_LSB   (1<<EXP_SHIFTS)
#define MANT_MASK   (EXP_LSB-1)
#define A_MOD   7

Functions

void UpdateLTypeTables (geWorld *World)
int32 FastDist (int32 dx, int32 dy, int32 dz)
void SetupWavyColorLight1 (DRV_RGB *light1, DRV_RGB *RGBM, int32 lw, int32 lh)
void SetupWavyColorLight2 (DRV_RGB *light1, DRV_RGB *RGBM, int32 lw, int32 lh)
void SetupColorLight1 (DRV_RGB *light1, DRV_RGB *RGBM, int32 lw, int32 lh, geFloat intensity)
void SetupColorLight2 (DRV_RGB *light1, DRV_RGB *RGBM, int32 lw, int32 lh, geFloat intensity)
BOOL CombineDLightWithRGBMap (int32 *LightData, Light_DLight *Light, GFX_Face *Face, Surf_SurfInfo *SInfo)
BOOL CombineDLightWithRGBMapWithShadow (int32 *LightData, Light_DLight *Light, GFX_Face *Face, Surf_SurfInfo *SInfo)
void BuildLightLUTS (geEngine *Engine)
void SetupDynamicLight_r (Light_DLight *pLight, geVec3d *Pos, int32 LNum, int32 Node)
void AddLightType0 (int32 *LightDest, uint8 *LightData, int32 lw, int32 lh)
void AddLightType (int32 *LightDest, uint8 *LightData, int32 lw, int32 lh, int32 Intensity)
void AddLightType1 (int32 *LightDest, uint8 *LightData, int32 lw, int32 lh, int32 Intensity)
void AddLightTypeWavy1 (int32 *LightDest, uint8 *LightData, int32 lw, int32 lh)
void AddLightTypeWavy (int32 *LightDest, uint8 *LightData, int32 lw, int32 lh)
void InitSqrtTab (void)
FastSqrtFloat FastSqrt (FastSqrtFloat f)
geBoolean Light_EngineInit (geEngine *Engine)
void Light_EngineShutdown (geEngine *Engine)
geBoolean Light_WorldInit (geWorld *World)
void Light_WorldShutdown (geWorld *World)
geBoolean Light_SetEngine (geEngine *Engine)
geBoolean Light_SetWorld (geWorld *World)
geBoolean Light_SetGBSP (World_BSP *BSP)
void Light_FogVerts (const geFog *Fog, const geVec3d *POV, const geVec3d *Verts, Surf_TexVert *TexVerts, int32 NumVerts)
geBoolean FogLightmap1 (geFog *Fog, int32 *LightData, GFX_Face *Face, Surf_SurfInfo *SInfo)
geBoolean FogLightmap2 (geFog *Fog, int32 *LightData, GFX_Face *Face, Surf_SurfInfo *SInfo)
void Light_SetupLightmap (DRV_LInfo *LInfo, BOOL *Dynamic)
geBoolean Light_SetupLights (geWorld *World)
char Light_WorldGetLTypeCurrent (geWorld *World, int32 LType)
Light_DLightLight_WorldAddLight (geWorld *World)
void Light_WorldRemoveLight (geWorld *World, Light_DLight *DLight)
geBoolean Light_SetAttributes (Light_DLight *Light, const geVec3d *Pos, const GE_RGBA *RGBA, geFloat Radius, geBoolean CastShadow)
geBoolean Light_WorldSetLTypeTable (geWorld *World, int32 LType, const char *Table)
geBoolean Light_GetLightmapRGB (Surf_SurfInfo *Surf, geVec3d *Pos, GE_RGBA *RGBA)
geBoolean Light_GetLightmapRGBBlended (Surf_SurfInfo *Surf, geVec3d *Pos, GE_RGBA *RGBA)

Variables

geEngineCEngine = NULL
geWorldCWorld = NULL
World_BSPCBSP
GBSP_BSPDataBSPData
Light_LightInfoLightInfo
Surf_SurfInfoGSurfInfo
DRV_RGB BlankRGB [MAX_LMAP_SIZE *MAX_LMAP_SIZE]
DRV_RGB TempRGB [MAX_LMAP_SIZE *MAX_LMAP_SIZE]
int32 TempRGB32 [MAX_LMAP_SIZE *MAX_LMAP_SIZE *3]
DRV_RGB TempRGBFog [MAX_LMAP_SIZE *MAX_LMAP_SIZE]
int32 TempRGB32Fog [MAX_LMAP_SIZE *MAX_LMAP_SIZE *3]
int32 SqrtTab [SQRT_TAB_SIZE]
int32 MirrorRecursion
geVec3d GlobalEyePos = {100.0f, 0.0f, 0.0f}


Define Documentation

#define A_MOD   7
 

Definition at line 1496 of file Light.c.

Referenced by AddLightTypeWavy(), AddLightTypeWavy1(), SetupWavyColorLight1(), and SetupWavyColorLight2().

#define EXP_BIAS   1023
 

Definition at line 75 of file Light.c.

Referenced by FastSqrt(), and InitSqrtTab().

#define EXP_LSB   (1<<EXP_SHIFTS)
 

Definition at line 77 of file Light.c.

Referenced by FastSqrt().

#define EXP_SHIFTS   20
 

Definition at line 76 of file Light.c.

Referenced by FastSqrt(), and InitSqrtTab().

#define FastSqrtFloat   double
 

Definition at line 74 of file Light.c.

Referenced by FastSqrt().

#define LIGHT_FRACT   8
 

Definition at line 38 of file Light.c.

Referenced by AddLightType0(), AddLightTypeWavy(), AddLightTypeWavy1(), Light_SetAttributes(), Light_SetupLightmap(), and UpdateLTypeTables().

#define MANT_MASK   (EXP_LSB-1)
 

Definition at line 78 of file Light.c.

Referenced by FastSqrt(), and InitSqrtTab().

#define MANT_SHIFTS   7
 

Definition at line 72 of file Light.c.

Referenced by FastSqrt(), and InitSqrtTab().

#define MOST_SIG_OFFSET   1
 

Definition at line 61 of file Light.c.

Referenced by FastSqrt(), and InitSqrtTab().

#define SQRT_TAB_SIZE   16384
 

Definition at line 65 of file Light.c.

Referenced by InitSqrtTab().


Function Documentation

void AddLightType int32 LightDest,
uint8 LightData,
int32  lw,
int32  lh,
int32  Intensity
[static]
 

Definition at line 982 of file Light.c.

References int32, and NULL.

Referenced by Light_SetupLightmap().

00983 {       
00984         int32   h;
00985 
00986         assert(LightDest != NULL);
00987         assert(LightData != NULL);
00988 
00989         for (h = 0; h < lw*lh; h++)
00990         {
00991                 *LightDest++ += *LightData++ * Intensity;
00992                 *LightDest++ += *LightData++ * Intensity;
00993                 *LightDest++ += *LightData++ * Intensity;
00994         }
00995 }

void AddLightType0 int32 LightDest,
uint8 LightData,
int32  lw,
int32  lh
[static]
 

Definition at line 1000 of file Light.c.

References int32, LIGHT_FRACT, and NULL.

Referenced by Light_SetupLightmap().

01001 {       
01002         int32   h;
01003 
01004         assert(LightDest != NULL);
01005         assert(LightData != NULL);
01006 
01007         for (h = 0; h < lw*lh; h++)
01008         {
01009                 *LightDest++ = (*LightData++) << LIGHT_FRACT;
01010                 *LightDest++ = (*LightData++) << LIGHT_FRACT;
01011                 *LightDest++ = (*LightData++) << LIGHT_FRACT;
01012         }
01013 }

void AddLightType1 int32 LightDest,
uint8 LightData,
int32  lw,
int32  lh,
int32  Intensity
[static]
 

Definition at line 1018 of file Light.c.

References int32, and NULL.

Referenced by Light_SetupLightmap().

01019 {       
01020         int32   h;
01021 
01022         assert(LightDest != NULL);
01023         assert(LightData != NULL);
01024 
01025         for (h = 0; h < lw*lh; h++)
01026         {
01027                 *LightDest++ = *LightData++ * Intensity;
01028                 *LightDest++ = *LightData++ * Intensity;
01029                 *LightDest++ = *LightData++ * Intensity;
01030         }
01031 }

void AddLightTypeWavy int32 LightDest,
uint8 LightData,
int32  lw,
int32  lh
[static]
 

Definition at line 1726 of file Light.c.

References A_MOD, CEngine, int32, LIGHT_FRACT, NULL, geEngine::StyleLUT1, uint16, uint8, and geEngine::WaveTable.

Referenced by Light_SetupLightmap().

01727 { 
01728         uint16  *WaveTable, II;
01729         int32   Index, h;
01730         uint8   *SLUT;
01731 
01732         assert(LightDest != NULL);
01733         assert(LightData != NULL);
01734         assert(CEngine != NULL);
01735 
01736         WaveTable = CEngine->WaveTable;
01737         
01738         Index = 0;
01739 
01740         SLUT = CEngine->StyleLUT1[0];
01741 
01742         for (h = 0; h < lh*lw; h++)
01743         {
01744                 // We know that WaterColor table is from 0-255...
01745                 II = WaveTable[Index++];
01746                 
01747                 if (Index > A_MOD)
01748                         Index -= A_MOD;
01749                 
01750                 II >>= 2;
01751                 if (II > 30) II = 30;
01752                 II <<= 8;
01753 
01754                 *LightDest++ += SLUT[II + *LightData++] << (LIGHT_FRACT);
01755                 *LightDest++ += SLUT[II + *LightData++] << (LIGHT_FRACT);
01756                 *LightDest++ += SLUT[II + *LightData++] << (LIGHT_FRACT);
01757         }
01758 }

void AddLightTypeWavy1 int32 LightDest,
uint8 LightData,
int32  lw,
int32  lh
[static]
 

Definition at line 1689 of file Light.c.

References A_MOD, CEngine, int32, LIGHT_FRACT, NULL, geEngine::StyleLUT1, uint16, uint8, and geEngine::WaveTable.

Referenced by Light_SetupLightmap().

01690 { 
01691         uint16  *WaveTable, II;
01692         int32   Index, h;
01693         uint8   *SLUT;
01694 
01695         assert(LightDest != NULL);
01696         assert(LightData != NULL);
01697         assert(CEngine != NULL);
01698 
01699         WaveTable = CEngine->WaveTable;
01700         
01701         Index = 0;
01702 
01703         SLUT = CEngine->StyleLUT1[0];
01704 
01705         for (h = 0; h < lh*lw; h++)
01706         {
01707                 // We know that WaterColor table is from 0-255...
01708                 II = WaveTable[Index++];
01709                 
01710                 if (Index > A_MOD)
01711                         Index -= A_MOD;
01712                 
01713                 II >>= 2;
01714                 if (II > 30) II = 30;
01715                 II <<= 8;
01716 
01717                 *LightDest++ = SLUT[II + *LightData++] << (LIGHT_FRACT);
01718                 *LightDest++ = SLUT[II + *LightData++] << (LIGHT_FRACT);
01719                 *LightDest++ = SLUT[II + *LightData++] << (LIGHT_FRACT);
01720         }
01721 }

void BuildLightLUTS geEngine Engine  )  [static]
 

Definition at line 1763 of file Light.c.

References Engine, geFloat, S32, geEngine::StyleLUT1, and U8.

Referenced by Light_EngineInit().

01764 {
01765         S32 i, k;
01766 
01767         for (i=0; i< 256; i++)
01768         {
01769                 for (k=0; k< 64; k++)
01770                 {
01771                         geFloat ii = (geFloat)i;
01772                         geFloat kk = (geFloat)k;
01773                         geFloat Intensity = (ii * (kk / 62.0f));// * 5.0f;
01774                         if (Intensity > 255) 
01775                                 Intensity = 255.0f;
01776                         Engine->StyleLUT1[k][i] = (U8)Intensity;
01777                 }
01778         }
01779 }

BOOL CombineDLightWithRGBMap int32 LightData,
Light_DLight Light,
GFX_Face Face,
Surf_SurfInfo SInfo
[static]
 

Definition at line 1036 of file Light.c.

References BSPData, GFX_Plane::Dist, FALSE, Light_DLight::FColorB, Light_DLight::FColorG, Light_DLight::FColorR, geFloat, geVec3d_Copy(), geVec3d_DotProduct(), GBSP_BSPData::GFXPlanes, GBSP_BSPData::GFXTexInfo, DRV_LInfo::Height, int32, Surf_SurfInfo::LInfo, DRV_LInfo::MinU, DRV_LInfo::MinV, GFX_Plane::Normal, NULL, GFX_Face::PlaneNum, Light_DLight::Pos, Light_DLight::Radius, GFX_Face::TexInfo, TRUE, v, GFX_TexInfo::Vecs, DRV_LInfo::Width, Surf_SurfInfo::XScale, Surf_SurfInfo::XStep, y, Surf_SurfInfo::YScale, and Surf_SurfInfo::YStep.

Referenced by Light_SetupLightmap().

01037 {
01038         BOOL            Hit;
01039         geFloat         Radius, Dist;
01040         GFX_Plane       *Plane;
01041         GFX_TexInfo     *TexInfo;
01042         geVec3d         LPos;
01043         int32           Sx, Sy, x, y, u, v, Val;
01044         int32           ColorR, ColorG, ColorB, Radius2, Dist2;
01045         int32           FixedX, FixedY, XStep, YStep;
01046 
01047         assert(BSPData != NULL);
01048         assert(BSPData->GFXTexInfo != NULL);
01049         assert(BSPData->GFXPlanes != NULL);
01050 
01051         TexInfo = &BSPData->GFXTexInfo[Face->TexInfo];
01052 
01053         Radius = Light->Radius;
01054         Plane = &BSPData->GFXPlanes[Face->PlaneNum];
01055 
01056         geVec3d_Copy(&Light->Pos, &LPos);
01057 
01058         Dist = geVec3d_DotProduct(&LPos, &Plane->Normal) - Plane->Dist;
01059 
01060         // Shrink the radius by the dist so we can avoid using z in the fast sqrt routine...
01061         Radius -= (geFloat)fabs(Dist);
01062 
01063         if (Radius <= 0)                // We can leave now if the dist is > radius
01064                 return FALSE;
01065 
01066         // Calculate where light is projected onto the 2d-plane
01067         Sx = (int32)(geVec3d_DotProduct(&LPos, &TexInfo->Vecs[0]));
01068         Sy = (int32)(geVec3d_DotProduct(&LPos, &TexInfo->Vecs[1]));
01069 
01070         // Align the light with the upper left corner of the ligtmap
01071         Sx -= SInfo->LInfo.MinU;                
01072         Sy -= SInfo->LInfo.MinV;
01073 
01074         // Scale by the texture scaling (1:21:10 fixed)
01075         Sx *= SInfo->XScale;
01076         Sy *= SInfo->YScale;
01077         
01078         Hit = FALSE;
01079 
01080         ColorR = Light->FColorR; 
01081         ColorG = Light->FColorG; 
01082         ColorB = Light->FColorB; 
01083 
01084         Radius2 = (int32)Radius;
01085         
01086         XStep = SInfo->XStep;
01087         YStep = SInfo->YStep;
01088 
01089         FixedY = Sy;
01090 
01091         for (v=0; v< SInfo->LInfo.Height; v++)
01092         {
01093                 y = FixedY >> 10;
01094 
01095                 if (y < 0)
01096                         y = -y;
01097 
01098                 FixedX = Sx;
01099                 
01100                 for (u=0; u< SInfo->LInfo.Width; u++)
01101                 {
01102                         x = FixedX >> 10;
01103 
01104                         if (x<0)
01105                                 x = -x;
01106 
01107                         if (x > y)
01108                                 Dist2 = (x + (y>>1));
01109                         else
01110                                 Dist2 = (y + (x>>1));
01111                         
01112                         if (Dist2 < Radius2)
01113                         {
01114                                 Hit = TRUE;
01115                                 
01116                                 Val = (Radius2 - Dist2);
01117 
01118                                 *LightData++ += (int32)(Val * ColorR);
01119                                 *LightData++ += (int32)(Val * ColorG);
01120                                 *LightData++ += (int32)(Val * ColorB);
01121                         }
01122                         else
01123                                 LightData+=3;
01124 
01125                         FixedX -= XStep;
01126                 }
01127 
01128                 FixedY -= YStep;
01129         }
01130 
01131         return Hit;
01132 }

BOOL CombineDLightWithRGBMapWithShadow int32 LightData,
Light_DLight Light,
GFX_Face Face,
Surf_SurfInfo SInfo
[static]
 

Definition at line 1137 of file Light.c.

References BSPData, CWorld, GFX_Plane::Dist, FALSE, Light_DLight::FColorB, Light_DLight::FColorG, Light_DLight::FColorR, geFloat, geVec3d_Add(), geVec3d_Copy(), geVec3d_DotProduct(), GBSP_BSPData::GFXPlanes, GBSP_BSPData::GFXTexInfo, DRV_LInfo::Height, int32, Surf_SurfInfo::LInfo, DRV_LInfo::MinU, DRV_LInfo::MinV, GFX_Plane::Normal, NULL, GFX_Face::PlaneNum, Light_DLight::Pos, Light_DLight::Radius, Surf_SurfInfo::T2WVecs, GFX_Face::TexInfo, Surf_SurfInfo::TexOrg, Trace_IntersectWorldBSP(), Trace_SetupIntersect(), TRUE, v, GFX_TexInfo::Vecs, DRV_LInfo::Width, Surf_SurfInfo::XScale, Surf_SurfInfo::XStep, y, Surf_SurfInfo::YScale, and Surf_SurfInfo::YStep.

Referenced by Light_SetupLightmap().

01138 {
01139         BOOL            Hit;
01140         geFloat         Radius, Dist;
01141         GFX_Plane       *Plane;
01142         GFX_TexInfo     *TexInfo;
01143         geVec3d         LPos, LMapPos, Right, Down, Start;
01144         int32           Sx, Sy, x, y, u, v, Val;
01145         int32           ColorR, ColorG, ColorB, Radius2, Dist2;
01146         int32           FixedX, FixedY, XStep, YStep;
01147 
01148         assert(BSPData != NULL);
01149         assert(BSPData->GFXTexInfo != NULL);
01150         assert(BSPData->GFXPlanes != NULL);
01151 
01152         TexInfo = &BSPData->GFXTexInfo[Face->TexInfo];
01153 
01154         Radius = Light->Radius;
01155         Plane = &BSPData->GFXPlanes[Face->PlaneNum];
01156 
01157         geVec3d_Copy(&Light->Pos, &LPos);
01158 
01159         Dist = geVec3d_DotProduct(&LPos, &Plane->Normal) - Plane->Dist;
01160 
01161         // Shrink the radius by the dist so we can avoid using z in the fast sqrt routine...
01162         Radius -= (geFloat)fabs(Dist);
01163 
01164         if (Radius <= 0)                // We can leave now if the dist is > radius
01165                 return FALSE;
01166 
01167         // Calculate where light is projected onto the 2d-plane
01168         Sx = (int32)(geVec3d_DotProduct(&LPos, &TexInfo->Vecs[0]));// + TexInfo->Shift[0]);
01169         Sy = (int32)(geVec3d_DotProduct(&LPos, &TexInfo->Vecs[1]));// + TexInfo->Shift[1]);
01170 
01171         // Shift into lightmap
01172         Sx -= SInfo->LInfo.MinU;
01173         Sy -= SInfo->LInfo.MinV;
01174 
01175         // Scale by the texture scaling (1:21:10 fixed)
01176         Sx *= SInfo->XScale;
01177         Sy *= SInfo->YScale;
01178                 
01179         Hit = FALSE;
01180 
01181         ColorR = Light->FColorR; 
01182         ColorG = Light->FColorG; 
01183         ColorB = Light->FColorB; 
01184 
01185         Radius2 = (int32)Radius;
01186         
01187         XStep = SInfo->XStep;
01188         YStep = SInfo->YStep;
01189 
01190         FixedY = Sy;
01191 
01192         LMapPos = Start = SInfo->TexOrg;
01193         Right = SInfo->T2WVecs[0];
01194         Down = SInfo->T2WVecs[1];
01195 
01196         Trace_SetupIntersect(CWorld);           // Setup intersection test with current world...
01197 
01198         for (v=0; v< SInfo->LInfo.Height; v++)
01199         {
01200                 y = FixedY >> 10;
01201 
01202                 if (y < 0)
01203                         y = -y;
01204 
01205                 FixedX = Sx;
01206                 
01207                 for (u=0; u< SInfo->LInfo.Width; u++)
01208                 {
01209                         x = FixedX >> 10;
01210 
01211                         if (x<0)
01212                                 x = -x;
01213 
01214                         if (x > y)
01215                                 Dist2 = (x + (y>>1));
01216                         else
01217                                 Dist2 = (y + (x>>1));
01218                         
01219                         if (Dist2 < Radius2)
01220                         {
01221                                 if (Trace_IntersectWorldBSP(&LPos, &LMapPos, 0))
01222                                 {
01223                                         LightData += 3;
01224                                         FixedX -= XStep;
01225                                         geVec3d_Add(&LMapPos, &Right, &LMapPos);
01226                                         continue;
01227                                 }
01228 
01229                                 Hit = TRUE;
01230                                 
01231                                 Val = (Radius2 - Dist2);
01232 
01233                                 *LightData++ += (int32)(Val * ColorR);
01234                                 *LightData++ += (int32)(Val * ColorG);
01235                                 *LightData++ += (int32)(Val * ColorB);
01236                         }
01237                         else
01238                                 LightData+=3;
01239 
01240                         geVec3d_Add(&LMapPos, &Right, &LMapPos);
01241 
01242                         FixedX -= XStep;
01243                 }
01244 
01245                 geVec3d_Add(&Start, &Down, &Start);
01246                 LMapPos = Start;
01247                 
01248                 FixedY -= YStep;
01249         }
01250 
01251         return Hit;
01252 }

int32 FastDist int32  dx,
int32  dy,
int32  dz
[static]
 

Definition at line 1474 of file Light.c.

References int32.

01475 {
01476         int32           Max, Med, Min;  // biggest, smallest, and middle values
01477         int32           Tmp;
01478 
01479         Max = (dx < 0) ? -dx : dx;
01480         Med = (dz < 0) ? -dz : dz;
01481         Min = (dy < 0) ? -dy : dy;
01482 
01483         if (Max < Med) 
01484         { 
01485                 Tmp = Max; Max = Med; Med = Tmp;
01486         }
01487         if (Max < Min) 
01488         { 
01489                 Tmp = Max; Max = Min; Min = Tmp;
01490         }
01491         Max <<= 2;
01492         Max += Med + Min;
01493         return Max>>2;
01494 }

FastSqrtFloat FastSqrt FastSqrtFloat  f  )  [static]
 

Definition at line 1977 of file Light.c.

References EXP_BIAS, EXP_LSB, EXP_SHIFTS, FastSqrtFloat, int32, MANT_MASK, MANT_SHIFTS, MOST_SIG_OFFSET, and SqrtTab.

Referenced by FogLightmap1(), and FogLightmap2().

01978 {
01979         int32 e;
01980         int32 *fi = (int32*) &f + MOST_SIG_OFFSET;
01981 
01982         //return sqrt(f);
01983 
01984         if (f == (FastSqrtFloat)0.0) 
01985                 return((FastSqrtFloat)0.0);
01986         
01987         e = (*fi >> EXP_SHIFTS) - EXP_BIAS;
01988         *fi &= MANT_MASK;
01989         
01990         if (e & 1)
01991                 *fi |= EXP_LSB;
01992         
01993         e >>= 1;
01994         *fi = (SqrtTab[*fi >> MANT_SHIFTS]) | ((e + EXP_BIAS) << EXP_SHIFTS);
01995         
01996         return(f);
01997 }

geBoolean FogLightmap1 geFog Fog,
int32 LightData,
GFX_Face Face,
Surf_SurfInfo SInfo
[static]
 

Definition at line 316 of file Light.c.

References GE_RGBA::b, geFog::Color, FastSqrt(), GE_RGBA::g, GE_FALSE, GE_TRUE, geBoolean, geFloat, geVec3d_DotProduct(), geVec3d_Normalize(), geVec3d_Subtract(), GlobalEyePos, DRV_LInfo::Height, int32, Surf_SurfInfo::LInfo, geFog::Pos, GE_RGBA::r, Red, t, Surf_SurfInfo::T2WVecs, Surf_SurfInfo::TexOrg, v, geFog::VolumeBrightness, geFog::VolumeRadius, geFog::VolumeRadius2, geFog::VolumeRadiusSquared, DRV_LInfo::Width, geVec3d::X, geVec3d::Y, and geVec3d::Z.

Referenced by Light_SetupLightmap().

00317 {
00318         int32           w, h;
00319         geBoolean       Hit;
00320         geVec3d         Start, UV, Ray;
00321         int32           Light1, Light2, Light3;
00322         geFloat         Dist, d2, UVDist, DistSq;
00323         geVec3d         FogRay, Ray2;
00324         geFloat         v,disc, d;
00325         geVec3d         Impact1, Impact2;
00326         geFloat         Radius, Red, Grn, Blu, EyeDist;
00327         geFloat         RadiusSq, FogRayDot, Radius2;
00328         geVec3d         UAdd, VAdd, FogPos;
00329         int32           Width, Height;
00330         
00331         Hit = GE_FALSE;
00332 
00333         Start = UV = SInfo->TexOrg;
00334 
00335         FogPos = Fog->Pos;
00336         
00337         geVec3d_Subtract(&FogPos, &GlobalEyePos, &FogRay);
00338         
00339         Ray2 = FogRay;
00340         EyeDist = geVec3d_Normalize(&Ray2);
00341 
00342         Radius = Fog->VolumeRadius;
00343         RadiusSq = Fog->VolumeRadiusSquared;
00344         Radius2 = Fog->VolumeRadius2;
00345 
00346         FogRayDot = geVec3d_DotProduct(&FogRay,&FogRay);
00347         
00348         Red = Fog->Color.r;
00349         Grn = Fog->Color.g;
00350         Blu = Fog->Color.b;
00351 
00352         //if (EyeDist < Radius)
00353         //      return GE_FALSE;
00354         
00355         UAdd = SInfo->T2WVecs[0];
00356         VAdd = SInfo->T2WVecs[1];
00357 
00358         Width = SInfo->LInfo.Width;
00359         Height = SInfo->LInfo.Height;
00360 
00361         for (h=0; h< Height; h++)
00362         {
00363                 for (w=0; w< Width; w++)
00364                 {
00365                         geFloat OneOver;
00366 
00367                         Ray.X = UV.X - GlobalEyePos.X;
00368                         Ray.Y = UV.Y - GlobalEyePos.Y;
00369                         Ray.Z = UV.Z - GlobalEyePos.Z;
00370                                 
00371                         DistSq = Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z;
00372                         Dist = (geFloat)FastSqrt(DistSq);
00373 
00374                         OneOver = 1.0f / Dist;
00375                         Ray.X *= OneOver;
00376                         Ray.Y *= OneOver;
00377                         Ray.Z *= OneOver;
00378 
00379                         v = FogRay.X*Ray.X + FogRay.Y*Ray.Y + FogRay.Z*Ray.Z;
00380 
00381                         disc = (RadiusSq) - (FogRayDot - (v*v));
00382 
00383                         if (disc > 0)
00384                         {
00385                                 geFloat t0, t1, t;
00386 
00387                                 d = (geFloat)FastSqrt(disc);
00388 
00389                                 t0 = v - d;
00390                                 t1 = v + d;
00391                                         
00392                                 if (t0 > 0)
00393                                         t = t0;
00394                                 else if (t1 > 0)
00395                                         t = t1;
00396                                 else
00397                                 {
00398                                         *LightData++ = 0;
00399                                         *LightData++ = 0;
00400                                         *LightData++ = 0;
00401                 
00402                                         UV.X += UAdd.X;
00403                                         UV.Y += UAdd.Y;
00404                                         UV.Z += UAdd.Z;
00405                                         continue;
00406                                 }
00407                                         
00408                         #if 1
00409                                 Ray2.X = UV.X - FogPos.X;
00410                                 Ray2.Y = UV.Y - FogPos.Y;
00411                                 Ray2.Z = UV.Z - FogPos.Z;
00412 
00413                                 //UVDist = sqrt(Ray2.X*Ray2.X + Ray2.Y*Ray2.Y + Ray2.Z*Ray2.Z);
00414                                 UVDist = (geFloat)FastSqrt(Ray2.X*Ray2.X + Ray2.Y*Ray2.Y + Ray2.Z*Ray2.Z);
00415                                         
00416                                 if (EyeDist < Radius && UVDist < Radius)
00417                                 {
00418                                         Impact1 = UV;
00419                                         Impact2 = GlobalEyePos;
00420                                 }
00421                                 else if (EyeDist < Radius)
00422                                 {
00423                                         Impact1 = GlobalEyePos;
00424 
00425                                         Impact2.X = GlobalEyePos.X + t*Ray.X;
00426                                         Impact2.Y = GlobalEyePos.Y + t*Ray.Y;
00427                                         Impact2.Z = GlobalEyePos.Z + t*Ray.Z;
00428                                 }
00429                                 else if (UVDist < Radius)                                                       // UV is inside
00430                                 {
00431                                         Impact1 = UV;
00432 
00433                                         Impact2.X = GlobalEyePos.X + t*Ray.X;
00434                                         Impact2.Y = GlobalEyePos.Y + t*Ray.Y;
00435                                         Impact2.Z = GlobalEyePos.Z + t*Ray.Z;
00436         
00437                                 }
00438                                 else                                                                                    // Both lie outside sphere
00439                                 {
00440                                         Impact1.X = GlobalEyePos.X + t0*Ray.X;
00441                                         Impact1.Y = GlobalEyePos.Y + t0*Ray.Y;
00442                                         Impact1.Z = GlobalEyePos.Z + t0*Ray.Z;
00443                                         
00444                                         Impact2.X = GlobalEyePos.X + t1*Ray.X;
00445                                         Impact2.Y = GlobalEyePos.Y + t1*Ray.Y;
00446                                         Impact2.Z = GlobalEyePos.Z + t1*Ray.Z;
00447                                         
00448                                         Ray.X = Impact1.X - GlobalEyePos.X;
00449                                         Ray.Y = Impact1.Y - GlobalEyePos.Y;
00450                                         Ray.Z = Impact1.Z - GlobalEyePos.Z;
00451                                         
00452                                         //d2 = sqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00453                                         //d2 = (geFloat)FastSqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00454                                         d2 = Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z;
00455 
00456                                         if (d2 > DistSq)
00457                                         {
00458                                                 /*
00459                                                 Ray.X = Impact2.X - GlobalEyePos.X;
00460                                                 Ray.Y = Impact2.Y - GlobalEyePos.Y;
00461                                                 Ray.Z = Impact2.Z - GlobalEyePos.Z;
00462                                                 d3 = sqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00463 
00464                                                 if (d3 > Dist)
00465                                                 */
00466                                                 {
00467                                                         *LightData++ = 0;
00468                                                         *LightData++ = 0;
00469                                                         *LightData++ = 0;
00470                                                 
00471                                                         UV.X += UAdd.X;
00472                                                         UV.Y += UAdd.Y;
00473                                                         UV.Z += UAdd.Z;
00474                                                         continue;
00475                                                 }
00476                                         }
00477                                         
00478                                 }
00479                         #endif
00480                                 // Get the distance of the part of the ray that is in the fog
00481                                 //geVec3d_Subtract(&Impact1, &Impact2, &Ray);
00482                                 //d = geVec3d_Length(&Ray);
00483                                 Ray.X = Impact1.X - Impact2.X;
00484                                 Ray.Y = Impact1.Y - Impact2.Y;
00485                                 Ray.Z = Impact1.Z - Impact2.Z;
00486 
00487                                 //d = (geFloat)FastSqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00488                                 //d = ((Radius / d)*18);
00489                                 //Dist = (Fog->VolumeBrightness) / (d*d);
00490                                 d = Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z;
00491                                 d = ((RadiusSq / d)*18);
00492                                 Dist = (Fog->VolumeBrightness) / (d);
00493                                 //Dist = 255.0f;
00494 
00495                                 Hit = GE_TRUE;
00496                                         
00497                                 Light1 = (int32)(Dist*Red);
00498                                 Light2 = (int32)(Dist*Grn);
00499                                 Light3 = (int32)(Dist*Blu);
00500 
00501                                 *LightData++ = Light1;
00502                                 *LightData++ = Light2;
00503                                 *LightData++ = Light3;
00504                         }
00505                         else
00506                         {
00507                                 *LightData++ = 0;
00508                                 *LightData++ = 0;
00509                                 *LightData++ = 0;
00510                         }
00511 
00512                         UV.X += UAdd.X;
00513                         UV.Y += UAdd.Y;
00514                         UV.Z += UAdd.Z;
00515 
00516                 }       
00517 
00518                 Start.X += VAdd.X;
00519                 Start.Y += VAdd.Y;
00520                 Start.Z += VAdd.Z;
00521                 UV = Start;
00522         }
00523 
00524         return Hit;
00525 }

geBoolean FogLightmap2 geFog Fog,
int32 LightData,
GFX_Face Face,
Surf_SurfInfo SInfo
[static]
 

Definition at line 531 of file Light.c.

References GE_RGBA::b, geFog::Color, FastSqrt(), GE_RGBA::g, GE_FALSE, GE_TRUE, geBoolean, geFloat, geVec3d_DotProduct(), geVec3d_Normalize(), geVec3d_Subtract(), GlobalEyePos, DRV_LInfo::Height, int32, Surf_SurfInfo::LInfo, geFog::Pos, GE_RGBA::r, Red, t, Surf_SurfInfo::T2WVecs, Surf_SurfInfo::TexOrg, v, geFog::VolumeBrightness, geFog::VolumeRadius, geFog::VolumeRadius2, geFog::VolumeRadiusSquared, DRV_LInfo::Width, geVec3d::X, geVec3d::Y, and geVec3d::Z.

Referenced by Light_SetupLightmap().

00532 {
00533         int32           w, h;
00534         geBoolean       Hit;
00535         geVec3d         Start, UV, Ray;
00536         int32           Light1, Light2, Light3;
00537         geFloat         Dist, d2, UVDist, DistSq;
00538         geVec3d         FogRay, Ray2;
00539         geFloat         v,disc, d;
00540         geVec3d         Impact1, Impact2;
00541         geFloat         Radius, Red, Grn, Blu, EyeDist;
00542         geFloat         RadiusSq, FogRayDot, Radius2;
00543         geVec3d         UAdd, VAdd, FogPos;
00544         int32           LightAdd, Width, Height;
00545         
00546         Hit = GE_FALSE;
00547 
00548         Start = UV = SInfo->TexOrg;
00549 
00550         FogPos = Fog->Pos;
00551         
00552         geVec3d_Subtract(&FogPos, &GlobalEyePos, &FogRay);
00553         
00554         Ray2 = FogRay;
00555         EyeDist = geVec3d_Normalize(&Ray2);
00556 
00557         Radius = Fog->VolumeRadius;
00558         RadiusSq = Fog->VolumeRadiusSquared;
00559         Radius2 = Fog->VolumeRadius2;
00560 
00561         FogRayDot = geVec3d_DotProduct(&FogRay,&FogRay);
00562         
00563         Red = Fog->Color.r;
00564         Grn = Fog->Color.g;
00565         Blu = Fog->Color.b;
00566 
00567         //if (EyeDist < Radius)
00568         //      return GE_FALSE;
00569         
00570         UAdd = SInfo->T2WVecs[0];
00571         VAdd = SInfo->T2WVecs[1];
00572 
00573         Width = SInfo->LInfo.Width;
00574         Height = SInfo->LInfo.Height;
00575 
00576         LightAdd = (SInfo->LInfo.Width - Width)*3;
00577 
00578         for (h=0; h< Height; h++)
00579         {
00580                 for (w=0; w< Width; w++)
00581                 {
00582                         geFloat OneOver;
00583 
00584                         Ray.X = UV.X - GlobalEyePos.X;
00585                         Ray.Y = UV.Y - GlobalEyePos.Y;
00586                         Ray.Z = UV.Z - GlobalEyePos.Z;
00587                                 
00588                         //Dist = (geFloat)sqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00589                         DistSq = Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z;
00590                         Dist = (geFloat)FastSqrt(DistSq);
00591 
00592                         OneOver = 1.0f / Dist;
00593                         Ray.X *= OneOver;
00594                         Ray.Y *= OneOver;
00595                         Ray.Z *= OneOver;
00596 
00597                         v = FogRay.X*Ray.X + FogRay.Y*Ray.Y + FogRay.Z*Ray.Z;
00598 
00599                         disc = (RadiusSq) - (FogRayDot - (v*v));
00600 
00601                         if (disc > 0)
00602                         {
00603                                 geFloat t0, t1, t;
00604 
00605                                 d = (geFloat)FastSqrt(disc);
00606                                 //d = (geFloat)sqrt(disc);
00607 
00608                                 t0 = v - d;
00609                                 t1 = v + d;
00610                                         
00611                                 if (t0 > 0)
00612                                         t = t0;
00613                                 else if (t1 > 0)
00614                                         t = t1;
00615                                 else
00616                                 {
00617                                         LightData+=3;
00618                 
00619                                         UV.X += UAdd.X;
00620                                         UV.Y += UAdd.Y;
00621                                         UV.Z += UAdd.Z;
00622                                         continue;
00623                                 }
00624                                         
00625                         #if 1
00626                                 Ray2.X = UV.X - FogPos.X;
00627                                 Ray2.Y = UV.Y - FogPos.Y;
00628                                 Ray2.Z = UV.Z - FogPos.Z;
00629 
00630                                 //UVDist = sqrt(Ray2.X*Ray2.X + Ray2.Y*Ray2.Y + Ray2.Z*Ray2.Z);
00631                                 UVDist = (geFloat)FastSqrt(Ray2.X*Ray2.X + Ray2.Y*Ray2.Y + Ray2.Z*Ray2.Z);
00632                                         
00633                                 if (EyeDist < Radius && UVDist < Radius)
00634                                 {
00635                                         Impact1 = UV;
00636                                         Impact2 = GlobalEyePos;
00637                                 }
00638                                 else if (EyeDist < Radius)
00639                                 {
00640                                         Impact1 = GlobalEyePos;
00641 
00642                                         Impact2.X = GlobalEyePos.X + t*Ray.X;
00643                                         Impact2.Y = GlobalEyePos.Y + t*Ray.Y;
00644                                         Impact2.Z = GlobalEyePos.Z + t*Ray.Z;
00645                                 }
00646                                 else if (UVDist < Radius)                                                       // UV is inside
00647                                 {
00648                                         Impact1 = UV;
00649 
00650                                         Impact2.X = GlobalEyePos.X + t*Ray.X;
00651                                         Impact2.Y = GlobalEyePos.Y + t*Ray.Y;
00652                                         Impact2.Z = GlobalEyePos.Z + t*Ray.Z;
00653         
00654                                 }
00655                                 else                                                                                    // Both lie outside sphere
00656                                 {
00657                                         Impact1.X = GlobalEyePos.X + t0*Ray.X;
00658                                         Impact1.Y = GlobalEyePos.Y + t0*Ray.Y;
00659                                         Impact1.Z = GlobalEyePos.Z + t0*Ray.Z;
00660                                         
00661                                         Impact2.X = GlobalEyePos.X + t1*Ray.X;
00662                                         Impact2.Y = GlobalEyePos.Y + t1*Ray.Y;
00663                                         Impact2.Z = GlobalEyePos.Z + t1*Ray.Z;
00664                                         
00665                                         Ray.X = Impact1.X - GlobalEyePos.X;
00666                                         Ray.Y = Impact1.Y - GlobalEyePos.Y;
00667                                         Ray.Z = Impact1.Z - GlobalEyePos.Z;
00668                                         
00669                                         //d2 = sqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00670                                         //d2 = (geFloat)FastSqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00671                                         d2 = Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z;
00672 
00673                                         if (d2 > DistSq)
00674                                         {
00675                                                 /*
00676                                                 Ray.X = Impact2.X - GlobalEyePos.X;
00677                                                 Ray.Y = Impact2.Y - GlobalEyePos.Y;
00678                                                 Ray.Z = Impact2.Z - GlobalEyePos.Z;
00679                                                 d3 = sqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00680 
00681                                                 if (d3 > Dist)
00682                                                 */
00683                                                 {
00684                                                         LightData+=3;
00685                                                 
00686                                                         UV.X += UAdd.X;
00687                                                         UV.Y += UAdd.Y;
00688                                                         UV.Z += UAdd.Z;
00689                                                         continue;
00690                                                 }
00691                                         }
00692                                         
00693                                 }
00694                         #endif
00695                                 // Get the distance of the part of the ray that is in the fog
00696                                 //geVec3d_Subtract(&Impact1, &Impact2, &Ray);
00697                                 //d = geVec3d_Length(&Ray);
00698                                 Ray.X = Impact1.X - Impact2.X;
00699                                 Ray.Y = Impact1.Y - Impact2.Y;
00700                                 Ray.Z = Impact1.Z - Impact2.Z;
00701 
00702                                 //d = (geFloat)FastSqrt(Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z);
00703                                 //d = ((Radius / d)*18);
00704                                 //Dist = (Fog->VolumeBrightness) / (d*d);
00705                                 d = Ray.X*Ray.X + Ray.Y*Ray.Y + Ray.Z*Ray.Z;
00706                                 d = ((RadiusSq / d)*18);
00707                                 Dist = (Fog->VolumeBrightness) / (d);
00708                                 //Dist = 255.0f;
00709 
00710                                 Hit = GE_TRUE;
00711                                         
00712                                 Light1 = (int32)(Dist*Red);
00713                                 Light2 = (int32)(Dist*Grn);
00714                                 Light3 = (int32)(Dist*Blu);
00715 
00716                                 *LightData += Light1;
00717                                 LightData++;
00718                                 *LightData += Light2;
00719                                 LightData++;
00720                                 *LightData += Light3;
00721                                 LightData++;
00722                         }
00723                         else
00724                         {
00725                                 LightData+=3;
00726                         }
00727 
00728                         UV.X += UAdd.X;
00729                         UV.Y += UAdd.Y;
00730                         UV.Z += UAdd.Z;
00731 
00732                 }       
00733 
00734                 Start.X += VAdd.X;
00735                 Start.Y += VAdd.Y;
00736                 Start.Z += VAdd.Z;
00737                 UV = Start;
00738                 
00739                 LightData += LightAdd;
00740 
00741         }
00742 
00743         return Hit;
00744 }

void InitSqrtTab void   )  [static]
 

Definition at line 1955 of file Light.c.

References EXP_BIAS, EXP_SHIFTS, int32, MANT_MASK, MANT_SHIFTS, MOST_SIG_OFFSET, SQRT_TAB_SIZE, and SqrtTab.

Referenced by Light_EngineInit().

01956 {
01957         int32   i;
01958         double  f;
01959         int32   *fi = (int32*) &f + MOST_SIG_OFFSET;
01960 
01961         for (i = 0; i < SQRT_TAB_SIZE/2; i++)
01962         {
01963                 f = 0; /* Clears least sig part */
01964                 *fi = (i << MANT_SHIFTS) | (EXP_BIAS << EXP_SHIFTS);
01965                 f = sqrt(f);
01966                 SqrtTab[i] = *fi & MANT_MASK;
01967 
01968                 f = 0; /* Clears least sig part */
01969                 *fi = (i << MANT_SHIFTS) | ((EXP_BIAS + 1) << EXP_SHIFTS);
01970                 f = sqrt(f);
01971                 SqrtTab[i + SQRT_TAB_SIZE/2] = *fi & MANT_MASK;
01972         }
01973 }

geBoolean Light_EngineInit geEngine Engine  ) 
 

Definition at line 117 of file Light.c.

References BuildLightLUTS(), Engine, GE_TRUE, geBoolean, and InitSqrtTab().

Referenced by Sys_EngineCreate().

00118 {
00119         BuildLightLUTS(Engine);
00120 
00121         InitSqrtTab();
00122 
00123         return GE_TRUE;
00124 }

void Light_EngineShutdown geEngine Engine  ) 
 

Definition at line 129 of file Light.c.

References BSPData, CEngine, CWorld, and NULL.

Referenced by Sys_EngineFree().

00130 {
00131         CEngine = NULL;
00132         CWorld = NULL;
00133         BSPData = NULL;
00134 }

void Light_FogVerts const geFog Fog,
const geVec3d POV,
const geVec3d Verts,
Surf_TexVert TexVerts,
int32  NumVerts
 

Definition at line 219 of file Light.c.

References Surf_TexVert::b, GE_RGBA::b, geFog::Color, Surf_TexVert::g, GE_RGBA::g, geFloat, geVec3d_AddScaled(), geVec3d_DotProduct(), geVec3d_Length(), geVec3d_Normalize(), geVec3d_Subtract(), int32, geFog::Pos, Surf_TexVert::r, GE_RGBA::r, t, v, geFog::VolumeBrightness, geFog::VolumeRadius, and geFog::VolumeRadiusSquared.

Referenced by RenderFace().

00220 {
00221         geVec3d         FogRay;
00222         geFloat         Radius, RadiusSq, FogRayDot, OneOverRadiusDotBright;
00223         geFloat         EyeDist;
00224         int32           i;
00225 
00226         Radius = Fog->VolumeRadius;
00227         RadiusSq = Fog->VolumeRadiusSquared;
00228         OneOverRadiusDotBright = (1.0f/Radius)*Fog->VolumeBrightness;
00229 
00230         geVec3d_Subtract(&Fog->Pos, POV, &FogRay);
00231         FogRayDot = geVec3d_DotProduct(&FogRay,&FogRay);
00232         EyeDist = (geFloat)sqrt(FogRayDot);
00233 
00234         for (i=0; i< NumVerts; i++, Verts++, TexVerts++)
00235         {
00236                 geVec3d         Ray, Ray2, Impact1, Impact2;
00237                 geFloat         DistSq, Dist, Disc, v;
00238                 geFloat         t0, t1, t, VertDist, d, d2;
00239 
00240                 geVec3d_Subtract(Verts, POV, &Ray);
00241                 geVec3d_Normalize(&Ray);
00242                 
00243                 v = geVec3d_DotProduct(&FogRay, &Ray);
00244 
00245                 Disc = (RadiusSq) - (FogRayDot - (v*v));
00246 
00247                 if (Disc <= 0)
00248                         continue;
00249                                 
00250                 d = (geFloat)sqrt(Disc);
00251 
00252                 t0 = v - d;
00253                 t1 = v + d;
00254                                         
00255                 if (t0 > 0)
00256                         t = t0;
00257                 else if (t1 > 0)
00258                         t = t1;
00259                 else
00260                         continue;
00261 
00262                 geVec3d_Subtract(Verts, &Fog->Pos, &Ray2);
00263                 DistSq = geVec3d_DotProduct(&Ray2, &Ray2);
00264                 VertDist = (geFloat)sqrt(DistSq);
00265                                         
00266                 if (EyeDist < Radius && VertDist < Radius)              // Both inside sphere
00267                 {
00268                         Impact1 = *Verts;
00269                         Impact2 = *POV;
00270                 }
00271                 else if (EyeDist < Radius)                                              // Eye inside
00272                 {
00273                         Impact1 = *POV;
00274                         geVec3d_AddScaled(POV, &Ray, t, &Impact2);
00275                 }
00276                 else if (VertDist < Radius)                                             // Vert is inside
00277                 {
00278                         Impact1 = *Verts;
00279                         geVec3d_AddScaled(POV, &Ray, t, &Impact2);
00280                 }
00281                 else                                                                                    // Both lie outside sphere
00282                 {
00283                         geVec3d_AddScaled(POV, &Ray, t0, &Impact1);
00284                         geVec3d_AddScaled(POV, &Ray, t1, &Impact2);
00285                         geVec3d_Subtract(&Impact1, POV, &Ray);
00286                                         
00287                         d2 = geVec3d_DotProduct(&Ray, &Ray);
00288 
00289                         if (d2 > DistSq)
00290                                 continue;
00291                 }
00292                 geVec3d_Subtract(&Impact1, &Impact2, &Ray);
00293         
00294                 Dist = geVec3d_Length(&Ray)*OneOverRadiusDotBright;
00295 
00296         #if 1
00297                 // Fog the Specular RGB
00298                 TexVerts->r += Dist*Fog->Color.r;
00299                 TexVerts->g += Dist*Fog->Color.g;
00300                 TexVerts->b += Dist*Fog->Color.b;
00301         #else
00302                 TexVerts->r = 255.0f;
00303                 TexVerts->g = 255.0f;
00304                 TexVerts->b = 255.0f;
00305         #endif
00306         }
00307 }

geBoolean Light_GetLightmapRGB Surf_SurfInfo Surf,
geVec3d Pos,
GE_RGBA RGBA
 

Definition at line 1838 of file Light.c.

References GE_RGBA::b, DRV_RGB::b, BSPData, Surf_SurfInfo::Flags, GE_RGBA::g, DRV_RGB::g, GE_FALSE, GE_TRUE, geBoolean, geFloat, geVec3d_DotProduct(), GBSP_BSPData::GFXTexInfo, DRV_LInfo::Height, int32, Surf_SurfInfo::LInfo, DRV_LInfo::MinU, DRV_LInfo::MinV, GE_RGBA::r, DRV_RGB::r, DRV_LInfo::RGBLight, SURFINFO_LIGHTMAP, Surf_SurfInfo::TexInfo, and DRV_LInfo::Width.

Referenced by gePuppet_ComputeAmbientLight(), and geSprite_UpdateLighting().

01839 {
01840 
01841         DRV_RGB         *RGBLight;
01842         geFloat         fr = 0.0f, fg = 0.0f, fb = 0.0f;
01843         geVec3d         VecU, VecV;
01844         geFloat         TexU, TexV;
01845         int32           Index, Width, Height;
01846         
01847         // Make sure this is a lightmaped face
01848         if (!(Surf->Flags & SURFINFO_LIGHTMAP))
01849                 return GE_FALSE;
01850 
01851         RGBLight = Surf->LInfo.RGBLight[0];
01852         
01853         if (!RGBLight)                                          // Make sure we are not null!!!
01854                 return GE_FALSE;
01855 
01856         VecU = BSPData->GFXTexInfo[Surf->TexInfo].Vecs[0];
01857         VecV = BSPData->GFXTexInfo[Surf->TexInfo].Vecs[1];
01858 
01859         // Project the Point into the texture space
01860         TexU = geVec3d_DotProduct(Pos, &VecU) + BSPData->GFXTexInfo[Surf->TexInfo].Shift[0];
01861         TexV = geVec3d_DotProduct(Pos, &VecV) + BSPData->GFXTexInfo[Surf->TexInfo].Shift[1];
01862 
01863         // Align into lightmap space
01864         TexU -= Surf->LInfo.MinU;
01865         TexV -= Surf->LInfo.MinV;
01866 
01867         if (TexU < 0 || TexV < 0)
01868                 return GE_FALSE;
01869         
01870         if (TexU > Surf->LInfo.Width<<4 || TexV > Surf->LInfo.Height<<4)
01871                 return GE_FALSE;
01872 
01873         // Scale into lightmap space
01874         TexU /= (16);
01875         TexV /= (16);
01876 
01877         Width = Surf->LInfo.Width;
01878         Height = Surf->LInfo.Height;
01879 
01880         // Cap it off if invalid (for some funky reason)
01881         if (TexU > Width) TexU = (geFloat)Width;
01882         if (TexV > Height) TexV = (geFloat)Height;
01883         if (TexU < 0) TexU = 0.0f;
01884         if (TexV < 0) TexV = 0.0f;
01885 
01886         Index = (int32)TexV * Width + (int32)TexU;
01887         
01888         // Return the color dude...
01889         RGBA->r = (geFloat)RGBLight[Index].r;
01890         RGBA->g = (geFloat)RGBLight[Index].g;
01891         RGBA->b = (geFloat)RGBLight[Index].b;
01892 
01893         return GE_TRUE;
01894 }

geBoolean Light_GetLightmapRGBBlended Surf_SurfInfo Surf,
geVec3d Pos,
GE_RGBA RGBA
 

Definition at line 1899 of file Light.c.

References GE_RGBA::b, DRV_RGB::b, BSPData, Surf_SurfInfo::Flags, GE_RGBA::g, DRV_RGB::g, GE_FALSE, GE_TRUE, geBoolean, geFloat, geVec3d_DotProduct(), GBSP_BSPData::GFXTexInfo, DRV_LInfo::Height, int32, Surf_SurfInfo::LInfo, DRV_LInfo::MinU, DRV_LInfo::MinV, GE_RGBA::r, DRV_RGB::r, DRV_LInfo::RGBLight, SURFINFO_LIGHTMAP, Surf_SurfInfo::TexInfo, and DRV_LInfo::Width.

01900 {
01901 
01902         DRV_RGB         *RGBLight;
01903         geFloat         fr = 0.0f, fg = 0.0f, fb = 0.0f;
01904         geVec3d         VecU, VecV;
01905         geFloat         TexU, TexV;
01906         int32           Index, Width, Height;
01907         
01908         // Make sure this is a lightmaped face
01909         if (!(Surf->Flags & SURFINFO_LIGHTMAP))
01910                 return GE_FALSE;
01911 
01912         RGBLight = Surf->LInfo.RGBLight[0];
01913         
01914         if (!RGBLight)                                          // Make sure we are not null!!!
01915                 return GE_FALSE;
01916 
01917         TexU = geVec3d_DotProduct(Pos, &VecU) + BSPData->GFXTexInfo[Surf->TexInfo].Shift[0];
01918         TexV = geVec3d_DotProduct(Pos, &VecV) + BSPData->GFXTexInfo[Surf->TexInfo].Shift[1];
01919 
01920         // Align into lightmap space
01921         TexU -= Surf->LInfo.MinU;
01922         TexV -= Surf->LInfo.MinV;
01923 
01924         if (TexU < 0 || TexV < 0)
01925                 return GE_FALSE;
01926         
01927         if (TexU > Surf->LInfo.Width<<4 || TexV > Surf->LInfo.Height<<4)
01928                 return GE_FALSE;
01929 
01930         // Scale into lightmap space
01931         TexU /= (16);
01932         TexV /= (16);
01933 
01934         Width = Surf->LInfo.Width;
01935         Height = Surf->LInfo.Height;
01936 
01937         // Cap it off if invalid (for some funky reason)
01938         if (TexU > Width) TexU = (geFloat)Width;
01939         if (TexV > Height) TexV = (geFloat)Height;
01940         if (TexU < 0) TexU = 0.0f;
01941         if (TexV < 0) TexV = 0.0f;
01942 
01943         Index = (int32)TexV * Width + (int32)TexU;
01944         
01945         // Return the color dude...
01946         RGBA->r = (geFloat)RGBLight[Index].r;
01947         RGBA->g = (geFloat)RGBLight[Index].g;
01948         RGBA->b = (geFloat)RGBLight[Index].b;
01949 
01950         return GE_TRUE;
01951 }

geBoolean Light_SetAttributes Light_DLight Light,
const geVec3d Pos,
const GE_RGBA RGBA,
geFloat  Radius,
geBoolean  CastShadow
 

Definition at line 1423 of file Light.c.

References GE_RGBA::b, Light_DLight::CastShadow, Light_DLight::Color, Light_DLight::FColorB, Light_DLight::FColorG, Light_DLight::FColorR, GE_RGBA::g, GE_TRUE, geBoolean, int32, LIGHT_FRACT, NULL, Light_DLight::Pos, GE_RGBA::r, and Light_DLight::Radius.

Referenced by geWorld_SetLightAttributes().

01428 {
01429         assert(Light != NULL);
01430         
01431         Light->Pos = *Pos;
01432         Light->Color = *RGBA;
01433         Light->Radius = Radius;
01434 
01435         // Pre-compute fixed point light colors
01436         Light->FColorR = (int32)((Light->Color.r/195.0f) * (1<<LIGHT_FRACT));
01437         Light->FColorG = (int32)((Light->Color.g/195.0f) * (1<<LIGHT_FRACT));
01438         Light->FColorB = (int32)((Light->Color.b/195.0f) * (1<<LIGHT_FRACT));
01439 
01440         Light->CastShadow = CastShadow;
01441 
01442         return GE_TRUE;
01443 }

geBoolean Light_SetEngine geEngine Engine  ) 
 

Definition at line 177 of file Light.c.

References CEngine, Engine, GE_TRUE, geBoolean, and NULL.

Referenced by World_SetEngine().

00178 {
00179         assert (Engine != NULL);
00180 
00181         CEngine = Engine;
00182 
00183         return GE_TRUE;
00184 }

geBoolean Light_SetGBSP World_BSP BSP  ) 
 

Definition at line 205 of file Light.c.

References BSPData, CBSP, GE_TRUE, geBoolean, and NULL.

Referenced by Surf_WorldInit(), and World_SetGBSP().

00206 {
00207         assert(BSP != NULL);
00208 
00209         // Make quick pointer to the world bsp data
00210         CBSP = BSP;
00211         BSPData = &BSP->BSPData;
00212 
00213         return GE_TRUE;
00214 }

void Light_SetupLightmap DRV_LInfo LInfo,
BOOL *  Dynamic
 

Definition at line 749 of file Light.c.

References Light_DLight::Active, AddLightType(), AddLightType0(), AddLightType1(), AddLightTypeWavy(), AddLightTypeWavy1(), DRV_RGB::b, BlankRGB, BSPData, Light_DLight::CastShadow, CBSP, CEngine, CombineDLightWithRGBMap(), CombineDLightWithRGBMapWithShadow(), geWorld::CurFrameDynamic, CWorld, geEngine::DebugInfo, Surf_SurfInfo::DLightFrame, Surf_SurfInfo::DLights, Light_LightInfo::DynamicLights, DRV_LInfo::Face, Surf_SurfInfo::Flags, FogLightmap1(), FogLightmap2(), DRV_RGB::g, GE_FALSE, GE_TRUE, geBoolean, GBSP_BSPData::GFXFaces, GBSP_BSPData::GFXLightData, GBSP_BSPData::GFXTexInfo, DRV_LInfo::Height, int32, LIGHT_FRACT, geWorld::LightInfo, LightInfo, GFX_Face::LightOfs, Sys_DebugInfo::LMap1, Sys_DebugInfo::LMap2, Light_LightInfo::LTypeDynamic, Light_LightInfo::LTypeIntensities, GFX_Face::LTypes, MAX_DYNAMIC_LIGHTS, MirrorRecursion, NULL, Sys_DebugInfo::NumDLights, Light_LightInfo::NumDynamicLights, Surf_SurfInfo::NumLTypes, geWorld::NumVisibleFog, DRV_RGB::r, DRV_LInfo::RGBLight, World_BSP::SurfInfo, SURFINFO_LTYPED, TempRGB, TempRGB32, TempRGB32Fog, TempRGBFog, GFX_Face::TexInfo, TEXINFO_FULLBRIGHT, TRUE, uint8, geWorld::VisibleFog, and DRV_LInfo::Width.

Referenced by Engine_InitDriver(), geEngine_CreateWorldLightmapTHandles(), gePuppet_ComputeAmbientLight(), and geSprite_UpdateLighting().

00750 {
00751         int32                   LightOffset;
00752         geBoolean               IsDyn, HasDLight;
00753         int32                   NumLTypes;
00754         int32                   i, Ln;
00755         Surf_SurfInfo   *SInfo;
00756         GFX_Face                *Face;
00757         int32                   Intensity;
00758         uint8                   *LightData;
00759         int32                   lWidth, lHeight, LMapSize, MapNum, SIndex;
00760         int32                   *pRGB1;
00761         DRV_RGB                 *pRGB2;
00762 
00763         assert (CBSP != NULL);
00764         assert(BSPData != NULL);
00765         assert(BSPData->GFXFaces != NULL);
00766         assert(BSPData->GFXLightData != NULL);
00767         assert(BSPData->GFXTexInfo != NULL);
00768         assert(CWorld->LightInfo != NULL);
00769 
00770         SInfo = &CBSP->SurfInfo[LInfo->Face];
00771         Face = &BSPData->GFXFaces[LInfo->Face];
00772 
00773         NumLTypes = SInfo->NumLTypes;
00774         
00775         LightOffset = Face->LightOfs;
00776         
00777         lWidth = LInfo->Width;
00778         lHeight = LInfo->Height;
00779         LMapSize = lHeight * lWidth;
00780 
00781         IsDyn = HasDLight = GE_FALSE;
00782 
00783         if (SInfo->DLightFrame == CWorld->CurFrameDynamic)
00784         if (LightInfo->NumDynamicLights > 0 && !(BSPData->GFXTexInfo[Face->TexInfo].Flags & TEXINFO_FULLBRIGHT)) 
00785                 HasDLight = GE_TRUE;
00786 
00787         // We can early out if no dlights on this surface, and no styled lighting...
00788         if (!HasDLight && !(SInfo->Flags & SURFINFO_LTYPED))
00789         {
00790                 if (LightOffset >=0) 
00791                         LInfo->RGBLight[0] = (DRV_RGB*)&BSPData->GFXLightData[LightOffset+1];
00792                 else
00793                         LInfo->RGBLight[0] = BlankRGB;
00794                 goto FogOnly;
00795         }
00796 
00797         CEngine->DebugInfo.LMap1++;
00798 
00799         // If there is light data
00800         if (LightOffset >=0) 
00801         {
00802                 // FIXME:       Take out one byte RGB check...
00803                 //      Lightmaps are allways RGB now...
00804                 LightData = &BSPData->GFXLightData[LightOffset+1];
00805 
00806                 // layer all styles on first map, using its intensity table
00807                 for (MapNum = 0; MapNum < 4; MapNum++) 
00808                 {
00809                         SIndex = Face->LTypes[MapNum];
00810                         
00811                         if (SIndex == 255)
00812                                 break;
00813                         
00814                         if (LightInfo->LTypeDynamic[SIndex])
00815                                 IsDyn = GE_TRUE;
00816 
00817                         Intensity = LightInfo->LTypeIntensities[SIndex];
00818 
00819                         if (SIndex == 11)
00820                         {
00821                                 if (MapNum == 0)
00822                                         AddLightTypeWavy1(TempRGB32, LightData, lWidth, lHeight);
00823                                 else
00824                                         AddLightTypeWavy(TempRGB32, LightData, lWidth, lHeight);
00825 
00826                                 IsDyn = GE_TRUE;                // Need to force to true
00827                         }
00828                         else
00829                         {
00830                                 if (SIndex == 0)                // LType 0 is always in first light slot
00831                                         AddLightType0(TempRGB32, LightData, lWidth, lHeight);
00832                                 else
00833                                 {
00834                                         if (MapNum == 0)
00835                                                 AddLightType1(TempRGB32, LightData, lWidth, lHeight, Intensity);
00836                                         else
00837                                                 AddLightType(TempRGB32, LightData, lWidth, lHeight, Intensity);
00838                                 }
00839                         }
00840 
00841                         LightData += LMapSize*3;
00842                 }
00843         }
00844         else
00845                 memset(TempRGB32, 0, LMapSize*3*sizeof(TempRGB32[0]));
00846         
00847         // Tack on dynamic lights
00848         if (HasDLight)
00849         {
00850                 Light_DLight    *DLights = LightInfo->DynamicLights;
00851 
00852                 for (Ln = 0; Ln <MAX_DYNAMIC_LIGHTS; Ln++, DLights++) 
00853                 {
00854                         if (!DLights->Active) 
00855                                 continue;
00856 
00857                         if (!(SInfo->DLights & (1<<Ln)))
00858                                 continue;
00859 
00860                         CEngine->DebugInfo.NumDLights++;
00861 
00862                         if (DLights->CastShadow)
00863                         {
00864                                 if (CombineDLightWithRGBMapWithShadow(TempRGB32, DLights, Face, SInfo))
00865                                         IsDyn = GE_TRUE;
00866                         }
00867                         else
00868                         {
00869                                 if (CombineDLightWithRGBMap(TempRGB32, DLights, Face, SInfo))
00870                                         IsDyn = GE_TRUE;
00871                         }
00872                 }
00873         }
00874 
00875         // Put the light into a driver compatible pointer, and clamp it 
00876         pRGB1 = TempRGB32;
00877         pRGB2 = TempRGB;
00878         for (i=0; i< LMapSize; i++)
00879         {
00880                 Intensity = (*pRGB1++) >> LIGHT_FRACT;
00881                 if (Intensity > 255)
00882                         Intensity = 255;
00883                 else if (Intensity < 0 )
00884                         Intensity = 0;
00885                 pRGB2->r = (uint8)Intensity;
00886 
00887                 Intensity = (*pRGB1++) >> LIGHT_FRACT;
00888                 if (Intensity > 255)
00889                         Intensity = 255;
00890                 else if (Intensity < 0 )
00891                         Intensity = 0;
00892                 pRGB2->g = (uint8)Intensity;
00893 
00894                 Intensity = (*pRGB1++) >> LIGHT_FRACT;
00895                 if (Intensity > 255)
00896                         Intensity = 255;
00897                 else if (Intensity < 0 )
00898                         Intensity = 0;
00899                 pRGB2->b = (uint8)Intensity;
00900 
00901                 pRGB2++;
00902         }
00903         
00904         // Point the lightmap to the data
00905         LInfo->RGBLight[0] = TempRGB;
00906 
00907         FogOnly:                // Jump to here, for fog lightmap only...
00908 
00909         //
00910         // Fog the lightmap (setup lightmap 1)
00911         //
00912         LInfo->RGBLight[1] = NULL;
00913 
00914 #if 1
00915         if (!MirrorRecursion)           // Only do fog on first pass, not in mirrors...
00916         {
00917                 geFog           *Fog;
00918                 geBoolean       WasFog;
00919                 
00920                 WasFog = GE_FALSE;
00921                 
00922                 if (CWorld->NumVisibleFog)
00923                 {
00924                         for (i=0; i< CWorld->NumVisibleFog; i++)
00925                         {
00926                                 Fog = CWorld->VisibleFog[i];
00927                         
00928                                 if (i == 0)             // Use FogLightmap1 for first one ONLY
00929                                 {
00930                                         if (FogLightmap1(Fog, TempRGB32Fog, Face, SInfo))
00931                                                 WasFog = GE_TRUE;
00932                                 }
00933                                 else                    // All other fog lights use FogLightmap2
00934                                 {
00935                                         if (FogLightmap2(Fog, TempRGB32Fog, Face, SInfo))
00936                                                 WasFog = GE_TRUE;
00937                                 }
00938                         }
00939                 }
00940                 
00941                 if (WasFog)
00942                 {
00943                         CEngine->DebugInfo.LMap2++;
00944 
00945                         // Put the light into a driver compatible pointer, and clamp it 
00946                         pRGB1 = TempRGB32Fog;
00947                         pRGB2 = TempRGBFog;
00948                         for (i=0; i< LMapSize; i++)
00949                         {
00950                                 Intensity = (*pRGB1++) >> LIGHT_FRACT;
00951                                 if (Intensity > 255)
00952                                         Intensity = 255;
00953                                 pRGB2->r = (uint8)Intensity;
00954 
00955                                 Intensity = (*pRGB1++) >> LIGHT_FRACT;
00956                                 if (Intensity > 255)
00957                                         Intensity = 255;
00958                                 pRGB2->g = (uint8)Intensity;
00959 
00960                                 Intensity = (*pRGB1++) >> LIGHT_FRACT;
00961                                 if (Intensity > 255)
00962                                         Intensity = 255;
00963                                 pRGB2->b = (uint8)Intensity;
00964 
00965                                 pRGB2++;
00966                         }
00967                         IsDyn = TRUE;                   // Force this face to be dynamic
00968                         LInfo->RGBLight[1] = TempRGBFog;
00969                 }
00970         }
00971 #endif
00972 
00973         if (Dynamic)
00974         {
00975                 *Dynamic = IsDyn;
00976         }
00977 }

geBoolean Light_SetupLights geWorld World  ) 
 

Definition at line 1258 of file Light.c.

References Light_DLight::Active, BSPData, CBSP, geWorld::CurFrameDynamic, Light_LightInfo::DynamicLights, GE_TRUE, geBoolean, geVec3d_Add(), geVec3d_Subtract(), geXForm3d_TransposeTransform(), GBSP_BSPData::GFXModels, int32, LightInfo, MAX_DYNAMIC_LIGHTS, World_BSP::Models, NULL, GBSP_BSPData::NumGFXModels, geWorld_Model::Pivot, Light_DLight::Pos, GFX_Model::RootNode, SetupDynamicLight_r(), UpdateLTypeTables(), geWorld_Model::VisFrame, and geWorld_Model::XForm.

Referenced by World_WorldRenderQ().

01259 {
01260         int32                   i, Node;
01261         Light_DLight    *DLights;
01262 
01263         assert(World != NULL);
01264 
01265         assert(BSPData != NULL);
01266         assert(BSPData->GFXModels != NULL);
01267         assert(LightInfo != NULL);
01268 
01269         // Update the intensity tables for dynamic ltyped lighting
01270         UpdateLTypeTables(World);
01271 
01272         DLights = LightInfo->DynamicLights;
01273 
01274 #if 0
01275         Node = BSPData->GFXModels[0].RootNode[0];
01276 
01277         for (i=0; i< MAX_DYNAMIC_LIGHTS; i++, DLights++)
01278         {
01279                 if (!DLights->Active)
01280                         continue;
01281 
01282                 SetupDynamicLight_r(DLights, &DLights->Pos, i, Node);
01283         }
01284 #else
01285         for (i=0; i< MAX_DYNAMIC_LIGHTS; i++, DLights++)
01286         {
01287                 int32           m;
01288                 geVec3d         NewPos;
01289                 geWorld_Model *Model;
01290 
01291                 if (!DLights->Active)
01292                         continue;
01293 
01294                 Model = CBSP->Models;
01295 
01296                 for (m=0; m< BSPData->NumGFXModels; m++, Model++)
01297                 {
01298                         if (Model->VisFrame != World->CurFrameDynamic)
01299                                 continue;
01300 
01301                         Node = BSPData->GFXModels[m].RootNode[0];
01302                         
01303                         geVec3d_Subtract(&DLights->Pos, &Model->Pivot, &NewPos);
01304                         // InverseTransform the light about models center of rotation
01305                         geXForm3d_TransposeTransform(&Model->XForm, &NewPos, &NewPos);
01306                         
01307                         geVec3d_Add(&NewPos , &Model->Pivot, &NewPos);
01308 
01309                         SetupDynamicLight_r(DLights, &NewPos, i, Node);
01310                 }
01311         }
01312 #endif
01313 
01314         return GE_TRUE;
01315 }

geBoolean Light_SetWorld geWorld World  ) 
 

Definition at line 190 of file Light.c.

References CWorld, GE_TRUE, geBoolean, GSurfInfo, LightInfo, and NULL.

Referenced by Surf_WorldInit(), and World_SetWorld().

00191 {
00192         assert(World != NULL);
00193         
00194         CWorld = World;
00195 
00196         LightInfo = World->LightInfo;
00197         GSurfInfo = World->CurrentBSP->SurfInfo;
00198 
00199         return GE_TRUE;
00200 }

Light_DLight* Light_WorldAddLight geWorld World  ) 
 

Definition at line 1367 of file Light.c.

References Light_DLight::Active, Light_LightInfo::DynamicLights, GE_ERR_RENDERQ_OVERFLOW, GE_TRUE, geErrorLog_Add, int32, geWorld::LightInfo, MAX_DYNAMIC_LIGHTS, NULL, and Light_LightInfo::NumDynamicLights.

Referenced by geWorld_AddLight().

01368 {
01369         Light_LightInfo *LInfo;
01370         Light_DLight    *DLights;
01371         int32                   i;
01372 
01373         assert(World != NULL);
01374 
01375         LInfo = World->LightInfo;
01376 
01377         assert(LInfo);
01378 
01379         DLights = LInfo->DynamicLights;
01380 
01381         for (i=0; i< MAX_DYNAMIC_LIGHTS; i++, DLights++)
01382         {
01383                 if (!DLights->Active)
01384                         break;
01385         }
01386 
01387         if (i >= MAX_DYNAMIC_LIGHTS)
01388         {
01389                 geErrorLog_Add(GE_ERR_RENDERQ_OVERFLOW, NULL);
01390                 return  NULL;
01391         }
01392 
01393         // Set it's attributes to some default...
01394         memset(DLights, 0, sizeof(Light_DLight));
01395 
01396         DLights->Active = GE_TRUE;
01397         LInfo->NumDynamicLights++;
01398         
01399 
01400         return DLights;
01401 }

char Light_WorldGetLTypeCurrent geWorld World,
int32  LType
 

Definition at line 1319 of file Light.c.

References Light_LightInfo::IPos, geWorld::LightInfo, Light_LightInfo::LTypeTable, MAX_LTYPES, and NULL.

01320 {
01321         Light_LightInfo *LInfo;
01322         assert( World != NULL );
01323         assert( LType >= 0 );
01324         assert( LType < MAX_LTYPES );
01325 
01326         LInfo = World->LightInfo;
01327         assert( LInfo != NULL );
01328 
01329         return (LInfo->LTypeTable[LType][LInfo->IPos[LType]]) ;
01330 }

geBoolean Light_WorldInit geWorld World  ) 
 

Definition at line 139 of file Light.c.

References GE_ERR_OUT_OF_MEMORY, GE_FALSE, GE_RAM_ALLOCATE_STRUCT, GE_TRUE, geBoolean, geErrorLog_Add, geWorld::LightInfo, NULL, and UpdateLTypeTables().

Referenced by geWorld_Create().

00140 {
00141         assert(World != NULL);
00142 
00143         World->LightInfo = GE_RAM_ALLOCATE_STRUCT(Light_LightInfo);
00144 
00145         if (!World->LightInfo)
00146         {
00147                 geErrorLog_Add(GE_ERR_OUT_OF_MEMORY, NULL);
00148                 return GE_FALSE;
00149         }
00150 
00151         memset(World->LightInfo, 0, sizeof(Light_LightInfo));
00152 
00153         UpdateLTypeTables(World);                       // Update ltype tables for first frame
00154 
00155         return GE_TRUE;
00156 }

void Light_WorldRemoveLight geWorld World,
Light_DLight DLight
 

Definition at line 1406 of file Light.c.

References Light_DLight::Active, GE_FALSE, geWorld::LightInfo, and Light_LightInfo::NumDynamicLights.

Referenced by geWorld_RemoveLight().

01407 {
01408         assert(World);
01409         assert(World->LightInfo);
01410         assert(DLight);
01411         assert(DLight->Active);
01412 
01413         if (!DLight->Active)
01414                 return;
01415 
01416         DLight->Active = GE_FALSE;
01417         World->LightInfo->NumDynamicLights--;
01418 }

geBoolean Light_WorldSetLTypeTable geWorld World,
int32  LType,
const char *  Table
 

Definition at line 1448 of file Light.c.

References GE_ERR_INVALID_LTYPE, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_Add, geWorld::LightInfo, Light_LightInfo::LTypeTable, MAX_LTYPES, and NULL.

Referenced by geWorld_SetLTypeTable().

01449 {
01450         assert(World != NULL);
01451         assert(World->LightInfo != NULL);
01452 
01453         if (LType < 0 || LType >= MAX_LTYPES)
01454         {
01455                 geErrorLog_Add(GE_ERR_INVALID_LTYPE, NULL);
01456                 return GE_FALSE;
01457         }
01458 
01459         assert(strlen(Table) < 70);
01460 
01461         strcpy(World->LightInfo->LTypeTable[LType], Table);
01462 
01463         return GE_TRUE;
01464 }

void Light_WorldShutdown geWorld World  ) 
 

Definition at line 161 of file Light.c.

References geRam_Free, geWorld::LightInfo, and NULL.

Referenced by geWorld_Free().

00162 {
00163         assert(World != NULL);
00164 
00165         if (!World->LightInfo)
00166                 return;
00167 
00168         geRam_Free(World->LightInfo);
00169 
00170         World->LightInfo = NULL;
00171 }

void SetupColorLight1 DRV_RGB light1,
DRV_RGB RGBM,
int32  lw,
int32  lh,
geFloat  intensity
[static]
 

Definition at line 1605 of file Light.c.

References DRV_RGB::b, CEngine, DRV_RGB::g, int32, NULL, DRV_RGB::r, r, geEngine::StyleLUT1, uint16, and uint8.

01606 {       
01607         int32   h;
01608         DRV_RGB *rgb;
01609         uint16  r,g,b;
01610         DRV_RGB *lm;
01611         uint16  II;
01612         uint8   *SLUT;
01613         
01614         assert(light1 != NULL);
01615         assert(RGBM != NULL);
01616         assert(CEngine != NULL);
01617 
01618         lm = light1;
01619         rgb = RGBM;
01620         II = (uint16)(intensity * 63);
01621 
01622         if (II > 63) II = 63;
01623 
01624         SLUT = &CEngine->StyleLUT1[II][0];
01625         
01626         for (h = 0; h < lh*lw; h++)
01627         {
01628                 r = SLUT[lm->r];
01629                 g = SLUT[lm->g];
01630                 b = SLUT[lm->b];
01631 
01632                 rgb->r = (uint8)r;
01633                 rgb->g = (uint8)g;
01634                 rgb->b = (uint8)b;
01635 
01636                 lm++;
01637                 rgb++;
01638         }
01639 }

void SetupColorLight2 DRV_RGB light1,
DRV_RGB RGBM,
int32  lw,
int32  lh,
geFloat  intensity
[static]
 

Definition at line 1644 of file Light.c.

References DRV_RGB::b, CEngine, DRV_RGB::g, int32, NULL, DRV_RGB::r, r, geEngine::StyleLUT1, uint16, and uint8.

01645 {
01646         int32   h;
01647         DRV_RGB *rgb;
01648         uint16  r,g,b;
01649         DRV_RGB *lm;
01650         uint16  II;
01651         uint8   *SLUT;
01652 
01653         assert(light1 != NULL);
01654         assert(RGBM != NULL);
01655         assert(CEngine != NULL);
01656 
01657         lm = light1;
01658         rgb = RGBM;
01659         II = (uint16)(intensity * 63);
01660 
01661         if (II > 63) 
01662                 II = 63;
01663         
01664         SLUT = &CEngine->StyleLUT1[II][0];
01665         
01666         for (h = 0; h < lh*lw; h++)
01667         {
01668                 
01669                 r = rgb->r + SLUT[lm->r];
01670                 g = rgb->g + SLUT[lm->g];
01671                 b = rgb->b + SLUT[lm->b];
01672 
01673                 if (r > 255) r = 255;
01674                 if (g > 255) g = 255;
01675                 if (b > 255) b = 255;
01676 
01677                 rgb->r = (uint8)r;
01678                 rgb->g = (uint8)g;
01679                 rgb->b = (uint8)b;
01680                 
01681                 lm++;
01682                 rgb++;
01683         }
01684 }

void SetupDynamicLight_r Light_DLight pLight,
geVec3d Pos,
int32  LNum,
int32  Node
[static]
 

Definition at line 1784 of file Light.c.

References BSPData, CBSP, GFX_Node::Children, geWorld::CurFrameDynamic, CWorld, Surf_SurfInfo::DLightFrame, Surf_SurfInfo::DLights, GFX_Node::FirstFace, geFloat, GBSP_BSPData::GFXNodes, GBSP_BSPData::GFXPlanes, int32, GFX_Node::NumFaces, Plane_PlaneDistanceFast(), GFX_Node::PlaneNum, Light_DLight::Radius, Surf_InSurfBoundingBox(), and World_BSP::SurfInfo.

Referenced by Light_SetupLights().

01785 {
01786         geFloat                 Dist;
01787         GFX_Plane               *pPlane;
01788         GFX_Node                *pNode;
01789         Surf_SurfInfo   *pSInfo;
01790         int32                   i;
01791 
01792         if (Node < 0)   // Hit a leaf no more searching
01793                 return;
01794 
01795         pNode = &BSPData->GFXNodes[Node];
01796         pPlane = &BSPData->GFXPlanes[pNode->PlaneNum];
01797 
01798         Dist = Plane_PlaneDistanceFast(pPlane, Pos);
01799 
01800         if (Dist > pLight->Radius)
01801         {
01802                 SetupDynamicLight_r(pLight, Pos, LNum, BSPData->GFXNodes[Node].Children[0]);
01803                 return;
01804         }
01805         if (Dist <-pLight->Radius)
01806         {
01807                 SetupDynamicLight_r(pLight, Pos, LNum, BSPData->GFXNodes[Node].Children[1]);
01808                 return;
01809         }
01810 
01811         // The light is within range of this plane, mark it and go down both sides
01812         pSInfo = &CBSP->SurfInfo[pNode->FirstFace];
01813         for (i=0; i< pNode->NumFaces; i++, pSInfo++)
01814         {
01815                 if (!Surf_InSurfBoundingBox(pSInfo, Pos, pLight->Radius) ) 
01816                         continue;
01817                 
01818                 if (pSInfo->DLightFrame != CWorld->CurFrameDynamic)
01819                 {
01820                         pSInfo->DLightFrame = CWorld->CurFrameDynamic;
01821                         pSInfo->DLights = 0;
01822                 }
01823                 
01824                 // We might need to go to a linked list, if more than 32 lights are needed
01825                 pSInfo->DLights |= 1<<LNum;
01826         }
01827 
01828         SetupDynamicLight_r(pLight, Pos, LNum, BSPData->GFXNodes[Node].Children[0]);
01829         SetupDynamicLight_r(pLight, Pos, LNum, BSPData->GFXNodes[Node].Children[1]);
01830 }

void SetupWavyColorLight1 DRV_RGB light1,
DRV_RGB RGBM,
int32  lw,
int32  lh
[static]
 

Definition at line 1501 of file Light.c.

References A_MOD, DRV_RGB::b, CEngine, DRV_RGB::g, int16, int32, NULL, DRV_RGB::r, r, geEngine::StyleLUT1, U16, uint16, uint8, and geEngine::WaveTable.

01502 { 
01503         int32   h;
01504         DRV_RGB *rgb;
01505         U16             r,g,b, II;
01506         DRV_RGB *lm;
01507         uint16  Index;
01508         uint8   *SLUT;
01509         int16   *WaveTable;
01510 
01511         assert(light1 != NULL);
01512         assert(RGBM != NULL);
01513 
01514         assert(CEngine != NULL);
01515 
01516         WaveTable = CEngine->WaveTable;
01517         
01518         lm = light1;
01519         rgb = RGBM;
01520         Index = 0;
01521 
01522         SLUT = CEngine->StyleLUT1[0];
01523 
01524         for (h = 0; h < lh*lw; h++)
01525         {
01526                 // We know that WaterColor table is from 0-255...
01527                 II = WaveTable[Index++];
01528                 if (Index > A_MOD)
01529                         Index -= A_MOD;
01530                 
01531                 II >>= 2;
01532                 if (II > 63) II = 63;
01533                 II <<= 8;
01534                 r = SLUT[II + lm->r];
01535                 g = SLUT[II + lm->g];
01536                 b = SLUT[II + lm->b];
01537 
01538                 rgb->r = (uint8)r;
01539                 rgb->g = (uint8)g;
01540                 rgb->b = (uint8)b;
01541 
01542                 lm++;
01543                 rgb++;
01544         }
01545 }

void SetupWavyColorLight2 DRV_RGB light1,
DRV_RGB RGBM,
int32  lw,
int32  lh
[static]
 

Definition at line 1550 of file Light.c.

References A_MOD, DRV_RGB::b, CEngine, DRV_RGB::g, int16, int32, NULL, DRV_RGB::r, r, geEngine::StyleLUT1, U16, uint16, uint8, and geEngine::WaveTable.

01551 {
01552         int32 h;
01553         DRV_RGB         *rgb;
01554         U16                     r,g,b, II;
01555         DRV_RGB         *lm;
01556         uint16          Index;
01557         uint8           *SLUT;
01558         int16           *WaveTable;
01559 
01560         assert(light1 != NULL);
01561         assert(RGBM != NULL);
01562 
01563         assert(CEngine != NULL);
01564         
01565         WaveTable = CEngine->WaveTable;
01566 
01567         lm = light1;
01568         rgb = RGBM;
01569         Index = 0;
01570 
01571         SLUT = CEngine->StyleLUT1[0];
01572 
01573         for (h = 0; h < lh*lw; h++)
01574         {
01575                 // We know that WaterColor table is from 0-255...
01576                 II = WaveTable[Index++];
01577                 if (Index > A_MOD)
01578                         Index -= A_MOD;
01579                 
01580                 II >>= 2;
01581                 if (II > 63) 
01582                         II = 63;
01583                 II <<= 8;
01584 
01585                 r = rgb->r + SLUT[II + lm->r];
01586                 g = rgb->g + SLUT[II + lm->g];
01587                 b = rgb->b + SLUT[II + lm->b];
01588                 
01589                 if (r > 255) r = 255;
01590                 if (g > 255) g = 255;
01591                 if (b > 255) b = 255;
01592 
01593                 rgb->r = (uint8)r;
01594                 rgb->g = (uint8)g;
01595                 rgb->b = (uint8)b;
01596 
01597                 lm++;
01598                 rgb++;
01599         }
01600 }

void UpdateLTypeTables geWorld World  )  [static]
 

Definition at line 1336 of file Light.c.

References FALSE, geFloat, int32, Light_LightInfo::IPos, LIGHT_FRACT, geWorld::LightInfo, Light_LightInfo::LTypeDynamic, Light_LightInfo::LTypeIntensities, Light_LightInfo::LTypeIntensities2, Light_LightInfo::LTypeTable, MAX_LTYPES, s, and TRUE.

Referenced by Light_SetupLights(), and Light_WorldInit().

01337 {
01338         int32                   s;
01339         geFloat                 i;
01340         Light_LightInfo *LInfo;
01341 
01342         LInfo = World->LightInfo;
01343                 
01344         for (s =0; s <MAX_LTYPES; s++) 
01345         {
01346                 LInfo->IPos[s]++;
01347 
01348                 if (LInfo->LTypeTable[s][LInfo->IPos[s]] == 0) 
01349                         LInfo->IPos[s] = 0;
01350 
01351                 i = (geFloat)(LInfo->LTypeTable[s][LInfo->IPos[s]]-96) / 27.0f;
01352 
01353                 LInfo->LTypeIntensities[s] = (int32)(i * (1<<LIGHT_FRACT));
01354 
01355                 if (LInfo->LTypeIntensities2[s] != LInfo->LTypeTable[s][LInfo->IPos[s]]-96)
01356                         LInfo->LTypeDynamic[s] = TRUE;
01357                 else
01358                         LInfo->LTypeDynamic[s] = FALSE;
01359         
01360                 LInfo->LTypeIntensities2[s] = LInfo->LTypeTable[s][LInfo->IPos[s]]-96;
01361         }
01362 }   


Variable Documentation

DRV_RGB BlankRGB[MAX_LMAP_SIZE*MAX_LMAP_SIZE] [static]
 

Definition at line 50 of file Light.c.

Referenced by Light_SetupLightmap().

GBSP_BSPData* BSPData [static]
 

Definition at line 45 of file Light.c.

Referenced by CombineDLightWithRGBMap(), CombineDLightWithRGBMapWithShadow(), Light_EngineShutdown(), Light_GetLightmapRGB(), Light_GetLightmapRGBBlended(), Light_SetGBSP(), Light_SetupLightmap(), Light_SetupLights(), and SetupDynamicLight_r().

World_BSP* CBSP [static]
 

Definition at line 44 of file Light.c.

Referenced by Light_SetGBSP(), Light_SetupLightmap(), Light_SetupLights(), and SetupDynamicLight_r().

geEngine* CEngine = NULL [static]
 

Definition at line 42 of file Light.c.

Referenced by AddLightTypeWavy(), AddLightTypeWavy1(), Light_EngineShutdown(), Light_SetEngine(), Light_SetupLightmap(), SetupColorLight1(), SetupColorLight2(), SetupWavyColorLight1(), and SetupWavyColorLight2().

geWorld* CWorld = NULL [static]
 

Definition at line 43 of file Light.c.

Referenced by CombineDLightWithRGBMapWithShadow(), Light_EngineShutdown(), Light_SetupLightmap(), Light_SetWorld(), and SetupDynamicLight_r().

geVec3d GlobalEyePos = {100.0f, 0.0f, 0.0f}
 

Definition at line 310 of file Light.c.

Referenced by FogLightmap1(), FogLightmap2(), and World_WorldRenderQ().

Surf_SurfInfo* GSurfInfo [static]
 

Definition at line 47 of file Light.c.

Referenced by Light_SetWorld().

Light_LightInfo* LightInfo [static]
 

Definition at line 46 of file Light.c.

Referenced by Light_SetupLightmap(), Light_SetupLights(), and Light_SetWorld().

int32 MirrorRecursion
 

Definition at line 309 of file Light.c.

Referenced by GList_AddOperation(), GList_RenderOperations(), Light_SetupLightmap(), RenderFace(), RenderScene(), RenderSubModels(), RenderTexturedPoint(), and World_WorldRenderQ().

int32 SqrtTab[SQRT_TAB_SIZE]
 

Definition at line 87 of file Light.c.

Referenced by FastSqrt(), and InitSqrtTab().

DRV_RGB TempRGB[MAX_LMAP_SIZE*MAX_LMAP_SIZE] [static]
 

Definition at line 51 of file Light.c.

Referenced by Light_SetupLightmap().

int32 TempRGB32[MAX_LMAP_SIZE*MAX_LMAP_SIZE*3] [static]
 

Definition at line 52 of file Light.c.

Referenced by Light_SetupLightmap().

int32 TempRGB32Fog[MAX_LMAP_SIZE*MAX_LMAP_SIZE*3] [static]
 

Definition at line 54 of file Light.c.

Referenced by Light_SetupLightmap().

DRV_RGB TempRGBFog[MAX_LMAP_SIZE*MAX_LMAP_SIZE] [static]
 

Definition at line 53 of file Light.c.

Referenced by Light_SetupLightmap().


Generated on Tue Sep 30 12:37:44 2003 for GTestAndEngine by doxygen 1.3.2