//-----------------------------------------------------------------------
	void EntityRenderer::_rotateTexture(VisualParticle* particle, Ogre::Entity* entity)
	{
		Ogre::TextureUnitState::EffectMap::const_iterator it;
		// Get the material and rotate it
		unsigned int numberOfSubEntities = entity->getNumSubEntities();
		for (unsigned short u = 0; u < numberOfSubEntities; ++u)
		{
			Ogre::MaterialPtr material = entity->getSubEntity(u)->getMaterial();
			unsigned short numberOfTechniques = material->getNumTechniques();
			for (unsigned short v = 0; v < numberOfTechniques; ++v)
			{
				Ogre::Technique* technique = material->getTechnique(v);
				unsigned short numberOfPasses = technique->getNumPasses();
				for (unsigned short w = 0; w < numberOfPasses; ++w)
				{
					Ogre::Pass* pass = technique->getPass(w);
					unsigned short numberOfTextureUnitStates = pass->getNumTextureUnitStates();
					for (unsigned short x = 0; x < numberOfTextureUnitStates; ++x)
					{
						// Set the rotation if not already available.
						// This can only be done once! Changing the rotationspeed or removing the rotation
						// and resetting it doesn´t seem to work.
						Ogre::TextureUnitState* textureUnitState = pass->getTextureUnitState(x);
						it = textureUnitState->getEffects().find(Ogre::TextureUnitState::ET_ROTATE);
						if (it == textureUnitState->getEffects().end())
						{
							textureUnitState->setRotateAnimation((particle->zRotationSpeed.valueRadians()));
						}
					}
				}
			}
		}
	}
void MeshResourceMarker::reset()
{
  //destroy entity
  if (entity_)
  {
    context_->getSceneManager()->destroyEntity( entity_ );
    entity_ = 0;
  }

  // destroy all the materials we've created
  S_MaterialPtr::iterator it;
  for ( it = materials_.begin(); it!=materials_.end(); it++ )
  {
    Ogre::MaterialPtr material = *it;
    if (!material.isNull())
    {
      for (size_t i = 0; i < material->getNumTechniques(); ++i)
      {
        Ogre::Technique* t = material->getTechnique(i);
        // hack hack hack, really need to do a shader-based way of picking, rather than
        // creating a texture for each object
        if (t->getSchemeName() == "Pick")
        {
          Ogre::TextureManager::getSingleton().remove(t->getPass(0)->getTextureUnitState(0)->getTextureName());
        }
      }

      material->unload();
      Ogre::MaterialManager::getSingleton().remove(material->getName());
    }
  }
  materials_.clear();
}
	//-----------------------------------------------------------------------
	void PrimitiveShapeSet::rotateTexture(Ogre::Real speed)
	{
		// Get the material and rotate it, assume the material is loaded already, otherwise skip.
		Ogre::MaterialPtr material = getMaterial();
		if (material.isNull())
			return;

		Ogre::TextureUnitState::EffectMap::const_iterator it;
		unsigned short numberOfTechniques = material->getNumTechniques();
		for (unsigned short u = 0; u < numberOfTechniques; ++u)
		{
			Ogre::Technique* technique = material->getTechnique(u);
			unsigned short numberOfPasses = technique->getNumPasses();
			for (unsigned short v = 0; v < numberOfPasses; ++v)
			{
				Ogre::Pass* pass = technique->getPass(v);
				unsigned short numberOfTextureUnitStates = pass->getNumTextureUnitStates();
				for (unsigned short w = 0; w < numberOfTextureUnitStates; ++w)
				{
					// Set the rotation if not already available.
					// This can only be done once! Changing the rotationspeed or removing the rotation
					// and resetting it doesn´t seem to work.
					Ogre::TextureUnitState* textureUnitState = pass->getTextureUnitState(w);
					it = textureUnitState->getEffects().find(Ogre::TextureUnitState::ET_ROTATE);
					if (it == textureUnitState->getEffects().end())
					{
						textureUnitState->setRotateAnimation(speed);
					}
				}
			}
		}
	}
Esempio n. 4
0
void EC_HoveringText::SetOverlayAlpha(float alpha)
{
    Ogre::MaterialManager &mgr = Ogre::MaterialManager::getSingleton();
    Ogre::MaterialPtr material = mgr.getByName(materialName_);
    if (!material.get() || material->getNumTechniques() < 1 || material->getTechnique(0)->getNumPasses() < 1 || material->getTechnique(0)->getPass(0)->getNumTextureUnitStates() < 1)
        return;

    material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(
        Ogre::LBX_BLEND_MANUAL, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1.0, 0.0, alpha);
}
	//------------------------------------------------------
	void MaterialService::addWorldMaterialTemplate(unsigned int idx, const Ogre::MaterialPtr& material) {
		assert(!material.isNull());

		mTemplateMaterials.insert(make_pair(idx, material));

		TextureDimensions2D dimensions;

		dimensions.first = 64;
		dimensions.second = 64;

		if (material->getNumTechniques() > 0) {
			Pass *shadPass = material->getTechnique(0)->getPass(0);

			if (shadPass->getNumTextureUnitStates() > 0) {
				TextureUnitState* tus = shadPass->getTextureUnitState(0);

				try {
					// ensure the material is loaded before getting the dimensions
					material->escalateLoading();

					// This is stupid, but can happen - the getTextureDimensions seems buggy in this regard
					if (tus->getNumFrames() <= 0) {
						LOG_ERROR("MaterialService: Error getting texture dimensions (Mat. %s) : Zero frame count!", material->getName().c_str());
					} else {
						dimensions = tus->getTextureDimensions();

						// register the scale
						std::pair<float, float> tscale;

						tscale.first = tus->getTextureUScale();
						tscale.second = tus->getTextureVScale();

						// register the texture scale...
						setWRTextureScale(idx, tscale);

						// reset the scale back, it is canceled out by the fact we UV map with different txt dimensions
						tus->setTextureUScale(1.0f);
						tus->setTextureVScale(1.0f);

						dimensions.first = static_cast<unsigned int> (tscale.first * dimensions.first);
						dimensions.second = static_cast<unsigned int> (tscale.second * dimensions.second);
					}
				} catch (Ogre::Exception &e) {
					// Nothing, just log it could not be done
					LOG_ERROR("MaterialService: Error getting texture dimensions : %s", e.getFullDescription().c_str());
				}
			}
		}

		LOG_INFO("MaterialService: Registered a WR template material %u - %s", idx, material->getName().c_str());

		// insert
		mTextureDimensionMap.insert(make_pair(idx, dimensions));
	}
