lightenvironment.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/lightenvironment.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Naty_h $*
  29. * *
  30. * $Modtime:: 4/01/01 12:01a $*
  31. * *
  32. * $Revision:: 4 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef LIGHTENVIRONMENT_H
  41. #define LIGHTENVIRONMENT_H
  42. #include "always.h"
  43. #include "vector3.h"
  44. class Matrix3D;
  45. class LightClass;
  46. /**
  47. ** LightEnvironmentClass
  48. ** This class represents an approximation of the local lighting for a given point. The idea
  49. ** is to collect all of the point light sources affecting an object at any given time and
  50. ** create temporary directional light sources representing them. Any distance or directional
  51. ** attenuation will be precalculated into the overall intensity of the light and a vector from
  52. ** the light source to the center of the bounding sphere of the model will be used as the
  53. ** directional component.
  54. ** In addition, the engine will provide the ambient component which will be determined by
  55. ** a combination of the ambient setting for the level and sampling the light maps in the area.
  56. **
  57. ** Notes:
  58. ** - will need fast collection of the lights affecting any one given object
  59. ** - intensity of these lights should take into account attenuation of the original light
  60. ** - intensity should also take into account spot attenuation (no-per vertex atten...)
  61. ** - we need the direction of the lights in eye-space
  62. ** - the ambient light from all lights should be added into the ambient light (not just scene)
  63. */
  64. class LightEnvironmentClass
  65. {
  66. public:
  67. LightEnvironmentClass(void);
  68. ~LightEnvironmentClass(void);
  69. /*
  70. ** Usage (starting from scratch each frame):
  71. ** - Reset the object
  72. ** - Set the scene ambient light (will be derived from lightmap sampling probably)
  73. ** - Add in all overlapping lights, this object will keep the most important ones
  74. ** - When ready to render, call Pre_Render_Update and push into the gerd.
  75. **
  76. ** Usage (caching the lights, only done if the object and the lights are not moving)
  77. ** - Reset and collect the lights once and keep this object around
  78. ** - When ready to render, call Pre_Render_Update and push into the gerd.
  79. */
  80. void Reset(const Vector3 & object_center,const Vector3 & scene_ambient);
  81. void Add_Light(const LightClass & light);
  82. void Pre_Render_Update(const Matrix3D & camera_tm);
  83. /*
  84. ** Accessors
  85. */
  86. const Vector3 & Get_Equivalent_Ambient(void) const { return OutputAmbient; }
  87. int Get_Light_Count(void) const { return LightCount; }
  88. const Vector3 & Get_Light_Direction(int i) const { return InputLights[i].Direction; }
  89. const Vector3 & Get_Light_Diffuse(int i) const { return InputLights[i].Diffuse; }
  90. /*
  91. ** Lighting LOD. This is a static setting that is used to convert weak diffuse lights
  92. ** into pure ambient lights.
  93. */
  94. static void Set_Lighting_LOD_Cutoff(float inten);
  95. static float Get_Lighting_LOD_Cutoff(void);
  96. protected:
  97. enum { MAX_LIGHTS = 4 };
  98. struct InputLightStruct
  99. {
  100. void Init(const LightClass & light,const Vector3 & object_center);
  101. void Init_From_Point_Or_Spot_Light(const LightClass & light,const Vector3 & object_center);
  102. void Init_From_Directional_Light(const LightClass & light,const Vector3 & object_center);
  103. float Contribution(void);
  104. Vector3 Direction;
  105. Vector3 Ambient;
  106. Vector3 Diffuse;
  107. bool DiffuseRejected;
  108. };
  109. struct OutputLightStruct
  110. {
  111. void Init(const InputLightStruct & input,const Matrix3D & camera_tm);
  112. Vector3 Direction; // direction to the light.
  113. Vector3 Diffuse; // diffuse color * attenuation
  114. };
  115. /*
  116. ** Member variables
  117. */
  118. int LightCount;
  119. Vector3 ObjectCenter; // center of the object to be lit
  120. InputLightStruct InputLights[MAX_LIGHTS]; // input lights
  121. Vector3 OutputAmbient; // scene ambient + lights' ambients
  122. OutputLightStruct OutputLights[MAX_LIGHTS]; // ouput lights
  123. };
  124. #endif //LIGHTENVIRONMENT_H