diff --git a/src/osgPlugins/3ds/ReaderWriter3DS.cpp b/src/osgPlugins/3ds/ReaderWriter3DS.cpp index cffe3cf5f..138bd3cf3 100644 --- a/src/osgPlugins/3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/3ds/ReaderWriter3DS.cpp @@ -1047,12 +1047,13 @@ osg::StateSet* ReaderWriter3DS::ReaderObject::createStateSet(Lib3dsMaterial *mat osg::Vec4 specular(mat->specular[0],mat->specular[1],mat->specular[2],alpha); specular *= mat->shin_strength; - float shininess = mat->shininess; + float shininess = mat->shininess*128.0f; + //float shininess = pow(2, 10.0*mat->shininess); // As in lib3ds example material->setName(mat->name); material->setAmbient(osg::Material::FRONT_AND_BACK,ambient); material->setDiffuse(osg::Material::FRONT_AND_BACK,diffuse); material->setSpecular(osg::Material::FRONT_AND_BACK,specular); - material->setShininess(osg::Material::FRONT_AND_BACK,shininess*128.0f); + material->setShininess(osg::Material::FRONT_AND_BACK,shininess); stateset->setAttribute(material); diff --git a/src/osgPlugins/3ds/WriterNodeVisitor.cpp b/src/osgPlugins/3ds/WriterNodeVisitor.cpp index 604925eac..867d1b48f 100644 --- a/src/osgPlugins/3ds/WriterNodeVisitor.cpp +++ b/src/osgPlugins/3ds/WriterNodeVisitor.cpp @@ -389,7 +389,12 @@ WriterNodeVisitor::Material::Material(WriterNodeVisitor & writerNodeVisitor, osg diffuse = mat->getDiffuse(osg::Material::FRONT); ambient = mat->getAmbient(osg::Material::FRONT); specular = mat->getSpecular(osg::Material::FRONT); - shininess = mat->getShininess(osg::Material::FRONT); + shininess = mat->getShininess(osg::Material::FRONT) / 128.f; + // OpenGL shininess = pow(2, 10.0*mat->shininess); (As in lib3ds example) + // => mat->shininess = log.2( OpenGL shininess ) /10 (if values are >0) + // => mat->shininess = log( OpenGL shininess ) / log(2) /10 + //shininess = mat->getShininess(osg::Material::FRONT) <= 0 ? 0 : log( mat->getShininess(osg::Material::FRONT) ) / log(2.f) / 10.f; + transparency = 1-diffuse.w(); name = writerNodeVisitor.getUniqueName(mat->getName(),"mat"); osg::StateAttribute * attribute = stateset->getAttribute(osg::StateAttribute::CULLFACE); @@ -421,7 +426,8 @@ WriterNodeVisitor::Material::Material(WriterNodeVisitor & writerNodeVisitor, osg if(img) { texture_transparency = (stateset->getMode(GL_BLEND) == osg::StateAttribute::ON); - texture_no_tile = (tex->getWrap(osg::Texture2D::WRAP_S) == osg::Texture2D::CLAMP); + osg::Texture::WrapMode wrapS = tex->getWrap(osg::Texture2D::WRAP_S); + texture_no_tile = !(wrapS == osg::Texture2D::REPEAT || wrapS == osg::Texture2D::MIRROR); image = img; } } @@ -576,8 +582,11 @@ void WriterNodeVisitor::writeMaterials() _imageSet.insert(mat.image.get()); osgDB::writeImageFile(*(mat.image), path); } + // Here we don't assume anything about initial flags state (actually it is set to LIB3DS_TEXTURE_NO_TILE by lib3DS, but this is subject to change) if (mat.texture_transparency) tex.flags |= LIB3DS_TEXTURE_ALPHA_SOURCE; + else tex.flags &= ~LIB3DS_TEXTURE_ALPHA_SOURCE; if (mat.texture_no_tile) tex.flags |= LIB3DS_TEXTURE_NO_TILE; + else tex.flags &= ~LIB3DS_TEXTURE_NO_TILE; } if (!succeeded()) return;