Esempio n. 6
0
void BillboardObject::setColour(const ColourValue& pColour)
{
    mColour = pColour;
    Ogre::MaterialPtr m = static_cast<sh::OgreMaterial*>(mMaterial->getMaterial ())->getOgreMaterial ();
    for (int i=0; i<m->getNumTechniques(); ++i)
    {
        Ogre::Technique* t = m->getTechnique(i);
        if (t->getNumPasses ())
            t->getPass(0)->setSelfIllumination (pColour);
    }
}
Esempio n. 7
0
void BillboardObject::setVisibility(const float visibility)
{
    mVisibility = visibility;
    Ogre::MaterialPtr m = static_cast<sh::OgreMaterial*>(mMaterial->getMaterial ())->getOgreMaterial ();
    for (int i=0; i<m->getNumTechniques(); ++i)
    {
        Ogre::Technique* t = m->getTechnique(i);
        if (t->getNumPasses ())
            t->getPass(0)->setDiffuse (0,0,0, visibility);
    }
}
Esempio n. 8
0
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);

    // fix texture extension to .dds
    if (textureOverride.size() > 4)
    {
        textureOverride[textureOverride.size()-3] = 'd';
        textureOverride[textureOverride.size()-2] = 'd';
        textureOverride[textureOverride.size()-1] = 's';
    }


    NifOgre::ObjectScenePtr scene = NifOgre::Loader::createObjects(sceneNode, model);

    // TODO: turn off shadow casting
    MWRender::Animation::setRenderProperties(scene, RV_Misc,
                        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())
    {
        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("textures\\" + textureOverride);
                    }
                }
            }
        }
    }

    mEffects.push_back(std::make_pair(sceneNode, scene));
}
//-----------------------------------------------------------------------
void MaterialTab::selectMaterial(wxString& materialName)
{
	Ogre::TextureUnitState* textureUnitState = 0;
	mTxtMaterialName->SetValue(materialName);
	if (isSelectedMaterialInUse())
	{
		mTxtMaterialName->Disable();
	}
	else
	{
		mTxtMaterialName->Enable();
	}
	mLastSelectedMaterial = materialName;
	Ogre::String name = wx2ogre(materialName);
	Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(name);
	if (!material.isNull() && material->getNumTechniques() > 0)
	{
		material->load();
		mTxtTextureLoad->SetValue(wxT(""));
		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)
			{
				// Set pass properties
				mCheckLighting->SetValue(pass->getLightingEnabled());
				mCheckDepthCheck->SetValue(pass->getDepthCheckEnabled());
				mCheckDepthWrite->SetValue(pass->getDepthWriteEnabled());
				mSceneBlendList->SetValue(getSceneBlending(pass));
				if (pass->getNumTextureUnitStates() > 0)
				{
					textureUnitState = pass->getTextureUnitState(0); // Get the first
					if (textureUnitState)
					{
						// Set texture properties
						if (textureUnitState->getNumFrames() > 0)
						{
							wxString name = ogre2wx(textureUnitState->getFrameTextureName(0));
							mTxtTextureLoad->SetValue(name);
						}

						mAddressingModeList->SetValue(getTextureAddressingMode(textureUnitState));
					}
				}
			}
		}
	}

	// Display image
	viewTexture(textureUnitState); // Clear the old texture if no TextureUnitState
}
Esempio n. 10
0
void EC_Sky::OnTextureAssetLoaded(AssetPtr tex)
{
    std::vector<std::string> texture_names;
    texture_names.reserve(cSkyBoxTextureCount);
    
    AssetReferenceList textureList = textureRefs.Get();

    const char * const defaultSkyTextures[cSkyBoxTextureCount] =
    {   "rex_sky_front.dds",
        "rex_sky_back.dds",
        "rex_sky_left.dds",
        "rex_sky_right.dds",
        "rex_sky_top.dds",
        "rex_sky_bot.dds"
    };

    for(size_t i = 0; i < textureAssets.size() || i < cSkyBoxTextureCount; ++i)
        if (i < textureAssets.size() && textureAssets[i])
        {
            AssetPtr asset = textureAssets[i]->Asset();
            TextureAsset *textureAsset = dynamic_cast<TextureAsset*>(asset.get());
            if (textureAsset)
                texture_names.push_back(textureAsset->ogreAssetName.toStdString());
            else
                texture_names.push_back(defaultSkyTextures[i]);
        }
        else
            texture_names.push_back(defaultSkyTextures[i]);

    assert(texture_names.size() == cSkyBoxTextureCount);

    ///\todo Use AssetAPI for the material.
    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(materialRef.Get().ref.toStdString().c_str());
    if (materialPtr.isNull())
    {
        LogError("EC_Sky::OnTextureAssetLoaded: Cannot find Ogre material \"" + materialRef.Get().ref.toStdString() + "\"!");
        return;
    }
    if (materialPtr->getNumTechniques() == 0 || materialPtr->getTechnique(0) == 0 ||
        materialPtr->getTechnique(0)->getNumPasses() == 0 || materialPtr->getTechnique(0)->getPass(0) == 0 ||
        materialPtr->getTechnique(0)->getPass(0)->getNumTextureUnitStates() == 0 ||
        materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0) == 0)
    {
        LogError("EC_Sky::OnTextureAssetLoaded: Cannot use material \"" + materialRef.Get().ref.toStdString() + "\" as Skybox material: It has 0 techniques, passes or texture unit states!");
        return;
    }

    materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setCubicTextureName(&texture_names[0], false);
    
    CreateSky();    
}
//-----------------------------------------------------------------------
Ogre::Pass* MaterialTab::getFirstPass(void)
{
	wxString materialName = mMaterialListBox->GetStringSelection();
	Ogre::String name = wx2ogre(materialName);
	Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(name);
	if (!material.isNull() && material->getNumTechniques() > 0)
	{
		Ogre::Technique* technique = 0;
		material->load();
		technique = material->getBestTechnique(); // Get the best technique
		if (technique && technique->getNumPasses() > 0)
		{
			return technique->getPass(0); // Get the first
		}
	}
	return 0;
}
//-----------------------------------------------------------------------
Ogre::TextureUnitState* MaterialTab::forceCreateFirstTexture(const Ogre::String textureName)
{
	// Ignore some materials because they result in a crash while unloading
	wxString materialName = mMaterialListBox->GetStringSelection();
	if (materialName == wxT("DefaultSettings"))
		return 0;

	Ogre::Technique* technique = 0;
	Ogre::TextureUnitState* texture = 0;
	Ogre::Pass* pass = getFirstPass();
	if (pass)
	{
		// There is a pass, check for textures or create one
		if (pass->getNumTextureUnitStates() > 0)
		{
			pass->removeAllTextureUnitStates();
		}
		texture = pass->createTextureUnitState(textureName);
	}
	else
	{
		// There is no pass
		wxString materialName = mMaterialListBox->GetStringSelection();
		Ogre::String name = wx2ogre(materialName);
		Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(name);
		if (!material.isNull())
		{
			material->load();
			if (material->getNumTechniques() > 0)
			{
				technique = material->getBestTechnique(); // Get the best technique
				pass = technique->createPass();
				texture = pass->createTextureUnitState(textureName);
			}
			else
			{
				// There is no technique, no pass and no textureunitstate
				technique = material->createTechnique();
				pass = technique->createPass();
				texture = pass->createTextureUnitState(textureName);
			}
		}
	}

	return texture;
}
Esempio n. 13
0
EC_WidgetCanvas::EC_WidgetCanvas(Scene *scene) :
    IComponent(scene),
    widget_(0),
    update_internals_(false),
    mesh_hooked_(false),
    refresh_timer_(0),
    update_interval_msec_(0),
    material_name_(""),
    texture_name_("")
{
    if (framework->IsHeadless())
        return;
	
	if (framework->Renderer())
    {
        // Create texture
        texture_name_ = framework->Renderer()->GetUniqueObjectName("EC_3DCanvas_tex");
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(
            texture_name_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            Ogre::TEX_TYPE_2D, 1, 1, 0, Ogre::PF_A8R8G8B8, 
            Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
        if (texture.isNull())
        {
            LogError("EC_WidgetCanvas: Could not create texture for usage!");
            return;
        }

        // Create material: Make sure we have one tech with one pass with one texture unit.
        // Don't use our lit textured templates here as emissive will not work there as it has vertex etc programs in it.
        material_name_ = framework->Renderer()->GetUniqueObjectName("EC_3DCanvas_mat");
        Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(material_name_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
        if (material->getNumTechniques() == 0)
            material->createTechnique();
        if (material->getTechnique(0) && 
            material->getTechnique(0)->getNumPasses() == 0)
            material->getTechnique(0)->createPass();
        if (material->getTechnique(0)->getPass(0) && 
            material->getTechnique(0)->getPass(0)->getNumTextureUnitStates() == 0)
            material->getTechnique(0)->getPass(0)->createTextureUnitState(texture_name_);        
    }

    connect(this, SIGNAL(ParentEntitySet()), SLOT(ParentEntitySet()), Qt::UniqueConnection);
}
Esempio n. 14
0
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);
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 15
0
    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);
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 16
0
Ogre::MaterialPtr gkMaterialLoader::createRTSSMaterial(const gkString& matName, bool enableLight)
{
#ifdef OGREKIT_USE_RTSHADER_SYSTEM
	Ogre::RTShader::ShaderGenerator* shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
	GK_ASSERT(shaderGenerator);

	Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(matName, 
			Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);

	if (material.isNull())
	{
		material = Ogre::MaterialManager::getSingleton().create(matName,
			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	}
	
	material->setLightingEnabled(enableLight);

	shaderGenerator->createShaderBasedTechnique(matName, 
		Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);	
	shaderGenerator->validateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, matName);
	if (material->getNumTechniques() > 1)
	{
		material->getTechnique(0)->getPass(0)->setVertexProgram(
			material->getTechnique(1)->getPass(0)->getVertexProgram()->getName());
		material->getTechnique(0)->getPass(0)->setFragmentProgram(
			material->getTechnique(1)->getPass(0)->getFragmentProgram()->getName());
	}

	GK_ASSERT(!material->getTechnique(0)->getPass(0)->getVertexProgram().isNull());
	GK_ASSERT(!material->getTechnique(0)->getPass(0)->getFragmentProgram().isNull());

	return material;
#else
	return Ogre::MaterialPtr();
#endif
}
Esempio n. 17
0
void Animation::addEffect(const std::string &model, int effectId, bool loop, const std::string &bonename, std::string texture)
{
    // Early out if we already have this effect
    for (std::vector<EffectParams>::iterator it = mEffects.begin(); it != mEffects.end(); ++it)
        if (it->mLoop && loop && it->mEffectId == effectId && it->mBoneName == bonename)
            return;

    // fix texture extension to .dds
    if (texture.size() > 4)
    {
        texture[texture.size()-3] = 'd';
        texture[texture.size()-2] = 'd';
        texture[texture.size()-1] = 's';
    }

    EffectParams params;
    params.mModelName = model;
    if (bonename.empty())
        params.mObjects = NifOgre::Loader::createObjects(mInsert, model);
    else
        params.mObjects = NifOgre::Loader::createObjects(mSkelBase, bonename, mInsert, model);

    // TODO: turn off shadow casting
    setRenderProperties(params.mObjects, RV_Misc,
                        RQG_Main, RQG_Alpha, 0.f, false, NULL);

    params.mLoop = loop;
    params.mEffectId = effectId;
    params.mBoneName = bonename;

    for(size_t i = 0;i < params.mObjects->mControllers.size();i++)
    {
        if(params.mObjects->mControllers[i].getSource().isNull())
            params.mObjects->mControllers[i].setSource(Ogre::SharedPtr<EffectAnimationTime> (new EffectAnimationTime()));
    }

    if (!texture.empty())
    {
        for(size_t i = 0;i < params.mObjects->mParticles.size(); ++i)
        {
            Ogre::ParticleSystem* partSys = params.mObjects->mParticles[i];

            Ogre::MaterialPtr mat = params.mObjects->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("textures\\" + texture);
                    }
                }
            }
        }
    }

    mEffects.push_back(params);
}
Esempio n. 18
0
bool ShaderManager::checkMaterial(const std::string& materialName, const std::string& schemeName)
{
  // OGRE scheme is switched in caller
  Ogre::MaterialPtr material = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().load(materialName, "General"));
  if (material->getNumSupportedTechniques() == 0) {
    S_LOG_INFO("The material '" << material->getName() << "' has no supported techniques with scheme " << schemeName << ". The reason for this is: \n" << material->getUnsupportedTechniquesExplanation());
    return false;
  }

  S_LOG_INFO("The material '" << material->getName() << "' has " << material->getNumSupportedTechniques() << " supported techniques out of " << material->getNumTechniques());

  // Check that we use desired scheme, but not fallbacked to default
  if (material->getBestTechnique()->getSchemeName() != schemeName) {
    S_LOG_INFO("The material '" << material->getName() << "' has best supported scheme " << material->getBestTechnique()->getSchemeName() << ". Was looking for " << schemeName);
    return false;
  }
  S_LOG_INFO("The material '" << material->getName() << "' supported with scheme " << schemeName);
  return true;
}
Esempio n. 19
0
/****************************************************************************
**
** Copyright (C) 2014
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

// Include
#include "mainwindow.h"
#include "Editor_dockwidget.h"
#include "constants.h"
#include "sme_asset_material.h"
#include "sme_node_material.h"
#include "sme_asset_technique.h"
#include "sme_node_technique.h"
#include "sme_asset_pass.h"
#include "sme_node_pass.h"
#include "sme_asset_texture_unit.h"
#include "sme_node_texture_unit.h"

//****************************************************************************/
EditorDockWidget::EditorDockWidget(QString title, MainWindow* parent, Qt::WindowFlags flags) : 
	QDockWidget (title, parent, flags), 
	mParent(parent)
{
    mInnerMain = new QMainWindow();
    setWidget(mInnerMain);

    // Perform standard functions
    createActions();
    createMenus();
    createToolBars();

    // Create the node editor widget.
    mNodeEditor = new Magus::QtNodeEditor(this);
    mNodeEditor->setMenuSelectionToCompoundEnabled(false); // Enabling this makes it a bit more complicated
    mNodeEditor->setMenuExpandCompoundsEnabled(false); // No compounds are used
    connect(mNodeEditor, SIGNAL(nodeRemoved(QtNode*)), this, SLOT(nodeDeleted()));
    connect(mNodeEditor, SIGNAL(nodeSelected(QtNode*)), this, SLOT(nodeSelected(QtNode*)));
    mInnerMain->setCentralWidget(mNodeEditor);
    mMaterialNode = 0;
}

