Пример #1
0
void Rect::Draw(Ogre::Vector3 pos)
{
    Ogre::Vector3 quad[4];
    quad[0] = Ogre::Vector3(pos.x - (length / 2.0), pos.y, pos.z - (height / 2.0)); // ll
    quad[1] = Ogre::Vector3(pos.x - (length / 2.0), pos.y, pos.z + (height / 2.0)); // ul
    quad[2] = Ogre::Vector3(pos.x + (length / 2.0), pos.y, pos.z + (height / 2.0)); // ur
    quad[3] = Ogre::Vector3(pos.x + (length / 2.0), pos.y, pos.z - (height / 2.0)); // lr

    Ogre::MaterialPtr matptr = Ogre::MaterialManager::getSingleton().create("BaseColoured", "General");
    matptr->load();
    matptr->getBestTechnique()->getPass(0)->setVertexColourTracking(Ogre::TVC_DIFFUSE);
    matptr->getBestTechnique()->getPass(0)->setLightingEnabled(false);

    mObj->begin("BaseColoured", Ogre::RenderOperation::OT_TRIANGLE_LIST);
    mObj->position(quad[0]);
    mObj->colour(colour);
    
    //mObj->textureCoord(1,1);
    mObj->position(quad[1]);
    mObj->colour(colour);
    //mObj->textureCoord(1,0);
    mObj->position(quad[2]);
    mObj->colour(colour);
    //mObj->textureCoord(0,0);
    mObj->position(quad[3]);
    mObj->colour(colour);
    //mObj->textureCoord(0,1);

    mObj->quad(0,1,2,3);
    mObj->end();
}
Пример #2
0
void HDRListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	
	if(pass_id == 600 || pass_id == 800)
	{
		Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
		Ogre::GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
    
		if (params->_findNamedConstantDefinition("toneMapSettings"))
		{
			Ogre::Vector4 toneMapSettings(1-mApp->pSet->hdrParam1, mApp->pSet->hdrParam2, mApp->pSet->hdrParam3, 1.0);
			params->setNamedConstant("toneMapSettings", toneMapSettings);
		}
		if (params->_findNamedConstantDefinition("bloomSettings"))
		{
			Ogre::Vector4 bloomSettings(mApp->pSet->hdrbloomorig*2, mApp->pSet->hdrbloomint, 1.0, 1.0);
			params->setNamedConstant("bloomSettings", bloomSettings);
		}
		if (params->_findNamedConstantDefinition("vignettingSettings"))
		{
			Ogre::Vector4 vignettingSettings(mApp->pSet->vignettingRadius, mApp->pSet->vignettingDarkness, 1.0, 1.0);
			params->setNamedConstant("vignettingSettings", vignettingSettings);
		}
	
	}
	else if(pass_id == 989)
	{
		Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
		Ogre::GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
		if (params->_findNamedConstantDefinition("AdaptationScale"))
		{
			params->setNamedConstant("AdaptationScale", mApp->pSet->hdrAdaptationScale);
		}
	}
}
Пример #3
0
 void GaussianListener::notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
 {
     // Prepare the fragment params offsets
     switch(pass_id)
     {
     case 701: // blur horz
     {
         // horizontal bloom
         mat->load();
         Ogre::GpuProgramParametersSharedPtr fparams =
             mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
         const Ogre::String& progName = mat->getBestTechnique()->getPass(0)->getFragmentProgramName();
         UNREFERENCED_PARAM(progName);
         fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsHorz[0], 15);
         fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
         break;
     }
     case 700: // blur vert
     {
         // vertical bloom
         mat->load();
         Ogre::GpuProgramParametersSharedPtr fparams =
             mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
         const Ogre::String& progName = mat->getBestTechnique()->getPass(0)->getFragmentProgramName();
         UNREFERENCED_PARAM(progName);
         fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsVert[0], 15);
         fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
         break;
     }
     }
 }
