BVB Source Codes

CRYENGINE Show LightVolumeManager.h Source code

Return Download CRYENGINE: download LightVolumeManager.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #define LV_MAX_COUNT                256
  6. #define LV_LIGHTS_MAX_COUNT         64
  7.  
  8. #define LV_WORLD_BUCKET_SIZE        512
  9. #define LV_LIGHTS_WORLD_BUCKET_SIZE 512
  10.  
  11. #define LV_WORLD_SIZEX              128
  12. #define LV_WORLD_SIZEY              128
  13. #define LV_WORLD_SIZEZ              64
  14.  
  15. #define LV_CELL_SIZEX               4
  16. #define LV_CELL_SIZEY               4
  17. #define LV_CELL_SIZEZ               8
  18.  
  19. #define LV_CELL_RSIZEX              (1.0f / (float)LV_CELL_SIZEX)
  20. #define LV_CELL_RSIZEY              (1.0f / (float)LV_CELL_SIZEY)
  21. #define LV_CELL_RSIZEZ              (1.0f / (float)LV_CELL_SIZEZ)
  22.  
  23. #define LV_LIGHT_CELL_SIZE          32
  24. #define LV_LIGHT_CELL_R_SIZE        (1.0f / (float)LV_LIGHT_CELL_SIZE)
  25.  
  26. #define LV_DLF_LIGHTVOLUMES_MASK    (DLF_DISABLED | DLF_FAKE | DLF_AMBIENT | DLF_DEFERRED_CUBEMAPS)
  27.  
  28. class CLightVolumesMgr : public Cry3DEngineBase
  29. {
  30. public:
  31.         CLightVolumesMgr()
  32.         {
  33.                 Init();
  34.         }
  35.  
  36.         void   Init();
  37.         void   Reset();
  38.         uint16 RegisterVolume(const Vec3& vPos, f32 fRadius, uint8 nClipVolumeRef, const SRenderingPassInfo& passInfo);
  39.         void   RegisterLight(const CDLight& pDL, uint32 nLightID, const SRenderingPassInfo& passInfo);
  40.         void   Update(const SRenderingPassInfo& passInfo);
  41.         void   Clear(const SRenderingPassInfo& passInfo);
  42.         void   GetLightVolumes(threadID nThreadID, SLightVolume*& pLightVols, uint32& nNumVols);
  43.         void   DrawDebug(const SRenderingPassInfo& passInfo);
  44.  
  45. private:
  46.         struct SLightVolInfo
  47.         {
  48.                 SLightVolInfo() : vVolume(ZERO, 0.0f), nNextVolume(0), nClipVolumeID(0)
  49.                 {
  50.                 };
  51.                 SLightVolInfo(const Vec3& pPos, float fRad, uint8 clipVolumeID)
  52.                         : vVolume(pPos, fRad), nNextVolume(0), nClipVolumeID(clipVolumeID)
  53.                 {
  54.                 };
  55.  
  56.                 Vec4   vVolume;       // xyz: position, w: radius
  57.                 uint16 nNextVolume;   // index of next light volume for this hash bucket (0 if none)
  58.                 uint8  nClipVolumeID; // clip volume stencil ref
  59.         };
  60.  
  61.         struct SLightCell
  62.         {
  63.                 SLightCell() : nLightCount(0)
  64.                 {
  65.                 };
  66.  
  67.                 uint16 nLightID[LV_LIGHTS_MAX_COUNT];
  68.                 uint8  nLightCount;
  69.         };
  70.  
  71.         inline int32 GetIntHash(const int32 k, const int32 nBucketSize = LV_WORLD_BUCKET_SIZE) const
  72.         {
  73.                 static const uint32 nHashBits = 9;
  74.                 static const uint32 nGoldenRatio32bits = 2654435761u; // (2^32) / (golden ratio)
  75.                 return (k * nGoldenRatio32bits) >> (32 - nHashBits);  // ref: knuths integer multiplicative hash function
  76.         }
  77.  
  78.         inline uint16 GetWorldHashBucketKey(const int32 x, const int32 y, const int32 z, const int32 nBucketSize = LV_WORLD_BUCKET_SIZE) const
  79.         {
  80.                 const uint32 nPrimeNum = 101;//0xd8163841;
  81.                 return (((GetIntHash(x) + nPrimeNum) * nPrimeNum + GetIntHash(y)) * nPrimeNum + GetIntHash(z)) & (nBucketSize - 1);
  82.         }
  83.  
  84.         void AddLight(const SRenderLight& pLight, const SLightVolInfo* __restrict pVolInfo, SLightVolume& pVolume);
  85.  
  86.         typedef DynArray<SLightVolume> LightVolumeVector;
  87.  
  88. private:
  89.         LightVolumeVector                           m_pLightVolumes[RT_COMMAND_BUF_COUNT]; // Final light volume list. <todo> move light list creation to renderer to avoid double-buffering this
  90.         CThreadSafeRendererContainer<SLightVolInfo> m_pLightVolsInfo;                      // World cells data
  91.         SLightCell m_pWorldLightCells[LV_LIGHTS_WORLD_BUCKET_SIZE];                        // 2D World cell buckets for light sources ids
  92.         uint16     m_nWorldCells[LV_WORLD_BUCKET_SIZE];                                    // World cell buckets for light volumes
  93.         bool       m_bUpdateLightVolumes : 1;
  94. };
  95.  
downloadLightVolumeManager.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top