コード例 #1
0
void CubeWorld::displaySimpleWorld (void)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0.5, 0));

	Ogre::ManualObject* testBox  = createCubeMesh("TestBox1", "BoxColor");
        Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	Ogre::MeshPtr Mesh = testBox->convertToMesh("TestBox2");
	Ogre::StaticGeometry* pGeom = new Ogre::StaticGeometry (mSceneMgr, "Boxes");

	Ogre::Entity* pEnt = mSceneMgr->createEntity("TestBox2");

	pGeom->setRegionDimensions(Ogre::Vector3(300, 300, 300));

	for (int z = 0; z < WORLD_SIZE; ++z)
	{
		for (int y = 0; y < WORLD_SIZE; ++y)
		{
			for (int x = 0; x < WORLD_SIZE; ++x)
			{
				if (GetBlock(x,y,z)) pGeom->addEntity(pEnt, Ogre::Vector3(x,y,z));
			}
		}
	}

	pGeom->build ();
}
コード例 #2
0
void CubeWorld::createWorldChunks (void)
{
	//std::vector<int> VertexArray;
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0.5, 0));

	Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshMatChunk");
	MeshChunk->begin("TerrainImage");

	for (int z = 0; z < WORLD_SIZE; z += CHUNK_SIZE)
	{
		for (int y = 0; y < WORLD_SIZE; y += CHUNK_SIZE)
		{
			for (int x = 0; x < WORLD_SIZE; x += CHUNK_SIZE)
			{
				createChunk(MeshChunk, x,y,z); /* WFaces or not */
				//createChunkWater(x, y, z);
			}
		}
	}

}
コード例 #3
0
	//--------------------------------------------------------------------------------
	void MaterialUtil::updateSelectedVersion(const MaterialPtr& _material)
	{
		String name = _material->getName();
		String selName = getSelectedVersionName(name);
		MaterialPtr material, selectedMaterial;
		if(selName == name)
		{
			name = getUnselectedVersionName(selName);
			selectedMaterial = _material;
			material = MaterialManager::getSingleton().getByName(name);
		}
		else
		{
			material = _material;
			selectedMaterial = MaterialManager::getSingleton().getByName(selName);
		}
		
		if(!material.isNull() && !selectedMaterial.isNull())
		{
			material->copyDetailsTo(selectedMaterial);
			Ogre::Technique* technique = selectedMaterial->getBestTechnique();
			Pass* pass0 = technique->getPass(0);
			Pass* passNew = technique->createPass();
			passNew->setDiffuse(1, 1, 1, 1);
			passNew->setPolygonMode(Ogre::PM_WIREFRAME);

			if(pass0->getNumTextureUnitStates() != 0)
			{
				Ogre::TextureUnitState* tu = pass0->getTextureUnitState(0);
				tu->setColourOperationEx(Ogre::LBX_MODULATE, 
					Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL,
					ColourValue::White, ColourValue(1, 0.6f, 0.6f, 1));
			}
		}
	}
コード例 #4
0
ファイル: deferredlight.cpp プロジェクト: arbonagw/Soyouz
void DeferredLight::updateFromCamera(Ogre::Camera* camera)
{
	const Ogre::MaterialPtr& mat = getMaterial();
	if (!mat->isLoaded()) 
	{
		mat->load();
	}
	Ogre::Technique* tech = mat->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);
		Ogre::GpuProgramParametersSharedPtr params = pass->getVertexProgramParameters();
		if (params->_findNamedConstantDefinition("farCorner"))
			params->setNamedConstant("farCorner", farCorner);
	    
		params = pass->getFragmentProgramParameters();
		if (params->_findNamedConstantDefinition("farCorner"))
			params->setNamedConstant("farCorner", farCorner);

		// If inside light geometry, render back faces with CMPF_GREATER, otherwise normally
		if (mParentLight->getType() == Ogre::Light::LT_DIRECTIONAL)
		{
			pass->setCullingMode(Ogre::CULL_CLOCKWISE);
			pass->setDepthCheckEnabled(false);
		}
		else
		{
			pass->setDepthCheckEnabled(true);
			if (isCameraInsideLight(camera))
			{
				pass->setCullingMode(Ogre::CULL_ANTICLOCKWISE);
				pass->setDepthFunction(Ogre::CMPF_GREATER_EQUAL);
			}
			else
			{
				pass->setCullingMode(Ogre::CULL_CLOCKWISE);
				pass->setDepthFunction(Ogre::CMPF_LESS_EQUAL);
			}
		}

		Ogre::Camera shadowCam("ShadowCameraSetupCam", 0);
		shadowCam._notifyViewport(camera->getViewport());
		Ogre::SceneManager* sm = mParentLight->_getManager();
		sm->getShadowCameraSetup()->getShadowCamera(sm, 
			camera, camera->getViewport(), mParentLight, &shadowCam, 0);
			
		//Get the shadow camera position
		if (params->_findNamedConstantDefinition("shadowCamPos")) 
		{
			params->setNamedConstant("shadowCamPos", shadowCam.getPosition());
		}
		if (params->_findNamedConstantDefinition("shadowFarClip"))
		{
			params->setNamedConstant("shadowFarClip", shadowCam.getFarClipDistance());
		}

	}
}
コード例 #5
0
	//-----------------------------------------------------------------------
	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);
					}
				}
			}
		}
	}
