Converted the osg::Material::set/getShininess option to use the standard

OpenGL range of 0.0 to 128.0 instead of the previous normalised shiniess
range. This brings it inline with the way the rest of the OSG uses a
1 to 1 mapping to OpenGL.

Converted the various loaders to use the new range, which is almost all
cases was simply removing the /128.0f which was required before!
This commit is contained in:
Robert Osfield
2002-07-18 09:55:30 +00:00
parent 1a139efbbc
commit 7a8eeb3c92
8 changed files with 15 additions and 19 deletions

View File

@@ -120,7 +120,7 @@ class SG_EXPORT Material : public StateAttribute
/** Get the whether emission values are equal for front and back faces.*/
inline const bool getEmissionFrontAndBack() const { return _emissionFrontAndBack; }
/** Set shininess of specified face(s) of the material, valid shininess range is 0.0 to 1.0.*/
/** Set shininess of specified face(s) of the material, valid shininess range is 0.0 to 128.0.*/
void setShininess( const Face face, float shininess );
/** Get the shininess value for specified face.*/
const float getShininess(const Face face) const;
@@ -158,8 +158,8 @@ class SG_EXPORT Material : public StateAttribute
Vec4 _emissionBack; // r, g, b, w
bool _shininessFrontAndBack;
float _shininessFront; // values 0 - 1.0
float _shininessBack; // values 0 - 1.0
float _shininessFront; // values 0 - 128.0
float _shininessBack; // values 0 - 128.0
};

View File

@@ -227,7 +227,7 @@ const Vec4& Material::getEmission(const Face face) const
void Material::setShininess( const Face face, float shininess )
{
clampBetweenRange(shininess,0.0f,1.0f,"Material::setShininess()");
clampBetweenRange(shininess,0.0f,128.0f,"Material::setShininess()");
switch(face)
{
@@ -389,12 +389,12 @@ void Material::apply(State&) const
if (_shininessFrontAndBack)
{
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, _shininessFront* 128.0f );
glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, _shininessFront );
}
else
{
glMaterialf( GL_FRONT, GL_SHININESS, _shininessFront* 128.0f );
glMaterialf( GL_BACK, GL_SHININESS, _shininessBack* 128.0f );
glMaterialf( GL_FRONT, GL_SHININESS, _shininessFront );
glMaterialf( GL_BACK, GL_SHININESS, _shininessBack );
}
}

View File

@@ -962,7 +962,7 @@ class ReaderWriterDW : public osgDB::ReaderWriter
matpalet[nmat].setspecular(spec);
} else if (strncmp(buff, "SmoothnessExponent:",19)==0) {
float spec=atof(buff+19);
matpalet[nmat].setspecexp(spec/100.0f); // convert to 0-1 from percent
matpalet[nmat].setspecexp(spec*128.0f/100.0f); // convert to 0-128 range from percent
} else if (strncmp(buff, "TextureWidthAndHeight:",22)==0) {
char *ct=strchr(buff+22,',');
float repx=atof(buff+23), repy=atof(ct+1);

View File

@@ -919,7 +919,7 @@ void ConvertFromFLT::visitFace(GeoSetBuilder* pBuilder, FaceRecord* rec)
osgMaterial->setSpecular(osg::Material::FRONT_AND_BACK, specular);
osgMaterial->setEmission(osg::Material::FRONT_AND_BACK, emissiv);
osgMaterial->setAlpha(osg::Material::FRONT_AND_BACK, alpha);
osgMaterial->setShininess(osg::Material::FRONT_AND_BACK, pSMaterial->sfShininess/128.0f);
osgMaterial->setShininess(osg::Material::FRONT_AND_BACK, pSMaterial->sfShininess);
osgStateSet->setAttribute(osgMaterial);
if (alpha < 1.0f) bBlend = true;

View File

@@ -117,7 +117,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil
osg::Vec4(omtl->emmissive[0], omtl->emmissive[1],
omtl->emmissive[2], omtl->emmissive[3]));
// note, osg shininess scales between 0.0 and 1.0.
mtl->setShininess(osg::Material::FRONT_AND_BACK, omtl->shininess/128.0f);
mtl->setShininess(osg::Material::FRONT_AND_BACK, omtl->shininess);
stateset->setAttribute(mtl);

View File

@@ -1013,8 +1013,7 @@ osg::Material* ConvertFromPerformer::visitMaterial(osg::StateSet* osgStateSet,pf
case(PFMTL_CMODE_OFF): osgMaterial->setColorMode(osg::Material::OFF); break;
}
float s = material->getShininess()/128.0f;
osgMaterial->setShininess(osg::Material::FRONT_AND_BACK,s);
osgMaterial->setShininess(osg::Material::FRONT_AND_BACK,material->getShininess());
float a = material->getAlpha();
float r,g,b;
@@ -1046,13 +1045,11 @@ osg::Material* ConvertFromPerformer::visitMaterial(osg::StateSet* osgStateSet,pf
case(PFMTL_CMODE_OFF): osgMaterial->setColorMode(osg::Material::OFF); break;
}
float s;
float a;
float r,g,b;
// front material
s = front_mat->getShininess();
osgMaterial->setShininess(osg::Material::FRONT,s);
osgMaterial->setShininess(osg::Material::FRONT,front_mat->getShininess());
a = front_mat->getAlpha();
@@ -1069,8 +1066,7 @@ osg::Material* ConvertFromPerformer::visitMaterial(osg::StateSet* osgStateSet,pf
osgMaterial->setSpecular(osg::Material::FRONT,osg::Vec4(r,g,b,a));
// back material
s = back_mat->getShininess();
osgMaterial->setShininess(osg::Material::BACK,s);
osgMaterial->setShininess(osg::Material::BACK,back_mat->getShininess());
a = back_mat->getAlpha();

View File

@@ -198,7 +198,7 @@ void TrPageArchive::LoadMaterials()
float64 shinines;
mat->GetShininess(shinines);
osg_material->setShininess(Material::FRONT_AND_BACK , (float)shinines/128.0);
osg_material->setShininess(Material::FRONT_AND_BACK , (float)shinines);
osg_material->setAlpha(Material::FRONT_AND_BACK ,(float)alpha);
osg_state_set->setAttributeAndModes(osg_material, StateAttribute::ON);

View File

@@ -726,7 +726,7 @@ void TrPageParser::LoadLocalMaterials()
float64 shinines;
mat->GetShininess(shinines);
osg_material->setShininess(Material::FRONT_AND_BACK , (float)shinines/128.0);
osg_material->setShininess(Material::FRONT_AND_BACK , (float)shinines);
osg_material->setAlpha(Material::FRONT_AND_BACK ,(float)alpha);
osg_state_set->setAttributeAndModes(osg_material, StateAttribute::ON);