From b34a552fb759d5aa810a7d48c90781b198d856f5 Mon Sep 17 00:00:00 2001 From: Matt Oliver Date: Mon, 9 Jan 2017 16:07:40 +1100 Subject: [PATCH 1/3] FBX: Add correct light locations and falloff values. Fbx lights are stored in the scene graph as well as having separate light properties. The separate light properties have a light position and direction that is already fully transformed based on its position in the scene graph so this results in the assimp light being transformed twice. Since the scene graph contains all the relevant transformations the light position and direction can just use default values. Fbx specifies lights along the negative y axis so the default light values have a up and direction set accordingly. The DecayStart value specifies the distance from the light that the light intensity will drop to half. Using the default assimp falloff equation of f=1/c+lr+qr^2 then the falloff coefficients can be calculated for either c,l or q accordingly by setting r=DecayStart and f=0.5. Fixes #851 --- code/FBXConverter.cpp | 21 ++++++++++++++++----- code/FBXDocument.h | 6 +++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 5148f23d5..ee9ce29fc 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -640,7 +640,7 @@ void Converter::ConvertLight( const Model& model, const Light& light ) out_light->mName.Set( FixNodeName( model.Name() ) ); - const float intensity = light.Intensity(); + const float intensity = light.Intensity() / 100.0f; const aiVector3D& col = light.Color(); out_light->mColorDiffuse = aiColor3D( col.x, col.y, col.z ); @@ -650,6 +650,11 @@ void Converter::ConvertLight( const Model& model, const Light& light ) out_light->mColorSpecular = out_light->mColorDiffuse; + //lights are defined along negative y direction + out_light->mPosition = aiVector3D(0.0f); + out_light->mDirection = aiVector3D(0.0f, -1.0f, 0.0f); + out_light->mUp = aiVector3D(0.0f, 0.0f, -1.0f); + switch ( light.LightType() ) { case Light::Type_Point: @@ -679,17 +684,23 @@ void Converter::ConvertLight( const Model& model, const Light& light ) ai_assert( false ); } - // XXX: how to best convert the near and far decay ranges? + float decay = light.DecayStart(); switch ( light.DecayType() ) { case Light::Decay_None: - out_light->mAttenuationConstant = 1.0f; + out_light->mAttenuationConstant = decay; + out_light->mAttenuationLinear = 0.0f; + out_light->mAttenuationQuadratic = 0.0f; break; case Light::Decay_Linear: - out_light->mAttenuationLinear = 1.0f; + out_light->mAttenuationConstant = 0.0f; + out_light->mAttenuationLinear = 2.0f / decay; + out_light->mAttenuationQuadratic = 0.0f; break; case Light::Decay_Quadratic: - out_light->mAttenuationQuadratic = 1.0f; + out_light->mAttenuationConstant = 0.0f; + out_light->mAttenuationLinear = 0.0f; + out_light->mAttenuationQuadratic = 2.0f / (decay * decay); break; case Light::Decay_Cubic: FBXImporter::LogWarn( "cannot represent cubic attenuation, set to Quadratic" ); diff --git a/code/FBXDocument.h b/code/FBXDocument.h index be67e32e6..0abcdcf07 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -302,12 +302,12 @@ public: fbx_simple_property(DrawVolumetricLight, bool, true) fbx_simple_property(DrawGroundProjection, bool, true) fbx_simple_property(DrawFrontFacingVolumetricLight, bool, false) - fbx_simple_property(Intensity, float, 1.0f) + fbx_simple_property(Intensity, float, 100.0f) fbx_simple_property(InnerAngle, float, 0.0f) fbx_simple_property(OuterAngle, float, 45.0f) fbx_simple_property(Fog, int, 50) - fbx_simple_enum_property(DecayType, Decay, 0) - fbx_simple_property(DecayStart, int, 0) + fbx_simple_enum_property(DecayType, Decay, 2) + fbx_simple_property(DecayStart, float, 1.0f) fbx_simple_property(FileName, std::string, "") fbx_simple_property(EnableNearAttenuation, bool, false) From 5be2351dc6aa06502a561a5e2e8905d6c60e39ca Mon Sep 17 00:00:00 2001 From: Matt Oliver Date: Mon, 9 Jan 2017 16:11:32 +1100 Subject: [PATCH 2/3] FBX: Correct camera position and clip planes. Fbx cameras are stored in the scene graph as well as having separate camera properties. The separate camera properties have a camera position and direction that is already fully transformed based on its position in the scene graph so this results in the assimp camera being transformed twice. Since the scene graph contains all the relevant transformations the camera position and direction can just use default values. Fbx specifies cameras along the positive x axis so the default camera values have a up and direction set accordingly. Fixes: #807 #643 --- code/FBXConverter.cpp | 9 ++++++--- code/FBXDocument.h | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index ee9ce29fc..be7c41f10 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -719,10 +719,13 @@ void Converter::ConvertCamera( const Model& model, const Camera& cam ) out_camera->mName.Set( FixNodeName( model.Name() ) ); out_camera->mAspect = cam.AspectWidth() / cam.AspectHeight(); - out_camera->mPosition = cam.Position(); - out_camera->mUp = cam.UpVector(); - out_camera->mLookAt = cam.InterestPosition() - out_camera->mPosition; + //cameras are defined along positive x direction + out_camera->mPosition = aiVector3D(0.0f); + out_camera->mLookAt = aiVector3D(1.0f, 0.0f, 0.0f); + out_camera->mUp = aiVector3D(0.0f, 1.0f, 0.0f); out_camera->mHorizontalFOV = AI_DEG_TO_RAD( cam.FieldOfView() ); + out_camera->mClipPlaneNear = cam.NearPlane(); + out_camera->mClipPlaneFar = cam.FarPlane(); } diff --git a/code/FBXDocument.h b/code/FBXDocument.h index 0abcdcf07..9c446250b 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -240,6 +240,9 @@ public: fbx_simple_property(FilmWidth, float, 1.0f) fbx_simple_property(FilmHeight, float, 1.0f) + fbx_simple_property(NearPlane, float, 0.1f) + fbx_simple_property(FarPlane, float, 100.0f) + fbx_simple_property(FilmAspectRatio, float, 1.0f) fbx_simple_property(ApertureMode, int, 0) From 2f2fe92b6247513f5ec02c98acd7c5a0f002b2c9 Mon Sep 17 00:00:00 2001 From: Matt Oliver Date: Mon, 9 Jan 2017 16:13:25 +1100 Subject: [PATCH 3/3] FBX: Add additional material properties. Currently there isnt a AI_MATKEY_DISPLACEMENTSCALING define but fbx supports the value so for the moment it is just manually specified. --- code/FBXConverter.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index be7c41f10..848da579e 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -2134,6 +2134,16 @@ void Converter::SetShadingPropertiesCommon( aiMaterial* out_mat, const PropertyT if ( ok ) { out_mat->AddProperty( &ShininessExponent, 1, AI_MATKEY_SHININESS ); } + + const float BumpFactor = PropertyGet(props, "BumpFactor", ok); + if (ok) { + out_mat->AddProperty(&BumpFactor, 1, AI_MATKEY_BUMPSCALING); + } + + const float DispFactor = PropertyGet(props, "DisplacementFactor", ok); + if (ok) { + out_mat->AddProperty(&DispFactor, 1, "$mat.displacementscaling", 0, 0); + } }