本文整理汇总了C++中ogre::Technique类的典型用法代码示例。如果您正苦于以下问题:C++ Technique类的具体用法?C++ Technique怎么用?C++ Technique使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Technique类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateFromCamera
void AmbientLight::updateFromCamera(Ogre::Camera* camera)
{
Ogre::Technique* tech = getMaterial()->getBestTechnique();
Ogre::Vector3 farCorner = camera->getViewMatrix(true) * camera->getWorldSpaceCorners()[4];
for (unsigned short i=0; i<tech->getNumPasses(); i++)
{
Ogre::Pass* pass = tech->getPass(i);
// get the vertex shader parameters
Ogre::GpuProgramParametersSharedPtr params = pass->getVertexProgramParameters();
// set the camera's far-top-right corner
if (params->_findNamedConstantDefinition("farCorner"))
params->setNamedConstant("farCorner", farCorner);
params = pass->getFragmentProgramParameters();
if (params->_findNamedConstantDefinition("farCorner"))
params->setNamedConstant("farCorner", farCorner);
}
}
示例2: addEffect
void EffectManager::addEffect(const std::string &model, std::string textureOverride, const Ogre::Vector3 &worldPosition, float scale)
{
Ogre::SceneNode* sceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(worldPosition);
sceneNode->setScale(scale,scale,scale);
NifOgre::ObjectScenePtr scene = NifOgre::Loader::createObjects(sceneNode, model);
MWRender::Animation::setRenderProperties(scene, RV_Effects,
RQG_Main, RQG_Alpha, 0.f, false, NULL);
for(size_t i = 0;i < scene->mControllers.size();i++)
{
if(scene->mControllers[i].getSource().isNull())
scene->mControllers[i].setSource(Ogre::SharedPtr<EffectAnimationTime> (new EffectAnimationTime()));
}
if (!textureOverride.empty())
{
std::string correctedTexture = Misc::ResourceHelpers::correctTexturePath(textureOverride);
for(size_t i = 0;i < scene->mParticles.size(); ++i)
{
Ogre::ParticleSystem* partSys = scene->mParticles[i];
Ogre::MaterialPtr mat = scene->mMaterialControllerMgr.getWritableMaterial(partSys);
for (int t=0; t<mat->getNumTechniques(); ++t)
{
Ogre::Technique* tech = mat->getTechnique(t);
for (int p=0; p<tech->getNumPasses(); ++p)
{
Ogre::Pass* pass = tech->getPass(p);
for (int tex=0; tex<pass->getNumTextureUnitStates(); ++tex)
{
Ogre::TextureUnitState* tus = pass->getTextureUnitState(tex);
tus->setTextureName(correctedTexture);
}
}
}
}
}
mEffects.push_back(std::make_pair(sceneNode, scene));
}
示例3: createdConfiguration
void Water::createdConfiguration (sh::MaterialInstance* m, const std::string& configuration)
{
if (configuration == "local_map" || !Settings::Manager::getBool("shader", "Water"))
{
// for simple water, set animated texture names
// these have to be set in code
std::string textureNames[32];
for (int i=0; i<32; ++i)
{
textureNames[i] = "textures\\water\\water" + StringConverter::toString(i, 2, '0') + ".dds";
}
Ogre::Technique* t = static_cast<sh::OgreMaterial*>(m->getMaterial())->getOgreTechniqueForConfiguration(configuration);
if (t->getPass(0)->getNumTextureUnitStates () == 0)
return;
t->getPass(0)->getTextureUnitState(0)->setAnimatedTextureName(textureNames, 32, 2);
t->getPass(0)->setDepthWriteEnabled (false);
t->getPass(0)->setSceneBlending (Ogre::SBT_TRANSPARENT_ALPHA);
}
}
示例4: getFirstTexture
//-----------------------------------------------------------------------
Ogre::TextureUnitState* MaterialTab::getFirstTexture(void)
{
wxString materialName = mMaterialListBox->GetStringSelection();
Ogre::String name = wx2ogre(materialName);
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(name);
if (!material.isNull() && material->getNumTechniques() > 0)
{
material->load();
Ogre::Technique* technique = material->getBestTechnique(); // Get the best technique
if (technique && technique->getNumPasses() > 0)
{
Ogre::Pass* pass = technique->getPass(0); // Get the first
if (pass->getNumTextureUnitStates() > 0)
{
return pass->getTextureUnitState(0); // Get the first
}
}
}
return 0;
}
示例5: OnDeleteMaterialObject
void MaterialEditor::OnDeleteMaterialObject(wxCommandEvent &e)
{
if(mMaterial.isNull())
return;
if(m_MaterialTree->getSelecteTextureUnit())
{
Ogre::TextureUnitState* pTexture = m_MaterialTree->getSelecteTextureUnit();
Ogre::Pass* pPass = pTexture->getParent();
if(pPass)
{
pPass->removeTextureUnitState(pPass->getTextureUnitStateIndex(pTexture));
}
}
else if(m_MaterialTree->getSelectePass())
{
Ogre::Pass* pPass = m_MaterialTree->getSelectePass();
Ogre::Technique* pTechnique = pPass->getParent();
if(pTechnique)
{
pTechnique->removePass(pPass->getIndex());
}
}
else if(m_MaterialTree->getSelecteTechnique())
{
Ogre::Technique* pTechnique = m_MaterialTree->getSelecteTechnique();
for(int i= 0;i<mMaterial->getNumTechniques();i++)
{
if(pTechnique == mMaterial->getTechnique(i))
{
mMaterial->removeTechnique(i);
break;
}
}
}
else
return;
m_Frame->GetEffectObjectProperty()->InitMaterialEditor(mMaterial,mMaterialName);
m_MaterialTree->DeleteAllItems();
m_MaterialTree->AddMaterialToTree(mMaterial,mMaterialName);
}
示例6: handleSchemeNotFound
/** This class demonstrates basic usage of the RTShader system.
It sub class the material manager listener class and when a target scheme callback
is invoked with the shader generator scheme it tries to create an equivalent shader
based technique based on the default technique of the given material.
*/
Ogre::Technique* MaterialMgrListener::handleSchemeNotFound(unsigned short schemeIndex,
const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex,
const Ogre::Renderable* rend)
{
Ogre::Technique* generatedTech = NULL;
// Case this is the default shader generator scheme.
if (schemeName == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME)
{
bool techniqueCreated;
// Create shader generated technique for this material.
techniqueCreated = mShaderGenerator->createShaderBasedTechnique(
originalMaterial->getName(),
Ogre::MaterialManager::DEFAULT_SCHEME_NAME,
schemeName);
// Case technique registration succeeded.
if (techniqueCreated)
{
// Force creating the shaders for the generated technique.
mShaderGenerator->validateMaterial(schemeName, originalMaterial->getName());
// Grab the generated technique.
Ogre::Material::TechniqueIterator itTech = originalMaterial->getTechniqueIterator();
while (itTech.hasMoreElements())
{
Ogre::Technique* curTech = itTech.getNext();
if (curTech->getSchemeName() == schemeName)
{
generatedTech = curTech;
break;
}
}
}
}
return generatedTech;
}
示例7: setColor
void MeshPersonVisual::setColor(const Ogre::ColourValue& c) {
Ogre::SceneBlendType blending;
bool depth_write;
if ( c.a < 0.9998 )
{
blending = Ogre::SBT_TRANSPARENT_ALPHA;
depth_write = false;
}
else
{
blending = Ogre::SBT_REPLACE;
depth_write = true;
}
std::set<Ogre::MaterialPtr>::iterator it;
for( it = materials_.begin(); it != materials_.end(); it++ )
{
Ogre::Technique* technique = (*it)->getTechnique( 0 );
technique->setAmbient( c.r*0.5, c.g*0.5, c.b*0.5 );
technique->setDiffuse( c.r, c.g, c.b, c.a );
technique->setSceneBlending( blending );
technique->setDepthWriteEnabled( depth_write );
technique->setLightingEnabled( true );
}
}
示例8: GetTextureNamesFromMaterial
void GetTextureNamesFromMaterial(Ogre::MaterialPtr material, StringVector& textures)
{
textures.clear();
if (material.isNull())
return;
// Use a set internally to avoid duplicates
std::set<std::string> textures_set;
Ogre::Material::TechniqueIterator iter = material->getTechniqueIterator();
while(iter.hasMoreElements())
{
Ogre::Technique *tech = iter.getNext();
assert(tech);
Ogre::Technique::PassIterator passIter = tech->getPassIterator();
while(passIter.hasMoreElements())
{
Ogre::Pass *pass = passIter.getNext();
Ogre::Pass::TextureUnitStateIterator texIter = pass->getTextureUnitStateIterator();
while(texIter.hasMoreElements())
{
Ogre::TextureUnitState *texUnit = texIter.getNext();
const std::string& texname = texUnit->getTextureName();
if (!texname.empty())
textures_set.insert(texname);
}
}
}
std::set<std::string>::iterator i = textures_set.begin();
while (i != textures_set.end())
{
textures.push_back(*i);
++i;
}
}
示例9: Animation
ActivatorAnimation::ActivatorAnimation(const MWWorld::Ptr &ptr)
: Animation(ptr)
{
MWWorld::LiveCellRef<ESM::Activator> *ref = mPtr.get<ESM::Activator>();
assert (ref->mBase != NULL);
if(!ref->mBase->mModel.empty())
{
std::string mesh = "meshes\\" + ref->mBase->mModel;
createEntityList(mPtr.getRefData().getBaseNode(), mesh);
for(size_t i = 0;i < mEntityList.mEntities.size();i++)
{
Ogre::Entity *ent = mEntityList.mEntities[i];
bool transparent = false;
for (unsigned int j=0;j < ent->getNumSubEntities() && !transparent; ++j)
{
Ogre::MaterialPtr mat = ent->getSubEntity(j)->getMaterial();
Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
while (techIt.hasMoreElements() && !transparent)
{
Ogre::Technique* tech = techIt.getNext();
Ogre::Technique::PassIterator passIt = tech->getPassIterator();
while (passIt.hasMoreElements() && !transparent)
{
Ogre::Pass* pass = passIt.getNext();
if (pass->getDepthWriteEnabled() == false)
transparent = true;
}
}
}
ent->setVisibilityFlags(RV_Misc);
ent->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
}
setAnimationSource(mesh);
}
}
示例10:
void RoR::SkinManager::ReplaceMaterialTextures(SkinDef* skin_def, std::string materialName) // Static
{
const auto not_found = skin_def->replace_textures.end();
Ogre::MaterialPtr mat = RoR::OgreSubsystem::GetMaterialByName(materialName);
if (!mat.isNull())
{
for (int t = 0; t < mat->getNumTechniques(); t++)
{
Ogre::Technique* tech = mat->getTechnique(0);
if (!tech)
continue;
for (int p = 0; p < tech->getNumPasses(); p++)
{
Ogre::Pass* pass = tech->getPass(p);
if (!pass)
continue;
for (int tu = 0; tu < pass->getNumTextureUnitStates(); tu++)
{
Ogre::TextureUnitState* tus = pass->getTextureUnitState(tu);
if (!tus)
continue;
//if (tus->getTextureType() != TEX_TYPE_2D) continue; // only replace 2d images
// walk the frames, usually there is only one
for (unsigned int fr = 0; fr < tus->getNumFrames(); fr++)
{
Ogre::String textureName = tus->getFrameTextureName(fr);
std::map<Ogre::String, Ogre::String>::iterator it = skin_def->replace_textures.find(textureName);
if (it != not_found)
{
textureName = it->second; //getReplacementForTexture(textureName);
tus->setFrameTextureName(textureName, fr);
}
}
}
}
}
}
}
示例11: SetMaterialParameters
void CompositionHandler::SetMaterialParameters(const Ogre::MaterialPtr &material, const QList< std::pair<std::string, Ogre::Vector4> > &source) const
{
assert (material.get());
material->load();
for(ushort t=0 ; t<material->getNumTechniques() ; ++t)
{
Ogre::Technique *technique = material->getTechnique(t);
if (technique)
{
for(ushort p=0 ; p<technique->getNumPasses() ; ++p)
{
Ogre::Pass *pass = technique->getPass(p);
if (pass)
{
if (pass->hasVertexProgram())
{
Ogre::GpuProgramParametersSharedPtr destination = pass->getVertexProgramParameters();
for(int i=0 ; i<source.size() ; ++i)
{
if (destination->_findNamedConstantDefinition(source[i].first, false))
destination->setNamedConstant(source[i].first, source[i].second);
}
}
if (pass->hasFragmentProgram())
{
Ogre::GpuProgramParametersSharedPtr destination = pass->getFragmentProgramParameters();
for(int i=0 ; i<source.size() ; ++i)
{
if (destination->_findNamedConstantDefinition(source[i].first, false))
destination->setNamedConstant(source[i].first, source[i].second);
}
}
}
}
}
}
}
示例12: unloadTheMesh
// unload all about this mesh. The mesh itself and the textures.
// BETWEEN FRAME OPERATION
void VisCalcFrustDist::unloadTheMesh(Ogre::MeshPtr meshP) {
if (m_shouldCullTextures) {
Ogre::Mesh::SubMeshIterator smi = meshP->getSubMeshIterator();
while (smi.hasMoreElements()) {
Ogre::SubMesh* oneSubMesh = smi.getNext();
Ogre::String subMeshMaterialName = oneSubMesh->getMaterialName();
Ogre::MaterialPtr subMeshMaterial = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().getByName(subMeshMaterialName);
if (!subMeshMaterial.isNull()) {
Ogre::Material::TechniqueIterator techIter = subMeshMaterial->getTechniqueIterator();
while (techIter.hasMoreElements()) {
Ogre::Technique* oneTech = techIter.getNext();
Ogre::Technique::PassIterator passIter = oneTech->getPassIterator();
while (passIter.hasMoreElements()) {
Ogre::Pass* onePass = passIter.getNext();
Ogre::Pass::TextureUnitStateIterator tusIter = onePass->getTextureUnitStateIterator();
while (tusIter.hasMoreElements()) {
Ogre::TextureUnitState* oneTus = tusIter.getNext();
Ogre::String texName = oneTus->getTextureName();
Ogre::TexturePtr texP = (Ogre::TexturePtr)Ogre::TextureManager::getSingleton().getByName(texName);
if (!texP.isNull()) {
// if (texP.useCount() <= 1) {
texP->unload();
LG::IncStat(LG::StatCullTexturesUnloaded);
// LG::Log("unloadTheMesh: unloading texture %s", texName.c_str());
// }
}
}
}
}
}
}
}
if (m_shouldCullMeshes) {
LG::OLMeshTracker::Instance()->MakeUnLoaded(meshP->getName(), Ogre::String(), NULL);
LG::IncStat(LG::StatCullMeshesUnloaded);
// LG::Log("unloadTheMesh: unloading mesh %s", mshName.c_str());
}
}
示例13: findFogPassesByName
void GroundFog::findFogPassesByName (const Ogre::String& passName) {
Ogre::MaterialManager *matManager = Ogre::MaterialManager::getSingletonPtr();
Ogre::MaterialManager::ResourceMapIterator matIt = matManager->getResourceIterator();
while (matIt.hasMoreElements()) {
#if (OGRE_VERSION < ((1 << 16) | (9 << 8) | 0))
Ogre::MaterialPtr mat = matIt.getNext();
#else
Ogre::MaterialPtr mat = matIt.getNext().staticCast<Ogre::Material>();
#endif
Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
while (techIt.hasMoreElements()) {
Ogre::Technique *tech = techIt.getNext();
Ogre::Technique::PassIterator passIt = tech->getPassIterator();
while (passIt.hasMoreElements()) {
Ogre::Pass *pass = passIt.getNext();
if (pass->getName() == passName) {
mPasses.insert(pass);
}
}
}
}
forceUpdate();
}
示例14: SetTextureUnitOnMaterial
void SetTextureUnitOnMaterial(Ogre::MaterialPtr material, const std::string& texture_name, uint index)
{
if (material.isNull())
return;
Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
Ogre::TexturePtr tex = tm.getByName(texture_name);
Ogre::Material::TechniqueIterator iter = material->getTechniqueIterator();
while(iter.hasMoreElements())
{
Ogre::Technique *tech = iter.getNext();
assert(tech);
Ogre::Technique::PassIterator passIter = tech->getPassIterator();
while(passIter.hasMoreElements())
{
Ogre::Pass *pass = passIter.getNext();
Ogre::Pass::TextureUnitStateIterator texIter = pass->getTextureUnitStateIterator();
uint cmp_index = 0;
while(texIter.hasMoreElements())
{
Ogre::TextureUnitState *texUnit = texIter.getNext();
if (index == cmp_index)
{
if (tex.get())
texUnit->setTextureName(texture_name);
else
texUnit->setTextureName("TextureMissing.png");
}
cmp_index++;
}
}
}
}
示例15: _updateShaders
void GrassLayerBase::_updateShaders()
{
if (shaderNeedsUpdate) {
shaderNeedsUpdate = false;
//Proceed only if there is no custom vertex shader and the user's computer supports vertex shaders
const RenderSystemCapabilities *caps = Root::getSingleton().getRenderSystem()->getCapabilities();
if (caps->hasCapability(RSC_VERTEX_PROGRAM) && geom->getShadersEnabled()) {
//Calculate fade range
float farViewDist = geom->getDetailLevels().front()->getFarRange();
float fadeRange = farViewDist / 1.2247449f;
//Note: 1.2247449 ~= sqrt(1.5), which is necessary since the far view distance is measured from the centers
//of pages, while the vertex shader needs to fade grass completely out (including the closest corner)
//before the page center is out of range.
//Generate a string ID that identifies the current set of vertex shader options
StringUtil::StrStreamType tmpName;
tmpName << "GrassVS_";
if (animate)
tmpName << "anim_";
if (blend)
tmpName << "blend_";
if (lighting)
tmpName << "lighting_";
tmpName << renderTechnique << "_";
tmpName << fadeTechnique << "_";
if (fadeTechnique == FADETECH_GROW || fadeTechnique == FADETECH_ALPHAGROW)
tmpName << maxHeight << "_";
tmpName << farViewDist << "_";
tmpName << "vp";
const String vsName = tmpName.str();
//Generate a string ID that identifies the material combined with the vertex shader
const String matName = material->getName() + "_" + vsName;
//Check if the desired material already exists (if not, create it)
MaterialPtr tmpMat = MaterialManager::getSingleton().getByName(matName);
if (tmpMat.isNull()) {
//Clone the original material
tmpMat = material->clone(matName);
//Disable lighting
tmpMat->setLightingEnabled(false);
//tmpMat->setReceiveShadows(false);
//Check if the desired shader already exists (if not, compile it)
String shaderLanguage = ShaderHelper::getShaderLanguage();
HighLevelGpuProgramPtr vertexShader = HighLevelGpuProgramManager::getSingleton().getByName(vsName);
if (vertexShader.isNull()) {
//Generate the grass shader
String vertexProgSource;
if (!shaderLanguage.compare("hlsl") || !shaderLanguage.compare("cg")) {
vertexProgSource = "void main( \n"
" float4 iPosition : POSITION, \n"
" float4 iColor : COLOR, \n"
" float2 iUV : TEXCOORD0, \n"
" out float4 oPosition : POSITION, \n"
" out float4 oColor : COLOR, \n"
" out float2 oUV : TEXCOORD0, \n";
if (lighting)
vertexProgSource += " uniform float4 objSpaceLight, \n"
" uniform float4 lightDiffuse, \n"
" uniform float4 lightAmbient, \n";
if (animate)
vertexProgSource += " uniform float time, \n"
" uniform float frequency, \n"
" uniform float4 direction, \n";
if (fadeTechnique == FADETECH_GROW || fadeTechnique == FADETECH_ALPHAGROW)
vertexProgSource += " uniform float grassHeight, \n";
if (renderTechnique == GRASSTECH_SPRITE || lighting)
vertexProgSource += " float4 iNormal : NORMAL, \n";
vertexProgSource += " uniform float4x4 worldViewProj, \n"
" uniform float3 camPos, \n"
" uniform float fadeRange ) \n"
"{ \n"
" oColor.rgb = iColor.rgb; \n"
" float4 position = iPosition; \n"
" float dist = distance(camPos.xz, position.xz); \n";
if (lighting) {
vertexProgSource += " float3 light = normalize(objSpaceLight.xyz - (iPosition.xyz * objSpaceLight.w)); \n"
" float diffuseFactor = max(dot(float4(0,1,0,0), light), 0); \n"
" oColor = (lightAmbient + diffuseFactor * lightDiffuse) * iColor; \n";
} else {
vertexProgSource += " oColor.rgb = iColor.rgb; \n";
}
if (fadeTechnique == FADETECH_ALPHA || fadeTechnique == FADETECH_ALPHAGROW)
vertexProgSource +=
//Fade out in the distance
" oColor.a = 2.0f - (2.0f * dist / fadeRange); \n";
else
//.........这里部分代码省略.........