示例#1
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();
        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();
        fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsVert[0], 15);
        fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);

        break;
    }
    }
}
示例#2
0
//===========================================================================
// MaterialSetShader
//===========================================================================
void MaterialSetShader::subEntityAction( SubEntityMaterial* subEntity ) const
{
  Pass * pass = getFirstPassOfFirstTechnique( subEntity ) ;

  pass->setLightingEnabled( _light );

  if ( "null" != _texture )
  {
     pass->createTextureUnitState( _texture );
     //TextureUnitState *texState = pass->createTextureUnitState( texture ) ;
     //texState->setTextureScroll( 0.f, 0.f ) ;
     //texState->setColourOperation( Ogre::LBO_MODULATE ) ;

     //texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
  }
  if ( "null" != _fragment)
  { //fragment Program
    pass->setFragmentProgram( _fragment );
    //copy params passed
    Ogre::GpuProgramParametersSharedPtr fragmentParams = pass->getFragmentProgramParameters() ;
    fragmentParams->copyConstantsFrom( *_fragmentPrm ) ;
  }
  if ( "null" != _vertex)
  { //vertex Program
    pass->setVertexProgram( _vertex );
    //copy params passed
    Ogre::GpuProgramParametersSharedPtr vertexParams = pass->getVertexProgramParameters() ;
    vertexParams->copyConstantsFrom( *_vertexPrm ) ;
  }
  pass->_load() ;
}
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));
					}
				}
			}
		}
	}
}
示例#4
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);
		}
     }
}
示例#5
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));
    }
}
    void setUpBaseParameters(const Ogre::GpuProgramParametersSharedPtr& params)
    {
        assert(params.isNull()==false);

        struct AutoParamPair { Ogre::String name; Ogre::GpuProgramParameters::AutoConstantType type; };

        //A list of auto params that might be present in the shaders generated
        static const AutoParamPair AUTO_PARAMS[] = {
            { "vpWidth",            Ogre::GpuProgramParameters::ACT_VIEWPORT_WIDTH },
            { "vpHeight",           Ogre::GpuProgramParameters::ACT_VIEWPORT_HEIGHT },
            { "worldView",          Ogre::GpuProgramParameters::ACT_WORLDVIEW_MATRIX },
            { "invProj",            Ogre::GpuProgramParameters::ACT_INVERSE_PROJECTION_MATRIX },
            { "invView",            Ogre::GpuProgramParameters::ACT_INVERSE_VIEW_MATRIX },
            { "flip",               Ogre::GpuProgramParameters::ACT_RENDER_TARGET_FLIPPING },
            { "lightDiffuseColor",  Ogre::GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR },
            { "lightSpecularColor", Ogre::GpuProgramParameters::ACT_LIGHT_SPECULAR_COLOUR },
            { "lightFalloff",       Ogre::GpuProgramParameters::ACT_LIGHT_ATTENUATION },
            { "lightPos",           Ogre::GpuProgramParameters::ACT_LIGHT_POSITION_VIEW_SPACE },
            { "lightDir",           Ogre::GpuProgramParameters::ACT_LIGHT_DIRECTION_VIEW_SPACE },
            { "spotParams",         Ogre::GpuProgramParameters::ACT_SPOTLIGHT_PARAMS },
            { "farClipDistance",    Ogre::GpuProgramParameters::ACT_FAR_CLIP_DISTANCE },
            { "shadowViewProjMat",  Ogre::GpuProgramParameters::ACT_TEXTURE_VIEWPROJ_MATRIX }
        };
        int numParams = sizeof(AUTO_PARAMS) / sizeof(AutoParamPair);
        
        for (int i=0; i<numParams; i++)
        {
            if (params->_findNamedConstantDefinition(AUTO_PARAMS[i].name))
            {
                params->setNamedAutoConstant(AUTO_PARAMS[i].name, AUTO_PARAMS[i].type);
            }
        }
    }
示例#7
0
	void GPUManager::setGpuProgramParameter(const GpuProgram &GpuP,  const Ogre::String &Name, const int &Value, const bool& UpdateGroundPasses)
	{
		if (!mSkyX->getMeshManager()->isCreated())
		{
			return;
		}

		Ogre::GpuProgramParametersSharedPtr Parameters;

		switch (GpuP)
		{
		    case GPUP_VERTEX:
			{
				Parameters = mSkydomeMaterial->getTechnique(0)->getPass(0)->getVertexProgramParameters();
			}
			break;

			case GPUP_FRAGMENT:
			{
				Parameters = mSkydomeMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
			}
			break;
		}

		Parameters->setNamedConstant(Name, Value);

		if (!UpdateGroundPasses)
		{
			return;
		}

		std::vector<Ogre::Pass*>::iterator PassIt;

		for(PassIt = mGroundPasses.begin(); PassIt != mGroundPasses.end(); PassIt++)
		{
			if (!(*PassIt))
			{
				mGroundPasses.erase(PassIt);
				continue;
			}

			switch (GpuP)
			{
			    case GPUP_VERTEX:
				{
					Parameters = (*PassIt)->getVertexProgramParameters();
				}
				break;

			    case GPUP_FRAGMENT:
				{
					Parameters = (*PassIt)->getFragmentProgramParameters();
				}
				break;
			}

			Parameters->setNamedConstant(Name, Value);
		}
	}