コード例 #6
0
ファイル: TextureManager.cpp プロジェクト: snus-mumrik/Khazad
Ogre::MaterialPtr TextureManager::makeOgreMaterial(int16_t MaterialTypeID, int16_t TextureID)
{
    Ogre::MaterialPtr NewMaterial = Ogre::MaterialManager::getSingleton().create("GrassMaterial", "General", true);

    Ogre::Image* NewImage = new Ogre::Image(); // Delete?
    uint16_t ImageID = IMAGE->GenerateMaterialImage(MaterialTypeID, TextureID);
    uint8_t* iData = IMAGE->getImageData(ImageID);
    uint16_t Width = IMAGE->getImageWidth(ImageID);
    uint16_t Height = IMAGE->getImageHeight(ImageID);


    NewImage->loadDynamicImage(iData, Width, Height, Ogre::PF_A8R8G8B8);
    Ogre::TexturePtr NewTex = Ogre::TextureManager::getSingleton().loadImage("TextureX", "General", *NewImage, Ogre::TEX_TYPE_2D, 1);

    Ogre::Technique* FirstTechnique = NewMaterial->getTechnique(0);
    Ogre::Pass* FirstPass = FirstTechnique->getPass(0);
    FirstPass->setLightingEnabled(false);

    Ogre::TextureUnitState* TextureUnit = FirstPass->createTextureUnitState();
    TextureUnit->setTextureName("TextureX", Ogre::TEX_TYPE_2D);

    delete NewImage;

    return NewMaterial;
}
コード例 #7
0
ファイル: Ground.cpp プロジェクト: agruzdev/OgreNature
//-------------------------------------------------------
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();
}
コード例 #8
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));
					}
				}
			}
		}
	}
}
コード例 #9
0
ファイル: IntroState.cpp プロジェクト: rradonic/tilt-ball
    IntroState::IntroState(Engine* p_engine) :
        GameState(p_engine),
        m_totalMilliseconds(std::time_t(2000)),
        m_elapsedMilliseconds(0)
    {
        std::clog << "Entering intro state..." << std::endl;

        // do one input state capture just to hide the mouse cursor
        InputSystem* inputSystem = m_engine->getInputSystem();
        inputSystem->capture();

        // get the material by name
        std::clog << "Loading fade overlay material..." << std::endl;
        Ogre::ResourcePtr resptr = Ogre::MaterialManager::getSingleton().
            getByName("Materials/FadeOverlay");
        Ogre::Material* material = dynamic_cast<Ogre::Material*>(resptr.getPointer());
        Ogre::Technique* tech = material->getTechnique(0);
        Ogre::Pass* pass = tech->getPass(0);

        m_textureUnitState = pass->getTextureUnitState(0);

        // get the overlay
        std::clog << "Loading fade overlay..." << std::endl;
        m_fadeOverlay = Ogre::OverlayManager::getSingleton().getByName("Overlays/FadeOverlay");

        m_alpha = 1.0;
        m_fadeOverlay->show();
    }
