Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
lightenvironment.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(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/***********************************************************************************************
20 *** 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 ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWPhys *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/lightenvironment.h $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Kenny Mitchell $*
30 * *
31 * $Modtime:: 06/27/02 9:23a $*
32 * *
33 * $Revision:: 5 $*
34 * *
35 * 06/27/02 KM Shader system light environment updates *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40#if defined(_MSC_VER)
41#pragma once
42#endif
43
44#ifndef LIGHTENVIRONMENT_H
45#define LIGHTENVIRONMENT_H
46
47#include "always.h"
48#include "vector3.h"
49
50
51class Matrix3D;
52class LightClass;
53
54
74{
75public:
76
79
80 /*
81 ** Usage (starting from scratch each frame):
82 ** - Reset the object
83 ** - Set the scene ambient light (will be derived from lightmap sampling probably)
84 ** - Add in all overlapping lights, this object will keep the most important ones
85 ** - When ready to render, call Pre_Render_Update and push into the gerd.
86 **
87 ** Usage (caching the lights, only done if the object and the lights are not moving)
88 ** - Reset and collect the lights once and keep this object around
89 ** - When ready to render, call Pre_Render_Update and push into the gerd.
90 */
91 void Reset(const Vector3 & object_center,const Vector3 & scene_ambient);
92 void Add_Light(const LightClass & light);
93 void Pre_Render_Update(const Matrix3D & camera_tm);
94 void Add_Fill_Light(void);
95 void Calculate_Fill_Light(void);
96 void Set_Fill_Intensity(float intensity) { FillIntensity = intensity; }
97
98 /*
99 ** Accessors
100 */
101 const Vector3 & Get_Equivalent_Ambient(void) const { return OutputAmbient; }
103 int Get_Light_Count(void) const { return LightCount; }
104 const Vector3 & Get_Light_Direction(int i) const { return InputLights[i].Direction; }
105 const Vector3 & Get_Light_Diffuse(int i) const { return InputLights[i].Diffuse; }
106
107 bool isPointLight(int i) const {return InputLights[i].m_point;}
108 float getPointIrad(int i) const {return InputLights[i].m_innerRadius;}
109 float getPointOrad(int i) const {return InputLights[i].m_outerRadius;}
110 const Vector3 & getPointDiffuse(int i) const { return InputLights[i].m_diffuse; }
111 const Vector3 & getPointAmbient(int i) const { return InputLights[i].m_ambient; }
112 const Vector3 & getPointCenter(int i) const { return InputLights[i].m_center; }
113
114 /*
115 ** Lighting LOD. This is a static setting that is used to convert weak diffuse lights
116 ** into pure ambient lights.
117 */
118 static void Set_Lighting_LOD_Cutoff(float inten);
119 static float Get_Lighting_LOD_Cutoff(void);
120
121 static int Get_Max_Lights() { return MAX_LIGHTS; }
122 enum { MAX_LIGHTS = 4 }; //Made this public, so other code can tell how many lights are allowed. - MW
123
124 inline bool operator== (const LightEnvironmentClass& that) const
125 {
126 if (LightCount!=that.LightCount) return false;
127 bool dif=!(ObjectCenter==that.ObjectCenter);
128 dif|=OutputAmbient!=that.OutputAmbient;
129 for (int i=0;i<LightCount;++i) {
130 dif|=!(OutputLights[i].Diffuse==that.OutputLights[i].Diffuse);
131 dif|=!(OutputLights[i].Direction==that.OutputLights[i].Direction);
132 if (dif) return false;
133 }
134 return true;
135 }
136
137protected:
138
140 {
141 void Init(const LightClass & light,const Vector3 & object_center);
142 void Init_From_Point_Or_Spot_Light(const LightClass & light,const Vector3 & object_center);
143 void Init_From_Directional_Light(const LightClass & light,const Vector3 & object_center);
144 float Contribution(void);
145
150
157
158 };
159
161 {
162 void Init(const InputLightStruct & input,const Matrix3D & camera_tm);
163
164 Vector3 Direction; // direction to the light.
165 Vector3 Diffuse; // diffuse color * attenuation
166 };
167
168 /*
169 ** Member variables
170 */
172 Vector3 ObjectCenter; // center of the object to be lit
173 InputLightStruct InputLights[MAX_LIGHTS]; // Sorted list of input lights from the greatest contributor to the least
174
175 Vector3 OutputAmbient; // scene ambient + lights' ambients
177
178 InputLightStruct FillLight; // Used to store the calculated fill light
179 float FillIntensity; // Used to determine how strong the fill light should be
180};
181
182
183#endif //LIGHTENVIRONMENT_H
184
int Get_Light_Count(void) const
InputLightStruct InputLights[MAX_LIGHTS]
bool operator==(const LightEnvironmentClass &that) const
void Set_Fill_Intensity(float intensity)
bool isPointLight(int i) const
const Vector3 & getPointDiffuse(int i) const
void Set_Output_Ambient(Vector3 &oa)
const Vector3 & getPointAmbient(int i) const
const Vector3 & Get_Light_Direction(int i) const
void Pre_Render_Update(const Matrix3D &camera_tm)
static float Get_Lighting_LOD_Cutoff(void)
static void Set_Lighting_LOD_Cutoff(float inten)
OutputLightStruct OutputLights[MAX_LIGHTS]
void Reset(const Vector3 &object_center, const Vector3 &scene_ambient)
float getPointOrad(int i) const
const Vector3 & Get_Equivalent_Ambient(void) const
void Add_Light(const LightClass &light)
float getPointIrad(int i) const
const Vector3 & getPointCenter(int i) const
InputLightStruct FillLight
const Vector3 & Get_Light_Diffuse(int i) const
void Init_From_Point_Or_Spot_Light(const LightClass &light, const Vector3 &object_center)
void Init(const LightClass &light, const Vector3 &object_center)
void Init_From_Directional_Light(const LightClass &light, const Vector3 &object_center)
void Init(const InputLightStruct &input, const Matrix3D &camera_tm)