Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Letwory <nathan@letworyinteractive.com>2010-10-14 13:40:56 +0400
committerNathan Letwory <nathan@letworyinteractive.com>2010-10-14 13:40:56 +0400
commit097a926d943c3b482305c295c60eaff7a85600d8 (patch)
treec1fdcbd2a5b62b9304e825fc91338426535a41b9 /source/blender/collada/LightExporter.cpp
parent380929624ca1d3d48de6e93ba321742bced3ee12 (diff)
Fix [#24201] COLLADA Exporter: Light source energy incorrect
lamp->energy and lamp->distance are now taken in account by calculating the constant, linear and quadratic attenuations based on this. The import tries to do the reverse. Note: this will work only properly for lamps that have att1 and att2 set to 1.0 or 0.0, other lamptypes won't import correctly again.
Diffstat (limited to 'source/blender/collada/LightExporter.cpp')
-rw-r--r--source/blender/collada/LightExporter.cpp47
1 files changed, 40 insertions, 7 deletions
diff --git a/source/blender/collada/LightExporter.cpp b/source/blender/collada/LightExporter.cpp
index 7327b309889..5786c682d6a 100644
--- a/source/blender/collada/LightExporter.cpp
+++ b/source/blender/collada/LightExporter.cpp
@@ -30,6 +30,8 @@
#include "DNA_lamp_types.h"
+#include "BLI_math.h"
+
#include "LightExporter.h"
#include "collada_internal.h"
@@ -48,6 +50,7 @@ void forEachLampObjectInScene(Scene *sce, Functor &f)
}
LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryLights(sw){}
+
void LightsExporter::exportLights(Scene *sce)
{
openLibrary();
@@ -62,18 +65,45 @@ void LightsExporter::operator()(Object *ob)
std::string la_id(get_light_id(ob));
std::string la_name(id_name(la));
COLLADASW::Color col(la->r, la->g, la->b);
- float e = la->energy;
+ float att1, att2;
+ float e, d, constatt, linatt, quadatt;
+ att1 = att2 = 0.0f;
+
+ if(la->falloff_type==LA_FALLOFF_INVLINEAR) {
+ att1 = 1.0f;
+ att2 = 0.0f;
+ }
+ else if(la->falloff_type==LA_FALLOFF_INVSQUARE) {
+ att1 = 0.0f;
+ att2 = 1.0f;
+ }
+ else if(la->falloff_type==LA_FALLOFF_SLIDERS) {
+ att1 = la->att1;
+ att2 = la->att2;
+ }
+
+ e = la->energy;
+ d = la->dist;
+
+ constatt = linatt = quadatt = MAXFLOAT;
+ if(e > 0.0f) {
+ constatt = 1.0f/e;
+ linatt = att1/(d*e);
+ quadatt = att2/(d*d*(e*2));
+ }
// sun
if (la->type == LA_SUN) {
COLLADASW::DirectionalLight cla(mSW, la_id, la_name, e);
cla.setColor(col);
+ cla.setConstantAttenuation(constatt);
addLight(cla);
}
// hemi
else if (la->type == LA_HEMI) {
COLLADASW::AmbientLight cla(mSW, la_id, la_name, e);
cla.setColor(col);
+ cla.setConstantAttenuation(constatt);
addLight(cla);
}
// spot
@@ -82,16 +112,18 @@ void LightsExporter::operator()(Object *ob)
cla.setColor(col);
cla.setFallOffAngle(la->spotsize);
cla.setFallOffExponent(la->spotblend);
- cla.setLinearAttenuation(la->att1);
- cla.setQuadraticAttenuation(la->att2);
+ cla.setConstantAttenuation(constatt);
+ cla.setLinearAttenuation(linatt);
+ cla.setQuadraticAttenuation(quadatt);
addLight(cla);
}
// lamp
else if (la->type == LA_LOCAL) {
COLLADASW::PointLight cla(mSW, la_id, la_name, e);
cla.setColor(col);
- cla.setLinearAttenuation(la->att1);
- cla.setQuadraticAttenuation(la->att2);
+ cla.setConstantAttenuation(constatt);
+ cla.setLinearAttenuation(linatt);
+ cla.setQuadraticAttenuation(quadatt);
addLight(cla);
}
// area lamp is not supported
@@ -99,8 +131,9 @@ void LightsExporter::operator()(Object *ob)
else {
COLLADASW::PointLight cla(mSW, la_id, la_name, e);
cla.setColor(col);
- cla.setLinearAttenuation(la->att1);
- cla.setQuadraticAttenuation(la->att2);
+ cla.setConstantAttenuation(constatt);
+ cla.setLinearAttenuation(linatt);
+ cla.setQuadraticAttenuation(quadatt);
addLight(cla);
}
}