Merge pull request #2434 from mvorbrodt/master
Generate attenuation constants if non are provided in the Blender file…pull/2458/head^2
commit
6fda615706
|
@ -1225,6 +1225,16 @@ aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* obj, c
|
|||
case Lamp::Type_Local:
|
||||
out->mType = aiLightSource_POINT;
|
||||
break;
|
||||
case Lamp::Type_Spot:
|
||||
out->mType = aiLightSource_SPOT;
|
||||
|
||||
// blender orients directional lights as facing toward -z
|
||||
out->mDirection = aiVector3D(0.f, 0.f, -1.f);
|
||||
out->mUp = aiVector3D(0.f, 1.f, 0.f);
|
||||
|
||||
out->mAngleInnerCone = lamp->spotsize * (1.0f - lamp->spotblend);
|
||||
out->mAngleOuterCone = lamp->spotsize;
|
||||
break;
|
||||
case Lamp::Type_Sun:
|
||||
out->mType = aiLightSource_DIRECTIONAL;
|
||||
|
||||
|
@ -1255,6 +1265,23 @@ aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* obj, c
|
|||
out->mColorAmbient = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy;
|
||||
out->mColorSpecular = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy;
|
||||
out->mColorDiffuse = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy;
|
||||
|
||||
// If default values are supplied, compute the coefficients from light's max distance
|
||||
// Read this: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/
|
||||
//
|
||||
if (lamp->constant_coefficient == 1.0f && lamp->linear_coefficient == 0.0f && lamp->quadratic_coefficient == 0.0f && lamp->dist > 0.0f)
|
||||
{
|
||||
out->mAttenuationConstant = 1.0f;
|
||||
out->mAttenuationLinear = 2.0f / lamp->dist;
|
||||
out->mAttenuationQuadratic = 1.0f / (lamp->dist * lamp->dist);
|
||||
}
|
||||
else
|
||||
{
|
||||
out->mAttenuationConstant = lamp->constant_coefficient;
|
||||
out->mAttenuationLinear = lamp->linear_coefficient;
|
||||
out->mAttenuationQuadratic = lamp->quadratic_coefficient;
|
||||
}
|
||||
|
||||
return out.release();
|
||||
}
|
||||
|
||||
|
|
|
@ -211,9 +211,12 @@ template <> void Structure :: Convert<Lamp> (
|
|||
ReadField<ErrorPolicy_Warn>(dest.b,"b",db);
|
||||
ReadField<ErrorPolicy_Warn>(dest.k,"k",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.energy,"energy",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.dist,"dist",db);
|
||||
ReadField<ErrorPolicy_Warn>(dest.dist,"dist",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.spotsize,"spotsize",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.spotblend,"spotblend",db);
|
||||
ReadField<ErrorPolicy_Warn>(dest.constant_coefficient, "coeff_const", db);
|
||||
ReadField<ErrorPolicy_Warn>(dest.linear_coefficient, "coeff_lin", db);
|
||||
ReadField<ErrorPolicy_Warn>(dest.quadratic_coefficient, "coeff_quad", db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.att1,"att1",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.att2,"att2",db);
|
||||
ReadField<ErrorPolicy_Igno>(temp,"falloff_type",db);
|
||||
|
|
|
@ -538,6 +538,10 @@ struct Lamp : ElemBase {
|
|||
float energy, dist, spotsize, spotblend;
|
||||
//float haint;
|
||||
|
||||
float constant_coefficient;
|
||||
float linear_coefficient;
|
||||
float quadratic_coefficient;
|
||||
|
||||
float att1, att2;
|
||||
//struct CurveMapping *curfalloff;
|
||||
FalloffType falloff_type;
|
||||
|
|
Loading…
Reference in New Issue