Example #1
0
Ogre::MaterialPtr DivBoxLevel::makeMaterial(
    Ogre::String name, Ogre::String textureName, float intensity) {
  Ogre::MaterialManager::getSingleton().unload(name);
  Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
      name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
  material.get()->getTechnique(0)-> getPass(0)->createTextureUnitState(
      textureName);
  material.get()->getTechnique(0)-> getPass(0)->setAmbient(
      intensity, intensity, intensity);
  return material;
}
Example #2
0
    void DebugCreateAmbientColorMaterial(const std::string &materialName, float r, float g, float b)
    {
        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        Ogre::MaterialPtr material = mm.getByName(materialName);
        if (material.get()) // The given material already exists, so no need to create it again.
            return;

        material = mm.getByName("SolidAmbient");
        if (!material.get())
            return;

        Ogre::MaterialPtr newMaterial = material->clone(materialName);
        newMaterial->setAmbient(r, g, b);
    }
Example #3
0
 Ogre::MaterialPtr GetOrCreateLegacyMaterial(const std::string& texture_name, uint variation)
 {
     if (variation >= MAX_MATERIAL_VARIATIONS)
     {
         OgreRenderingModule::LogWarning("Requested suffix for non-existing material variation " + ToString<uint>(variation));
         variation = 0;
     }
     const std::string& suffix = MaterialSuffix[variation];
     
     Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
     Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
     
     std::string material_name = texture_name + suffix;
     Ogre::MaterialPtr material = mm.getByName(material_name);
     
     if (!material.get())
     {
         material = mm.create(material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
         assert(material.get());
     }
     else
         return material;
     
     Ogre::TexturePtr tex = tm.getByName(texture_name);
     bool has_alpha = false;
     if (!tex.isNull())
     {
         // As far as the legacy materials are concerned, DXT1 is not alpha
         if (tex->getFormat() == Ogre::PF_DXT1)
             has_alpha = false;
         else if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
             has_alpha = true;
     }
     
     Ogre::MaterialPtr base_material;
     if (!has_alpha)
         base_material = mm.getByName(BaseMaterials[variation]);
     else
         base_material = mm.getByName(AlphaBaseMaterials[variation]);
     if (!base_material.get())
     {
         OgreRenderingModule::LogError("Could not find " + MaterialSuffix[variation] + " base material for " + texture_name);
         return Ogre::MaterialPtr();
     }
     
     base_material->copyDetailsTo(material);
     SetTextureUnitOnMaterial(material, texture_name, 0);
     
     return material;
 }
Example #4
0
//-------------------------------------------------------
Ogre::Material* Ground::CreateGroundMaterialTextured(const std::string & name, const Ogre::Image* texture)
{
    Ogre::TexturePtr heightMapTexture = Ogre::TextureManager::getSingleton().loadImage("Texture/Terrain",
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, *texture);

    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    {
        Ogre::Technique* techniqueGL = material->getTechnique(0);
        Ogre::Pass* pass = techniqueGL->getPass(0);
        {
            auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/" + CLASS_NAME + "/GL/Textured/V",
                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
            vprogram->setSource(Shader_GL_Simple_V);
            //auto vparams = vprogram->createParameters();
            //vparams->setNamedAutoConstant("modelviewproj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);

            pass->setVertexProgram(vprogram->getName());
        }
        {
            auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/" + CLASS_NAME + "/GL/Textured/F",
                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
            fprogram->setSource(Shader_GL_Simple_F);

            auto unit0 = pass->createTextureUnitState(heightMapTexture->getName());
            unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
            unit0->setTextureFiltering(Ogre::TFO_NONE);

            pass->setFragmentProgram(fprogram->getName());
        }
    }
#if !NDEBUG
    material->load();
#endif
    return material.get();
}
Example #5
0
    void UpdateLegacyMaterials(const std::string& texture_name)
    {
        Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        
        Ogre::TexturePtr tex = tm.getByName(texture_name);
        bool has_alpha = false;
        if (!tex.isNull())
            if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
                has_alpha = true;

        for (uint i = 0; i < MAX_MATERIAL_VARIATIONS; ++i)
        {
            std::string material_name = texture_name + MaterialSuffix[i];
            Ogre::MaterialPtr material = mm.getByName(material_name);
            
            if (!material.get())
                continue;
            
            Ogre::MaterialPtr base_material;
            if (!has_alpha)
                base_material = mm.getByName(BaseMaterials[i]);
            else
                base_material = mm.getByName(AlphaBaseMaterials[i]);
            if (!base_material.get())
            {
                OgreRenderingModule::LogError("Could not find " + MaterialSuffix[i] + " base material for " + texture_name);
                continue;
            }
            
            base_material->copyDetailsTo(material);
            SetTextureUnitOnMaterial(material, texture_name, 0);
        }
    }
void RenderComponentBillboardSet::setChangeWorldFactor(double factor)
{
	Ogre::Technique * technique;
	Ogre::GpuProgramParametersSharedPtr params;
	Ogre::Pass * pass;

	Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(mChangeWorldMaterial);

	if(material.get())
	{
		technique= material->getTechnique(0);
		if(technique)
		{
			if(technique->getNumPasses()>0)
			{
				pass=technique->getPass(0);
				if(pass->hasFragmentProgram())
				{
					params=pass->getFragmentProgramParameters();

					if(params.get())
					{
						params->setNamedConstant("mix_factor",Ogre::Real(factor));
					}
				}
			}
		}
	}
}
Example #7
0
        Ogre::Pass *getPass(const string &matName, size_t t, const string &passName, bool clone)
        {
            if (!Ogre::MaterialManager::getSingleton().resourceExists(matName))
            {
                log("could not find \"" + matName + "\" material");
                return NULL;
            }

            Ogre::MaterialPtr mat = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().load(
                matName, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
            assert(mat.get());

            static idGen id;

            if (clone)
                mat = mat->clone(id(matName));

            try
            {
                Ogre::Pass *ret = mat->getTechnique(t)->getPass(passName);
                return ret;
            }
            catch (...)
            {
                log("Could not find pass \"" + passName + "\" in material \"" + matName + "\"");
            }
            return NULL;
        }
Example #8
0
    Ogre::MaterialPtr GetOrCreateLitTexturedMaterial(const std::string& materialName)
    {
        const char baseMaterialName[] = "LitTextured";

        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        Ogre::MaterialPtr material = mm.getByName(materialName);

        if (!material.get())
        {
            Ogre::MaterialPtr baseMaterial = mm.getByName(baseMaterialName);
            material = baseMaterial->clone(materialName);
        }

        assert(material.get());
        return material;
    }
void EC_OgreMovableTextOverlay::SetMaterial(const std::string& new_base_material)
{
    ///\todo Make this work for other materials!
    // Clone own copy of the material for this overlay.
    Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
    Ogre::MaterialPtr material = mm.getByName(new_base_material);
    if (material.get())
    {
        baseMaterialName_ = new_base_material;
        Ogre::MaterialPtr baseMaterial = mm.getByName(baseMaterialName_);
        materialName_ = renderer_.lock()->GetUniqueObjectName();
        material = baseMaterial->clone(materialName_);

        //todo Check that the the material alpha channel?
        const Ogre::LayerBlendModeEx &blend = baseMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getAlphaBlendMode();
        if (blend.alphaArg1 > 0)
            materialHasAlpha_ = true;
        else
            materialHasAlpha_ = false;

        // Set the max alpha for the material.
        materialMaxAlpha_ = blend.alphaArg1;

        container_->setMaterialName(materialName_);
    }
    else
        OgreRenderingModule::LogError("Invalid material name!");
}
Example #10
0
    void CreateLegacyMaterials(const std::string& texture_name, bool update)
    {
        Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        
        Ogre::TexturePtr tex = tm.getByName(texture_name);
        bool has_alpha = false;
        if (!tex.isNull())
        {
            if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
                has_alpha = true;
        }
        
        // Early out: if texture does not yet exist and materials have already been created once
        if (((tex.isNull()) || (!update)) && (!mm.getByName(texture_name).isNull()))
            return;
        
        for (uint i = 0; i < MAX_MATERIAL_VARIATIONS; ++i)
        {
            const std::string& base_material_name = BaseMaterials[i];
            const std::string& alpha_base_material_name = AlphaBaseMaterials[i];
            
            std::string material_name = texture_name + MaterialSuffix[i];
            Ogre::MaterialPtr material = mm.getByName(material_name);

            if (!material.get())
            {
                material = mm.create(material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
                assert(material.get());
            }
            
            Ogre::MaterialPtr base_material;
            if (!has_alpha)
                base_material = mm.getByName(base_material_name);
            else
                base_material = mm.getByName(alpha_base_material_name);
            if (!base_material.get())
            {
                OgreRenderingModule::LogError("Could not find " + MaterialSuffix[i] + " base material for " + texture_name);
                return;
            }

            base_material->copyDetailsTo(material);
            SetTextureUnitOnMaterial(material, texture_name, 0);
        }
    }
Example #11
0
/// \todo Use Asset API for fetching sky resources.
EC_SkyBox::EC_SkyBox(IModule *module) :
    IComponent(module->GetFramework()),
    materialRef(this, "Material", AssetReference("RexSkyBox")), ///< \todo Add "orge://" when AssetAPI can handle it.
    textureRefs(this, "Texture"),
    orientation(this, "Orientation", Quaternion(f32(M_PI/2.0), Vector3df(1.0,0.0,0.0))),
    distance(this, "Distance",50.0),
    drawFirst(this, "Draw first", true)
{
     connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), SLOT(OnAttributeUpdated(IAttribute*)));

     static AttributeMetadata materialRefMetadata;
     AttributeMetadata::ButtonInfoList materialRefButtons;
     materialRefButtons.push_back(AttributeMetadata::ButtonInfo(materialRef.GetName(), "V", "View"));
     materialRefMetadata.buttons = materialRefButtons;
     materialRef.SetMetadata(&materialRefMetadata);

     // Find out default textures.
     renderer_ = module->GetFramework()->GetServiceManager()->GetService<OgreRenderer::Renderer>();

     StringVector names;
     Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(materialRef.Get().ref.toStdString().c_str());
     if ( materialPtr.get() != 0)
     {
         OgreRenderer::GetTextureNamesFromMaterial(materialPtr, names);
         AssetReferenceList lst;
         if (names.size() == cSkyBoxTextureCount)
         {
            // This code block is not currently working, but if for some reason GetTextureNamesFromMaterialn understands cubic_textures this codeblock is runned
            for(int i = 0; i < cSkyBoxTextureCount; ++i)
                lst.Append(AssetReference(names[i].c_str()));
         }
         else
         {
            // Add default values, hardcoded
            /// HACK use hardcoded-values because ogre textureunit state class cannot find out texture names for cubic_texture type.
            lst.Append(AssetReference(names[0].c_str()));
            lst.Append(AssetReference("rex_sky_back.dds"));
            lst.Append(AssetReference("rex_sky_left.dds"));
            lst.Append(AssetReference("rex_sky_right.dds"));
            lst.Append(AssetReference("rex_sky_top.dds"));
            lst.Append(AssetReference("rex_sky_bot.dds"));
         }

        textureRefs.Set(lst, AttributeChange::LocalOnly);
     }

    // Disable old sky.
    // DisableSky();
     CreateSky();

     lastMaterial_ = materialRef.Get().ref;
     lastOrientation_ = orientation.Get();
     lastDistance_ = distance.Get();
     lastDrawFirst_ = drawFirst.Get();
     lastTextures_ = textureRefs.Get();
}
Example #12
0
    Ogre::MaterialPtr CloneMaterial(const std::string& sourceMaterialName, const std::string &newName)
    {
        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        Ogre::MaterialPtr material = mm.getByName(sourceMaterialName);

        material = material->clone(newName);

        assert(material.get());
        return material;
    }
Example #13
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 EC_OgreMovableTextOverlay::SetAlphaChannelIntensity(const float &distance)
{
    float materialAlpha, textAlpha;

    textAlpha = (MAX_VISIBILITY_DISTANCE - distance) / MAX_VISIBILITY_DISTANCE;
    materialAlpha = (MAX_VISIBILITY_DISTANCE - distance) / MAX_VISIBILITY_DISTANCE;
    if (materialAlpha > materialMaxAlpha_)
        materialAlpha = materialMaxAlpha_;

    Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
    Ogre::MaterialPtr material = mm.getByName(materialName_);
    if (material.get())
        material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(
            Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, materialAlpha, materialAlpha, 0);

    text_element_->setColour(Ogre::ColourValue(fontColor_.r, fontColor_.g, fontColor_.b, textAlpha));
}
Example #15
0
void ParticleEffect::Initialize(Ogre::SceneManager *sceneManager, Ogre::SceneNode* parentNode, Ogre::String object_name, Ogre::String material_name, PhysicsEngine &physicsEngine, unsigned int parentID)
{
	PhysicsEntity::Initialize(sceneManager, parentNode, physicsEngine, parentID);
	bodyType = ENTITY_BODY_METAPHYSICAL;

	 Ogre::Entity* entity = sceneManager->createEntity(object_name);

	/* Apply a material to the entity */
	materialName = material_name + std::to_string(objectID);
	Ogre::MaterialPtr origMat = Ogre::MaterialManager::getSingleton().getByName(material_name);
	Ogre::Material* mat = origMat.get();
	mat->clone(materialName);
	entity->setMaterialName(materialName);

	sceneNode->attachObject(entity);
	sceneNode->translate(0,0,0);
	
}
Example #16
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);
                            }
                        }
                    }
                }
            }
        }
    }
