Exemple #1
0
    void fade(Ogre::Real tpf) {
        if (m_eFadeOperation != FADE_NONE && m_pTextUnitState) {
            m_pTextUnitState->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, m_fAlpha);

            if (m_eFadeOperation == FADE_IN) {
                m_fCurrentDuration -= tpf;
                m_fAlpha = m_fCurrentDuration / m_fTotalDuration;
                if (m_fAlpha < 0.0) {
                    m_pOverlay->hide();
                    m_eFadeOperation = FADE_NONE;
                    if (m_pFaderCallback) {
                        m_pFaderCallback->fadeInCallback();
                    }
                }
            }
            else if (m_eFadeOperation == FADE_OUT) {
                m_fCurrentDuration += tpf;
                m_fAlpha = m_fCurrentDuration / m_fTotalDuration;
                if (m_fAlpha > 1.0) {
                    m_eFadeOperation = FADE_NONE;
                    if (m_pFaderCallback) {
                        m_pFaderCallback->fadeOutCallback();
                    }
                }
            }
        }
#ifdef USE_SPRITE_SHADER
        m_SpritePixelShaderParameters->setNamedConstant("colour", Ogre::ColourValue(1, 1, 1, m_fAlpha));
#endif
    }
Exemple #2
0
//  HUD utils
//---------------------------------------------------------------------------------------------------------------
void CHud::UpdMiniTer()
{
	MaterialPtr mm = MaterialManager::getSingleton().getByName("circle_minimap");
	Pass* pass = mm->getTechnique(0)->getPass(0);
	if (!pass)  return;
	try
	{	Ogre::GpuProgramParametersSharedPtr par = pass->getFragmentProgramParameters();
		if (par->_findNamedConstantDefinition("showTerrain",false))
			par->setNamedConstant("showTerrain", pSet->mini_terrain && app->sc->ter ? 1.f : 0.f);
		if (par->_findNamedConstantDefinition("showBorder",false))
			par->setNamedConstant("showBorder", pSet->mini_border && app->sc->ter ? 1.f : 0.f);
		if (par->_findNamedConstantDefinition("square",false))
			par->setNamedConstant("square", pSet->mini_zoomed && app->sc->ter ? 0.f : 1.f);
	}
	catch(...){  }
}
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));
					}
				}
			}
		}
	}
}
Exemple #4
0
	void GroundFog::setColour (const Ogre::ColourValue &colour) {
		for (PassSet::iterator it = mPasses.begin(); it != mPasses.end(); ++it) {
			Ogre::GpuProgramParametersSharedPtr params = (*it)->getFragmentProgramParameters();
			params->setNamedConstant("fogColour", colour);
		}
		mFogColour = colour;
		updateSkyFogging();
	}
Exemple #5
0
	void GroundFog::notifyCameraChanged (Ogre::Camera *cam)
	{
        CameraBoundElement::notifyCameraChanged (cam);

		// Send camera height to shader.
		Ogre::GpuProgramParametersSharedPtr params = 
			mDomeMaterial->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
		params->setNamedConstant("cameraHeight", cam->getDerivedPosition().dotProduct(mDomeNode->_getDerivedOrientation() * Ogre::Vector3::UNIT_Y));
    }
Exemple #6
0
void DepthOfFieldListener::notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	if(pass_id == 1)
	{
		float blurScale =.5f;

		Ogre::Vector4 pixelSize(1.0f / (mViewportWidth * blurScale), 1.0f / (mViewportHeight * blurScale), 0.0f, 0.0f);
		
		mat->load();
		Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
        Ogre::GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
    
	   if (params->_findNamedConstantDefinition("pixelSize"))
			params->setNamedConstant("pixelSize", pixelSize);
     
	}
	else 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("far"))
            params->setNamedConstant("far", cam->getFarClipDistance());
		
		if (params->_findNamedConstantDefinition("dofparams"))
		{
			Ogre::Vector4 dofParams(0.0f,mApp->pSet->depthOfFieldFocus,mApp->pSet->depthOfFieldFar,1.0);
			params->setNamedConstant("dofparams", dofParams);
		}
     }
}
Exemple #7
0
	void GroundFog::setDensity (Ogre::Real density) {
		if (Ogre::Math::Abs(mDensity - density) > 0.000001) {
			for (PassSet::iterator it = mPasses.begin(); it != mPasses.end(); ++it) {
				Ogre::GpuProgramParametersSharedPtr params = (*it)->getFragmentProgramParameters();
				params->setNamedConstant("fogDensity", density);
			}
			mDensity = density;
		}
		updateSkyFogging();
	}