コード例 #10
0
ファイル: ovkCMaterial.cpp プロジェクト: Akanoa/PRI
//=============================================================================
// IMaterialAction
//=============================================================================
Ogre::Pass* IMaterialAction::getFirstPassOfFirstTechnique( SubEntityMaterial* subEntity )
{
	//OMASSERTM( 0 < subEntity->getMaterial()->getNumTechniques(), "Don't get Any Tecnnique on Material" << subEntity->getMaterial()->getName() );
  Ogre::Technique * technique = subEntity->getMaterial()->getTechnique( 0 );
	//OMASSERTM( 0 < technique->getNumPasses(), "Don't get Any PASS on Material " << subEntity->getMaterial()->getName() );
  return technique->getPass( 0 ) ;
}
コード例 #11
0
const Ogre::MaterialPtr& MaterialGenerator::GetMaterial(Perm permutation)
{
    // Check if material/shader permutation already was generated
    MaterialMap::iterator i = mMaterials.find(permutation);
    if (i != mMaterials.end())
    {
        return i->second;
    }
    else
    {
        // Create it
        Ogre::MaterialPtr templ = GetTemplateMaterial(permutation & mMatMask);
        Ogre::GpuProgramPtr vs = GetVertexShader(permutation & mVsMask);
        Ogre::GpuProgramPtr fs = GetFragmentShader(permutation & mFsMask);

        // Create material name
        string name = mMaterialBaseName + Ogre::StringConverter::toString(permutation);

        // Create material from template, and set shaders
        Ogre::MaterialPtr mat = templ->clone(name);
        Ogre::Technique* tech = mat->getTechnique(0);
        Ogre::Pass* pass = tech->getPass(0);
        pass->setFragmentProgram(fs->getName());
        pass->setVertexProgram(vs->getName());

        // And store it
        mMaterials[permutation] = mat;
        return mMaterials[permutation];
    }
}
コード例 #12
0
	//-----------------------------------------------------------------------
	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()));
						}
					}
				}
			}
		}
	}
