Recognize normalHeightMap in the ShaderVisitor

move
scrawl 9 years ago
parent b59b2c6d6d
commit df6fd5f206

@ -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)

@ -39,6 +39,7 @@ namespace Shader
void setAutoUseNormalMaps(bool use); void setAutoUseNormalMaps(bool use);
void setNormalMapPattern(const std::string& pattern); void setNormalMapPattern(const std::string& pattern);
void setNormalHeightMapPattern(const std::string& pattern);
void setAutoUseSpecularMaps(bool use); void setAutoUseSpecularMaps(bool use);
@ -62,6 +63,7 @@ namespace Shader
bool mAutoUseNormalMaps; bool mAutoUseNormalMaps;
std::string mNormalMapPattern; std::string mNormalMapPattern;
std::string mNormalHeightMapPattern;
bool mAutoUseSpecularMaps; bool mAutoUseSpecularMaps;
std::string mSpecularMapPattern; std::string mSpecularMapPattern;
@ -83,6 +85,7 @@ namespace Shader
// osg::Material::ColorMode // osg::Material::ColorMode
int mVertexColorMode; int mVertexColorMode;
bool mMaterialOverridden; bool mMaterialOverridden;
bool mNormalHeight; // true if normal map has height info in alpha channel
// -1 == no tangents required // -1 == no tangents required
int mTexStageRequiringTangents; int mTexStageRequiringTangents;

Loading…
Cancel
Save