Torque3D Documentation / _generateds / terrLighting.cpp

terrLighting.cpp

Engine/source/terrain/terrLighting.cpp

More...

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#include "terrain/terrRender.h"
25#include "lighting/lightInfo.h"
26#include "scene/sceneRenderState.h"
27
28/*
29
30U32 TerrainRender::testSquareLights(GridSquare *sq, S32 level, const Point2I &pos, U32 lightMask)
31{
32   
33   // Calculate our Box3F for this GridSquare
34   Point3F boxMin(pos.x * mSquareSize + mBlockPos.x, pos.y * mSquareSize + mBlockPos.y, fixedToFloat(sq->minHeight));
35   F32 blockSize = F32(mSquareSize * (1 << level));
36   F32 blockHeight = fixedToFloat(sq->maxHeight - sq->minHeight);
37   Point3F boxMax(boxMin);
38   boxMax += Point3F(blockSize, blockSize, blockHeight);
39   Box3F gridBox(boxMin, boxMax);
40
41   U32 retMask = 0;
42
43   for(S32 i = 0; (lightMask >> i) != 0; i++)
44   {
45      if(lightMask & (1 << i))
46      {
47         if (mTerrainLights[i].light->mType != LightInfo::Vector)
48         {
49            // test the visibility of this light to box         
50            F32 dist = gridBox.getDistanceFromPoint(mTerrainLights[i].pos);
51            static F32 minDist = 1e14f;
52            minDist = getMin(minDist, dist);
53            if(dist < mTerrainLights[i].radius)
54               retMask |= (1 << i);
55         } else {
56            retMask  |= (1 << i);
57         }
58      }
59   }
60   return retMask;
61}
62
63void TerrainRender::buildLightArray(SceneState * state)
64{
65   PROFILE_SCOPE(TerrainRender_buildLightArray);
66
67   mDynamicLightCount = 0;
68   if ((mTerrainLighting == NULL) || (!TerrainRender::mEnableTerrainDynLights))
69      return;
70
71   static LightInfoList lights;
72   lights.clear();   
73
74   LIGHTMGR->getBestLights(lights);
75   // create terrain lights from these...
76   U32 curIndex = 0;
77   for(U32 i = 0; i < lights.size(); i++)
78   {
79      LightInfo* light = lights[i];
80      if((light->mType != LightInfo::Point) && (light->mType != LightInfo::Spot))
81         continue;
82
83      // set the 'fo
84      TerrLightInfo & info = mTerrainLights[curIndex++];
85      mCurrentBlock->getWorldTransform().mulP(light->mPos, &info.pos);
86      info.radius = light->getRadius();
87      info.light = light;
88   }
89
90   mDynamicLightCount = curIndex;
91}
92
93*/
94