Пример #4
0
//---------------------------------------------------------------------------
void BlurListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	Ogre::GpuProgramParametersSharedPtr fparams = mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
	if( pass_id == 700 || pass_id == 701 )
	{
		bool horizontal = pass_id == 700;

		Ogre::Vector2 sampleOffsets[15];
		Ogre::Vector4 sampleWeights[15];

		// calculate gaussian texture offsets & weights
		Ogre::Vector2 textureSize = Vector2(1280,720);
		float texelSize = 1.0f / (float)( horizontal ? textureSize.x : textureSize.y );

		texelSize *= fuzziness;

		// central sample, no offset
		sampleOffsets[ 0 ] = Vector2::ZERO;
		{
			float distribution = GaussianDistribution( 0, 0, 3 );
			sampleWeights[ 0 ] = Ogre::Vector4( distribution, distribution, distribution, 0 );
		}

		// 'pre' samples
		for( int n = 1; n < 8; n++ )
		{
			float distribution = GaussianDistribution( n, 0, 3 );
			sampleWeights[ n ] = Vector4( distribution, distribution, distribution, 1 );

			if( horizontal )
				sampleOffsets[ n ] = Vector2( (float)n * texelSize, 0 );
			else
				sampleOffsets[ n ] = Vector2( 0, (float)n * texelSize );
		}
		// 'post' samples
		for( int n = 8; n < 15; n++ )
		{
			sampleWeights[ n ] = sampleWeights[ n - 7 ];
			sampleOffsets[ n ] = -sampleOffsets[ n - 7 ];
		}

		//convert to Vec4 array
		Vector4 vec4Offsets [15];
		for( int n = 0; n < 15; n++ )
		{
			Vector2 offset = sampleOffsets[ n ];
			vec4Offsets[ n ] = Vector4( offset.x, offset.y, 0, 0 );
		}

		Ogre::GpuProgramParametersSharedPtr fparams = mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();

		//fparams->setNamedConstant( "sampleOffsets", vec4Offsets );
		//fparams->setNamedConstant( "sampleWeights", sampleWeights );
	}
}
Пример #5
0
	// this callback we will use to modify SSAO parameters
    void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
    {
        if (pass_id != 42) // not SSAO, return
            return;

        // this is the camera you're using
		Ogre::Camera *cam = mInstance->getChain()->getViewport()->getCamera();

        // calculate the far-top-right corner in view-space
        Ogre::Vector3 farCorner = cam->getViewMatrix(true) * cam->getWorldSpaceCorners()[4];

        // get the pass
        Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);

        // 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);

        // get the fragment shader parameters
        params = pass->getFragmentProgramParameters();
        // set the projection matrix we need
        static const Ogre::Matrix4 CLIP_SPACE_TO_IMAGE_SPACE(
            0.5,    0,    0,  0.5,
            0,   -0.5,    0,  0.5,
            0,      0,    1,    0,
            0,      0,    0,    1);
        if (params->_findNamedConstantDefinition("ptMat"))
            params->setNamedConstant("ptMat", CLIP_SPACE_TO_IMAGE_SPACE * cam->getProjectionMatrixWithRSDepth());
        if (params->_findNamedConstantDefinition("far"))
            params->setNamedConstant("far", cam->getFarClipDistance());
    }