Exemple #8
0
	void GroundFog::setVerticalDecay (Ogre::Real verticalDecay) {
		if (Ogre::Math::Abs(mVerticalDecay - verticalDecay) > 0.000001) {
			for (PassSet::iterator it = mPasses.begin(); it != mPasses.end(); ++it) {
				Ogre::GpuProgramParametersSharedPtr params = (*it)->getFragmentProgramParameters();
				params->setNamedConstant("fogVerticalDecay", verticalDecay);
			}
			mVerticalDecay = verticalDecay;
		}
		updateSkyFogging();
	}
Exemple #9
0
	void GroundFog::setGroundLevel (Ogre::Real groundLevel) {
		if (Ogre::Math::Abs(mGroundLevel - groundLevel) > 0.000001) {
			for (PassSet::iterator it = mPasses.begin(); it != mPasses.end(); ++it) {
				Ogre::GpuProgramParametersSharedPtr params = (*it)->getFragmentProgramParameters();
				params->setNamedConstant("fogGroundLevel", groundLevel);
			}
			mGroundLevel = groundLevel;
		}
		updateSkyFogging();
	}
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);
	}
}
Exemple #11
0
	void OgrePass::setTextureUnitIndex (int programType, const std::string& name, int index)
	{
		Ogre::GpuProgramParametersSharedPtr params;
		if (programType == GPT_Vertex)
			params = mPass->getVertexProgramParameters();
		else if (programType == GPT_Fragment)
			params = mPass->getFragmentProgramParameters();

		params->setNamedConstant(name, index);
	}
Exemple #12
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
		try
		{	mat->load();
			Ogre::GpuProgramParametersSharedPtr fparams =
				mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
			fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsHorz[0], 15);
			fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
		}catch(...)
		{	}

			break;
		}
	case 700: // rt_bloom0
		{
			// vertical bloom
		try
		{	mat->load();
			Ogre::GpuProgramParametersSharedPtr fparams =
				mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
			fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsVert[0], 15);
			fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
		}catch(...)
		{	}

			break;
		}
	}
}
void
    GraphicsController::_setSHParameterMultipleMaterials(int paramIdx,
    const Ogre::String &namer, const Ogre::String &nameg, const Ogre::String &nameb,
    const std::vector<Ogre::String> &materialNames)
{
    //for(auto iter = materialNames.cbegin(); iter != materialNames.cend(); ++iter)
	for(const Ogre::String &materialName : materialNames)
	{
        Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName);
        //No checking
        Ogre::Pass* pass = mat->getTechnique(0)->getPass(0);

        Ogre::GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
        if(params->_findNamedConstantDefinition(namer))
            params->setNamedConstant(namer,_SHC_R[paramIdx]);
        if(params->_findNamedConstantDefinition(nameg))
            params->setNamedConstant(nameg,_SHC_G[paramIdx]);
        if(params->_findNamedConstantDefinition(nameb))
            params->setNamedConstant(nameb,_SHC_B[paramIdx]); 
    }
}
Exemple #14
0
//---------------------------------------------------------------------------
void HeatVisionListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
    if(pass_id == 0xDEADBABE)
    {
        // "random_fractions" parameter
        fpParams->setNamedConstant("random_fractions", Ogre::Vector4(Ogre::Math::RangeRandom(0.0, 1.0), Ogre::Math::RangeRandom(0, 1.0), 0, 0));

        // "depth_modulator" parameter
        float inc = ((float)timer->getMilliseconds())/1000.0f;
        if ( (fabs(curr-end) <= 0.001) ) {
            // take a new value to reach
            end = Ogre::Math::RangeRandom(0.95, 1.0);
            start = curr;
        } else {
            if (curr > end) curr -= inc;
            else curr += inc;
        }
        timer->reset();

        fpParams->setNamedConstant("depth_modulator", Ogre::Vector4(curr, 0, 0, 0));
    }
}
Exemple #15
0
void App::UpdMiniTer()
{
	MaterialPtr mm = MaterialManager::getSingleton().getByName("circle_minimap");
	Pass* pass = mm->getTechnique(0)->getPass(0);
	if (!pass)  return;
	try
	{	Ogre::GpuProgramParametersSharedPtr fparams = pass->getFragmentProgramParameters();
		if(fparams->_findNamedConstantDefinition("showTerrain",false))
		{
			fparams->setNamedConstant("showTerrain", pSet->mini_terrain ? 1.f : 0.f);
		}
	}catch(...){  }
}
Exemple #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);
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #17
0
	void OgrePass::setGpuConstant (int type, const std::string& name, ValueType vt, PropertyValuePtr value, PropertySetGet* context)
	{
		Ogre::GpuProgramParametersSharedPtr params;
		if (type == GPT_Vertex)
		{
			if (!mPass->hasVertexProgram ())
				return;
			params = mPass->getVertexProgramParameters();
		}
		else if (type == GPT_Fragment)
		{
			if (!mPass->hasFragmentProgram ())
				return;
			params = mPass->getFragmentProgramParameters();
		}

		if (vt == VT_Float)
			params->setNamedConstant (name, retrieveValue<FloatValue>(value, context).get());
		else if (vt == VT_Int)
			params->setNamedConstant (name, retrieveValue<IntValue>(value, context).get());
		else if (vt == VT_Vector4)
		{
			Vector4 v = retrieveValue<Vector4>(value, context);
			params->setNamedConstant (name, Ogre::Vector4(v.mX, v.mY, v.mZ, v.mW));
		}
		else if (vt == VT_Vector3)
		{
			Vector3 v = retrieveValue<Vector3>(value, context);
			params->setNamedConstant (name, Ogre::Vector4(v.mX, v.mY, v.mZ, 1.0));
		}
		else if (vt == VT_Vector2)
		{
			Vector2 v = retrieveValue<Vector2>(value, context);
			params->setNamedConstant (name, Ogre::Vector4(v.mX, v.mY, 1.0, 1.0));
		}
		else
			throw std::runtime_error ("unsupported constant type");
	}