コード例 #13
0
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();
}
コード例 #14
0
void CubeWorld::updateSkyTextureLight (void)
{
	if (m_SkyMaterial.isNull())
		return;

	Ogre::Technique* tech = m_SkyMaterial->getTechnique(0);
#if defined(__linux__) || defined(__APPLE__)
	if (tech == NULL) return;
#else
	if (tech == nullptr) return;

#endif
	Ogre::Pass* pass = tech->getPass(0);
#if defined(__linux__) || defined(__APPLE__)
	if (pass == NULL) return;
#else
	if (pass == nulptr) return;
#endif

	Ogre::TextureUnitState* tex = pass->getTextureUnitState(1);
#if defined(__linux__) || defined(__APPLE__)
	if (tex == NULL) return;
#else
	if (tex == nullptr) return;
#endif

	// Update the texture unit's color operation with the world light level
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, m_LightColor);
}
コード例 #15
0
void CubeWorld::createSolidTexture (const TCHAR* pName)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0.5, 0));
}
コード例 #16
0
ファイル: water.cpp プロジェクト: sergey-shambir/openmw
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);
    }
}
コード例 #17
0
ファイル: sky.cpp プロジェクト: Adrian-Revk/openmw
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);
    }
}
コード例 #18
0
ファイル: sky.cpp プロジェクト: Adrian-Revk/openmw
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);
    }
}
コード例 #19
0
ファイル: mainwindow.cpp プロジェクト: ironsteel/QtOME
void MainWindow::populateWorkSpaceTree(const QStringList &itemNames)
{
    for(int count = 0; count < itemNames.size(); ++count)
    {
        QTreeWidgetItem *matItem = new QTreeWidgetItem(ui->workspaceTree);
        QString parentName = itemNames.at(count);
        matItem->setText(0, parentName);
        matItem->setText(1, "material");
        Ogre::MaterialPtr parMat = Ogre::MaterialManager::getSingleton().getByName(parentName.toStdString());

        unsigned short numTech = parMat.getPointer()->getNumTechniques();

        for (int countTech = 0; countTech < numTech; ++countTech)
        {
            Ogre::Technique *parTech = parMat.getPointer()->getTechnique(countTech);
            int numPass = parTech->getNumPasses();
            QTreeWidgetItem *techItem = new QTreeWidgetItem(matItem);
            techItem->setText(0, QString("technique(")+QString(Ogre::String(parTech->getName()).c_str())+QString(")"));

            for (int countPass = 0; countPass < numPass; ++countPass)
            {
                QTreeWidgetItem *passItem = new QTreeWidgetItem(techItem);
                Ogre::Pass* pass = parTech->getPass(countPass);
                passItem->setText(0, QString("pass(")+QString(Ogre::String(pass->getName()).c_str())+QString(")"));
                passItem->setText(1, QString("pass"));

                if(pass->hasVertexProgram())
                {
                    QTreeWidgetItem *vpItem = new QTreeWidgetItem(passItem);
                    vpItem->setText(0,Ogre::String(pass->getVertexProgramName()).c_str());
                    vpItem->setText(1,QString("VertexProgram"));
                    vpItem->setText(2,QString(parentName));
                    vpItem->setText(3,QString(countTech));
                    vpItem->setText(4,QString(countPass));
                }
                if(pass->hasFragmentProgram())
                {
                    QTreeWidgetItem *fpItem = new QTreeWidgetItem(passItem);
                    fpItem->setText(0,Ogre::String(pass->getFragmentProgramName()).c_str());
                    fpItem->setText(1,QString("FragmentProgram"));
                    fpItem->setText(2,QString(parentName));
                    fpItem->setText(3,QString(countTech));
                    fpItem->setText(4,QString(countPass));
                }
                if(pass->hasGeometryProgram())
                {
                    QTreeWidgetItem *gpItem = new QTreeWidgetItem(passItem);
                    gpItem->setText(0,Ogre::String(pass->getGeometryProgramName()).c_str());
                }
            }
        }
    }
}
コード例 #20
0
//-----------------------------------------------------------------------
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
}
コード例 #21
0
ファイル: effectmanager.cpp プロジェクト: 0xmono/openmw
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));
}
コード例 #22
0
ファイル: imageconverter.cpp プロジェクト: jacmoe/ogitor
//----------------------------------------------------------------------------------------
QImage ImageConverter::_imageFromRenderTarget(const Ogre::Image& img)
{
    Ogre::TextureManager::getSingletonPtr()->loadImage("QTTextureName", "QTImageConverter", img);

    // create our material
    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingletonPtr()->create("terrainMaterial", "QTImageConverter");
    Ogre::Technique * technique = material->getTechnique(0);
    Ogre::Pass* pass = technique->getPass(0);
    Ogre::TextureUnitState* textureUnit = pass->createTextureUnitState();
    textureUnit->setTextureName("QTTextureName");

    return _getRenderTarget(material->getName());
}
コード例 #23
0
ファイル: BasicTutorial2.cpp プロジェクト: asvsfs/TheJourney
//-------------------------------------------------------------------------------------
void BasicTutorial2::createScene(void)
{
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
    //mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
 
	//Create cube
	    //Create a basic green color texture 
 
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();
 
	tex->setTextureName("grassTexture.png");
	//tex->setNumMipmaps(4);
	tex->setTextureAnisotropy(1);
	tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

	    //Create the one box and the supporting class objects
	Ogre::ManualObject* testBox  = createCubeMesh("TestBox1", "BoxColor");	
    Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	Ogre::MeshPtr Mesh = testBox->convertToMesh("TestBox2");
	Ogre::StaticGeometry* pGeom = new Ogre::StaticGeometry (mSceneMgr, "Boxes");
	Ogre::Entity* pEnt = mSceneMgr->createEntity("TestBox2");
	
	//testBox->triangle
	pGeom->setRegionDimensions(Ogre::Vector3(300, 300, 300));
 
	World::Instance();
	 
	pGeom->build ();
 
        mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
	Ogre::Light* l = mSceneMgr->createLight("MainLight");
        l->setPosition(20,80,50);
	//Create Cube

 /*   Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh");
    entNinja->setCastShadows(true);
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);*/
 
 
    Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight");
    directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
    directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0));
    directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0));
 
    directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 )); 
 
 
}
コード例 #24
0
//-------------------------------------------------------------------------------
Ogre::MaterialPtr CSceneManagerEditor::buildDepthShadowMaterial(Ogre::MaterialPtr cpyMat)
{
    if(mShadowsTechnique->get() >= (int)Ogre::SHADOWTYPE_TEXTURE_ADDITIVE && mShadowsTechnique->get() <= (int)Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED)
    {
        Ogre::String matName = "DepthShadows/" + cpyMat->getName();

        Ogre::MaterialPtr ret = Ogre::MaterialManager::getSingleton().getByName(matName);
        if (ret.isNull())
        {
            ret = cpyMat->clone(matName);

            Ogre::Technique *t = ret->getTechnique(0);
            t->setShadowCasterMaterial("Ogre/shadow/depth/caster");
            Ogre::Pass *p = t->getPass(0);
            p->setVertexProgram("Ogre/shadow/receiver/depth/pssm3/vp");
            p->setFragmentProgram("Ogre/shadow/receiver/depth/pssm3/fp");

            Ogre::TextureUnitState *tu = p->createTextureUnitState();
            tu->setName("shadow0");
            tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW);
            tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER);
            tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1));
            
            tu = p->createTextureUnitState();
            tu->setName("shadow1");
            tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW);
            tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER);
            tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1));
            
            tu = p->createTextureUnitState();
            tu->setName("shadow2");
            tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW);
            tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER);
            tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1));

            Ogre::Vector4 splitPoints;
            const Ogre::PSSMShadowCameraSetup::SplitPointList& splitPointList = 
                static_cast<Ogre::PSSMShadowCameraSetup*>(mPSSMSetup.get())->getSplitPoints();
            for (int i = 0; i < 3; ++i)
            {
                splitPoints[i] = splitPointList[i];
            }
            p->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);
        }
        
        return ret;
    }
    else
        return cpyMat;
}
コード例 #25
0
void CubeWorld::createWaterTexture (const TCHAR* pName)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();

	tech->setLightingEnabled(false);

	pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
	pass->setDepthWriteEnabled(false);

	tex->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0, 1));
	tex->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.5);
}
コード例 #26
0
void CubeWorld::createTexture (const TCHAR* pName, const TCHAR* pImageFilename)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();

	tex->setTextureName(pImageFilename);
	tex->setNumMipmaps(4);
	tex->setTextureAnisotropy(1);
	tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

	pass->setVertexColourTracking(Ogre::TVC_DIFFUSE);
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_DIFFUSE, Ogre::LBS_TEXTURE);

	tech->setLightingEnabled(false);
}
コード例 #27
0
//-----------------------------------------------------------------------
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;
}
コード例 #28
0
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);
	}
}
コード例 #29
0
Ogre::Technique* GBufferSchemeHandler::handleSchemeNotFound(unsigned short schemeIndex, 
		const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, 
		const Ogre::Renderable* rend)
{
	Ogre::MaterialManager& matMgr = Ogre::MaterialManager::getSingleton();
	Ogre::String curSchemeName = matMgr.getActiveScheme();
	matMgr.setActiveScheme(Ogre::MaterialManager::DEFAULT_SCHEME_NAME);
	Ogre::Technique* originalTechnique = originalMaterial->getBestTechnique(lodIndex, rend);
	matMgr.setActiveScheme(curSchemeName);

	Ogre::Technique* gBufferTech = originalMaterial->createTechnique();
	gBufferTech->removeAllPasses();
	gBufferTech->setSchemeName(schemeName);

	Ogre::Technique* noGBufferTech = originalMaterial->createTechnique();
	noGBufferTech->removeAllPasses();
	noGBufferTech->setSchemeName("NoGBuffer");

	for (unsigned short i=0; i<originalTechnique->getNumPasses(); i++)
	{
		Ogre::Pass* originalPass = originalTechnique->getPass(i);
		PassProperties props = inspectPass(originalPass, lodIndex, rend);
		
		if (!props.isDeferred)
		{
			//Just copy the technique so it gets rendered regularly
			Ogre::Pass* clonePass = noGBufferTech->createPass();
			*clonePass = *originalPass;
			continue;
		}

		Ogre::Pass* newPass = gBufferTech->createPass();
		MaterialGenerator::Perm perm = getPermutation(props);

		const Ogre::MaterialPtr& templateMat = mMaterialGenerator.getMaterial(perm);
    	
		//We assume that the GBuffer technique contains only one pass. But its true.
		*newPass = *(templateMat->getTechnique(0)->getPass(0));
		fillPass(newPass, originalPass, props);    
	}
    
	return gBufferTech;
}
コード例 #30
0
ファイル: Fader.cpp プロジェクト: ChWick/Zelda
 Fader::Fader(const char *OverlayName, const char *MaterialName, FaderCallback *instance)
 {
     _fadeop = FADE_NONE;
     _alpha = 0.0;
     _inst = instance;

     // Get the material by name
     Ogre::ResourcePtr resptr = Ogre::MaterialManager::getSingleton().getByName(MaterialName);
     Ogre::Material * mat = dynamic_cast<Ogre::Material*>(resptr.getPointer());

     Ogre::Technique *tech = mat->getTechnique(0);    // Get the technique
     Ogre::Pass *pass = tech->getPass(0);            // Get the pass
     _tex_unit = pass->getTextureUnitState(0);        // Get the texture_unit state

     // Get the _overlay
     _overlay = Ogre::OverlayManager::getSingleton().getByName(OverlayName);
     _overlay->hide();

 }