light.h
1 /*************************************************************************/
2 /* light.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef LIGHT_H
30 #define LIGHT_H
31 
32 
33 #include "scene/3d/visual_instance.h"
34 #include "scene/resources/texture.h"
35 #include "servers/visual_server.h"
36 
40 class Light : public VisualInstance {
41 
42  OBJ_TYPE( Light, VisualInstance );
43  OBJ_CATEGORY("3D Light Nodes");
44 
45 public:
46 
47  enum Parameter {
48  PARAM_RADIUS=VisualServer::LIGHT_PARAM_RADIUS,
49  PARAM_ENERGY=VisualServer::LIGHT_PARAM_ENERGY,
50  PARAM_ATTENUATION=VisualServer::LIGHT_PARAM_ATTENUATION,
51  PARAM_SPOT_ANGLE=VisualServer::LIGHT_PARAM_SPOT_ANGLE,
52  PARAM_SPOT_ATTENUATION=VisualServer::LIGHT_PARAM_SPOT_ATTENUATION,
53  PARAM_SHADOW_DARKENING=VisualServer::LIGHT_PARAM_SHADOW_DARKENING,
54  PARAM_SHADOW_Z_OFFSET=VisualServer::LIGHT_PARAM_SHADOW_Z_OFFSET,
55  PARAM_SHADOW_Z_SLOPE_SCALE=VisualServer::LIGHT_PARAM_SHADOW_Z_SLOPE_SCALE,
56  PARAM_SHADOW_ESM_MULTIPLIER=VisualServer::LIGHT_PARAM_SHADOW_ESM_MULTIPLIER,
57  PARAM_SHADOW_BLUR_PASSES=VisualServer::LIGHT_PARAM_SHADOW_BLUR_PASSES,
58  PARAM_MAX=VisualServer::LIGHT_PARAM_MAX
59  };
60 
61 
62  enum LightColor {
63 
64  COLOR_DIFFUSE=VisualServer::LIGHT_COLOR_DIFFUSE,
65  COLOR_SPECULAR=VisualServer::LIGHT_COLOR_SPECULAR
66  };
67 
68  enum BakeMode {
69 
70  BAKE_MODE_DISABLED,
71  BAKE_MODE_INDIRECT,
72  BAKE_MODE_INDIRECT_AND_SHADOWS,
73  BAKE_MODE_FULL
74 
75  };
76 
77 
78  enum Operator {
79 
80  OPERATOR_ADD,
81  OPERATOR_SUB
82  };
83 private:
84 
85 
86  Ref<Texture> projector;
87  float vars[PARAM_MAX];
88  Color colors[3];
89 
90 
91  BakeMode bake_mode;
92  VisualServer::LightType type;
93  bool shadows;
94  bool enabled;
95  bool editor_only;
96  Operator op;
97 
98  void _update_visibility();
99 // bind helpers
100 
101 protected:
102 
103  RID light;
104 
105  virtual bool _can_gizmo_scale() const;
106  virtual RES _get_gizmo_geometry() const;
107 
108  static void _bind_methods();
109  void _notification(int p_what);
110 
111 
112  Light(VisualServer::LightType p_type);
113 public:
114 
115  VS::LightType get_light_type() const { return type; }
116 
117  void set_parameter(Parameter p_var, float p_value);
118  float get_parameter(Parameter p_var) const;
119 
120  void set_color(LightColor p_color,const Color& p_value);
121  Color get_color(LightColor p_color) const;
122 
123  void set_project_shadows(bool p_enabled);
124  bool has_project_shadows() const;
125 
126  void set_projector(const Ref<Texture>& p_projector);
127  Ref<Texture> get_projector() const;
128 
129  void set_operator(Operator p_op);
130  Operator get_operator() const;
131 
132  void set_bake_mode(BakeMode p_bake_mode);
133  BakeMode get_bake_mode() const;
134 
135  void set_enabled(bool p_enabled);
136  bool is_enabled() const;
137 
138  void set_editor_only(bool p_editor_only);
139  bool is_editor_only() const;
140 
141  virtual AABB get_aabb() const;
142  virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const;
143 
144  void approximate_opengl_attenuation(float p_constant, float p_linear, float p_quadratic, float p_radius_treshold=0.5);
145 
146  Light();
147  ~Light();
148 
149 };
150 
151 VARIANT_ENUM_CAST( Light::Parameter );
152 VARIANT_ENUM_CAST( Light::LightColor );
153 VARIANT_ENUM_CAST( Light::Operator );
154 VARIANT_ENUM_CAST( Light::BakeMode);
155 
156 
157 class DirectionalLight : public Light {
158 
159  OBJ_TYPE( DirectionalLight, Light );
160 
161 public:
162 
163  enum ShadowMode {
164  SHADOW_ORTHOGONAL,
165  SHADOW_PERSPECTIVE,
166  SHADOW_PARALLEL_2_SPLITS,
167  SHADOW_PARALLEL_4_SPLITS
168  };
169  enum ShadowParam {
170  SHADOW_PARAM_MAX_DISTANCE,
171  SHADOW_PARAM_PSSM_SPLIT_WEIGHT,
172  SHADOW_PARAM_PSSM_ZOFFSET_SCALE
173  };
174 
175 private:
176  ShadowMode shadow_mode;
177  float shadow_param[3];
178 protected:
179  static void _bind_methods();
180 public:
181 
182  void set_shadow_mode(ShadowMode p_mode);
183  ShadowMode get_shadow_mode() const;
184 
185  void set_shadow_max_distance(float p_distance);
186  float get_shadow_max_distance() const;
187  void set_shadow_param(ShadowParam p_param, float p_value);
188  float get_shadow_param(ShadowParam p_param) const;
189 
191 };
192 
193 VARIANT_ENUM_CAST( DirectionalLight::ShadowMode );
194 VARIANT_ENUM_CAST( DirectionalLight::ShadowParam );
195 
196 
197 class OmniLight : public Light {
198 
199  OBJ_TYPE( OmniLight, Light );
200 protected:
201  static void _bind_methods();
202 
203 public:
204 
205 
206  OmniLight() : Light( VisualServer::LIGHT_OMNI ) { set_parameter(PARAM_SHADOW_Z_OFFSET,0.001);}
207 };
208 
209 class SpotLight : public Light {
210 
211  OBJ_TYPE( SpotLight, Light );
212 protected:
213  static void _bind_methods();
214 public:
215 
216 
217  SpotLight() : Light( VisualServer::LIGHT_SPOT ) {}
218 };
219 
220 
221 #endif
Definition: light.h:40
Definition: aabb.h:43
Definition: color.h:37
Definition: light.h:209
Definition: rid.h:47
Definition: light.h:157
Definition: light.h:197
Definition: visual_instance.h:39