Пример #6
0
void CameraBlurListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	if (pass_id == 999) 
	{
		if(mApp->pGame->pause == false)
		{
			//acquire the texture flipping attribute in the first frame
			if(compositorinstance)
			{
				mRequiresTextureFlipping  = compositorinstance->getRenderTarget("previousscene")->requiresTextureFlipping();
				compositorinstance=NULL;
			}
			// this is the camera you're using
			#ifndef ROAD_EDITOR
			Ogre::Camera *cam = mApp->mSplitMgr->mCameras.front();
			#else
			Ogre::Camera *cam = mApp->mCamera;
			#endif
			// get the pass
			Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
			Ogre::GpuProgramParametersSharedPtr  params = pass->getFragmentProgramParameters();
       
			const Ogre::RenderTarget::FrameStats& stats =  mApp->getWindow()->getStatistics();
			float m_lastFPS =stats.lastFPS;
	
			Ogre::Matrix4 projectionMatrix   = cam->getProjectionMatrix();
			if (mRequiresTextureFlipping)
            {
                // Because we're not using setProjectionMatrix, this needs to be done here
                // Invert transformed y
                projectionMatrix[1][0] = -projectionMatrix[1][0];
                projectionMatrix[1][1] = -projectionMatrix[1][1];
                projectionMatrix[1][2] = -projectionMatrix[1][2];
                projectionMatrix[1][3] = -projectionMatrix[1][3];
            }
			Ogre::Matrix4 iVP = (projectionMatrix * cam->getViewMatrix()).inverse();

			if (params->_findNamedConstantDefinition("EPF_ViewProjectionInverseMatrix"))
				 params->setNamedConstant("EPF_ViewProjectionInverseMatrix", iVP);
			if (params->_findNamedConstantDefinition("EPF_PreviousViewProjectionMatrix"))
				params->setNamedConstant("EPF_PreviousViewProjectionMatrix", prevviewproj);
			if (params->_findNamedConstantDefinition("intensity"))
				params->setNamedConstant("intensity", mApp->pSet->motionblurintensity);
	
			float interpolationFactor = m_lastFPS * 0.03f ; //* m_timeScale m_timeScale is a multiplier to control motion blur interactively
			Ogre::Quaternion current_orientation = cam->getDerivedOrientation();
			Ogre::Vector3 current_position = cam->getDerivedPosition();
			Ogre::Quaternion estimatedOrientation = Ogre::Quaternion::Slerp(interpolationFactor, current_orientation, (m_pPreviousOrientation));
			Ogre::Vector3 estimatedPosition    = (1-interpolationFactor) * current_position + interpolationFactor * (m_pPreviousPosition);
			Ogre::Matrix4 prev_viewMatrix = Ogre::Math::makeViewMatrix(estimatedPosition, estimatedOrientation);//.inverse().transpose();
			// compute final matrix
			prevviewproj = projectionMatrix * prev_viewMatrix;

			// update position and orientation for next update time
			m_pPreviousOrientation = current_orientation;
			m_pPreviousPosition = current_position;			
		}

	}
}
Пример #7
0
void DepthOfFieldListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
    if(pass_id == 2)
	{
		float blurScale =.5f;
		Ogre::Vector4  pixelSize(1.0f / mViewportWidth, 1.0f / mViewportHeight,1.0f / (mViewportWidth * blurScale), 1.0f / (mViewportHeight * blurScale) );

		Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
        Ogre::GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
    
	   	if (params->_findNamedConstantDefinition("pixelSize"))
			params->setNamedConstant("pixelSize", pixelSize);

	    // this is the camera you're using
        #ifndef ROAD_EDITOR
		Ogre::Camera *cam = mApp->mSplitMgr->mCameras.front();
		#else
		Ogre::Camera *cam = mApp->mCamera;
		#endif
       		
		if (params->_findNamedConstantDefinition("dofparams"))
		{
			Ogre::Vector4 dofParams(0.0f,mApp->pSet->depthOfFieldFocus,mApp->pSet->depthOfFieldFar,1.0);
			params->setNamedConstant("dofparams", dofParams);
		}
     }
}
Пример #8
0
void loadMaterialControlsFile(MaterialControlsContainer& controlsContainer, const Ogre::String& filename)
{
    // Load material controls from config file
    Ogre::ConfigFile cf;

    try
    {

        cf.load(filename, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "\t;=", true);

        // Go through all sections & controls in the file
        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

        Ogre::String secName, typeName, materialName, dataString;

        while (seci.hasMoreElements())
        {
            secName = seci.peekNextKey();
            Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext();
            if (!secName.empty() && settings)
            {
                materialName = cf.getSetting("material", secName);
				
				Ogre::MaterialPtr curMat = Ogre::MaterialManager::getSingleton().getByName(materialName);
				curMat->load();
				Ogre::Technique * curTec = curMat->getBestTechnique();
				if (!curTec || !curTec->isSupported())
				{
					continue;
				}

                MaterialControls newMaaterialControls(secName, materialName);
                controlsContainer.push_back(newMaaterialControls);

                size_t idx = controlsContainer.size() - 1;

                Ogre::ConfigFile::SettingsMultiMap::iterator i;

                for (i = settings->begin(); i != settings->end(); ++i)
                {
                    typeName = i->first;
                    dataString = i->second;
                    if (typeName == "control")
                        controlsContainer[idx].addControl(dataString);
                }
            }
        }

	    Ogre::LogManager::getSingleton().logMessage( "Material Controls setup" );
    }
    catch (Ogre::Exception e)
    {
        // Guess the file didn't exist
    }
}
Пример #9
0
	//-----------------------------------------------------------------------
	void ParticleRenderer::setSoftParticlesDelta(Ogre::Real softParticlesDelta)
	{
		mSoftParticlesDelta = softParticlesDelta;
		if (mUseSoftParticles)
		{
			// Set GPU param
			Ogre::MaterialPtr mat = mParentTechnique->getMaterial();
			if (!mat.isNull())
			{
				if (mat->getBestTechnique() && mat->getBestTechnique()->getPass(0))
				{
					Ogre::Pass* gpuPass = mat->getBestTechnique()->getPass(0);
					if (gpuPass->hasFragmentProgram())
					{
						Ogre::GpuProgramParametersSharedPtr fragmentParams = gpuPass->getFragmentProgramParameters();
						fragmentParams->setNamedConstant("delta", mSoftParticlesDelta);
					}
				}
			}
		}
	}
