|
|
@ -25,6 +25,7 @@ namespace Shader
|
|
|
|
, mColorMaterial(false)
|
|
|
|
, mColorMaterial(false)
|
|
|
|
, mVertexColorMode(GL_AMBIENT_AND_DIFFUSE)
|
|
|
|
, mVertexColorMode(GL_AMBIENT_AND_DIFFUSE)
|
|
|
|
, mMaterialOverridden(false)
|
|
|
|
, mMaterialOverridden(false)
|
|
|
|
|
|
|
|
, mNormalHeight(false)
|
|
|
|
, mTexStageRequiringTangents(-1)
|
|
|
|
, mTexStageRequiringTangents(-1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -120,6 +121,12 @@ namespace Shader
|
|
|
|
if ((texName.empty() || !isTextureNameRecognized(texName)) && unit == 0)
|
|
|
|
if ((texName.empty() || !isTextureNameRecognized(texName)) && unit == 0)
|
|
|
|
texName = "diffuseMap";
|
|
|
|
texName = "diffuseMap";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (texName == "normalHeightMap")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mRequirements.back().mNormalHeight = true;
|
|
|
|
|
|
|
|
texName = "normalMap";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!texName.empty())
|
|
|
|
if (!texName.empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRequirements.back().mTextures[unit] = texName;
|
|
|
|
mRequirements.back().mTextures[unit] = texName;
|
|
|
@ -133,9 +140,9 @@ namespace Shader
|
|
|
|
writableStateSet->setTextureMode(unit, GL_TEXTURE_2D, osg::StateAttribute::ON);
|
|
|
|
writableStateSet->setTextureMode(unit, GL_TEXTURE_2D, osg::StateAttribute::ON);
|
|
|
|
normalMap = texture;
|
|
|
|
normalMap = texture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (texName == "diffuseMap")
|
|
|
|
else if (texName == "diffuseMap")
|
|
|
|
diffuseMap = texture;
|
|
|
|
diffuseMap = texture;
|
|
|
|
if (texName == "specularMap")
|
|
|
|
else if (texName == "specularMap")
|
|
|
|
specularMap = texture;
|
|
|
|
specularMap = texture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -147,10 +154,28 @@ namespace Shader
|
|
|
|
if (mAutoUseNormalMaps && diffuseMap != NULL && normalMap == NULL)
|
|
|
|
if (mAutoUseNormalMaps && diffuseMap != NULL && normalMap == NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string normalMap = diffuseMap->getImage(0)->getFileName();
|
|
|
|
std::string normalMap = diffuseMap->getImage(0)->getFileName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> image;
|
|
|
|
|
|
|
|
bool normalHeight = false;
|
|
|
|
|
|
|
|
std::string normalHeightMap = normalMap;
|
|
|
|
|
|
|
|
boost::replace_last(normalHeightMap, ".", mNormalHeightMapPattern + ".");
|
|
|
|
|
|
|
|
if (mImageManager.getVFS()->exists(normalHeightMap))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
image = mImageManager.getImage(normalHeightMap);
|
|
|
|
|
|
|
|
normalHeight = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
boost::replace_last(normalMap, ".", mNormalMapPattern + ".");
|
|
|
|
boost::replace_last(normalMap, ".", mNormalMapPattern + ".");
|
|
|
|
if (mImageManager.getVFS()->exists(normalMap))
|
|
|
|
if (mImageManager.getVFS()->exists(normalMap))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Texture2D> normalMapTex (new osg::Texture2D(mImageManager.getImage(normalMap)));
|
|
|
|
image = mImageManager.getImage(normalMap);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (image)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> normalMapTex (new osg::Texture2D(image));
|
|
|
|
normalMapTex->setWrap(osg::Texture::WRAP_S, diffuseMap->getWrap(osg::Texture::WRAP_S));
|
|
|
|
normalMapTex->setWrap(osg::Texture::WRAP_S, diffuseMap->getWrap(osg::Texture::WRAP_S));
|
|
|
|
normalMapTex->setWrap(osg::Texture::WRAP_T, diffuseMap->getWrap(osg::Texture::WRAP_T));
|
|
|
|
normalMapTex->setWrap(osg::Texture::WRAP_T, diffuseMap->getWrap(osg::Texture::WRAP_T));
|
|
|
|
normalMapTex->setFilter(osg::Texture::MIN_FILTER, diffuseMap->getFilter(osg::Texture::MIN_FILTER));
|
|
|
|
normalMapTex->setFilter(osg::Texture::MIN_FILTER, diffuseMap->getFilter(osg::Texture::MIN_FILTER));
|
|
|
@ -165,6 +190,7 @@ namespace Shader
|
|
|
|
mRequirements.back().mTextures[unit] = "normalMap";
|
|
|
|
mRequirements.back().mTextures[unit] = "normalMap";
|
|
|
|
mRequirements.back().mTexStageRequiringTangents = unit;
|
|
|
|
mRequirements.back().mTexStageRequiringTangents = unit;
|
|
|
|
mRequirements.back().mShaderRequired = true;
|
|
|
|
mRequirements.back().mShaderRequired = true;
|
|
|
|
|
|
|
|
mRequirements.back().mNormalHeight = normalHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mAutoUseSpecularMaps && diffuseMap != NULL && specularMap == NULL)
|
|
|
|
if (mAutoUseSpecularMaps && diffuseMap != NULL && specularMap == NULL)
|
|
|
|