Exemple #18
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");
	}
}
Exemple #19
0
void SSAOListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	  if (pass_id != 42) // not SSAO, return
            return;

        // this is the camera you're using
        #ifndef ROAD_EDITOR
		Ogre::Camera *cam = mApp->mSplitMgr->mCameras.front();
		#else
		Ogre::Camera *cam = mApp->mCamera;
		#endif
        // 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());
}
Exemple #20
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);
	 }
}
 void StereoController::ChangeShaderColour(qreal r, qreal g, qreal b,const Ogre::String& name)
 {
     try
     {
         Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName("Stereo/Anaglyph");
         Ogre::Pass* pass = mat->getTechnique(0)->getPass(0);
         Ogre::GpuProgramParametersSharedPtr param = pass->getFragmentProgramParameters();
         Ogre::ColourValue colour(r,g,b,1);
         param->setNamedConstant(name, colour);
     }
     catch (Ogre::Exception &e)
     {
         LogWarning("StereoController: Failed to set Anaglyph shader constant.");
         LogWarning(e.what());
     }
 }
Exemple #22
0
	void CMesh::setMeshAmbientColour(Ogre::ColourValue colourValue) {
		
		unsigned int nbSubEnt = mEntity->getNumSubEntities();
		for(unsigned int i = 0;i < nbSubEnt;i++) {

			MaterialPtr mat = mEntity->getSubEntity(i)->getMaterial();

			 mEntity->getSubEntity(i)->getMaterial()->getTechnique(0)->getPass(0)->setAmbient(colourValue);

			Ogre::GpuProgramParametersSharedPtr gpup;

			Ogre::String name = mat->getTechnique(0)->getPass(0)->getVertexProgramName();
			if(name == "ambient_vs") {
				gpup = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();
				gpup->setNamedConstant("ambient", colourValue);
			}
		}
	}
