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
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')
-rw-r--r--source/blender/collada/DocumentImporter.cpp47
-rw-r--r--source/blender/collada/LightExporter.cpp47
2 files changed, 79 insertions, 15 deletions
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index a406845c8a2..25787e18b06 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -29,9 +29,6 @@
#include <map>
#include <algorithm> // sort()
-#include <math.h>
-#include <float.h>
-
#include "COLLADAFWRoot.h"
#include "COLLADAFWIWriter.h"
#include "COLLADAFWStableHeaders.h"
@@ -67,6 +64,7 @@
#include "BKE_image.h"
#include "BLI_listbase.h"
+#include "BLI_math.h"
#include "BLI_string.h"
#include "DNA_camera_types.h"
@@ -841,6 +839,38 @@ public:
lamp->g = col.getGreen();
lamp->b = col.getBlue();
}
+ float constatt = light->getConstantAttenuation().getValue();
+ float linatt = light->getLinearAttenuation().getValue();
+ float quadatt = light->getQuadraticAttenuation().getValue();
+ float d = 25.0f;
+ float att1 = 0.0f;
+ float att2 = 0.0f;
+
+ float e = 1.0f/constatt;
+
+ /* NOTE: We assume for now that inv square is used for quadratic light
+ * and inv linear for linear light. Exported blender lin/quad weighted
+ * most likely will result in wrong import. */
+ /* quadratic light */
+ if(IS_EQ(linatt, 0.0f) && quadatt > 0.0f) {
+ //quadatt = att2/(d*d*(e*2));
+ float invquadatt = 1.0f/quadatt;
+ float d2 = invquadatt / (2 * e);
+ d = sqrtf(d2);
+ }
+ // linear light
+ else if(IS_EQ(quadatt, 0.0f) && linatt > 0.0f) {
+ //linatt = att1/(d*e);
+ float invlinatt = 1.0f/linatt;
+ d = invlinatt / e;
+ } else {
+ printf("no linear nor quad light, using defaults for attenuation, import will be incorrect: Lamp %s\n", lamp->id.name);
+ att2 = 1.0f;
+ }
+
+ lamp->dist = d;
+ lamp->energy = e;
+
COLLADAFW::Light::LightType type = light->getLightType();
switch(type) {
case COLLADAFW::Light::AMBIENT_LIGHT:
@@ -851,9 +881,9 @@ public:
case COLLADAFW::Light::SPOT_LIGHT:
{
lamp->type = LA_SPOT;
- lamp->falloff_type = LA_FALLOFF_SLIDERS;
- lamp->att1 = light->getLinearAttenuation().getValue();
- lamp->att2 = light->getQuadraticAttenuation().getValue();
+ lamp->falloff_type = LA_FALLOFF_INVSQUARE;
+ lamp->att1 = att1;
+ lamp->att2 = att2;
lamp->spotsize = light->getFallOffAngle().getValue();
lamp->spotblend = light->getFallOffExponent().getValue();
}
@@ -866,8 +896,9 @@ public:
case COLLADAFW::Light::POINT_LIGHT:
{
lamp->type = LA_LOCAL;
- lamp->att1 = light->getLinearAttenuation().getValue();
- lamp->att2 = light->getQuadraticAttenuation().getValue();
+ lamp->falloff_type = LA_FALLOFF_INVSQUARE;
+ lamp->att1 = att1;
+ lamp->att2 = att2;
}
break;
case COLLADAFW::Light::UNDEFINED:
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);
}
}