//****************************************************************************/
EditorDockWidget::~EditorDockWidget(void)
{
}

//****************************************************************************/
void EditorDockWidget::createActions(void)
{
    mMaterialHToolbarAction = new QAction(QIcon(ICON_MATERIAL), QString("Add a material node to the editor"), this);
    connect(mMaterialHToolbarAction, SIGNAL(triggered()), this, SLOT(doMaterialHToolbarAction()));
    mTechniqueHToolbarAction = new QAction(QIcon(ICON_TECHNIQUE), QString("Add a technique node to the editor"), this);
    connect(mTechniqueHToolbarAction, SIGNAL(triggered()), this, SLOT(doTechniqueHToolbarAction()));
    mPassHToolbarAction = new QAction(QIcon(ICON_PASS), QString("Add a pass node to the editor"), this);
    connect(mPassHToolbarAction, SIGNAL(triggered()), this, SLOT(doPassHToolbarAction()));
    mTextureHToolbarAction = new QAction(QIcon(ICON_TEXTURE), QString("Add a texture unit node to the editor"), this);
    connect(mTextureHToolbarAction, SIGNAL(triggered()), this, SLOT(doTextureHToolbarAction()));
    mCogHToolbarAction = new QAction(QIcon(ICON_COG), QString("Generate material"), this);
    connect(mCogHToolbarAction, SIGNAL(triggered()), this, SLOT(doCogHToolbarAction()));
}

