[Gameplay] Reduce loom cost
[0ad.git] / source / graphics / LightEnv.h
blobd97383f7fa67e1bcd5058ca4a19e2af21d747b98
1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
19 * CLightEnv, a class describing the current lights
22 #ifndef INCLUDED_LIGHTENV
23 #define INCLUDED_LIGHTENV
25 #include "graphics/Color.h"
26 #include "maths/MathUtil.h"
27 #include "maths/Vector3D.h"
29 class CMapWriter;
30 class CMapReader;
32 /**
33 * Class CLightEnv: description of a lighting environment - contains all the
34 * necessary parameters for representation of the lighting within a scenario
36 class CLightEnv
38 public:
39 RGBColor m_SunColor;
40 RGBColor m_AmbientColor;
41 RGBColor m_FogColor;
43 float m_FogFactor;
44 float m_FogMax;
46 float m_Brightness, m_Contrast, m_Saturation, m_Bloom;
48 CLightEnv();
50 float GetElevation() const { return m_Elevation; }
51 float GetRotation() const { return m_Rotation; }
52 const CVector3D& GetSunDir() const { return m_SunDir; }
54 void SetElevation(float f);
55 void SetRotation(float f);
57 /**
58 * Calculate brightness of a point of a unit with the given normal vector,
59 * for rendering with CPU lighting.
60 * The resulting color contains both ambient and diffuse light.
61 * To cope with sun overbrightness, the color is scaled by 0.5.
63 * @param normal normal vector (must have length 1)
65 RGBColor EvaluateUnitScaled(const CVector3D& normal) const
67 float dot = -normal.Dot(m_SunDir);
69 RGBColor color = m_AmbientColor;
70 if (dot > 0)
71 color += m_SunColor * dot;
73 return color * 0.5f;
76 // Comparison operators
77 bool operator==(const CLightEnv& o) const
79 return m_Elevation == o.m_Elevation &&
80 m_Rotation == o.m_Rotation &&
81 m_SunColor == o.m_SunColor &&
82 m_AmbientColor == o.m_AmbientColor &&
83 m_FogColor == o.m_FogColor &&
84 m_FogFactor == o.m_FogFactor &&
85 m_FogMax == o.m_FogMax &&
86 m_Brightness == o.m_Brightness &&
87 m_Contrast == o.m_Contrast &&
88 m_Saturation == o.m_Saturation &&
89 m_Bloom == o.m_Bloom;
92 bool operator!=(const CLightEnv& o) const
94 return !(*this == o);
97 private:
98 friend class CMapWriter;
99 friend class CMapReader;
100 friend class CXMLReader;
103 * Height of sun above the horizon, in radians.
104 * For example, an elevation of M_PI/2 means the sun is straight up.
106 float m_Elevation;
109 * Direction of sun on the compass, in radians.
110 * For example, a rotation of zero means the sun is in the direction (0,0,-1)
111 * and a rotation of M_PI/2 means the sun is in the direction (1,0,0) (not taking
112 * elevation into account).
114 float m_Rotation;
117 * Vector corresponding to m_Elevation and m_Rotation.
118 * Updated by CalculateSunDirection.
120 CVector3D m_SunDir;
122 void CalculateSunDirection();
125 #endif // INCLUDED_LIGHTENV