void OGKSceneManager::update(Ogre::Real timeElapsed)
{
    if(mTransitionTimeRemaining > 0.f) {
        mTransitionTimeRemaining -= timeElapsed;
        if(mTransitionTimeRemaining <= 0.f) {
            OGKLOG("Transition completed");
            if(mPreviousScene) mPreviousScene->onExit();
            if(mActiveScene) mActiveScene->onEnterTransitionDidFinish();
            if(mOverlay) mOverlay->hide();
        }
        else if(mPreviousScene) {
            mPreviousScene->update(timeElapsed);
            
            if(mRenderTexture) {
                //OGKLOG("updating render texture");
                mRenderTexture->update();
            }
            
            if(mTransitionTextureUnitState) {
                Ogre::Real fadeAmt = MIN(1.0,MAX(0.0,mTransitionTimeRemaining) / mTransitionTime);
                //OGKLOG("updating fade amt " +  Ogre::StringConverter::toString(fadeAmt) );
                
#ifdef OGRE_IS_IOS
                // Retrieve the shader parameters
                Ogre::GpuProgramParametersSharedPtr pParams = mTransitionMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
                if ( !pParams.isNull() ) {
                    if ( pParams->_findNamedConstantDefinition( "quadAlpha" ) ) {
                        pParams->setNamedConstant( "quadAlpha", fadeAmt );
                    }
                }
#else
                mTransitionTextureUnitState->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, fadeAmt);
#endif
                
#ifdef INCLUDE_RTSHADER_SYSTEM
                Ogre::RTShader::ShaderGenerator::getSingletonPtr()->invalidateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, kTransitionMaterialName);
#endif
            }
        }
    }
    
    if(mActiveScene) mActiveScene->update(timeElapsed);
}
	//-----------------------------------------------------------------------
	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 CVolumetricLightScattering::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat) {
		Ogre::GpuProgramParametersSharedPtr fpParams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();

		// Pasamos la matriz de vista y proyeccion
		Matrix4 projectionMatrix = _sceneCamera->getProjectionMatrix();
		Matrix4 viewMatrix = _sceneCamera->getViewMatrix();
		Matrix4 viewProjMatrix = projectionMatrix * viewMatrix;
		fpParams->setNamedConstant("viewProjMatrix", viewProjMatrix);

		// Seteamos los valores del foco de luz mas cercano
		if( _currentScene != _mapScatterParams.end() ) {
			std::pair<ScatteringParams, bool> closestLightSrc = getClosestLightSource(_currentScene->second);

			if(closestLightSrc.second) {
				fpParams->setNamedConstant("lightPosition", closestLightSrc.first.lightPosition);
				fpParams->setNamedConstant("Density", closestLightSrc.first.density);
				fpParams->setNamedConstant("Decay", closestLightSrc.first.decay);
				fpParams->setNamedConstant("Weight", closestLightSrc.first.weight);
				fpParams->setNamedConstant("Exposure", closestLightSrc.first.exposure);
			}
		}
	}