//-----------------------------------------------------------------------
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
}
Пример #11
0
 void HDRListener::notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
 {
     // Prepare the fragment params offsets
     switch(pass_id)
     {
     //case 994: // rt_lum4
     case 993: // rt_lum3
     case 992: // rt_lum2
     case 991: // rt_lum1
     case 990: // rt_lum0
         break;
     case 800: // rt_brightpass
         break;
     case 701: // rt_bloom1
     {
         // horizontal bloom
         mat->load();
         Ogre::GpuProgramParametersSharedPtr fparams =
             mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
         const Ogre::String& progName = mat->getBestTechnique()->getPass(0)->getFragmentProgramName();
         UNREFERENCED_PARAM(progName);
         fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsHorz[0], 15);
         fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
         break;
     }
     case 700: // rt_bloom0
     {
         // vertical bloom
         mat->load();
         Ogre::GpuProgramParametersSharedPtr fparams =
             mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
         const Ogre::String& progName = mat->getBestTechnique()->getPass(0)->getFragmentProgramName();
         UNREFERENCED_PARAM(progName);
         fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsVert[0], 15);
         fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
         break;
     }
     }
 }
Пример #12
0
void Bomber::update(float timer_,ObjectManager* manager)
{
	std::vector<GameObject*> tempList = manager->getObjectList();
	Ogre::MaterialPtr mat;
	for(int i = 1; i<=26; i++){
		mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(m_pNode->getName()+"_SField_SplineParticleMaterial_"+ Ogre::StringConverter::toString(i)));
		mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("timer", timer_ - i);
	}

	if(hasExploded){
		personalTimer += 1;
		mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(m_pNode->getName()+"_Explosion_ParticleMaterial_"+ Ogre::StringConverter::toString(27)));
		mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("timer", personalTimer);

		if(personalTimer >= 50){
			m_pNode->setVisible(false);
			dead = true;
		}
	}
	Ogre::Vector3 temp = m_pNode->getPosition() - tempList.at(0)->getNode().getPosition();
	move(temp);
}
Пример #13
0
	SimpleOverlay::SimpleOverlay(QEngine* engine,String bucket,String name)
		:LogicObject(engine,bucket,name)
	{
		mOverlay = Ogre::OverlayManager::getSingletonPtr()->getByName("HUD");
		mOverlay->show();
		tx = 3000.f;
		ty = 3000.f;
		Real w = mEngine->getGraphicsManager()->getWindow()->getWidth();
		Real h = mEngine->getGraphicsManager()->getWindow()->getHeight();
		Ogre::MaterialPtr ptr = Ogre::MaterialManager::getSingletonPtr()->getByName("EscherTile");
		ptr->getBestTechnique()->getPass(0)->getTextureUnitState(0)->setTextureUScale(1024.f/w);
		ptr->getBestTechnique()->getPass(0)->getTextureUnitState(0)->setTextureVScale(1024.f/h);
		//Ogre::OverlayManager::getSingletonPtr()->getOverlayElement("HUDPanel")->
	}