//****************************************************************************/
void EditorDockWidget::createMenus(void)
{

}

//****************************************************************************/
void EditorDockWidget::createToolBars(void)
{
    mHToolBar = new QToolBar();
    mInnerMain->addToolBar(Qt::TopToolBarArea, mHToolBar);
    mHToolBar->setMinimumHeight(TB_ICON_AND_SPACING);
    mHToolBar->setMinimumWidth(1200);
    mHToolBar->addAction(mMaterialHToolbarAction);
    mHToolBar->addAction(mTechniqueHToolbarAction);
    mHToolBar->addAction(mPassHToolbarAction);
    mHToolBar->addAction(mTextureHToolbarAction);
    mHToolBar->addAction(mCogHToolbarAction);
}

//****************************************************************************/
void EditorDockWidget::doMaterialHToolbarAction(void)
{
    // Add a material node; only 1 is allowed
    if (!mMaterialNode)
    {
        mMaterialNode = new Magus::QtNodeMaterial(NODE_TITLE_MATERIAL);
        mNodeEditor->addNode(mMaterialNode);
    }
}

//****************************************************************************/
void EditorDockWidget::doTechniqueHToolbarAction(void)
{
    // Add a technique node
    Magus::QtNodeTechnique* techniqueNode = new Magus::QtNodeTechnique(NODE_TITLE_TECHNIQUE);
    mNodeEditor->addNode(techniqueNode);
}

