terrLighting.cpp 3.2 KB

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