Example #17
0
Ogre::MaterialPtr TextureManager::MapTexture(int16_t MaterialID, int16_t TextureID)
{
    if (MaterialID != -1 && TextureID != -1)
    {
        uint32_t Key = MaterialID;
        Key = Key << 16;
        Key += TextureID;

        if (TextureMap.find(Key) != TextureMap.end())
        {
            return TextureMap.find(Key)->second;
        }
        else
        {
            Ogre::MaterialPtr SelectedMaterial = makeOgreMaterial(MaterialID, TextureID);
            if (SelectedMaterial.get() != NULL)
            {
                TextureMap[Key] = SelectedMaterial;
                return SelectedMaterial;
            }
        }
    }
    return Ogre::MaterialPtr(NULL);
}
Example #18
0
    void TerrainWeightEditor::SetUseWeights(bool val)
    {
        if(!GetSceneManager())
            return;

        Scene::EntityList list = scene_manager_->GetEntitiesWithComponent("EC_Terrain");
        Scene::EntityList::const_iterator it = list.begin();

        //Quick fix, we will clone a new material copy for each terrain and assume there does not exist previous material clones
        int i = 0;
        Ogre::String mat_name;
        while(it!= list.end())
        {
            boost::shared_ptr<EC_Terrain> ptr = (*it)->GetComponent<EC_Terrain>();
            if (val)
                ptr->material.Set(AssetReference("Rex/TerrainPCF_weighted"/*, "OgreMaterial"*/), AttributeChange::Disconnected);
            else
                ptr->material.Set(AssetReference("Rex/TerrainPCF"/*, "OgreMaterial"*/), AttributeChange::Disconnected);

            Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(mat_name);
            if(mat.get())
            {
                if(i>0)
                    //So we have several terrains, need to create more materials
                    mat_name += Ogre::StringConverter::toString(i);

                Ogre::MaterialPtr new_mat =Ogre::MaterialManager::getSingleton().getByName(mat_name);
                if(!new_mat.get())
                    new_mat =  mat->clone(mat_name);
                if(new_mat.get())
                    ptr->material.Set(QString(new_mat->getName().c_str()),AttributeChange::Default);
            }
            it++;
            i++;
        }
    }
