Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.0 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. //
  3. // Classes to aid in transferring lightmap data (luxels) between BSPs.
  4. //
  5. //===============================================================================
  6. #ifndef LIGHTMAPTRANSFER_H
  7. #define LIGHTMAPTRANSFER_H
  8. #if defined( COMPILER_MSVC )
  9. #pragma once
  10. #endif
  11. #include "utlvector.h"
  12. #include "mathlib/vector.h"
  13. #include "mathlib/intvector3d.h"
  14. #include "bspfile.h"
  15. class CMemoryBSPFile;
  16. //-----------------------------------------------------------------------------
  17. // A class which acts as a spatial hash for lightmap values.
  18. // Multiple source files can be processed into the hash such that every single
  19. // lightmap sample has its own entry in the hash.
  20. // This data can then be copied into the lightmap lump of a given BSP file.
  21. //-----------------------------------------------------------------------------
  22. class CLuxelHash
  23. {
  24. public:
  25. CLuxelHash( int nHashBucketCount );
  26. //-----------------------------------------------------------------------------
  27. // Adds all of the luxels in the source BSP file to a spatial hash.
  28. // vOffset is the world-space translation to add to all coordinates in the
  29. // source BSP file.
  30. //-----------------------------------------------------------------------------
  31. void AddSourceBSPFile( const CMemoryBSPFile *pSourceBSPFile, const Vector &vOffset );
  32. //-----------------------------------------------------------------------------
  33. // Copies lighting from the luxel hash into the target BSP file.
  34. // Values which are not found are initialized to black.
  35. //-----------------------------------------------------------------------------
  36. void CopyLighting( CMemoryBSPFile *pTargetBSPFile ) const;
  37. private:
  38. // nDataLength is the number of ColorRGBExp32 (4 bytes each) per luxel.
  39. // This is typically 1 for lightmaps without bump light information, or 4 for those with.
  40. void AddLuxel( const Vector &vPosition, const Vector &vNormal, const ColorRGBExp32 *pLuxelData, int nDataLength );
  41. bool FindLuxel( const Vector &vPosition, const Vector &vNormal, const ColorRGBExp32 **ppLuxelData, int *pDataLength ) const;
  42. void CopyFaceLighting( CMemoryBSPFile *pTargetBSPFile, int nFace ) const;
  43. void CopyWorldLights( CMemoryBSPFile *pTargetBSPFile ) const;
  44. // Hashes the position and returns a hash bucket index in the range [ 0, m_HashEntries.Count() )
  45. int GetGridEntry( const IntVector3D &vIntegerPosition ) const;
  46. struct LuxelHashEntry_t
  47. {
  48. Vector m_vPosition;
  49. Vector m_vNormal;
  50. int m_nDataStart;
  51. int m_nDataLength;
  52. int m_nNextEntryIndex;
  53. };
  54. CUtlVector< ColorRGBExp32 > m_LuxelData; // Contiguous luxel data
  55. CUtlVector< LuxelHashEntry_t > m_HashEntries; // Pool of hash entry linked list nodes, one per luxel
  56. CUtlVector< dworldlight_t > m_WorldLightsLDR;
  57. CUtlVector< dworldlight_t > m_WorldLightsHDR;
  58. CUtlVector< int > m_UniformGrid; // 3D grid of indices into a linked list of LuxelHashEntry_t (-1 means no entry)
  59. };
  60. #endif // LIGHTMAPTRANSFER_H