Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 167 vs 168 for /trunk/Source Code/Rendering/Lighting/Light.cpp

Diff revisions: vs.
  @@ -25,7 +25,7 @@
25 25 _shadowMapInfo(NULL),
26 26 _score(0)
27 27 {
28 - ///All lights default to fully dynamic for now.
28 + //All lights default to fully dynamic for now.
29 29 setLightMode(LIGHT_MODE_MOVABLE);
30 30
31 31 _properties._ambient = vec4<F32>(0.1f,0.1f,0.1f,1.0f);
  @@ -36,7 +36,7 @@
36 36 _properties._attenuation = vec4<F32>(1.0f, 0.1f, 0.0f, range); //constAtt, linearAtt, quadAtt, range
37 37 _properties._brightness;
38 38 _properties._padding = 1.0f;
39 - setShadowMappingCallback(SCENE_GRAPH_UPDATE(GET_ACTIVE_SCENE()->getSceneGraph()));
39 + setShadowMappingCallback(SCENE_GRAPH_UPDATE(GET_ACTIVE_SCENEGRAPH()));
40 40 setRange(1);//<Default range of 1
41 41 _dirty = true;
42 42 _enabled = true;
  @@ -61,35 +61,42 @@
61 61 }
62 62
63 63 void Light::updateState(){
64 - if(_dirty){
65 - if(_drawImpostor){
66 - if(!_impostor){
67 - _impostor = New Impostor(_name,_properties._attenuation.w);
68 - _impostor->getDummy()->getSceneNodeRenderState().setDrawState(false);
69 - _impostorSGN = _lightSGN->addNode(_impostor->getDummy());
70 - _impostorSGN->setActive(false);
71 - }
72 - _lightSGN->getTransform()->setPosition(_properties._position);
73 - _impostor->getDummy()->getMaterial()->setDiffuse(getDiffuseColor());
74 - _impostor->getDummy()->getMaterial()->setAmbient(getDiffuseColor());
75 - _impostorSGN->getTransform()->setPosition(_properties._position);
76 - ///Updating impostor range is expensive, so check if we need to
77 - F32 range = _properties._attenuation.w;
78 - if(!FLOAT_COMPARE(range,_impostor->getDummy()->getRadius())){
79 - _impostor->getDummy()->setRadius(range);
80 - }
81 - }
64 + if(!_dirty)
65 + return;
82 66
83 - ///Do not set GL lights for deferred rendering
84 - if(!GFX_DEVICE.getDeferredRendering()){ GFX_DEVICE.setLight(this);
85 - }
86 - _dirty = false;
87 - }
67 + if(_drawImpostor){
68 + Sphere3D* lightDummy = NULL;
69 + if(!_impostor){
70 + _impostor = New Impostor(_name,_properties._attenuation.w);
71 + lightDummy = _impostor->getDummy();
72 + lightDummy->getSceneNodeRenderState().setDrawState(false);
73 + _impostorSGN = _lightSGN->addNode(lightDummy);
74 + _impostorSGN->setActive(false);
75 + }
76 +
77 + lightDummy = _impostor->getDummy();
78 + _lightSGN->getTransform()->setPosition(_properties._position);
79 + lightDummy->getMaterial()->setDiffuse(getDiffuseColor());
80 + lightDummy->getMaterial()->setAmbient(getDiffuseColor());
81 + _impostorSGN->getTransform()->setPosition(_properties._position);
82 + //Updating impostor range is expensive, so check if we need to
83 + F32 range = _properties._attenuation.w;
84 +
85 + if(!FLOAT_COMPARE(range, lightDummy->getRadius()))
86 + _impostor->getDummy()->setRadius(range);
87 + }
88 +
89 + //Do not set GL lights for deferred rendering
90 + if(GFX_DEVICE.getRenderer()->getType() == RENDERER_FORWARD)
91 + GFX_DEVICE.setLight(this);
92 +
93 + _dirty = false;
88 94 }
89 95
90 96 void Light::setLightProperties(const LightPropertiesV& key, const vec4<F32>& value){
91 97 ///Light properties are very dependent on scene state. Some lights can't be changed on runtime!
92 - if(!GET_ACTIVE_SCENE()->state()->getRunningState()) return;
98 + if(!GET_ACTIVE_SCENE()->state().getRunningState())
99 + return;
93 100
94 101 ///Simple light's can't be changed. Period!
95 102 if(_mode == LIGHT_MODE_SIMPLE){
  @@ -99,10 +106,10 @@
99 106
100 107 ///Movable lights have no restrictions
101 108 switch(key){
102 - default: ERROR_FN(Locale::get("WARNING_INVALID_PROPERTY_SET"),_id); return;
103 - case LIGHT_PROPERTY_DIFFUSE : _properties._diffuse = value; break;
104 - case LIGHT_PROPERTY_AMBIENT : _properties._ambient = value; break;
105 - case LIGHT_PROPERTY_SPECULAR : _properties._specular = value; break;
109 + default: ERROR_FN(Locale::get("WARNING_INVALID_PROPERTY_SET"),_id); return;
110 + case LIGHT_PROPERTY_DIFFUSE : _properties._diffuse = value; break;
111 + case LIGHT_PROPERTY_AMBIENT : _properties._ambient = value; break;
112 + case LIGHT_PROPERTY_SPECULAR : _properties._specular = value; break;
106 113 };
107 114
108 115 _dirty = true;
  @@ -130,17 +137,20 @@
130 137
131 138 void Light::setLightProperties(const LightPropertiesF& key, F32 value){
132 139 //Light properties are very dependent on scene state. Some lights can't be changed on runtime!
133 - if(! GET_ACTIVE_SCENE()->state()->getRunningState()) return;
140 + if(! GET_ACTIVE_SCENE()->state().getRunningState())
141 + return;
134 142
135 143 if(key == LIGHT_PROPERTY_RANGE){
136 144 setRange(value);
137 145 return;
138 146 }
147 +
139 148 //Simple light's can't be changed. Period!
140 149 if(_mode == LIGHT_MODE_SIMPLE){
141 150 ERROR_FN(Locale::get("WARNING_ILLEGAL_PROPERTY"),_id, "Light_Simple",LightEnum(key));
142 151 return;
143 152 }
153 +
144 154 //Togglable lights can't be moved.
145 155 if(_mode == LIGHT_MODE_TOGGLABLE){
146 156 if(key == LIGHT_PROPERTY_RANGE || key == LIGHT_PROPERTY_BRIGHTNESS ||
  @@ -204,29 +214,31 @@
204 214 }
205 215
206 216 bool Light::computeBoundingBox(SceneGraphNode* const sgn){
207 - if(sgn->getBoundingBox().isComputed()) return true;
217 + if(sgn->getBoundingBox().isComputed())
218 + return true;
219 +
208 220 F32 range = getRange() * 0.5f; //diameter to radius
209 - sgn->getBoundingBox().set(vec3<F32>(-range,-range,-range),vec3<F32>(range,range,range));
221 + sgn->getBoundingBox().set(vec3<F32>(-range), vec3<F32>(range));
210 222 return SceneNode::computeBoundingBox(sgn);
211 223 }
212 224
213 225 bool Light::isInView(const bool distanceCheck,const BoundingBox& boundingBox,const BoundingSphere& sphere){
214 - if(!_drawImpostor) return false;
215 - return (_impostorSGN != NULL);
226 + return ((_impostorSGN != NULL) && _drawImpostor);
216 227 }
217 228
218 229 void Light::render(SceneGraphNode* const sgn){
219 230 ///The isInView call should stop impostor rendering if needed
220 - if(!_impostor) return;
231 + if(!_impostor)
232 + return;
233 +
221 234 _impostor->render(_impostorSGN);
222 235 }
223 236
224 237 void Light::setRange(F32 range) {
225 238 _dirty = true;
226 239 _properties._attenuation.w = range;
227 - if(_impostor){
240 + if(_impostor)
228 241 _impostor->setRadius(range);
229 - }
230 242 }
231 243
232 244 void Light::addShadowMapInfo(ShadowMapInfo* shadowMapInfo){
  @@ -239,24 +251,24 @@
239 251 }
240 252
241 253 void Light::setCameraToSceneView(){
242 - GFXDevice& gfx = GFX_DEVICE;
243 - Frustum& frust = Frustum::getInstance();
244 254 //Set the ortho projection so that it encompasses the entire scene
245 - gfx.setOrthoProjection(vec4<F32>(-1.0, 1.0, -1.0, 1.0), _zPlanes);
255 + GFX_DEVICE.setOrthoProjection(vec4<F32>(-1.0, 1.0, -1.0, 1.0), _zPlanes);
246 256 //Extract the view frustum from this projection mode
247 - frust.Extract(_eyePos - _lightPos);
257 + Frustum::getInstance().Extract(_eyePos - _lightPos);
248 258 //get the MVP from the new Frustum as this is the light's full MVP
249 259 //mat4<F32> bias;
250 - gfx.getMatrix(MVP_MATRIX,_lightProjectionMatrix);
260 + GFX_DEVICE.getMatrix(MVP_MATRIX,_lightProjectionMatrix);
251 261 //gfx.getMatrix(BIAS_MATRIX,bias);
252 262 //_lightProjectionMatrix = bias * _lightProjectionMatrix;
253 263 }
254 264
255 - void Light::generateShadowMaps(SceneRenderState* renderState){
256 - ShadowMap* sm = _shadowMapInfo->getOrCreateShadowMap(renderState);
257 - if(sm){
258 - sm->render(renderState, _callback);
259 - }
265 + void Light::generateShadowMaps(const SceneRenderState& sceneRenderState){
266 + ShadowMap* sm = _shadowMapInfo->getOrCreateShadowMap(sceneRenderState);
267 +
268 + if(!sm)
269 + return;
270 +
271 + sm->render(sceneRenderState, _callback);
260 272 }
261 273
262 274 void Light::setShadowMappingCallback(boost::function0<void> callback) {
  @@ -266,9 +278,8 @@
266 278 void Light::setLightMode(const LightMode& mode) {
267 279 _mode = mode;
268 280 //if the light became dominant, inform the lightmanager
269 - if(mode == LIGHT_MODE_DOMINANT){
281 + if(mode == LIGHT_MODE_DOMINANT)
270 282 LightManager::getInstance().setDominantLight(this);
271 - }
272 283 }
273 284
274 285 const char* Light::LightEnum(const LightPropertiesV& key) const {