Example #19
0
void EC_HoveringText::Redraw()
{
    if (!ViewEnabled())
        return;

    if (world_.expired() || !billboardSet_ || !billboard_ || materialName_.empty())
        return;

    bool textEmpty = text.Get().isEmpty();

    billboardSet_->setVisible(!textEmpty);
    if (textEmpty)
        return;

    try
    {
        if (texture_.get() == 0)
        {
            textureName_ = framework->Asset()->GenerateUniqueAssetName("tex", "EC_HoveringText_").toStdString();
            QString name(textureName_.c_str());
            texture_  = dynamic_pointer_cast<TextureAsset>(framework->Asset()->CreateNewAsset("Texture", name));
            assert(texture_);
            if (texture_ == 0)
            {
                LogError("Failed to create texture " + textureName_);
                return;
            }
        }
       
        QBrush brush(backgroundColor.Get());
       
        if (usingGrad.Get())
        {
            QRect rect(0,0,texWidth.Get(), texHeight.Get());
            bg_grad_.setStart(QPointF(0,rect.top()));
            bg_grad_.setFinalStop(QPointF(0,rect.bottom()));
            brush = QBrush(bg_grad_);
        }

        QColor borderCol;
        Color col = borderColor.Get();
        borderCol.setRgbF(col.r, col.g, col.b, col.a);

        QPen borderPen;
        borderPen.setColor(borderCol);
        borderPen.setWidthF(borderThickness.Get());
        
        float2 corners =  cornerRadius.Get();

        texture_->SetContentsDrawText(texWidth.Get(), 
                                texHeight.Get(), 
                                text.Get(), 
                                textColor_, 
                                font_, 
                                brush, 
                                borderPen, Qt::AlignCenter | Qt::TextWordWrap, enableMipmapping.Get(), false, corners.x, corners.y);
    }
    catch(Ogre::Exception &e)
    {
        LogError("Failed to create texture " + textureName_  + ": " + std::string(e.what()));
        return;
    }

    // Set new texture for the material
    assert(!materialName_.empty());
    if (!materialName_.empty())
    {
        Ogre::MaterialManager &mgr = Ogre::MaterialManager::getSingleton();
        Ogre::MaterialPtr material = mgr.getByName(materialName_);
        assert(material.get());
        OgreRenderer::SetTextureUnitOnMaterial(material, textureName_);
    }
}
Example #20
0
/// \todo Use Asset API for fetching sky resources.
EC_Sky::EC_Sky(Scene* scene) :
    IComponent(scene),
    materialRef(this, "Material", AssetReference("RexSkyBox")), ///< \todo Add "ogre://" when AssetAPI can handle it.
    textureRefs(this, "Texture", AssetReferenceList("Texture")),
    orientation(this, "Orientation", Quat::identity),
    distance(this, "Distance",50.0),
    drawFirst(this, "Draw first", true)
{
    connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), SLOT(OnAttributeUpdated(IAttribute*)));

    static AttributeMetadata materialRefMetadata;
    AttributeMetadata::ButtonInfoList materialRefButtons;
    materialRefButtons.push_back(AttributeMetadata::ButtonInfo(materialRef.Name(), "V", "View"));
    materialRefMetadata.buttons = materialRefButtons;
    materialRef.SetMetadata(&materialRefMetadata);

    // Find out default textures.
    if (scene)
        world_ = scene->GetWorld<OgreWorld>();

    StringVector names;
    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(materialRef.Get().ref.toStdString().c_str());
    if (materialPtr.get() != 0)
    {
        OgreRenderer::GetTextureNamesFromMaterial(materialPtr, names);
        AssetReferenceList lst("Texture");
        if (names.size() == cSkyBoxTextureCount)
        {
            // This code block is not currently working, but if for some reason GetTextureNamesFromMaterial understands cubic_textures this codeblock is runned
            for(int i = 0; i < cSkyBoxTextureCount; ++i)
                lst.Append(AssetReference(names[i].c_str()));
        }
        else
        {
            // Add default values, hardcoded
            /// HACK use hardcoded-values because ogre textureunit state class cannot find out texture names for cubic_texture type.
            lst.Append(AssetReference(names[0].c_str()));
            lst.Append(AssetReference("rex_sky_back.dds"));
            lst.Append(AssetReference("rex_sky_left.dds"));
            lst.Append(AssetReference("rex_sky_right.dds"));
            lst.Append(AssetReference("rex_sky_top.dds"));
            lst.Append(AssetReference("rex_sky_bot.dds"));
    }

    textureRefs.Set(lst, AttributeChange::LocalOnly);
    }

    // Disable old sky.
    // DisableSky();
    CreateSky();

    lastMaterial_ = materialRef.Get().ref;
    lastOrientation_ = orientation.Get();
    lastDistance_ = distance.Get();
    lastDrawFirst_ = drawFirst.Get();

    while(textureAssets.size() < cSkyBoxTextureCount)
    textureAssets.push_back(boost::shared_ptr<AssetRefListener>(new AssetRefListener));

    for(int i = 0; i < cSkyBoxTextureCount; ++i)
    {
        connect(textureAssets[i].get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnTextureAssetLoaded(AssetPtr)), Qt::UniqueConnection);
        //materialAssets[i]->HandleAssetRefChange(framework->Asset(), materials[i].ref);
    }
}
        virtual MaterialsVector CreateEffectMaterialPrototypes() override
        {
            Ogre::MaterialPtr materialThreshold = Ogre::MaterialManager::getSingleton().create(
                "Material/PostEffect/" + GetUniquePostfix() + "/Threshold", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            {
                Ogre::Technique* techniqueGL = materialThreshold->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);
                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/Threshold/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Common_V);
                    pass->setVertexProgram(vprogram->getName());
                }
                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/Threshold/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Threshold_F);

                    auto unit0 = pass->createTextureUnitState(TEXTURE_MARKER_SCENE);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_NONE);

                    pass->setFragmentProgram(fprogram->getName());
                }
            }
            auto outputThreshold = CreateOutputTexture(materialThreshold->getName(), mRenderWindow->getWidth() / 2, mRenderWindow->getHeight() / 2);
            //-------------------------------------------------------

            Ogre::MaterialPtr materialDownsample = Ogre::MaterialManager::getSingleton().create(
                "Material/Downsample/" + GetUniquePostfix(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

            {
                Ogre::Technique* techniqueGL = materialDownsample->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);
                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/DS/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Common_V);
                    pass->setVertexProgram(vprogram->getName());
                }
                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/DS/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Copy_F);

                    auto unit0 = pass->createTextureUnitState(outputThreshold);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_BILINEAR);

                    pass->setFragmentProgram(fprogram->getName());
                }
            }
            auto outputDownsample = CreateOutputTexture(materialDownsample->getName(), mRenderWindow->getWidth() / 4, mRenderWindow->getHeight() / 4);
            //-------------------------------------------------------

            Ogre::MaterialPtr materialDownsample2 = Ogre::MaterialManager::getSingleton().create(
                "Material/Downsample2/" + GetUniquePostfix(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

            {
                Ogre::Technique* techniqueGL = materialDownsample2->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);
                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/DS2/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Common_V);
                    pass->setVertexProgram(vprogram->getName());
                }
                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/DS2/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Copy_F);

                    auto unit0 = pass->createTextureUnitState(outputDownsample);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_BILINEAR);

                    pass->setFragmentProgram(fprogram->getName());
                }
            }
            auto outputDownsample2 = CreateOutputTexture(materialDownsample2->getName(), mRenderWindow->getWidth() / 8, mRenderWindow->getHeight() / 8);
            //-------------------------------------------------------

            Ogre::MaterialPtr materialHorz = Ogre::MaterialManager::getSingleton().create(
                "Material/PostEffect/" + GetUniquePostfix() + "/Horz", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            {
                Ogre::Technique* techniqueGL = materialHorz->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);
                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/H/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Common_V);
                    pass->setVertexProgram(vprogram->getName());
                }
                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/H/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Blur_Horz_F);

                    auto unit0 = pass->createTextureUnitState(outputDownsample2);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_BILINEAR);

                    pass->setFragmentProgram(fprogram->getName());

                    auto fparams = pass->getFragmentProgramParameters();
                    fparams->setNamedConstant("texture", 0);
                    fparams->setNamedAutoConstant("offset", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
                }
            }
            auto outputHorz = CreateOutputTexture(materialHorz->getName(), mRenderWindow->getWidth() / 8, mRenderWindow->getHeight() / 8);
            //-------------------------------------------------------
            Ogre::MaterialPtr materialVert = Ogre::MaterialManager::getSingleton().create(
                "Material/PostEffect/" + GetUniquePostfix() + "/Vert", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            {
                Ogre::Technique* techniqueGL = materialVert->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);
                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/V/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Common_V);

                    pass->setVertexProgram(vprogram->getName());
                }
                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/V/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Blur_Vert_F);

                    auto unit0 = pass->createTextureUnitState(outputHorz);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_BILINEAR);

                    pass->setFragmentProgram(fprogram->getName());

                    auto fparams = pass->getFragmentProgramParameters();
                    fparams->setNamedConstant("texture", 0);
                    fparams->setNamedAutoConstant("offset", Ogre::GpuProgramParameters::ACT_VIEWPORT_SIZE);
                }
            }
            auto outputVert = CreateOutputTexture(materialVert->getName(), mRenderWindow->getWidth() / 8, mRenderWindow->getHeight() / 8);
            //-------------------------------------------------------
            Ogre::MaterialPtr materialBlend = Ogre::MaterialManager::getSingleton().create(
                "Material/Blend/" + GetUniquePostfix(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            {
                Ogre::Technique* techniqueGL = materialBlend->getTechnique(0);
                Ogre::Pass* pass = techniqueGL->getPass(0);
                {
                    auto vprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/V/Blend/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_VERTEX_PROGRAM);
                    vprogram->setSource(Shader_GL_Common_V);
                    pass->setVertexProgram(vprogram->getName());
                }
                {
                    auto fprogram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram("Shader/GL/F/Blend/" + GetUniquePostfix(),
                        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
                    fprogram->setSource(Shader_GL_Blend_F);

                    auto unit0 = pass->createTextureUnitState(TEXTURE_MARKER_SCENE);
                    unit0->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit0->setTextureFiltering(Ogre::TFO_NONE);

                    auto unit1 = pass->createTextureUnitState(outputVert);
                    unit1->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
                    unit1->setTextureFiltering(Ogre::TFO_BILINEAR);

                    pass->setFragmentProgram(fprogram->getName());
                    auto fparams = pass->getFragmentProgramParameters();
                    fparams->setNamedConstant("texture", 0);
                    fparams->setNamedConstant("texbloom", 1);
                }
            }

            //-------------------------------------------------------
            return{ materialThreshold.get(), materialDownsample.get(), materialDownsample2.get(), materialHorz.get(), materialVert.get(), materialBlend.get() };
        }