From 81c23564b5599baa119c46f80e95f7820fd4ecd2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 25 Jun 2014 08:18:05 +0000 Subject: [PATCH] =?UTF-8?q?From=20Bj=C3=B6rn=20Blissing,=20"Fix=20to=20sup?= =?UTF-8?q?port=20correct=20shininess=20and=20transparency=20in=20FBX=20pl?= =?UTF-8?q?ugin"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14272 16af8721-9629-0410-8352-f15c8da7e697 --- .../fbx/fbxMaterialToOsgStateSet.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp index 1a2fb8398..4f29eccce 100644 --- a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp +++ b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp @@ -50,10 +50,20 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat) } } + double transparencyColorFactor = 1.0; + bool useTransparencyColorFactor = false; + // opacity map... const FbxProperty lOpacityProperty = pFbxMat->FindProperty(FbxSurfaceMaterial::sTransparentColor); if (lOpacityProperty.IsValid()) { + FbxDouble3 transparentColor = lOpacityProperty.Get(); + // If transparent color is defined set the transparentFactor to gray scale value of transparentColor + if (transparentColor[0] < 1.0 || transparentColor[1] < 1.0 || transparentColor[2] < 1.0) { + transparencyColorFactor = transparentColor[0]*0.30 + transparentColor[1]*0.59 + transparentColor[2]*0.11; + useTransparencyColorFactor = true; + } + int lNbTex = lOpacityProperty.GetSrcObjectCount(); for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++) { @@ -121,11 +131,12 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat) { FbxDouble3 color = pFbxLambert->Diffuse.Get(); double factor = pFbxLambert->DiffuseFactor.Get(); + double transparencyFactor = useTransparencyColorFactor ? transparencyColorFactor : pFbxLambert->TransparencyFactor.Get(); pOsgMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4( static_cast(color[0] * factor), static_cast(color[1] * factor), static_cast(color[2] * factor), - static_cast(1.0 - pFbxLambert->TransparencyFactor.Get()))); + static_cast(1.0 - transparencyFactor))); color = pFbxLambert->Ambient.Get(); factor = pFbxLambert->AmbientFactor.Get(); @@ -155,9 +166,12 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat) static_cast(color[1] * factor), static_cast(color[2] * factor), 1.0f)); - + // Since Maya and 3D studio Max stores their glossiness values in exponential format (2^(log2(x)) + // We need to linearize to values between 0-100 and then scale to values between 0-128. + // Glossiness values above 100 will result in shininess larger than 128.0 and will be clamped + double shininess = (64.0 * log (pFbxPhong->Shininess.Get())) / (5.0 * log(2.0)); pOsgMat->setShininess(osg::Material::FRONT_AND_BACK, - static_cast(pFbxPhong->Shininess.Get())); + static_cast(shininess)); // get maps factors... result.reflectionFactor = pFbxPhong->ReflectionFactor.Get();