1 /**
2 Provides a base class for different kinds of light nodes.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.light;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.visualinstance;
24 /**
25 Provides a base class for different kinds of light nodes.
26 
27 Light is the $(I abstract) base class for light nodes. As it can't be instanced, it shouldn't be used directly. Other types of light nodes inherit from it. Light contains the common variables and parameters used for lighting.
28 */
29 @GodotBaseClass struct Light
30 {
31 	package(godot) enum string _GODOT_internal_name = "Light";
32 public:
33 @nogc nothrow:
34 	union { /** */ godot_object _godot_object; /** */ VisualInstance _GODOT_base; }
35 	alias _GODOT_base this;
36 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
37 	package(godot) __gshared bool _classBindingInitialized = false;
38 	package(godot) static struct GDNativeClassBinding
39 	{
40 		__gshared:
41 		@GodotName("get_bake_mode") GodotMethod!(Light.BakeMode) getBakeMode;
42 		@GodotName("get_color") GodotMethod!(Color) getColor;
43 		@GodotName("get_cull_mask") GodotMethod!(long) getCullMask;
44 		@GodotName("get_param") GodotMethod!(double, long) getParam;
45 		@GodotName("get_shadow_color") GodotMethod!(Color) getShadowColor;
46 		@GodotName("get_shadow_reverse_cull_face") GodotMethod!(bool) getShadowReverseCullFace;
47 		@GodotName("has_shadow") GodotMethod!(bool) hasShadow;
48 		@GodotName("is_editor_only") GodotMethod!(bool) isEditorOnly;
49 		@GodotName("is_negative") GodotMethod!(bool) isNegative;
50 		@GodotName("set_bake_mode") GodotMethod!(void, long) setBakeMode;
51 		@GodotName("set_color") GodotMethod!(void, Color) setColor;
52 		@GodotName("set_cull_mask") GodotMethod!(void, long) setCullMask;
53 		@GodotName("set_editor_only") GodotMethod!(void, bool) setEditorOnly;
54 		@GodotName("set_negative") GodotMethod!(void, bool) setNegative;
55 		@GodotName("set_param") GodotMethod!(void, long, double) setParam;
56 		@GodotName("set_shadow") GodotMethod!(void, bool) setShadow;
57 		@GodotName("set_shadow_color") GodotMethod!(void, Color) setShadowColor;
58 		@GodotName("set_shadow_reverse_cull_face") GodotMethod!(void, bool) setShadowReverseCullFace;
59 	}
60 	/// 
61 	pragma(inline, true) bool opEquals(in Light other) const
62 	{ return _godot_object.ptr is other._godot_object.ptr; }
63 	/// 
64 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
65 	{ _godot_object.ptr = n; return null; }
66 	/// 
67 	pragma(inline, true) bool opEquals(typeof(null) n) const
68 	{ return _godot_object.ptr is n; }
69 	/// 
70 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
71 	mixin baseCasts;
72 	/// Construct a new instance of Light.
73 	/// Note: use `memnew!Light` instead.
74 	static Light _new()
75 	{
76 		static godot_class_constructor constructor;
77 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Light");
78 		if(constructor is null) return typeof(this).init;
79 		return cast(Light)(constructor());
80 	}
81 	@disable new(size_t s);
82 	/// 
83 	enum BakeMode : int
84 	{
85 		/**
86 		Light is ignored when baking.
87 		$(B Note:) Hiding a light does $(I not) affect baking.
88 		*/
89 		bakeDisabled = 0,
90 		/**
91 		Only indirect lighting will be baked (default).
92 		*/
93 		bakeIndirect = 1,
94 		/**
95 		Both direct and indirect light will be baked.
96 		$(B Note:) You should hide the light if you don't want it to appear twice (dynamic and baked).
97 		*/
98 		bakeAll = 2,
99 	}
100 	/// 
101 	enum Param : int
102 	{
103 		/**
104 		Constant for accessing $(D lightEnergy).
105 		*/
106 		paramEnergy = 0,
107 		/**
108 		Constant for accessing $(D lightIndirectEnergy).
109 		*/
110 		paramIndirectEnergy = 1,
111 		/**
112 		Constant for accessing $(D lightSpecular).
113 		*/
114 		paramSpecular = 2,
115 		/**
116 		Constant for accessing $(D OmniLight.omniRange) or $(D SpotLight.spotRange).
117 		*/
118 		paramRange = 3,
119 		/**
120 		Constant for accessing $(D OmniLight.omniAttenuation) or $(D SpotLight.spotAttenuation).
121 		*/
122 		paramAttenuation = 4,
123 		/**
124 		Constant for accessing $(D SpotLight.spotAngle).
125 		*/
126 		paramSpotAngle = 5,
127 		/**
128 		Constant for accessing $(D SpotLight.spotAngleAttenuation).
129 		*/
130 		paramSpotAttenuation = 6,
131 		/**
132 		Constant for accessing $(D shadowContact).
133 		*/
134 		paramContactShadowSize = 7,
135 		/**
136 		Constant for accessing $(D DirectionalLight.directionalShadowMaxDistance).
137 		*/
138 		paramShadowMaxDistance = 8,
139 		/**
140 		Constant for accessing $(D DirectionalLight.directionalShadowSplit1).
141 		*/
142 		paramShadowSplit1Offset = 9,
143 		/**
144 		Constant for accessing $(D DirectionalLight.directionalShadowSplit2).
145 		*/
146 		paramShadowSplit2Offset = 10,
147 		/**
148 		Constant for accessing $(D DirectionalLight.directionalShadowSplit3).
149 		*/
150 		paramShadowSplit3Offset = 11,
151 		/**
152 		Constant for accessing $(D DirectionalLight.directionalShadowNormalBias).
153 		*/
154 		paramShadowNormalBias = 12,
155 		/**
156 		Constant for accessing $(D shadowBias).
157 		*/
158 		paramShadowBias = 13,
159 		/**
160 		Constant for accessing $(D DirectionalLight.directionalShadowBiasSplitScale).
161 		*/
162 		paramShadowBiasSplitScale = 14,
163 		/**
164 		Represents the size of the $(D param) enum.
165 		*/
166 		paramMax = 15,
167 	}
168 	/// 
169 	enum Constants : int
170 	{
171 		paramEnergy = 0,
172 		bakeDisabled = 0,
173 		paramIndirectEnergy = 1,
174 		bakeIndirect = 1,
175 		paramSpecular = 2,
176 		bakeAll = 2,
177 		paramRange = 3,
178 		paramAttenuation = 4,
179 		paramSpotAngle = 5,
180 		paramSpotAttenuation = 6,
181 		paramContactShadowSize = 7,
182 		paramShadowMaxDistance = 8,
183 		paramShadowSplit1Offset = 9,
184 		paramShadowSplit2Offset = 10,
185 		paramShadowSplit3Offset = 11,
186 		paramShadowNormalBias = 12,
187 		paramShadowBias = 13,
188 		paramShadowBiasSplitScale = 14,
189 		paramMax = 15,
190 	}
191 	/**
192 	
193 	*/
194 	Light.BakeMode getBakeMode() const
195 	{
196 		checkClassBinding!(typeof(this))();
197 		return ptrcall!(Light.BakeMode)(GDNativeClassBinding.getBakeMode, _godot_object);
198 	}
199 	/**
200 	
201 	*/
202 	Color getColor() const
203 	{
204 		checkClassBinding!(typeof(this))();
205 		return ptrcall!(Color)(GDNativeClassBinding.getColor, _godot_object);
206 	}
207 	/**
208 	
209 	*/
210 	long getCullMask() const
211 	{
212 		checkClassBinding!(typeof(this))();
213 		return ptrcall!(long)(GDNativeClassBinding.getCullMask, _godot_object);
214 	}
215 	/**
216 	Returns the value of the specified $(D Light.param) parameter.
217 	*/
218 	double getParam(in long param) const
219 	{
220 		checkClassBinding!(typeof(this))();
221 		return ptrcall!(double)(GDNativeClassBinding.getParam, _godot_object, param);
222 	}
223 	/**
224 	
225 	*/
226 	Color getShadowColor() const
227 	{
228 		checkClassBinding!(typeof(this))();
229 		return ptrcall!(Color)(GDNativeClassBinding.getShadowColor, _godot_object);
230 	}
231 	/**
232 	
233 	*/
234 	bool getShadowReverseCullFace() const
235 	{
236 		checkClassBinding!(typeof(this))();
237 		return ptrcall!(bool)(GDNativeClassBinding.getShadowReverseCullFace, _godot_object);
238 	}
239 	/**
240 	
241 	*/
242 	bool hasShadow() const
243 	{
244 		checkClassBinding!(typeof(this))();
245 		return ptrcall!(bool)(GDNativeClassBinding.hasShadow, _godot_object);
246 	}
247 	/**
248 	
249 	*/
250 	bool isEditorOnly() const
251 	{
252 		checkClassBinding!(typeof(this))();
253 		return ptrcall!(bool)(GDNativeClassBinding.isEditorOnly, _godot_object);
254 	}
255 	/**
256 	
257 	*/
258 	bool isNegative() const
259 	{
260 		checkClassBinding!(typeof(this))();
261 		return ptrcall!(bool)(GDNativeClassBinding.isNegative, _godot_object);
262 	}
263 	/**
264 	
265 	*/
266 	void setBakeMode(in long bake_mode)
267 	{
268 		checkClassBinding!(typeof(this))();
269 		ptrcall!(void)(GDNativeClassBinding.setBakeMode, _godot_object, bake_mode);
270 	}
271 	/**
272 	
273 	*/
274 	void setColor(in Color color)
275 	{
276 		checkClassBinding!(typeof(this))();
277 		ptrcall!(void)(GDNativeClassBinding.setColor, _godot_object, color);
278 	}
279 	/**
280 	
281 	*/
282 	void setCullMask(in long cull_mask)
283 	{
284 		checkClassBinding!(typeof(this))();
285 		ptrcall!(void)(GDNativeClassBinding.setCullMask, _godot_object, cull_mask);
286 	}
287 	/**
288 	
289 	*/
290 	void setEditorOnly(in bool editor_only)
291 	{
292 		checkClassBinding!(typeof(this))();
293 		ptrcall!(void)(GDNativeClassBinding.setEditorOnly, _godot_object, editor_only);
294 	}
295 	/**
296 	
297 	*/
298 	void setNegative(in bool enabled)
299 	{
300 		checkClassBinding!(typeof(this))();
301 		ptrcall!(void)(GDNativeClassBinding.setNegative, _godot_object, enabled);
302 	}
303 	/**
304 	Sets the value of the specified $(D Light.param) parameter.
305 	*/
306 	void setParam(in long param, in double value)
307 	{
308 		checkClassBinding!(typeof(this))();
309 		ptrcall!(void)(GDNativeClassBinding.setParam, _godot_object, param, value);
310 	}
311 	/**
312 	
313 	*/
314 	void setShadow(in bool enabled)
315 	{
316 		checkClassBinding!(typeof(this))();
317 		ptrcall!(void)(GDNativeClassBinding.setShadow, _godot_object, enabled);
318 	}
319 	/**
320 	
321 	*/
322 	void setShadowColor(in Color shadow_color)
323 	{
324 		checkClassBinding!(typeof(this))();
325 		ptrcall!(void)(GDNativeClassBinding.setShadowColor, _godot_object, shadow_color);
326 	}
327 	/**
328 	
329 	*/
330 	void setShadowReverseCullFace(in bool enable)
331 	{
332 		checkClassBinding!(typeof(this))();
333 		ptrcall!(void)(GDNativeClassBinding.setShadowReverseCullFace, _godot_object, enable);
334 	}
335 	/**
336 	If `true`, the light only appears in the editor and will not be visible at runtime.
337 	*/
338 	@property bool editorOnly()
339 	{
340 		return isEditorOnly();
341 	}
342 	/// ditto
343 	@property void editorOnly(bool v)
344 	{
345 		setEditorOnly(v);
346 	}
347 	/**
348 	The light's bake mode. See $(D bakemode).
349 	*/
350 	@property Light.BakeMode lightBakeMode()
351 	{
352 		return getBakeMode();
353 	}
354 	/// ditto
355 	@property void lightBakeMode(long v)
356 	{
357 		setBakeMode(v);
358 	}
359 	/**
360 	The light's color. An $(I overbright) color can be used to achieve a result equivalent to increasing the light's $(D lightEnergy).
361 	*/
362 	@property Color lightColor()
363 	{
364 		return getColor();
365 	}
366 	/// ditto
367 	@property void lightColor(Color v)
368 	{
369 		setColor(v);
370 	}
371 	/**
372 	The light will affect objects in the selected layers.
373 	*/
374 	@property long lightCullMask()
375 	{
376 		return getCullMask();
377 	}
378 	/// ditto
379 	@property void lightCullMask(long v)
380 	{
381 		setCullMask(v);
382 	}
383 	/**
384 	The light's strength multiplier (this is not a physical unit). For $(D OmniLight) and $(D SpotLight), changing this value will only change the light color's intensity, not the light's radius.
385 	*/
386 	@property double lightEnergy()
387 	{
388 		return getParam(0);
389 	}
390 	/// ditto
391 	@property void lightEnergy(double v)
392 	{
393 		setParam(0, v);
394 	}
395 	/**
396 	Secondary multiplier used with indirect light (light bounces). This works on both $(D BakedLightmap) and $(D GIProbe).
397 	*/
398 	@property double lightIndirectEnergy()
399 	{
400 		return getParam(1);
401 	}
402 	/// ditto
403 	@property void lightIndirectEnergy(double v)
404 	{
405 		setParam(1, v);
406 	}
407 	/**
408 	If `true`, the light's effect is reversed, darkening areas and casting bright shadows.
409 	*/
410 	@property bool lightNegative()
411 	{
412 		return isNegative();
413 	}
414 	/// ditto
415 	@property void lightNegative(bool v)
416 	{
417 		setNegative(v);
418 	}
419 	/**
420 	The intensity of the specular blob in objects affected by the light. At `0`, the light becomes a pure diffuse light. When not baking emission, this can be used to avoid unrealistic reflections when placing lights above an emissive surface.
421 	*/
422 	@property double lightSpecular()
423 	{
424 		return getParam(2);
425 	}
426 	/// ditto
427 	@property void lightSpecular(double v)
428 	{
429 		setParam(2, v);
430 	}
431 	/**
432 	Used to adjust shadow appearance. Too small a value results in self-shadowing ("shadow acne"), while too large a value causes shadows to separate from casters ("peter-panning"). Adjust as needed.
433 	*/
434 	@property double shadowBias()
435 	{
436 		return getParam(13);
437 	}
438 	/// ditto
439 	@property void shadowBias(double v)
440 	{
441 		setParam(13, v);
442 	}
443 	/**
444 	The color of shadows cast by this light.
445 	*/
446 	@property Color shadowColor()
447 	{
448 		return getShadowColor();
449 	}
450 	/// ditto
451 	@property void shadowColor(Color v)
452 	{
453 		setShadowColor(v);
454 	}
455 	/**
456 	Attempts to reduce $(D shadowBias) gap.
457 	*/
458 	@property double shadowContact()
459 	{
460 		return getParam(7);
461 	}
462 	/// ditto
463 	@property void shadowContact(double v)
464 	{
465 		setParam(7, v);
466 	}
467 	/**
468 	If `true`, the light will cast shadows.
469 	*/
470 	@property bool shadowEnabled()
471 	{
472 		return hasShadow();
473 	}
474 	/// ditto
475 	@property void shadowEnabled(bool v)
476 	{
477 		setShadow(v);
478 	}
479 	/**
480 	If `true`, reverses the backface culling of the mesh. This can be useful when you have a flat mesh that has a light behind it. If you need to cast a shadow on both sides of the mesh, set the mesh to use double-sided shadows with $(D constant GeometryInstance.SHADOW_CASTING_SETTING_DOUBLE_SIDED).
481 	*/
482 	@property bool shadowReverseCullFace()
483 	{
484 		return getShadowReverseCullFace();
485 	}
486 	/// ditto
487 	@property void shadowReverseCullFace(bool v)
488 	{
489 		setShadowReverseCullFace(v);
490 	}
491 }