Skylicht Engine
Loading...
Searching...
No Matches
CLight.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "Components/CComponentSystem.h"
28#include "CLightCullingData.h"
29
30namespace Skylicht
31{
34 class SKYLICHT_API CLight : public CComponentSystem
35 {
36 public:
37 enum ERenderLightType
38 {
39 Realtime = 0,
40 Baked,
41 Mixed
42 };
43
44 enum ELightType
45 {
46 DirectionalLight = 0,
47 PointLight,
48 SpotLight,
49 AreaLight
50 };
51
52 protected:
54 SColorf m_color;
55
57
60
62 float m_radius;
63
66 float m_spotInnerCutoff;
67 float m_spotExponent;
68
70
71 core::vector3df m_direction;
72
75
78
81
84
86 ERenderLightType m_renderType;
87
90
93
94 bool m_needValidate;
95
96 CLightCullingData* m_cullingData;
97
98 ITexture* m_shadowTex;
99
100 float* m_shadowMatrices;
101 public:
102 CLight();
103
104 virtual ~CLight();
105
106 virtual CObjectSerializable* createSerializable();
107
108 virtual void loadSerializable(CObjectSerializable* object);
109
110 inline const SColorf& getColor()
111 {
112 return m_color;
113 }
114
115 inline void setColor(const SColorf& c)
116 {
117 m_color = c;
118 }
119
120 inline float getAttenuation()
121 {
122 return m_attenuation;
123 }
124
125 inline float getRadius()
126 {
127 return m_radius;
128 }
129
130 core::aabbox3df getBBBox();
131
132 inline ERenderLightType getRenderLightType()
133 {
134 return m_renderType;
135 }
136
137 virtual void setRenderLightType(ERenderLightType type)
138 {
139 m_renderType = type;
140 }
141
142 inline int getLightTypeId()
143 {
144 return m_cullingData->LightType;
145 }
146
147 inline void setBounce(u32 b)
148 {
149 m_bakeBounce = b;
150 }
151
152 inline u32 getBounce()
153 {
154 return m_bakeBounce;
155 }
156
157 void setRadius(float r)
158 {
159 r = core::max_(r, 0.01f);
160 m_radius = r;
161 m_attenuation = 1.0f / m_radius;
162 }
163
164 inline void setSpotAngle(float angle)
165 {
166 m_spotCutoff = angle;
167 }
168
169 inline float getSplotCutoff()
170 {
171 return m_spotCutoff;
172 }
173
174 inline void setSpotInnerAngle(float angle)
175 {
176 m_spotInnerCutoff = angle;
177 }
178
179 inline float getSpotInnerCutof()
180 {
181 return m_spotInnerCutoff;
182 }
183
184 inline void setSpotExponent(float e)
185 {
186 m_spotExponent = e;
187 }
188
189 inline float getSpotExponent()
190 {
191 return m_spotExponent;
192 }
193
194 inline core::vector3df& getDirection()
195 {
196 return m_direction;
197 }
198
199 inline bool isCastShadow()
200 {
201 return m_castShadow;
202 }
203
204 inline void setShadow(bool shadow)
205 {
206 m_castShadow = shadow;
207 m_shadowTex = NULL;
208 }
209
210 inline bool isDynamicShadow()
211 {
212 return m_dynamicShadow;
213 }
214
215 inline void setDynamicShadow(bool shadow)
216 {
217 m_dynamicShadow = shadow;
218 m_shadowTex = NULL;
219 }
220
221 inline void setIntensity(float f)
222 {
223 m_intensity = f;
224 }
225
226 inline float getIntensity()
227 {
228 return m_intensity;
229 }
230
231 inline u32 getLightLayers()
232 {
233 return m_lightLayers;
234 }
235
236 inline void setLightLayers(u32 layers)
237 {
238 m_lightLayers = layers;
239 }
240
241 inline bool isAffectingDefaultObjects()
242 {
243 return m_lightLayers & 1;
244 }
245
246 inline void setLightPriority(u32 priority)
247 {
248 m_lightPriority = priority;
249 }
250
251 inline u32 getLightPriority()
252 {
253 return m_lightPriority;
254 }
255
256 inline void validate()
257 {
258 m_needValidate = true;
259 }
260
261 inline ITexture* getShadowTexture()
262 {
263 return m_shadowTex;
264 }
265
266 inline void setShadowTexture(ITexture* tex)
267 {
268 m_shadowTex = tex;
269 }
270
271 void setShadowMatrices(float* m);
272
273 inline float* getShadowMatrices()
274 {
275 return m_shadowMatrices;
276 }
277 };
278}
Definition CLightCullingData.h:34
float m_attenuation
Attenuation factors (constant, linear, quadratic).
Definition CLight.h:59
u32 m_lightPriority
Priority order of lights selected for shaders.
Definition CLight.h:92
float m_spotCutoff
The angle of the spot's outer cone. Ignored for other lights.
Definition CLight.h:65
float m_intensity
Intensity of light.
Definition CLight.h:80
ERenderLightType m_renderType
Light type.
Definition CLight.h:86
SColorf m_color
Diffuse color emitted by the light.
Definition CLight.h:54
u32 m_lightLayers
The layers where the light will shine on.
Definition CLight.h:89
float m_radius
Radius of light. Everything within this radius will be lighted.
Definition CLight.h:62
bool m_castShadow
Does the light cast shadows?
Definition CLight.h:74
bool m_dynamicShadow
Does this shadow alway updates.
Definition CLight.h:77
u32 m_bakeBounce
Number bounce of light on bake lighting.
Definition CLight.h:83
core::vector3df m_direction
Direction of the light.
Definition CLight.h:71
Definition CObjectSerializable.h:36
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58