Пример #14
0
void ParticleEffect::Update(const Ogre::FrameEvent& fe)
{
	PhysicsEntity::Update(fe);
	if(alive){
		timer += fe.timeSinceLastFrame;
		//std::cout << "Passing in Timer: " <<timer <<std::endl;
		Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(materialName));
		mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("timer", timer);

		if(duration > 0.0f && timer > duration){
			alive = false;
		}
	}
}
Пример #15
0
void MotionBlurListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	if (pass_id != 120) return;
	//Ogre::LogManager::getSingleton().logMessage("notifyMaterialRender");
	try
	{	mat->load();
		Ogre::GpuProgramParametersSharedPtr fparams =
			mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
		fparams->setNamedConstant("blur", pApp->motionBlurIntensity);
	}catch(Ogre::Exception& e)
	{
		Ogre::LogManager::getSingleton().logMessage("Error setting motion blur");
	}
}
Пример #16
0
void FilmGrainListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	if(pass_id == 1)
	{
		float noiseIntensity = 0.1f;
		float exposure = 1-mApp->pSet->hdrParam3;
		Ogre::Vector4  grainparams(1.0f / mViewportWidth, 1.0f / mViewportHeight, noiseIntensity, exposure);

		Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
        Ogre::GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
    
	   	if (params->_findNamedConstantDefinition("grainparams"))
			params->setNamedConstant("grainparams", grainparams);
	 }
}
Пример #17
0
void Rocket::update(float timer_)
{
	Ogre::MaterialPtr mat;
	mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(m_pNode->getName()+"_Thruster_FireMaterial_"+ Ogre::StringConverter::toString(1)));
	mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("timer", timer_);

	if(hasExploded){
		personalTimer += 1;
		mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(m_pNode->getName()+"_Explosion_ParticleMaterial_"+ Ogre::StringConverter::toString(2)));
		mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("timer", personalTimer);

		if(personalTimer >= 15){
			m_pNode->setVisible(false);
			dead = true;
		}
		return;
	}
	move();

	flyTime -= 0.75f;
	if(flyTime < 0.0f){
		dead = true;
	}
}
Пример #18
0
	void DepthComposerInstance::notifyMaterialSetup(uint pass_id, Ogre::MaterialPtr &mat)
	{
        //LogManager::getSingleton ().logMessage (
        //            "Caelum::DepthComposer: Material setup");

        Pass* pass = mat->getBestTechnique ()->getPass (0);

        TextureUnitState *depthTus = pass->getTextureUnitState(1);
        if (depthTus->getTextureName () != mDepthRenderer->getDepthRenderTexture ()->getName()) {
            depthTus->setTextureName (mDepthRenderer->getDepthRenderTexture ()->getName ());
            LogManager::getSingleton ().logMessage (
                        "Caelum::DepthComposer: Assigned depth texture in compositor material");
        }

        mParams.setup(pass->getFragmentProgramParameters ());
	}
//-----------------------------------------------------------------------
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;
}
//-----------------------------------------------------------------------
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;
}
Пример #21
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;
}
Пример #22
0
bool OgreApplication::frameRenderingQueued(const Ogre::FrameEvent& fe){
  
	/* This event is called after a frame is queued for rendering */
	/* Do stuff in this event since the GPU is rendering and the CPU is idle */

	/* Keep animating if flag is on */
	if (animating_){
		animation_state_->addTime(fe.timeSinceLastFrame);
	}

	/* Update shader variables: timer */
	if (animating_particles_){
		timer_ += fe.timeSinceLastFrame;
		Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(particle_material_name_));
		mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("timer", timer_);
	}

	/* Capture input */
	keyboard_->capture();
	mouse_->capture();

	/* Handle specific key events */
	if (keyboard_->isKeyDown(OIS::KC_SPACE)){
		space_down_ = true;
	}
	if ((!keyboard_->isKeyDown(OIS::KC_SPACE)) && space_down_){
		animating_ = !animating_;
		animating_particles_ = !animating_particles_;
		space_down_ = false;
	}
	if (keyboard_->isKeyDown(OIS::KC_RETURN)){
		animation_state_->setTimePosition(0);
		timer_ = 0.0;
	}
	if (keyboard_->isKeyDown(OIS::KC_ESCAPE)){
		ogre_root_->shutdown();
		ogre_window_->destroy();
		return false;
	}
 
    return true;
}
Пример #23
0
void SmallShip::update(float timer_)
{
	Ogre::MaterialPtr mat;
	//Ogre::Entity* mEntity =(Ogre::Entity*) m_pNode->getChild("");
	
	for(int i = 1; i<=numMaterials; i++){
		mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(m_pNode->getName()+"_Thruster_FireMaterial_"+ Ogre::StringConverter::toString(i)));
		mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("timer", timer_);
	}


	//std::cout << "MATNAME:: " << m_pNode->getName()+"SField_SplineParticleMaterial_"+ Ogre::StringConverter::toString(5) << std::endl;
	//"_SField","SplineParticleMaterial"
	for(int i = 5; i<=30; i++){
		//mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(m_pNode->getName()+"_SField_SplineParticleMaterial_"+ Ogre::StringConverter::toString(i)));
		//mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("timer", timer_ - i);
	}

	//SAF_0_SField_SplineParticleMaterial_5
	move();
}
Пример #24
0
	void DepthComposerInstance::notifyMaterialRender(uint pass_id, Ogre::MaterialPtr &mat)
	{
        Camera* camera = getViewport ()->getCamera ();

        assert(mParams.fpParams == mat->getBestTechnique ()->getPass (0)->getFragmentProgramParameters ());

        // Auto param in a compositor does not use the external camera.
        // This means that sending matrices as auto_param will not work as expected.
        // Do it manually instead.
        Matrix4 projMatrix = camera->getProjectionMatrixWithRSDepth();
        Matrix4 viewMatrix = camera->getViewMatrix();

        mParams.invViewProjMatrix.set(mParams.fpParams, (projMatrix * viewMatrix).inverse());

        mParams.worldCameraPos.set(mParams.fpParams, camera->getDerivedPosition ());

        mParams.groundFogDensity.set(mParams.fpParams, getParent ()->getGroundFogDensity ());
        mParams.groundFogVerticalDecay.set(mParams.fpParams, getParent ()->getGroundFogVerticalDecay ());
        mParams.groundFogBaseLevel.set(mParams.fpParams, getParent ()->getGroundFogBaseLevel ());
        mParams.groundFogColour.set(mParams.fpParams, getParent ()->getGroundFogColour ());

        mParams.sunDirection.set(mParams.fpParams, getParent ()->getSunDirection ());
        mParams.hazeColour.set(mParams.fpParams, getParent ()->getHazeColour ());
	}