//****************************************************************************/
void EditorDockWidget::doPassHToolbarAction(void)
{
    // Add a pass node
    Magus::QtNodePass* passNode = new Magus::QtNodePass(NODE_TITLE_PASS);
    mNodeEditor->addNode(passNode);
}

//****************************************************************************/
void EditorDockWidget::doTextureHToolbarAction(void)
{
    // Add a texture unit node
    Magus::QtNodeTextureUnit* textureUnitNode = new Magus::QtNodeTextureUnit(NODE_TITLE_TEXTURE_UNIT);
    mNodeEditor->addNode(textureUnitNode);
}

//****************************************************************************/
void EditorDockWidget::doCogHToolbarAction(void)
{
    if (!mMaterialNode)
        return;

    if (mMaterialNode->getMaterialName().isEmpty())
        return;

    // ---------------------------------------- Create a material ----------------------------------------
    Ogre::LogManager* logManager = Ogre::LogManager::getSingletonPtr();
    Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
    Ogre::String materialName = mMaterialNode->getMaterialName().toStdString(); // Convert to std format
    logManager->logMessage("SME: create Ogre material: " + materialName);
    Ogre::MaterialPtr material = materialManager->create(materialName, "General");

    // Remark: Sceneblending is done for each pass individually, although it is defined on material level

    // ---------------------------------------- Add the technique ----------------------------------------
    Magus::QtNode* node = mMaterialNode->getNodeConnectedToPort(PORT_TECHNIQUE_OUT);
    if (!node)
    {
        logManager->logMessage("SME: No technique node available");
        return;
    }

    Magus::QtNodeTechnique* techniqueNode = static_cast<Magus::QtNodeTechnique*>(node);
    material->removeAllTechniques();
    Ogre::Technique* technique = material->createTechnique();
    technique->removeAllPasses();
    logManager->logMessage("SME: Technique created" + Ogre::StringConverter::toString(material->getNumTechniques()));

    // ---------------------------------------- Add the passes ----------------------------------------
    Magus::QtNodePass* passNode;
    Magus::QtNodeTextureUnit* textureUnitNode;
    Ogre::Pass* pass;
    Ogre::TextureUnitState* textureUnit;
    for (unsigned int i = 1; i < 5; ++i)
    {
        node = techniqueNode->getNodeConnectedToPort(PORT_PASS_OUT, i); // node with the same name
        if (node)
        {
            passNode = static_cast<Magus::QtNodePass*>(node);
            pass = technique->createPass();
            pass->removeAllTextureUnitStates();
            logManager->logMessage("SME: Pass on port nr. " + Ogre::StringConverter::toString(i) + " created");
            propagatePassNodeData(passNode, pass);

            // ---------------------------------------- Add the texture units ----------------------------------------
            for (unsigned int j = 1; j < 9; ++j)
            {
                node = passNode->getNodeConnectedToPort(PORT_TEXTURE_OUT, j);
                if (node)
                {
                    logManager->logMessage("SME: Texture unit on port nr. " +
                                           Ogre::StringConverter::toString(j) +
                                           " of Pass port nr. " +
                                           Ogre::StringConverter::toString(i) +
                                           " created");
                    textureUnitNode = static_cast<Magus::QtNodeTextureUnit*>(node);
                    textureUnit = pass->createTextureUnitState();
                    propagateTextureUnitNodeData(textureUnitNode, textureUnit);
                }
            }
        }
    }

    // Assign the material to the ogrehead
    material->compile();
    material->load();
    mParent->getOgreManager()->getOgreWidget(1)->mEntity->setMaterial(material);
}
Esempio n. 20
0
void MeshObject::loadMesh()
{
    try
    {
        Ogre::String resourceGroup = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
        mesh = static_cast<Ogre::MeshPtr>(Ogre::MeshManager::getSingleton().create(meshName, resourceGroup));
        if(backgroundLoading)
        {
            mesh->setBackgroundLoaded(true);
            mesh->addListener(this);
            ticket = Ogre::ResourceBackgroundQueue::getSingleton().load(
                         Ogre::MeshManager::getSingletonPtr()->getResourceType(),
                         mesh->getName(),
                         resourceGroup,
                         false,
                         0,
                         0,
                         0);

            // try to load its textures in the background
            for(int i=0; i<mesh->getNumSubMeshes(); i++)
            {
                SubMesh *sm = mesh->getSubMesh(i);
                String materialName = sm->getMaterialName();
                Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(materialName)); //, resourceGroup));
                if(mat.isNull()) continue;
                for(int tn=0; tn<mat->getNumTechniques(); tn++)
                {
                    Technique *t = mat->getTechnique(tn);
                    for(int pn=0; pn<t->getNumPasses(); pn++)
                    {
                        Pass *p = t->getPass(pn);
                        for(int tun=0; tun<p->getNumTextureUnitStates(); tun++)
                        {
                            TextureUnitState *tu = p->getTextureUnitState(tun);
                            String textureName = tu->getTextureName();
                            // now add this texture to the background loading queue
                            Ogre::TexturePtr tex = static_cast<Ogre::TexturePtr>(Ogre::TextureManager::getSingleton().create(textureName, resourceGroup));
                            tex->setBackgroundLoaded(true);
                            tex->addListener(this);
                            ticket = Ogre::ResourceBackgroundQueue::getSingleton().load(
                                         Ogre::TextureManager::getSingletonPtr()->getResourceType(),
                                         tex->getName(),
                                         resourceGroup,
                                         false,
                                         0,
                                         0,
                                         0);

                        }
                    }

                }
            }
        }

        if(!backgroundLoading)
            postProcess();
    }
    catch (Ogre::Exception* e)
    {
        LOG("exception while loading mesh: " + e->getFullDescription());
    }

}
CFakeObjectEntityManager::FakeObjectMap::iterator CFakeObjectEntityManager::_GetFakeNode(LPCTSTR szNodeName, tEntityNode* pNode, LPCTSTR szCameraName, int nTexWidth, int nTexHeight, LPCTSTR szBackgroundName)
{
	//缺省摄像机的位置
	static const float s_fHeight	= 0.8f;
	static const float s_fDistance = 3.2f;
	static const float s_fPitch = 0.21f;

	FakeObjectMap::iterator it = m_mapObject.find(szNodeName);
	if(it != m_mapObject.end()) return it;

	//不存在,创建
	FakeObject newNode;
	newNode.strName = szNodeName;

	//--------------------------------------------------
	//创建RenderTarget
	Ogre::TexturePtr ptrTex =
		Ogre::TextureManager::getSingleton().createManual(
		Ogre::String(szNodeName) + "_RenderTexture",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Ogre::TEX_TYPE_2D,
		nTexWidth, nTexHeight, 1, 0,
		Ogre::PF_R8G8B8A8,
		Ogre::TU_RENDERTARGET,
		0);

	//ptrTex->load();
	newNode.ptrRenderTexture = ptrTex;
	Ogre::RenderTexture* pTexture = ptrTex->getBuffer()->getRenderTarget();

	//缺省不刷新
	pTexture->setAutoUpdated(false);
	pTexture->addListener(&g_theListener);

	//--------------------------------------------------
	//放置摄像机
	Ogre::SceneManager* pScnManager = CEngineInterface::GetMe()->GetFairySystem()->getSceneManager();
	newNode.pCamera = pScnManager->createCamera(Ogre::String(szNodeName) + "_Camera");

	//放缩系数
	fVector3 fvScale = CEngineInterface::GetMe()->GetSacle();

	newNode.fCameraHeight=s_fHeight;
	newNode.fCameraDistance=s_fDistance;
	newNode.fCameraPitch=s_fPitch;

	STRING szUserCameraValue;
	pNode->Actor_GetObjectProperty(szCameraName, szUserCameraValue);
	//	if(szUserCameraValue.size() > 2 && szUserCameraValue.find(';') != STRING::npos)
	//	{
	//		sscanf(szUserCameraValue.c_str(), "%f;%f", &(newNode.fCameraHeight), &(newNode.fCameraDistance));
	//	}
	int Row_Index;
	Row_Index = atoi(szUserCameraValue.c_str());

	const tDataBase* pDBC = g_pDataBase->GetDataBase(DBC_MODEL_PARAMETER);
	KLAssert(pDBC);
	const _DBC_MODEL_PARAMETER* pParameter = NULL;

	pParameter = (const _DBC_MODEL_PARAMETER*)((tDataBase*)pDBC)->Search_Index_EQU(Row_Index);

	if(pParameter)
	{
		newNode.fCameraHeight = pParameter->nHeight;
		newNode.fCameraDistance = pParameter->nDistance;
	}

	//设置摄像机
	_UpdateCamera(newNode);

	newNode.pCamera->setNearClipDistance(10.f);
	newNode.pCamera->setAspectRatio((float)nTexWidth/nTexHeight);
	newNode.pCamera->setFOVy(Ogre::Degree(45.0f));	// 经验值
	newNode.pCamera->setProjectionType(Ogre::PT_PERSPECTIVE);	//透视投影 (平行投影 Ogre::PT_ORTHOGRAPHIC)

	//--------------------------------------------------
	//创建ViewPort
	newNode.pViewPort = pTexture->addViewport(newNode.pCamera, 1);
	newNode.pViewPort->setClearEveryFrame(true);	
	newNode.pViewPort->setBackgroundColour(Ogre::ColourValue(0,0,0,0));
	newNode.pViewPort->setOverlaysEnabled(false);
	newNode.pViewPort->setSkiesEnabled(false);
	newNode.pViewPort->setShadowsEnabled(false);

	//--------------------------------------------------
	//创建rectangle(如果纹理名称不为空并且所需的material template存在)
	Ogre::String backgroundTexName(szBackgroundName);

	Ogre::MaterialPtr originMat = Ogre::MaterialManager::getSingleton().getByName("UIModelBackground");

	if (false == backgroundTexName.empty() && false == originMat.isNull())
	{
		newNode.pRectange = new Ogre::Rectangle2D(true);
		newNode.pRectange->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);

		Ogre::String cloneMatName = Ogre::String(szNodeName) + "_Rectangle";
		Ogre::MaterialPtr cloneMat = Ogre::MaterialManager::getSingleton().getByName(cloneMatName);

		if (cloneMat.isNull())
		{
			cloneMat = originMat->clone(cloneMatName);

			if (cloneMat->getNumTechniques())
			{
				Ogre::Technique* tech = cloneMat->getTechnique(0);

				if (tech->getNumPasses())
				{
					Ogre::Pass* pass = tech->getPass(0);

					if (pass->getNumTextureUnitStates())
					{
						Ogre::TextureUnitState* tex = pass->getTextureUnitState(0);

						tex->setTextureName(szBackgroundName);
					}
				}
			}

		}  

		newNode.pRectange->setMaterial(cloneMat->getName());

		newNode.pRectange->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
		newNode.pRectange->setVisibilityFlags(Fairy::OVF_GUI_ELEMENTS);

		// 设置boundingbox为无限大,以防被camera剔除掉(默认的包围盒大小为-1,1)
		newNode.pRectange->setBoundingBox( 
			Ogre::AxisAlignedBox( 
			Ogre::Vector3(Ogre::Math::NEG_INFINITY, Ogre::Math::NEG_INFINITY, Ogre::Math::NEG_INFINITY),
			Ogre::Vector3(Ogre::Math::POS_INFINITY, Ogre::Math::POS_INFINITY, Ogre::Math::POS_INFINITY) 
			) );

		Ogre::SceneNode* parentNode = 
			CEngineInterface::GetMe()->GetFairySystem()->getBaseSceneNode()->createChildSceneNode();

		parentNode->attachObject(newNode.pRectange);
	}

	//--------------------------------------------------
	//加入Map
	m_mapObject.insert(std::make_pair(newNode.strName, newNode));

	it = m_mapObject.find(newNode.strName);
	KLAssert(it != m_mapObject.end());

	//加入索引Map
	m_mapIndexOfViewPort.insert(std::make_pair(newNode.pViewPort, &(it->second)));
	return it;
}
Esempio n. 22
0
bool OgreMaterialResource::SetData(Foundation::AssetPtr source)
{
    // Remove old material if any
    RemoveMaterial();
    references_.clear();
    original_textures_.clear();

    Ogre::MaterialManager& matmgr = Ogre::MaterialManager::getSingleton();

    OgreRenderingModule::LogDebug("Parsing material " + source->GetId());

    if (!source)
    {
        OgreRenderingModule::LogError("Null source asset data pointer");
        return false;
    }
    if (!source->GetSize())
    {
        OgreRenderingModule::LogError("Zero sized material asset");
        return false;
    }

    Ogre::DataStreamPtr data = Ogre::DataStreamPtr(new Ogre::MemoryDataStream(const_cast<u8 *>(source->GetData()), source->GetSize()));

    static int tempname_count = 0;
    tempname_count++;
    std::string tempname = "TempMat" + ToString<int>(tempname_count);

    try
    {
        int num_materials = 0;
        int brace_level = 0;
        bool skip_until_next = false;
        int skip_brace_level = 0;
        // Parsed/modified material script
        std::ostringstream output;


        while (!data->eof())
        {
            Ogre::String line = data->getLine();

            // Skip empty lines & comments
            if ((line.length()) && (line.substr(0, 2) != "//"))
            {
                // Process opening/closing braces
                if (!ResourceHandler::ProcessBraces(line, brace_level))
                {
                    // If not a brace and on level 0, it should be a new material; replace name
                    if ((brace_level == 0) && (line.substr(0, 8) == "material"))
                    {
                        if (num_materials == 0)
                        {
                            line = "material " + tempname;
                            ++num_materials;
                        }
                        else
                        {
                            OgreRenderingModule::LogWarning("More than one material defined in material asset " + source->GetId() + " - only first one supported");
                            break;
                        }
                    }
                    else
                    {
                        // Check for textures
                        if ((line.substr(0, 8) == "texture ") && (line.length() > 8))
                        {
                            std::string tex_name = line.substr(8);
                            // Note: we assume all texture references are asset based. ResourceHandler checks later whether this is true,
                            // before requesting the reference
                            references_.push_back(Foundation::ResourceReference(tex_name, OgreTextureResource::GetTypeStatic()));
                            original_textures_.push_back(tex_name);
                            // Replace any / with \ in the material, then change the texture names back later, so that Ogre does not go nuts
                            ReplaceCharInplace(line, '/', '\\');
                            ReplaceCharInplace(line, ':', '@');
                        }
                    }

                    // Write line to the modified copy
                    if (!skip_until_next)
                        output << line << std::endl;
                }
                else
                {
                    // Write line to the modified copy
                    if (!skip_until_next)
                        output << line << std::endl;
                    if (brace_level <= skip_brace_level)
                        skip_until_next = false;
                }
            }
        }

        std::string output_str = output.str();
        Ogre::DataStreamPtr modified_data = Ogre::DataStreamPtr(new Ogre::MemoryDataStream((u8 *)(&output_str[0]), output_str.size()));

        matmgr.parseScript(modified_data, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
        Ogre::MaterialPtr tempmat;
        tempmat = matmgr.getByName(tempname);
        if (tempmat.isNull())
        {
            OgreRenderingModule::LogWarning(std::string("Failed to create an Ogre material from material asset ") +
                                            source->GetId());

            return false;
        }
        if(!tempmat->getNumTechniques())
        {
            OgreRenderingModule::LogWarning("Failed to create an Ogre material from material asset "  +
                                            source->GetId());
            return false;
        }

        ogre_material_ = tempmat->clone(id_);
        tempmat.setNull();
        matmgr.remove(tempname);
        if (ogre_material_.isNull())
        {
            OgreRenderingModule::LogWarning("Failed to create an Ogre material from material asset "  +
                                            source->GetId());
            return false;
        }

        // Now go through all the texturenames and restore \ back to / and @ to :
        Ogre::Material::TechniqueIterator iter = ogre_material_->getTechniqueIterator();
        while (iter.hasMoreElements())
        {
            Ogre::Technique *tech = iter.getNext();
            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();
                    std::string texname = texUnit->getTextureName();
                    if (texname.find('\\') != std::string::npos)
                    {
                        ReplaceCharInplace(texname, '\\', '/');
                        ReplaceCharInplace(texname, '@', ':');
                        texUnit->setTextureName(texname);
                    }
                }
            }
        }

        //workaround: if receives shadows, check the amount of shadowmaps. If only 1 specified, add 2 more to support 3 shadowmaps
        if(ogre_material_->getReceiveShadows() && shadowquality_ == Shadows_High && ogre_material_->getNumTechniques() > 0)
        {
            Ogre::Technique *tech = ogre_material_->getTechnique(0);
            if(tech)
            {
                Ogre::Technique::PassIterator passiterator = tech->getPassIterator();
                while(passiterator.hasMoreElements())
                {
                    Ogre::Pass* pass = passiterator.getNext();
                    Ogre::Pass::TextureUnitStateIterator texiterator = pass->getTextureUnitStateIterator();
                    int shadowmaps = 0;
                    while(texiterator.hasMoreElements())
                    {
                        Ogre::TextureUnitState* state = texiterator.getNext();
                        if(state->getContentType() == Ogre::TextureUnitState::CONTENT_SHADOW)
                        {
                            shadowmaps++;
                        }
                    }
                    if(shadowmaps>0 && shadowmaps<3)
                    {
                        Ogre::TextureUnitState* sm2 = pass->createTextureUnitState();
                        sm2->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW);

                        Ogre::TextureUnitState* sm3 = pass->createTextureUnitState();
                        sm3->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW);
                    }
                }
            }

        }

    } catch (Ogre::Exception &e)
    {
        OgreRenderingModule::LogWarning(e.what());
        OgreRenderingModule::LogWarning("Failed to parse Ogre material " + source->GetId() + ".");
        try
        {
            if (!matmgr.getByName(tempname).isNull())
                Ogre::MaterialManager::getSingleton().remove(tempname);
        }
        catch (...) {}

        return false;
    }
    return true;
}