本文整理汇总了C++中ogre::MaterialPtr::applyTextureAliases方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialPtr::applyTextureAliases方法的具体用法?C++ MaterialPtr::applyTextureAliases怎么用?C++ MaterialPtr::applyTextureAliases使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::MaterialPtr
的用法示例。
在下文中一共展示了MaterialPtr::applyTextureAliases方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateMaterialUsingTextureAliases
//---------------------------------------------------------------------
bool SubMesh::updateMaterialUsingTextureAliases(void)
{
bool newMaterialCreated = false;
// if submesh has texture aliases
// ask the material manager if the current summesh material exists
if (hasTextureAliases() && MaterialManager::getSingleton().resourceExists(mMaterialName))
{
// get the current submesh material
MaterialPtr material = MaterialManager::getSingleton().getByName( mMaterialName );
// get test result for if change will occur when the texture aliases are applied
if (material->applyTextureAliases(mTextureAliases, false))
{
Ogre::String newMaterialName;
// If this material was already derived from another material
// due to aliasing, let's strip off the aliasing suffix and
// generate a new one using our current aliasing table.
Ogre::String::size_type pos = mMaterialName.find("?TexAlias(", 0);
if( pos != Ogre::String::npos )
newMaterialName = mMaterialName.substr(0, pos);
else
newMaterialName = mMaterialName;
newMaterialName += "?TexAlias(";
// Iterate deterministically over the aliases (always in the same
// order via std::map's sorted iteration nature).
AliasTextureIterator aliasIter = getAliasTextureIterator();
while( aliasIter.hasMoreElements() )
{
newMaterialName += aliasIter.peekNextKey();
newMaterialName += "=";
newMaterialName += aliasIter.getNext();
newMaterialName += " ";
}
newMaterialName += ")";
// Reuse the material if it's already been created. This decreases batch
// count and keeps material explosion under control.
if(!MaterialManager::getSingleton().resourceExists(newMaterialName))
{
Ogre::MaterialPtr newMaterial = Ogre::MaterialManager::getSingleton().create(
newMaterialName, material->getGroup());
// copy parent material details to new material
material->copyDetailsTo(newMaterial);
// apply texture aliases to new material
newMaterial->applyTextureAliases(mTextureAliases);
}
// place new material name in submesh
setMaterialName(newMaterialName);
newMaterialCreated = true;
}
}
return newMaterialCreated;
}
示例2: updateMaterialUsingTextureAliases
//---------------------------------------------------------------------
bool SubMesh::updateMaterialUsingTextureAliases(void)
{
bool newMaterialCreated = false;
// if submesh has texture aliases
// ask the material manager if the current summesh material exists
if (hasTextureAliases() && MaterialManager::getSingleton().resourceExists(mMaterialName))
{
// get the current submesh material
MaterialPtr material = MaterialManager::getSingleton().getByName( mMaterialName );
// get test result for if change will occur when the texture aliases are applied
if (material->applyTextureAliases(mTextureAliases, false))
{
// material textures will be changed so copy material,
// new material name is old material name + index
// check with material manager and find a unique name
size_t index = 0;
String newMaterialName = mMaterialName + "_" + StringConverter::toString(index);
while (MaterialManager::getSingleton().resourceExists(newMaterialName))
{
// increment index for next name
newMaterialName = mMaterialName + "_" + StringConverter::toString(++index);
}
Ogre::MaterialPtr newMaterial = Ogre::MaterialManager::getSingleton().create(
newMaterialName, material->getGroup());
// copy parent material details to new material
material->copyDetailsTo(newMaterial);
// apply texture aliases to new material
newMaterial->applyTextureAliases(mTextureAliases);
// place new material name in submesh
setMaterialName(newMaterialName);
newMaterialCreated = true;
}
}
return newMaterialCreated;
}
示例3: generate
Ogre::MaterialPtr EmberTerrainProfile::generate(const Ogre::Terrain* terrain)
{
const EmberTerrain* emberTerrain = static_cast<const EmberTerrain*>(terrain);
const auto& index = emberTerrain->getIndex();
IPageData* pageData = mDataProvider.getPageData(index);
if (!pageData) {
S_LOG_WARNING("Could not find corresponding page data for OgreTerrain at " << "[" << index.first << "|" << index.second << "]");
return getOrCreateMaterialClone(mErrorMaterialTemplate, terrain->getMaterialName());
}
S_LOG_INFO("Loading material for terrain page: " << "[" << index.first << "|" << index.second << "]");
Ogre::MaterialPtr mat = pageData->getMaterial();
if (mat.isNull()) {
S_LOG_WARNING("Terrain material was not found.");
return getOrCreateMaterialClone(mErrorMaterialTemplate, terrain->getMaterialName());
}
Ogre::AliasTextureNamePairList aliases;
aliases[Techniques::Shader::NORMAL_TEXTURE_ALIAS] = terrain->getTerrainNormalMap()->getName();
auto compositeMap = terrain->getCompositeMap();
if (!compositeMap.isNull()) {
aliases[Techniques::Shader::COMPOSITE_MAP_ALIAS] = compositeMap->getName();
}
bool success = mat->applyTextureAliases(aliases);
if (!success) {
S_LOG_WARNING("Could not apply alias for normal map and/or composite map for terrain material \"" << mat->getName() << "\"");
}
return mat;
}
示例4: id
const Ogre::MaterialPtr&
Terrain::_getGridMaterial(const TerrainData::GridInfo &gridInfo, ushort depthBias, int nTileX, int nTileZ)
{
assert(mData != NULL);
size_t textureIds[TerrainData::NumLayers] = { 0 };
for (size_t i = 0; i < TerrainData::NumLayers; ++i)
{
if (gridInfo.layers[i].pixmapId)
{
textureIds[i] = _getPixmapAtlasId(gridInfo.layers[i].pixmapId - 1) + 1;
}
}
assert(textureIds[0] && "Internal fault while create grid material");
bool lightmapped = mData->mLightmapImage && getLightmapQuality() != LMQ_NONE;
Ogre::ulong lightmapId = lightmapped ? (nTileZ << 16) | nTileX : ~0;
MaterialId id(textureIds[0], textureIds[1], lightmapId, depthBias);
// find the material that already created
MaterialMap::const_iterator it = mMaterials.find(id);
if (it != mMaterials.end())
return it->second;
Ogre::String name = "Terrain/";
if (!mData->mName.empty())
name += mData->mName + "/";
name += Ogre::StringConverter::toString(textureIds[0]) + "." + Ogre::StringConverter::toString(textureIds[1]);
if (depthBias)
name += "_" + Ogre::StringConverter::toString(depthBias);
Ogre::String lightmapName = "<Lightmap>(" +
Ogre::StringConverter::toString(nTileX / mData->mTileSize) + "," +
Ogre::StringConverter::toString(nTileZ / mData->mTileSize) + ")";
if (lightmapped)
name += "_" + lightmapName;
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(name);
if (material.isNull())
{
// get user supplied material
Ogre::String templateName = textureIds[1] ? "TwoLayer" : "OneLayer";
if (lightmapped)
templateName += "Lightmap";
TerrainData::MaterialTemplates::const_iterator it =
mData->mMaterialTemplates.find(templateName);
if (it == mData->mMaterialTemplates.end())
OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
"Can't found grid material template for '" + templateName + "'!",
"Terrain::_getGridMaterial");
const Ogre::String& baseName = it->second;
Ogre::MaterialPtr templateMaterial = Ogre::MaterialManager::getSingleton().getByName(baseName);
if (templateMaterial.isNull())
OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
"Can't load grid material template '" + baseName + "'!",
"Terrain::_getGridMaterial");
// clone the material
material = templateMaterial->clone(name, true, BRUSH_RESOURCE_GROUP_NAME);
// Setup texture alias list
Ogre::AliasTextureNamePairList aliasList;
aliasList["<layer0>"] = mAtlases[textureIds[0]-1].texture->getName();
if (textureIds[1])
aliasList["<layer1>"] = mAtlases[textureIds[1]-1].texture->getName();
if (lightmapped)
aliasList["<lightmap>"] = lightmapName;
// Applies texture names
material->applyTextureAliases(aliasList);
// Applies surface params
_applySurfaceParams(material);
// Applies fog
_applyFogMode(material, Ogre::FOG_NONE, mCurrentFogMode);
// Adjust other material attributes
Ogre::Material::TechniqueIterator ti = material->getTechniqueIterator();
while (ti.hasMoreElements())
{
Ogre::Technique* technique = ti.getNext();
Ogre::Technique::PassIterator pi = technique->getPassIterator();
while (pi.hasMoreElements())
{
Ogre::Pass* pass = pi.getNext();
if (depthBias)
{
#if OGRE_VERSION >= 0x010300
pass->setDepthBias(depthBias + pass->getDepthBiasConstant(), pass->getDepthBiasSlopeScale());
#else
pass->setDepthBias(depthBias + pass->getDepthBias());
#endif
}
}
}
}
//.........这里部分代码省略.........
示例5: createTerrain
bool Terrain::createTerrain()
{
if(mMainViewport == NULL)
mMainViewport = Core::getSingleton().mCamera->getViewport();
Ogre::CompositorManager::getSingleton().addCompositor(mMainViewport, "DemoCompositor");
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mMainViewport, "DemoCompositor", true);
mMapData = MapDataManager::getSingletonPtr();
DataLibrary* datalib = DataLibrary::getSingletonPtr();
int terrainszie = mMapData->getMapSize() + 2 * MAPBOLDER + 1;
Core::getSingleton().mSceneMgr->setSkyBox(true, "SkyBox",200);
Ogre::GpuSharedParametersPtr sharedparams = Ogre::GpuProgramManager::getSingleton().getSharedParameters("TestSharedParamsName");
float border = mMapData->getMapSize() * 12.0f;
sharedparams->setNamedConstant("border", border);
//创建灯光
Core::getSingleton().mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
mLight = Core::getSingleton().mSceneMgr->createLight("TerrainLight");
mLight->setType(Ogre::Light::LT_DIRECTIONAL);
mLight->setPosition(-500.0f,500.0f, 500.0f);
mLight->setDirection(1.0f, -1.0f, -1.0f);
mLight->setDiffuseColour(Ogre::ColourValue(0.5f, 0.5f,0.5f));
mLight->setSpecularColour(Ogre::ColourValue(0.8f, 0.8f,0.8f));
//设置深度图投影
Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().getByName("shadowdepthmap");
if(tex.isNull())
tex = Ogre::TextureManager::getSingleton().createManual("shadowdepthmap",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 2048, 2048, 0, Ogre::PF_FLOAT16_R, Ogre::TU_RENDERTARGET);
mShadowDepthMapTarget = tex->getBuffer()->getRenderTarget();
Ogre::Viewport* vp = mShadowDepthMapTarget->addViewport(CameraContral::getSingleton().getShadowMapCamera());
vp->setSkiesEnabled(false);
vp->setOverlaysEnabled(false);
vp->setVisibilityMask(VISMASK_OPAQUE);
vp->setMaterialScheme("WriteDepthMap");
vp->setBackgroundColour(Ogre::ColourValue(1.0f,1.0f,1.0f));
mShadowDepthMapTarget->addListener(this);
//弱爆了……
Ogre::MaterialPtr mat;
mat = Ogre::MaterialManager::getSingleton().getByName("TerrainTile");
Ogre::AliasTextureNamePairList texAliasList;
std::string texname;
datalib->getData("GameData/BattleData/MapData/Ground/G0Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
datalib->getData("GameData/BattleData/MapData/Ground/G1Tex",texname);
texAliasList.insert(std::make_pair("Diffuse1",texname));
datalib->getData("GameData/BattleData/MapData/Ground/G2Tex",texname);
texAliasList.insert(std::make_pair("Diffuse2",texname));
datalib->getData("GameData/BattleData/MapData/Ground/G3Tex",texname);
texAliasList.insert(std::make_pair("Diffuse3",texname));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("CliffMat1");
datalib->getData("GameData/BattleData/MapData/Ground/G0Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("CliffMat2");
datalib->getData("GameData/BattleData/MapData/Ground/G1Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("CliffMat3");
datalib->getData("GameData/BattleData/MapData/Ground/G2Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("CliffMat4");
datalib->getData("GameData/BattleData/MapData/Ground/G3Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("BankMat1");
datalib->getData("GameData/BattleData/MapData/Ground/G0Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("BankMat2");
datalib->getData("GameData/BattleData/MapData/Ground/G1Tex",texname);
texAliasList.insert(std::make_pair("Diffuse",texname));
texAliasList.insert(std::make_pair("Diffuse1","Cliff.tga"));
mat->applyTextureAliases(texAliasList);
texAliasList.clear();
mat = Ogre::MaterialManager::getSingleton().getByName("BankMat3");
datalib->getData("GameData/BattleData/MapData/Ground/G2Tex",texname);
//.........这里部分代码省略.........