Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 330 vs 331 for /trunk/Source Code/Rendering/Lighting/Headers/Light.h

Diff revisions: vs.
  @@ -29,32 +29,40 @@
29 29 namespace Divide {
30 30
31 31 ///The different types of lights supported
32 - enum LightType{
32 + enum LightType {
33 33 LIGHT_TYPE_DIRECTIONAL = 0,
34 34 LIGHT_TYPE_POINT = 1, ///< or omni light, if you prefer
35 35 LIGHT_TYPE_SPOT = 2,
36 36 LightType_PLACEHOLDER
37 37 };
38 38
39 - enum LightMode{
39 + enum LightMode {
40 40 LIGHT_MODE_SIMPLE = 0, ///< normal light. Can't be moved or changed at runtime
41 - LIGHT_MODE_TOGGLABLE = 1, ///< can be switched on or off and can change brightness,color, range at runtime
41 + LIGHT_MODE_TOGGLABLE = 1, ///< can be switched on or off, change brightness, color, range at runtime
42 42 LIGHT_MODE_MOVABLE = 2, ///< can change position at runtime / most expensive
43 - //LIGHT_MODE_DOMINANT = 3 ///< only shadow caster in scene
43 + //LIGHT_MODE_DOMINANT = 3 ///< only shadow caster in scene
44 44 };
45 45
46 46 struct LightProperties {
47 - vec4<F32> _diffuse; //< rgb = diffuse, w = ambientFactor;
48 - vec4<F32> _attenuation; //< x = constAtt, y = linearAtt, z = quadraticAtt, w = brightness
49 - vec4<F32> _position; //< Position is a direction for directional lights. w = reserved
50 - vec4<F32> _direction; //< xyz = Used by spot lights, w = spotExponent
51 - vec4<I32> _options; //< x = light type: 0.0 - directional, 1.0 - point, 2.0 - spot, y = casts shadows, zw - reserved;
47 + /// rgb = diffuse, w = ambientFactor;
48 + vec4<F32> _diffuse;
49 + /// x = constAtt, y = linearAtt, z = quadraticAtt, w = brightness
50 + vec4<F32> _attenuation;
51 + /// Position is a direction for directional lights. w = reserved
52 + vec4<F32> _position;
53 + /// xyz = Used by spot lights, w = spotExponent
54 + vec4<F32> _direction;
55 + /// x = light type: 0.0 - directional, 1.0 - point, 2.0 - spot, y = casts shadows, zw - reserved;
56 + vec4<I32> _options;
52 57 };
53 58
54 59 struct LightShadowProperties {
55 - mat4<F32> _lightVP[4]; //< light viewProjection matrices
56 - vec4<F32> _floatValues; //< random float values (e.g. split distances)
57 - vec4<F32> _lightPosition[4]; //<light's position in world space
60 + /// light viewProjection matrices
61 + mat4<F32> _lightVP[4];
62 + /// random float values (e.g. split distances)
63 + vec4<F32> _floatValues;
64 + /// light's position in world space
65 + vec4<F32> _lightPosition[4];
58 66 };
59 67
60 68 class Camera;
  @@ -62,7 +70,7 @@
62 70 class ParamHandler;
63 71 class ShadowMapInfo;
64 72 class SceneRenderState;
65 - ///A light object placed in the scene at a certain position
73 + /// A light object placed in the scene at a certain position
66 74 class Light : public SceneNode {
67 75 public:
68 76 enum PropertyType{
  @@ -74,76 +82,164 @@
74 82
75 83 typedef hashMapImpl<I64, Light*> LightMap;
76 84
77 - ///Create a new light assigned to the specified slot with the specified range
85 + /// Create a new light assigned to the specified slot with the specified range
78 86 /// @param slot = the slot the light is assigned to (as in OpenGL slot for example)
79 87 /// @param range = the light influence range (for spot/point lights)
80 88 Light(const F32 range,const LightType& type);
81 89 virtual ~Light();
82 90
83 - ///Light score determines the importance of this light for the current node queries
84 - inline F32 getScore() const {return _score;}
85 - inline void setScore(const F32 score) {_score = score;}
86 -
87 - ///Is the light a shadow caster?
88 - inline bool castsShadows() const {return _properties._options.y == 1;}
89 - ///Get the entire property block
90 - inline const LightProperties& getProperties() const { return _properties; }
91 - inline const LightShadowProperties& getShadowProperties() const {return _shadowProperties;}
92 -
93 - inline F32 getRange() const {return _properties._attenuation.w;}
94 - void setRange(F32 range);
95 - ///Get light diffuse color
96 - inline vec3<F32> getDiffuseColor() const { return _properties._diffuse.rgb(); }
97 - void setDiffuseColor(const vec3<F32>& newDiffuseColor);
98 - ///Get light position for omni and spot or direction for a directional light
99 - inline vec3<F32> getPosition() const { return _properties._position.xyz(); }
100 - void setPosition(const vec3<F32>& newPosition);
101 - ///Get direction for spot lights
102 - inline vec3<F32> getDirection() const { return _properties._direction.xyz(); }
103 - void setDirection(const vec3<F32>& newDirection);
104 - ///Light state (on/off)
105 - inline bool getEnabled() const {return _enabled;}
106 -
107 - ///Does this list cast shadows?
108 - inline void setCastShadows(const bool state) { _properties._options.y = (state ? 1 : 0);}
109 - ///Draw a sphere at the lights position
110 - ///The impostor has the range of the light's effect range and the diffuse color as the light's diffuse property
111 - inline void setDrawImpostor(const bool state) {_drawImpostor = state;}
112 - ///Turn the light on/off
113 - inline void setEnabled(const bool state) {_enabled = state;}
114 - ///Get the light type.
115 - ///See LightType enum
116 - inline const LightType& getLightType() const {return _type;}
117 - inline const LightMode& getLightMode() const {return _mode;}
118 - ///Get a pointer to the light's impostor
119 - inline Impostor* const getImpostor() const {return _impostor;}
120 - //Checks if this light needs and update
91 + /// Light score determines the importance of this light for the current node queries
92 + inline F32 getScore() const {
93 + return _score;
94 + }
95 +
96 + inline void setScore(const F32 score) {
97 + _score = score;
98 + }
99 +
100 + /// Is the light a shadow caster?
101 + inline bool castsShadows() const {
102 + return _properties._options.y == 1;
103 + }
104 +
105 + /// Get the entire property block
106 + inline const LightProperties& getProperties() const {
107 + return _properties;
108 + }
109 +
110 + inline const LightShadowProperties& getShadowProperties() const {
111 + return _shadowProperties;
112 + }
113 +
114 + inline F32 getRange() const {
115 + return _properties._attenuation.w;
116 + }
117 +
118 + void setRange(F32 range);
119 +
120 + /// Get light diffuse color
121 + inline vec3<F32> getDiffuseColor() const {
122 + return _properties._diffuse.rgb();
123 + }
124 +
125 + void setDiffuseColor(const vec3<F32>& newDiffuseColor);
126 +
127 + /// Get light position for omni and spot or direction for a directional light
128 + inline vec3<F32> getPosition() const {
129 + return _properties._position.xyz();
130 + }
131 +
132 + void setPosition(const vec3<F32>& newPosition);
133 +
134 + /// Get direction for spot lights
135 + inline vec3<F32> getDirection() const {
136 + return _properties._direction.xyz();
137 + }
138 +
139 + void setDirection(const vec3<F32>& newDirection);
140 +
141 + /// Light state (on/off)
142 + inline bool getEnabled() const {
143 + return _enabled;
144 + }
145 +
146 + /// Does this list cast shadows?
147 + inline void setCastShadows(const bool state) {
148 + _properties._options.y = (state ? 1 : 0);
149 + }
150 +
151 + /// Draw a sphere at the lights position
152 + /// The impostor has the range of the light's effect range and the diffuse color as the light's diffuse property
153 + inline void setDrawImpostor(const bool state) {
154 + _drawImpostor = state;
155 + }
156 +
157 + /// Turn the light on/off
158 + inline void setEnabled(const bool state) {
159 + _enabled = state;
160 + }
161 +
162 + /// Get the light type. (see LightType enum)
163 + inline const LightType& getLightType() const {
164 + return _type;
165 + }
166 +
167 + inline const LightMode& getLightMode() const {
168 + return _mode;
169 + }
170 +
171 + /// Get a pointer to the light's impostor
172 + inline Impostor* const getImpostor() const {
173 + return _impostor;
174 + }
175 +
176 + /// Checks if this light needs and update
121 177 void onCameraChange();
122 178
123 - ///Dummy function from SceneNode;
124 - bool onDraw(SceneGraphNode* const sgn, const RenderStage& currentStage) { return true; }
179 + /// Dummy function from SceneNode;
180 + bool onDraw(SceneGraphNode* const sgn, const RenderStage& currentStage) {
181 + return true;
182 + }
125 183
126 - ///SceneNode concrete implementations
184 + /// SceneNode concrete implementations
127 185 bool unload();
186 +
128 187 bool computeBoundingBox(SceneGraphNode* const sgn);
129 - bool isInView( const SceneRenderState& sceneRenderState, SceneGraphNode* const sgn, const bool distanceCheck = true );
130 - void sceneUpdate(const U64 deltaTime, SceneGraphNode* const sgn, SceneState& sceneState);
188 +
189 + bool isInView(const SceneRenderState& sceneRenderState,
190 + SceneGraphNode* const sgn,
191 + const bool distanceCheck = true );
192 +
193 + void sceneUpdate(const U64 deltaTime,
194 + SceneGraphNode* const sgn,
195 + SceneState& sceneState);
131 196
132 197 /*----------- Shadow Mapping-------------------*/
133 - ///Set the function used to generate shadows for this light (usually _scenegraph->render)
134 - inline ShadowMapInfo* getShadowMapInfo() const {return _shadowMapInfo;}
135 - inline void setShadowMappingCallback(const DELEGATE_CBK<>& callback) { _callback = callback; }
198 + /// Set the function used to generate shadows for this light (usually _scenegraph->render)
199 + inline ShadowMapInfo* getShadowMapInfo() const {
200 + return _shadowMapInfo;
201 + }
202 +
203 + inline void setShadowMappingCallback(const DELEGATE_CBK<>& callback) {
204 + _callback = callback;
205 + }
206 +
136 207 void addShadowMapInfo(ShadowMapInfo* const shadowMapInfo);
137 208 bool removeShadowMapInfo();
209 +
138 210 virtual void generateShadowMaps(SceneRenderState& sceneRenderState);
139 - inline const mat4<F32>& getShadowVPMatrix(U8 index) const { return _shadowProperties._lightVP[index]; }
140 - inline const vec4<F32>& getShadowFloatValues() const { return _shadowProperties._floatValues; }
141 - inline const vec4<F32>& getShadowLightPos(U8 index) const { return _shadowProperties._lightPosition[index]; }
142 - inline void setShadowVPMatrix(U8 index, const mat4<F32>& newValue) { _shadowProperties._lightVP[index].set(newValue); }
143 - inline void setShadowFloatValue(U8 index, F32 newValue) { _shadowProperties._floatValues[index] = newValue; }
144 - inline void setShadowLightPos(U8 index, const vec3<F32>& newValue) { _shadowProperties._lightPosition[index].set(newValue, 1.0f); }
145 - inline void shadowMapResolutionFactor(U8 factor) {_resolutionFactor = factor;}
146 - inline U8 shadowMapResolutionFactor() const {return _resolutionFactor;}
211 +
212 + inline const mat4<F32>& getShadowVPMatrix(U8 index) const {
213 + return _shadowProperties._lightVP[index];
214 + }
215 +
216 + inline const vec4<F32>& getShadowFloatValues() const {
217 + return _shadowProperties._floatValues;
218 + }
219 +
220 + inline const vec4<F32>& getShadowLightPos(U8 index) const {
221 + return _shadowProperties._lightPosition[index];
222 + }
223 +
224 + inline void setShadowVPMatrix(U8 index, const mat4<F32>& newValue) {
225 + _shadowProperties._lightVP[index].set(newValue);
226 + }
227 +
228 + inline void setShadowFloatValue(U8 index, F32 newValue) {
229 + _shadowProperties._floatValues[index] = newValue;
230 + }
231 +
232 + inline void setShadowLightPos(U8 index, const vec3<F32>& newValue) {
233 + _shadowProperties._lightPosition[index].set(newValue, 1.0f);
234 + }
235 +
236 + inline void shadowMapResolutionFactor(U8 factor) {
237 + _resolutionFactor = factor;
238 + }
239 +
240 + inline U8 shadowMapResolutionFactor() const {
241 + return _resolutionFactor;
242 + }
147 243
148 244 protected:
149 245 friend class LightManager;
  @@ -151,21 +247,39 @@
151 247 friend class ImplResourceLoader;
152 248 bool load(const stringImpl& name);
153 249
154 - ///When the SceneGraph calls the light's render function, we draw the impostor if needed
155 - virtual void render(SceneGraphNode* const sgn, const SceneRenderState& sceneRenderState, const RenderStage& currentRenderStage);
156 - virtual void getDrawCommands(SceneGraphNode* const sgn, const RenderStage& currentRenderStage, SceneRenderState& sceneRenderState, vectorImpl<GenericDrawCommand>& drawCommandsOut) {}
250 + /// When the SceneGraph calls the light's render function, we draw the impostor if needed
251 + virtual void render(SceneGraphNode* const sgn,
252 + const SceneRenderState& sceneRenderState,
253 + const RenderStage& currentRenderStage);
254 +
255 + virtual void getDrawCommands(SceneGraphNode* const sgn,
256 + const RenderStage& currentRenderStage,
257 + SceneRenderState& sceneRenderState,
258 + vectorImpl<GenericDrawCommand>& drawCommandsOut) {
259 + }
260 +
157 261 void postLoad(SceneGraphNode* const sgn);
158 - ///Set light type
159 - ///@param type Directional/Spot/Omni (see LightType enum)
160 - inline void setLightType(const LightType& type) { _type = type; _properties._options.x = getLightTypeValue(); }
161 - ///Set light mode
162 - ///@param mode Togglable, Movable, Simple, Dominant (see LightMode enum)
262 +
263 + /// Set light type
264 + /// @param type Directional/Spot/Omni (see LightType enum)
265 + inline void setLightType(const LightType& type) {
266 + _type = type;
267 + _properties._options.x = getLightTypeValue();
268 + }
269 +
270 + /// Set light mode
271 + /// @param mode Togglable, Movable, Simple, Dominant (see LightMode enum)
163 272 void setLightMode(const LightMode& mode);
164 - ///Called when the rendering resolution changes
273 + /// Called when the rendering resolution changes
165 274 void updateResolution(I32 newWidth, I32 newHeight);
166 - ///Get a ref to the shadow camera used by this light
167 - Camera* const shadowCamera() const {return _shadowCamera;}
168 - const I32 getLightTypeValue() const { return _type == LIGHT_TYPE_DIRECTIONAL ? 0 : (_type == LIGHT_TYPE_POINT ? 1 : 2); }
275 + /// Get a ref to the shadow camera used by this light
276 + Camera* const shadowCamera() const {
277 + return _shadowCamera;
278 + }
279 +
280 + const I32 getLightTypeValue() const {
281 + return _type == LIGHT_TYPE_DIRECTIONAL ? 0 : (_type == LIGHT_TYPE_POINT ? 1 : 2);
282 + }
169 283
170 284 protected:
171 285 LightProperties _properties;
  @@ -179,7 +293,8 @@
179 293 U8 _resolutionFactor;
180 294 bool _drawImpostor;
181 295 bool _updateLightBB;
182 - Impostor* _impostor; ///< Used for debug rendering -Ionut
296 + /// Used for debug rendering
297 + Impostor* _impostor;
183 298 SceneGraphNode* _lightSGN;
184 299 SceneGraphNode* _impostorSGN;
185 300 Camera* _shadowCamera;