示例#8
0
	void GroundFog::updateSkyFogging() {
		Ogre::GpuProgramParametersSharedPtr params = 
			mDomeMaterial->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
		params->setNamedConstant("fogDensity", getDensity());
		params->setNamedConstant("fogColour", getColour());
		params->setNamedConstant("fogVerticalDecay", getVerticalDecay());
		params->setNamedConstant("fogGroundLevel", getGroundLevel());
	}
示例#9
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();
	}
示例#10
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));
    }
示例#11
0
void WaterMaterialGenerator::individualVertexProgramParams(Ogre::GpuProgramParametersSharedPtr params)
{
	params->setIgnoreMissingParams(true); //! workaround 'Parameter texWorldViewProjMatrix0 does not exist' - no idea why its happening
	if (needShadows())
	for (int i=0; i<mParent->getNumShadowTex(); ++i)
	{
		params->setNamedAutoConstant("texWorldViewProjMatrix"+toStr(i), GpuProgramParameters::ACT_TEXTURE_WORLDVIEWPROJ_MATRIX, i);
	}
}
示例#12
0
	void GroundFog::forceUpdate () {
		for (PassSet::iterator it = mPasses.begin(); it != mPasses.end(); ++it) {
			Ogre::GpuProgramParametersSharedPtr params = (*it)->getFragmentProgramParameters();
			params->setNamedConstant("fogDensity", mDensity);
			params->setNamedConstant("fogVerticalDecay", mVerticalDecay);
			params->setNamedConstant("fogGroundLevel", mGroundLevel);
			params->setNamedConstant("fogColour", mFogColour);
		}
		updateSkyFogging();
	}
示例#13
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);
	}
示例#14
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();
	}
示例#15
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();
	}
示例#16
0
	void OgrePass::addSharedParameter (int type, const std::string& name)
	{
		Ogre::GpuProgramParametersSharedPtr params;
		if (type == GPT_Vertex)
			params = mPass->getVertexProgramParameters();
		else if (type == GPT_Fragment)
			params = mPass->getFragmentProgramParameters();

		params->addSharedParameters (name);
	}
示例#17
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();
	}
示例#18
0
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());
		}

	}
}
示例#19
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);
		}
	}
}
示例#20
0
 void cleanupContent()
 {
     // get rid of the shared pointers before shutting down ogre or exceptions occure
     std::cout << "Imposto i servizi per gli shader di texture\n";
     mActiveFragmentProgram.setNull();
     mActiveFragmentParameters.setNull();
     mActiveVertexProgram.setNull();
     mActiveVertexParameters.setNull();
     mActiveMaterial.setNull();
     std::cout << "Impostazione terminata\n";
 }
	virtual Ogre::GpuProgramPtr generateFragmentShader(Perm permutation)
	{
		/// Create shader
		if (mMasterSource.empty())
		{
			Ogre::DataStreamPtr ptrMasterSource;
            if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles"))
                ptrMasterSource = Ogre::ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsles",
                                                                                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            else
                ptrMasterSource = Ogre::ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsl",
                                                                                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

			assert(ptrMasterSource.isNull()==false);
			mMasterSource = ptrMasterSource->getAsString();
		}

		assert(mMasterSource.empty()==false);

		// Create name
		Ogre::String name = mBaseName+Ogre::StringConverter::toString(permutation)+"_ps";

		// Create shader object
		Ogre::HighLevelGpuProgramPtr ptrProgram;
        if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles"))
        {
            ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                                  "glsles", Ogre::GPT_FRAGMENT_PROGRAM);
            ptrProgram->setParameter("profiles", "glsles");
        }
        else
        {
            ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                                  "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
            ptrProgram->setParameter("profiles", "glsl150");
        }
        ptrProgram->setSource(mMasterSource);
		// set up the preprocessor defines
		// Important to do this before any call to get parameters, i.e. before the program gets loaded
		ptrProgram->setParameter("preprocessor_defines", getPPDefines(permutation));

		setUpBaseParameters(ptrProgram->getDefaultParameters());

        // Bind samplers
		Ogre::GpuProgramParametersSharedPtr params = ptrProgram->getDefaultParameters();
        int numSamplers = 0;
        params->setNamedConstant("Tex0", (int)numSamplers++);
        params->setNamedConstant("Tex1", (int)numSamplers++);

        if(permutation & LightMaterialGenerator::MI_SHADOW_CASTER)
            params->setNamedConstant("ShadowTex", (int)numSamplers++);

		return Ogre::GpuProgramPtr(ptrProgram);
	}
示例#22
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(...){  }
}
示例#23
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");
	}
}
示例#24
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);
	 }
}
示例#25
0
文件: Fader.hpp 项目: ChWick/Mencus
    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
    }
 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());
     }
 }
示例#27
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());
    }
示例#28
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;			
		}

	}
}
示例#29
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);
			}
		}
	}
示例#30
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);
	}
}