Пример #25
0
// 设置选中的外观颜色.
void CEditDobject_NT::SetSelectLook(Ogre::ColourValue color)
{

	if(0 == m_materialSelVector.size())
	{
		// 选中材质的名字.
		Ogre::String strCloneName;
		int iCount = m_EntityList.size();
		Ogre::Entity* pEntity = NULL;

		for(int i = 0; i < iCount; i++)
		{
			pEntity = m_EntityList[i].pEntity;
			if(pEntity)
			{
				Ogre::SubEntity* pSubEntiy = pEntity->getSubEntity(0);
				if(pSubEntiy)
				{
					
					Ogre::MaterialPtr pMaterial = pSubEntiy->getMaterial();
					
					if(pMaterial.isNull())
					{
						return;
					}//

					const Ogre::String& strName = pMaterial->getName();

					if("BaseWhite" == strName)
					{
						continue;
					}

					strCloneName = strName;
					strCloneName += "_select";
					
					Ogre::MaterialManager* pMaterialManager = (Ogre::MaterialManager*)(pMaterial->getCreator());

					if(NULL == pMaterialManager)
					{
						return;
					}

					Ogre::MaterialPtr pMaterialClone = pMaterialManager->getByName(strCloneName); 
						
					if(pMaterialClone.isNull())
					{
						pMaterialClone = pMaterial->clone(strCloneName);
					}
					//if(!pMaterialClone)
					//{
					//	return;
					//}//

					Ogre::Technique* pTechnique = pMaterialClone->getBestTechnique();
					Ogre::Pass* pPass = pTechnique->getPass(0);

					//pPass->setSceneBlending(SBT_ADD);
					//pPass->setSceneBlending(SBF_SOURCE_ALPHA , SBF_ONE_MINUS_SOURCE_ALPHA );
					//pTextureState->setAlphaOperation(LBX_MODULATE, LBS_TEXTURE, LBS_MANUAL, 1, Transparence, 1);//
				
					Ogre::TextureUnitState* pTextureState = pPass->getTextureUnitState(0);
					pTextureState->setColourOperationEx(Ogre::LBX_ADD , Ogre::LBS_TEXTURE , Ogre::LBS_MANUAL, color, color );
					pSubEntiy->setMaterialName(strCloneName);
					m_materialSelVector.push_back(pMaterialClone);
					m_materilaOldVector.push_back(pMaterial);
					
				}

			}
		}
	}
	else
	{
		int iIndex = 0;

		int iCount = m_EntityList.size();
		Ogre::Entity* pEntity = NULL;

		for(int i = 0; i < iCount; i++)
		{
			pEntity = m_EntityList[i].pEntity;
			if(pEntity)
			{
				Ogre::SubEntity* pSubEntiy = pEntity->getSubEntity(0);
				
				if(pSubEntiy)
				{
					if(iIndex >= (int)m_materialSelVector.size())
					{
						continue;
					}

					std::string strMaterialName = m_materialSelVector[iIndex]->getName();
					pSubEntiy->setMaterialName(strMaterialName);	
					iIndex++;
				}

			}
		}
	}
}
void  ParticleFactory::CreateSplineControlPoints(Ogre::String control_points_name, int num_control_points, Ogre::String material_name){

		// Control points for the spline
		Ogre::Vector3 *control_point;

		/* Allocate memory for control points */
		control_point = new Ogre::Vector3[num_control_points];

		/* Create control points of a piecewise spline */
		/* We store the control points in groups of 4 */
		/* Each group represents the control points (p0, p1, p2, p3) of a cubic Bezier curve */
		/* To ensure C1 continuity, we constrain the first and second point of each curve according to the previous curve */
        
		// Initialize the first two control points to fixed values */
		control_point[0] = Ogre::Vector3(-20.0, 0.0, 0.0);
		control_point[1] = Ogre::Vector3(20.0, 0.0, 0.0);

		// Create remaining points
		for (int i = 2; i < num_control_points; i++){
			// Check if we have the first or second point of a curve
			// Then we need to constrain the points
			if (i % 4 == 0){
				// Constrain the first point of the curve
				// p3 = q0, where the previous curve is (p0, p1, p2, p3) and the current curve is (q0, q1, q2, q3)
				// p3 is at position -1 from the current point q0
				control_point[i] = control_point[i - 1];
			} else if (i % 4 == 1){
				// Constrain the second point of the curve
				// q1 = 2*p3 – p2
				// p3 is at position -1 and we add another -1 since we are at i%4 == 1 (not i%4 == 0)
				// p2 is at position -2 and we add another -1 since we are at i%4 == 1 (not i%4 == 0)
				control_point[i] = 2.0*control_point[i -2] - control_point[i - 3];
			} else {
				// Other points: we can freely assign random values to them
				// Get 3 random numbers
				float u, v, w;
				//u = ((double) rand() / (RAND_MAX));
				//v = ((double) rand() / (RAND_MAX));
				//w = ((double) rand() / (RAND_MAX));
				// Define control points based on u, v, and w and scale by the control point index
				//control_point[i] = Ogre::Vector3(u*3.0*(i/4 + 1), v*3.0*(i/4+1), w*3.0*(i/4+1));
				//control_point[i] = Ogre::Vector3(u*3.0*(i/4 + 1), v*3.0*(i/4+1), 0.0); // Easier to visualize with the control points on the screen

				//x = cx + r * cos(a)
				//y = cy + r * sin(a)
			
				u = 20 * cos(Ogre::Math::RangeRandom(-25,25));
				v = 20 * sin(Ogre::Math::RangeRandom(-50,50));
				w = (Ogre::Math::RangeRandom(-15,15));
				control_point[i] = Ogre::Vector3(u, w, v);

			}
		}

		/* Add control points to the material's shader */
		/* Translate the array of Ogre::Vector3 to an accepted format */
		float *shader_data;
		shader_data = new float[num_control_points*4];
		for (int i = 0; i < num_control_points; i++){
			shader_data[i*4] = control_point[i].x;
			shader_data[i*4 + 1] = control_point[i].y;
			shader_data[i*4 + 2] = control_point[i].z;
			shader_data[i*4 + 3] = 0.0;
		}

		/* Add array as a parameter to the shader of the specified material */
		Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(material_name));
		mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("control_point", shader_data, num_control_points, 4);

		/* Also create a mesh out of the control points, so that we can render them, if needed */
		
        Ogre::ManualObject* object = NULL;
        object = scene_manager->createManualObject(control_points_name);
        object->setDynamic(false);
		object->begin("", Ogre::RenderOperation::OT_POINT_LIST);
		for (int i = 0; i < num_control_points; i++){
			object->position(control_point[i]);
			// Color allows us to keep track of control point ordering
			object->colour(1.0 - ((float) i)/((float)num_control_points), 0.0, ((float) i)/((float)num_control_points));
		}
		object->end();
        object->convertToMesh(control_points_name);

		/* Free memory we used to store control points temporarily */
		delete [] control_point;
		
}
void GPUSurfFeatureDetector::allocOgreResource()
{
	int hwidth  = (int)mWidth  / 2;
	int hheight = (int)mHeight / 2;

	//create ogre tex
	mGrayTexture = Ogre::TextureManager::getSingleton().createManual("GPGPU/Gray", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mWidth,  mHeight,  mNbOctave-1, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
	mGxTexture   = Ogre::TextureManager::getSingleton().createManual("GPGPU/Gx",   Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mWidth,  mHeight,  mNbOctave-1, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
	mGyTexture   = Ogre::TextureManager::getSingleton().createManual("GPGPU/Gy",   Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mWidth,  mHeight,  mNbOctave-1, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
	mHTexture    = Ogre::TextureManager::getSingleton().createManual("GPGPU/H",    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mWidth,  mHeight,  mNbOctave-1, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
	mNMSTexture  = Ogre::TextureManager::getSingleton().createManual("GPGPU/NMS",  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, hwidth,  hheight,  mNbOctave-1, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
	//mFeatureCudaTexture = Ogre::TextureManager::getSingleton().createManual("GPGPU/Feature/Cuda", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_1D, mNbFeatureMax, 1, 0, Ogre::PF_FLOAT32_RGBA, Ogre::TU_RENDERTARGET);
	//mFeatureTexture     = Ogre::TextureManager::getSingleton().createManual("GPGPU/Feature",      Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_1D, mNbFeatureMax, 1, 0, Ogre::PF_FLOAT32_RGBA, Ogre::TU_RENDERTARGET);	

	//create operation
	for (int i=0; i<mNbOctave; ++i)
	{		
		mGrayResults.push_back(mGPGPURoot->createResult(mGrayTexture->getBuffer(0, i)));
		mGxResults.push_back(mGPGPURoot->createResult(mGxTexture->getBuffer(0,     i)));
		mGyResults.push_back(mGPGPURoot->createResult(mGyTexture->getBuffer(0,     i)));
		mHResults.push_back(mGPGPURoot->createResult(mHTexture->getBuffer(0,       i)));
		mNMSResults.push_back(mGPGPURoot->createResult(mNMSTexture->getBuffer(0,   i)));

		std::stringstream materialName;		
		{
			if (i == 0)
				materialName << "GPGPU/RGB2Gray/Mipmap0";
			else 
				materialName << "GPGPU/DownSampling/Mipmap" << i;
			Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName.str());
			mat->load();
			materialName.str("");
			mGrayOperations.push_back(mGPGPURoot->createOperation(mat->getBestTechnique()->getPass(0)));
		}
		{
			materialName << "GPGPU/GaussianX/Mipmap" << i;
			Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName.str());
			mat->load();
			materialName.str("");
			mGxOperations.push_back(mGPGPURoot->createOperation(mat->getBestTechnique()->getPass(0)));
		}
		{
			materialName << "GPGPU/GaussianY/Mipmap" << i;
			Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName.str());
			mat->load();
			materialName.str("");
			mGyOperations.push_back(mGPGPURoot->createOperation(mat->getBestTechnique()->getPass(0)));
		}
		{
			materialName << "GPGPU/Hessian/Mipmap" << i;
			Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName.str());
			mat->load();
			materialName.str("");
			mHOperations.push_back(mGPGPURoot->createOperation(mat->getBestTechnique()->getPass(0)));
		}
		{
			materialName << "GPGPU/NMS/Mipmap" << i;
			Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName.str());
			mat->load();
			materialName.str("");
			mNMSOperations.push_back(mGPGPURoot->createOperation(mat->getBestTechnique()->getPass(0)));
		}
	}
	mOgreIsAllocated = true;
}
Пример #28
0
		/**
		 * Inherited from CompositorInstance::Listener.
		 */
		void notifyMaterialRender(Ogre::uint32 passId, Ogre::MaterialPtr &mat)
		{
			mat->getBestTechnique()->getPass( passId)->getTextureUnitState("SecondTexture")->setTexture( createDynamicTexture());
		}
Пример #29
0
//---------------------------------------------------------------------------
void PoissonBlurListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	Ogre::GpuProgramParametersSharedPtr fparams = mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
	fparams->setNamedConstant("DiskRadius", this->DiskRadius);
	fparams->setNamedConstant("InputSize", this->InputSize);
}
Пример #30
0
		/**
		 * Inherited from CompositorInstance::Listener.
		 */
		void notifyMaterialSetup( Ogre::uint32 passId, Ogre::MaterialPtr &mat)
		{
			assert( mat->getBestTechnique()->getPass( passId)->getTextureUnitState("SecondTexture") != NULL);

			mat->getBestTechnique()->getPass( passId)->getTextureUnitState("SecondTexture")->setTexture( createDynamicTexture());
		}