Exemple #26
0
void Oculus::setupOgreOculus( Ogre::SceneManager *sm, Ogre::RenderWindow* win, Ogre::Root* root )
{
	mSceneMgr = root->createSceneManager(Ogre::ST_GENERIC);
	mSceneMgr->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5 ) );
	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
	

	Ogre::SceneNode* meshNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();


	// Configure Render Textures:
	Sizei recommendedTex0Size = ovrHmd_GetFovTextureSize( mHMD, ovrEye_Left,
			mHMD->DefaultEyeFov[0], 1.0f );
	Sizei recommendedTex1Size = ovrHmd_GetFovTextureSize( mHMD, ovrEye_Right,
			mHMD->DefaultEyeFov[1], 1.0f );

	// Generate a texture for each eye, as a rendertarget:
	mLeftEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual(
			"RiftRenderTextureLeft", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			Ogre::TEX_TYPE_2D, recommendedTex0Size.w, recommendedTex0Size.h, 0, Ogre::PF_X8B8G8R8,
			Ogre::TU_RENDERTARGET );
	mRightEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual(
			"RiftRenderTextureRight", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			Ogre::TEX_TYPE_2D, recommendedTex1Size.w, recommendedTex1Size.h, 0, Ogre::PF_X8B8G8R8,
			Ogre::TU_RENDERTARGET );

	// Assign the textures to the eyes used later:
	mMatLeft = Ogre::MaterialManager::getSingleton().getByName( "Oculus/LeftEye" );
	mMatLeft->getTechnique(0)->getPass(0)->getTextureUnitState(0)->
		setTexture( mLeftEyeRenderTexture );
		
	mMatRight = Ogre::MaterialManager::getSingleton().getByName( "Oculus/RightEye" );
	mMatRight->getTechnique(0)->getPass(0)->getTextureUnitState(0)->
		setTexture( mRightEyeRenderTexture );
		
	ovrEyeRenderDesc eyeRenderDesc[2];

	eyeRenderDesc[0] = ovrHmd_GetRenderDesc( mHMD, ovrEye_Left, mHMD->DefaultEyeFov[0] );
	eyeRenderDesc[1] = ovrHmd_GetRenderDesc( mHMD, ovrEye_Right, mHMD->DefaultEyeFov[1] );

	ovrVector2f UVScaleOffset[2];
	ovrRecti viewports[2];
	viewports[0].Pos.x = 0;
	viewports[0].Pos.y = 0;
	viewports[0].Size.w = recommendedTex0Size.w;
	viewports[0].Size.h = recommendedTex0Size.h;
	viewports[1].Pos.x = recommendedTex0Size.w;
	viewports[1].Pos.y = 0;
	viewports[1].Size.w = recommendedTex1Size.w;
	viewports[1].Size.h = recommendedTex1Size.h;
	Ogre::ManualObject* manual;
	// Create the Distortion Meshes:
	for ( int eyeNum = 0; eyeNum < 2; eyeNum ++ )
	{
		ovrDistortionMesh meshData;
		ovrHmd_CreateDistortionMesh( mHMD,
				eyeRenderDesc[eyeNum].Eye,
				eyeRenderDesc[eyeNum].Fov,
				0,
				&meshData );

		Ogre::GpuProgramParametersSharedPtr params;

		if( eyeNum == 0 )
		{
			ovrHmd_GetRenderScaleAndOffset( eyeRenderDesc[eyeNum].Fov,
					recommendedTex0Size, viewports[eyeNum],
					UVScaleOffset);
			params = mMatLeft->getTechnique(0)->getPass(0)->getVertexProgramParameters();
		} else {
			ovrHmd_GetRenderScaleAndOffset( eyeRenderDesc[eyeNum].Fov,
					recommendedTex1Size, viewports[eyeNum],
					UVScaleOffset);
			params = mMatRight->getTechnique(0)->getPass(0)->getVertexProgramParameters();
		}

		params->setNamedConstant( "eyeToSourceUVScale",
				Ogre::Vector4( UVScaleOffset[0].x, UVScaleOffset[0].y,0,0 ) );
		params->setNamedConstant( "eyeToSourceUVOffset",
				Ogre::Vector4( UVScaleOffset[1].x, UVScaleOffset[1].y,0,0 ) );

		std::cout << "UVScaleOffset[0]: " << UVScaleOffset[0].x << ", " << UVScaleOffset[0].y << std::endl;
		std::cout << "UVScaleOffset[1]: " << UVScaleOffset[1].x << ", " << UVScaleOffset[1].y << std::endl;

		// create ManualObject
		// TODO: Destroy the manual objects!!
			
		if( eyeNum == 0 )
		{
			manual = mSceneMgr->createManualObject("RiftRenderObjectLeft");
			manual->begin("Oculus/LeftEye", Ogre::RenderOperation::OT_TRIANGLE_LIST);
			//manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		}
		else
		{
			manual = mSceneMgr->createManualObject("RiftRenderObjectRight");
			manual->begin("Oculus/RightEye", Ogre::RenderOperation::OT_TRIANGLE_LIST);
			//manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		}

		for( unsigned int i = 0; i < meshData.VertexCount; i++ )
		{
			ovrDistortionVertex v = meshData.pVertexData[i];
			manual->position( v.ScreenPosNDC.x,
					v.ScreenPosNDC.y, 0 );
			manual->textureCoord( v.TanEyeAnglesR.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesR.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			manual->textureCoord( v.TanEyeAnglesG.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesG.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			manual->textureCoord( v.TanEyeAnglesB.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesB.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			//float vig = std::max( v.VignetteFactor, (float)0.0 );
			//manual->colour( vig, vig, vig, vig );
			manual->colour( 1, 1, 1, 1 );

		}
		for( unsigned int i = 0; i < meshData.IndexCount; i++ )
		{
			manual->index( meshData.pIndexData[i] );
		}

		// tell Ogre, your definition has finished
		manual->end();

		ovrHmd_DestroyDistortionMesh( &meshData );

		meshNode->attachObject( manual );
	}
	
	// Set up IPD in meters:
	mIPD = ovrHmd_GetFloat(mHMD, OVR_KEY_IPD,  0.064f);
	
	// Set a default value for interpupillary distance:
	mIPD = 0.064f;
	
	// Create a camera in the (new, external) scene so the mesh can be rendered onto it:
	mCamera = mSceneMgr->createCamera("OculusRiftExternalCamera");
	mCamera->setFarClipDistance(1000000.0f);
	mCamera->setNearClipDistance( 0.1f );
	mCamera->setProjectionType( Ogre::PT_ORTHOGRAPHIC );
	mCamera->setOrthoWindow(2 , 2);
	mCamera->lookAt( 0, 0, -1 );
	

	mSceneMgr->getRootSceneNode()->attachObject( mCamera );

	meshNode->setPosition( 0, 0, -1 );
	meshNode->setScale( 1, 1, -0.1f );

	mViewport = m_window->addViewport( mCamera);
	mViewport->setBackgroundColour(Ogre::ColourValue::Black);
	mViewport->setOverlaysEnabled(true);
}
Exemple #27
0
void RenderState::updateMaterial()
{
    Ogre::Pass* pass = mainMat->getBestTechnique()->getPass(0);

    Ogre::GpuProgramParametersSharedPtr fparams = pass->getFragmentProgramParameters();

    Ogre::Vector3 lightpos(1,0,0); // Bunny
    //Ogre::Vector3 lightpos(-1,-1,10);

    // static double ro = 0;
    // ro += 0.005;

    // try { fparams->setNamedConstant("uLightP", lightpos); }
    // catch (Ogre::Exception) {}

    // Ogre::Vector3 campos = _camera->getPosition();
    // try { fparams->setNamedConstant("uCamPos", campos); }
    // catch (Ogre::Exception) {}

    // OgreFramework* framework = OgreFramework::getSingletonPtr();
    // Real width_inv  = 1.0 / Real(framework->_viewport->getActualWidth());
    // Real height_inv = 1.0 / Real(framework->_viewport->getActualHeight());

    // try { fparams->setNamedConstant("width_inv", width_inv); }
    // catch (Ogre::Exception) {}

    // try { fparams->setNamedConstant("height_inv", height_inv); }
    // catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uTMK", tmk);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uTMK2", tmk2);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uMinTm", mintm);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uDiffuseCoeff", diffuseCoeff);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uColor", ucolor);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uSpecCoeff", specCoeff);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uSpecMult", specMult);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uShininess", shininess);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uMaxSteps", steps);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uAmbient", ambient);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uBackIllum", backIllum);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uGamma", gamma);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uMisc", misc);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uMisc2", misc2);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uMisc3", misc3);
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uTexDim", shapeVolume.getSize());
    }
    catch (Ogre::Exception) {}

    try {
        fparams->setNamedConstant("uInvTexDim", 1.0 / shapeVolume.getSize());
    }
    catch (Ogre::Exception) {}

}
Exemple #28
0
void RenderState::updateMaterial()
{
        Ogre::Pass* pass = breadMat->getBestTechnique()->getPass(0);

        Ogre::GpuProgramParametersSharedPtr fparams = pass->getFragmentProgramParameters();

        Ogre::Vector3 lightpos(1,0,0);

        static double ro = 0;
        ro += 0.005;
        
        // lightpos = Ogre::Vector3(sin(ro), cos(ro), 0);
        // try { fparams->setNamedConstant("uLightP", lightpos); } 
        // catch (Ogre::Exception) {}

        // Ogre::Vector3 campos = _camera->getPosition();
        // try { fparams->setNamedConstant("uCamPos", campos); } 
        // catch (Ogre::Exception) {}

        // OgreFramework* framework = OgreFramework::getSingletonPtr();
        // Real width_inv  = 1.0 / Real(framework->_viewport->getActualWidth());
        // Real height_inv = 1.0 / Real(framework->_viewport->getActualHeight());

        // try { fparams->setNamedConstant("width_inv", width_inv); } 
        // catch (Ogre::Exception) {}

        // try { fparams->setNamedConstant("height_inv", height_inv); } 
        // catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uTMK", tmk); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uTMK2", tmk2); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uMinTm", mintm); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uShadeCoeff", shadeCoeff); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uSpecCoeff", specCoeff); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uSpecMult", specMult); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uShininess", shininess); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uMaxSteps", steps); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uAmbient", ambient); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uBackIllum", backIllum); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uGlowCoeff", glowCoeff); } 
        catch (Ogre::Exception) {}

        try { fparams->setNamedConstant("uMisc", misc); } 
        catch (Ogre::Exception) {}

}
Exemple #29
0
	void CMesh::updateMaterial() {

		try {

			unsigned int nbSubEnt = mEntity->getNumSubEntities();
			for(unsigned int i = 0;i < nbSubEnt;i++) {

				Ogre::String tex1 = mDesc.textureFileName;
				if(tex1 != "") {

					if(OgreManager::getSingleton().isDepthShadowMapping()) {
						MaterialPtr material;

						material = Ogre::MaterialManager::getSingleton().getByName("Ogre/DepthShadowmap/Receiver/RockWall");
						//material = Ogre::MaterialManager::getSingleton().getByName("Ogre/DepthShadowmap/Receiver/Athene");
						MaterialPtr mat = material->clone(getOwnerObject()->getID() + "_Material");

						Ogre::String meshName = getOwnerObject()->getID() + ".tga";
						//mat->getTechnique(0)->getPass(2)->getTextureUnitState(0)->setTextureName(meshName);

						Ogre::String normal = tex1.substr(0,tex1.length()-4);
						Ogre::String ext = tex1.substr(tex1.length()-3,3);

						Ogre::String textDest;
						textDest = normal + "_n." + ext;
						//mat->getTechnique(0)->getPass(1)->getTextureUnitState(0)->setTextureName(textDest);
						
						mat->getTechnique(0)->getPass(2)->getTextureUnitState(0)->setTextureName(tex1);

						mEntity->getSubEntity(i)->setMaterial(mat);

					} else {

						MaterialPtr material;
						
						bool hasLightMap = true;

						//if(shadows) {
						//mDesc.actorParams.mGroupAsName
						CPhysicsActor* actor = dynamic_cast<CPhysicsActor*>(getOwnerObject()->getComponent("CPhysicsActor")); //->toActor();
						if(actor) {
							//if(actor->)
							//if(actor->getNxActor()->isDynamic())
							//	hasLightMap = true;
							//else
								hasLightMap = false;
						}

						if(hasLightMap) {
							material = Ogre::MaterialManager::getSingleton().getByName("ogre");
						} else {
							material = Ogre::MaterialManager::getSingleton().getByName("ogre_diff_only");
						}

						MaterialPtr mat = material->clone(getOwnerObject()->getID() + "_Material");

						Ogre::String tu1 = material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();
						Ogre::String tu2 = material->getTechnique(0)->getPass(1)->getTextureUnitState(0)->getTextureName();
						Ogre::String tu3 = material->getTechnique(0)->getPass(1)->getTextureUnitState(2)->getTextureName();

						mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(tex1);
						mat->getTechnique(0)->getPass(1)->getTextureUnitState(0)->setTextureName(tex1);
						mat->getTechnique(0)->getPass(1)->getTextureUnitState(1)->setTextureName(tex1);

						Ogre::String meshName = getOwnerObject()->getID() + ".tga";
						
						if(hasLightMap)
							mat->getTechnique(0)->getPass(1)->getTextureUnitState(1)->setTextureName(meshName);

						Ogre::String normal = tex1.substr(0,tex1.length()-4);
						Ogre::String ext = tex1.substr(tex1.length()-3,3);

						Ogre::String textDest;
						textDest = normal + "_n." + ext;
						mat->getTechnique(0)->getPass(1)->getTextureUnitState(3)->setTextureName(textDest);

						Ogre::GpuProgramParametersSharedPtr gpup = mat->getTechnique(0)->getPass(1)->getVertexProgramParameters();

						gpup->setNamedConstant("scaleU", Ogre::StringConverter::parseReal(mDesc.textureTileU) );
						gpup->setNamedConstant("scaleV", Ogre::StringConverter::parseReal(mDesc.textureTileV) );

						mat->getTechnique(0)->getPass(1)->setVertexProgramParameters(gpup);

						mEntity->getSubEntity(i)->setMaterial(mat);
					}

				}
			}

		} catch (Ogre::Exception& e) {

		}

	}
Exemple #30
0
//-----------------------------------------------------------------------
void DLight::updateFromCamera(Ogre::Camera* camera)
{
    //Set shader params
    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);
        // 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);

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

        Camera shadowCam("ShadowCameraSetupCam", 0);
        shadowCam._notifyViewport(camera->getViewport());
        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());
        }

    }
}