void CarModel::ChangeClr()
{
	int i = iColor;
	float c_h = pSet->gui.car_hue[i], c_s = pSet->gui.car_sat[i],
	      c_v = pSet->gui.car_val[i], gloss = pSet->gui.car_gloss[i], refl = pSet->gui.car_refl[i];
	color.setHSB(1-c_h, c_s, c_v);  //set, mini pos clr

	MaterialPtr mtr = MaterialManager::getSingleton().getByName(sMtr[Mtr_CarBody]);
	if (!mtr.isNull())
	{	Material::TechniqueIterator techIt = mtr->getTechniqueIterator();
		while (techIt.hasMoreElements())
		{	Technique* tech = techIt.getNext();
			Technique::PassIterator passIt = tech->getPassIterator();
			while (passIt.hasMoreElements())
			{	Pass* pass = passIt.getNext();
				if (pass->hasFragmentProgram())
				{
					GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
					params->setNamedConstant("carColour", color);
					params->setNamedConstant("glossiness", 1 - gloss);
					params->setNamedConstant("reflectiveness", refl);
	}	}	}	}

	if (pNickTxt)
		pNickTxt->setTextColour(MyGUI::Colour(color.r,color.g,color.b));
	
	// opp list text and mini pos colors - auto in hud update
}
Example #2
0
void HDRListener::notifyMaterialRender(uint32 pass_id, MaterialPtr &mat)
{

	if (pass_id == 600 || pass_id == 800)
	{
		Pass *pass = mat->getBestTechnique()->getPass(0);
		GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();

		if (params->_findNamedConstantDefinition("toneMapSettings"))
		{
			Vector4 toneMapSettings(1-mApp->pSet->hdrParam1, mApp->pSet->hdrParam2, mApp->pSet->hdrParam3, 1.0);
			params->setNamedConstant("toneMapSettings", toneMapSettings);
		}
		if (params->_findNamedConstantDefinition("bloomSettings"))
		{
			Vector4 bloomSettings(mApp->pSet->hdrBloomorig*2, mApp->pSet->hdrBloomint, 1.0, 1.0);
			params->setNamedConstant("bloomSettings", bloomSettings);
		}
		if (params->_findNamedConstantDefinition("vignettingSettings"))
		{
			Vector4 vignettingSettings(mApp->pSet->vignRadius, mApp->pSet->vignDarkness, 1.0, 1.0);
			params->setNamedConstant("vignettingSettings", vignettingSettings);
		}

	}
	else if(pass_id == 989)
	{
		Pass *pass = mat->getBestTechnique()->getPass(0);
		GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
		if (params->_findNamedConstantDefinition("AdaptationScale"))
		{
			params->setNamedConstant("AdaptationScale", mApp->pSet->hdrAdaptationScale);
		}
	}
}
	//---------------------------------------------------------------------
	void TerrainMaterialGeneratorC::SM2Profile::ShaderHelper::updateVpParams(
		const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params)
	{
		params->setIgnoreMissingParams(true);
		uint maxLayers = prof->getMaxLayers(terrain);
		uint numLayers = std::min(maxLayers, static_cast<uint>(terrain->getLayerCount()));
		uint numUVMul = numLayers / 4;
		if (numLayers % 4)
			++numUVMul;
		for (uint i = 0; i < numUVMul; ++i)
		{
			Vector4 uvMul(
				terrain->getLayerUVMultiplier(i * 4), 
				terrain->getLayerUVMultiplier(i * 4 + 1), 
				terrain->getLayerUVMultiplier(i * 4 + 2), 
				terrain->getLayerUVMultiplier(i * 4 + 3) 
				);
			params->setNamedConstant("uvMul_" + StringConverter::toString(i), uvMul);
		}
 
		if (terrain->_getUseVertexCompression() && tt != RENDER_COMPOSITE_MAP)
		{
			Real baseUVScale = 1.0f / (terrain->getSize() - 1);
			params->setNamedConstant("baseUVScale", baseUVScale);
		}
 
	}
Example #4
0
void DepthOfFieldListener::notifyMaterialRender(uint32 pass_id, MaterialPtr &mat)
{
	if(pass_id == 2)
	{
		float blurScale =.5f;
		Vector4  pixelSize(1.0f / mViewportWidth, 1.0f / mViewportHeight,1.0f / (mViewportWidth * blurScale), 1.0f / (mViewportHeight * blurScale) );

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

		if (params->_findNamedConstantDefinition("pixelSize"))
			params->setNamedConstant("pixelSize", pixelSize);

		// this is the camera you're using
		#ifndef SR_EDITOR
		Camera *cam = mApp->mSplitMgr->mCameras.front();
		#else
		Camera *cam = mApp->mCamera;
		#endif

		if (params->_findNamedConstantDefinition("dofparams"))
		{
			Vector4 dofParams(0.0f,mApp->pSet->dof_focus,mApp->pSet->dof_far,1.0);
			params->setNamedConstant("dofparams", dofParams);
		}
	}
}
Example #5
0
void GrassLoader::frameUpdate()
{
	unsigned long currentTime = windTimer.getMilliseconds();
	unsigned long ellapsedTime = currentTime - lastTime;
	lastTime = currentTime;

	float ellapsed = ellapsedTime / 1000.0f;

	//Update the vertex shader parameters
	std::list<GrassLayer*>::iterator it;
	for (it = layerList.begin(); it != layerList.end(); ++it){
		GrassLayer *layer = *it;

		layer->_updateShaders();

		GpuProgramParametersSharedPtr params = layer->material->getTechnique(0)->getPass(0)->getVertexProgramParameters();
		if (layer->animate){
			//Increment animation frame
			layer->waveCount += ellapsed * (layer->animSpeed * Math::PI);
			if (layer->waveCount > Math::PI*2) layer->waveCount -= Math::PI*2;

			//Set vertex shader parameters
			params->setNamedConstant("time", layer->waveCount);
			params->setNamedConstant("frequency", layer->animFreq);

			Vector3 direction = windDir * layer->animMag;
			params->setNamedConstant("direction", Vector4(direction.x, direction.y, direction.z, 0));

		}
	}
}
Example #6
0
void CameraBlurListener::notifyMaterialRender(uint32 pass_id, 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 SR_EDITOR
			Camera *cam = mApp->mSplitMgr->mCameras.front();
			#else
			Camera *cam = mApp->mCamera;
			#endif

			// get the pass
			Pass *pass = mat->getBestTechnique()->getPass(0);
			GpuProgramParametersSharedPtr  params = pass->getFragmentProgramParameters();

			const RenderTarget::FrameStats& stats =  mApp->getWindow()->getStatistics();
			float m_lastFPS =stats.lastFPS;

			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];
			}
			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->blur_int);

			float interpolationFactor = m_lastFPS * 0.03f ; //* m_timeScale m_timeScale is a multiplier to control motion blur interactively
			Quaternion current_orientation = cam->getDerivedOrientation();
			Vector3 current_position = cam->getDerivedPosition();
			Quaternion estimatedOrientation = Quaternion::Slerp(interpolationFactor, current_orientation, (m_pPreviousOrientation));
			Vector3 estimatedPosition    = (1-interpolationFactor) * current_position + interpolationFactor * (m_pPreviousPosition);
			Matrix4 prev_viewMatrix = 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;			
		}
	}
}
Example #7
0
	virtual GpuProgramPtr generateFragmentShader(Perm permutation)
	{
		/// Create shader
		if (mMasterSource.empty())
		{
			DataStreamPtr ptrMasterSource;
            if(GpuProgramManager::getSingleton().isSyntaxSupported("glsles"))
                ptrMasterSource = ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsles",
                                                                                    ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            else
                ptrMasterSource = ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsl",
                                                                                    ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

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

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

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

		// Create shader object
		HighLevelGpuProgramPtr ptrProgram;
        if(GpuProgramManager::getSingleton().isSyntaxSupported("glsles"))
        {
            ptrProgram = HighLevelGpuProgramManager::getSingleton().createProgram(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                                  "glsles", GPT_FRAGMENT_PROGRAM);
            ptrProgram->setParameter("profiles", "glsles");
        }
        else
        {
            ptrProgram = HighLevelGpuProgramManager::getSingleton().createProgram(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                                  "glsl", 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
		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 GpuProgramPtr(ptrProgram);
	}
Example #8
0
	bool frameStarted(const FrameEvent& evt) 
	{ 
		//Set shader parameters
		GpuProgramParametersSharedPtr geomParams = particleSystem->
			getRenderToVertexBuffer()->getRenderToBufferMaterial()->
			getTechnique(0)->getPass(0)->getGeometryProgramParameters();
		geomParams->setNamedConstant("elapsedTime", evt.timeSinceLastFrame);
		demoTime += evt.timeSinceLastFrame;
		geomParams->setNamedConstant("globalTime", demoTime);
		geomParams->setNamedConstant("frameGravity", GRAVITY_VECTOR * evt.timeSinceLastFrame);
		
		return true; 
	}
	//-----------------------------------------------------------------------------------
	void PbsMaterial::createTexturUnits(Pass* pass)
	{
		GpuProgramParametersSharedPtr fragmentParams = pass->getFragmentProgramParameters();
		fragmentParams->setIgnoreMissingParams(true);

		// Create the texture unit states
		for (int i = 0; i < ST_COUNT; i++)
		{
			SamplerContainer& s = _samplers[i];
			if (s.status == SS_ACTIVE || s.status == SS_ADDED || s.status == SS_UPDATED)
			{
				s.textureUnitState = pass->createTextureUnitState();
				s.textureUnitState->setName("in_map_" + s.name);
				s.status = SS_UPDATED;
			}
			else
			{
				s.status = SS_NOT_ACTIVE;
			}
		}

		// set the sampler name for the texture unit state
		int size = pass->getNumTextureUnitStates();
		for (int i = 0; i < size; i++)
		{
			TextureUnitState* tus = pass->getTextureUnitState(i);
			fragmentParams->setNamedConstant(tus->getName(), i);
		}

		_hasSamplerChanged = true;
	}
Example #10
0
void MaterialGenerator::vertexProgramParams(HighLevelGpuProgramPtr program)
{
	GpuProgramParametersSharedPtr params = program->getDefaultParameters();
	
	//#ifndef _DEBUG
	params->setIgnoreMissingParams(true);
	//#endif
		
	if (vpNeedWMat())
		params->setNamedAutoConstant("wMat", GpuProgramParameters::ACT_WORLD_MATRIX);
	params->setNamedAutoConstant("wvpMat", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
	if (vpNeedWvMat())
		params->setNamedAutoConstant("wvMat", GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
	if (fpNeedEyeVector() || mShader->wind == 1)
		params->setNamedAutoConstant("eyePosition", GpuProgramParameters::ACT_CAMERA_POSITION);
	
	params->setNamedAutoConstant("fogParams", GpuProgramParameters::ACT_FOG_PARAMS);
			
	if (mShader->wind == 2)
		params->setNamedConstant("enableWind", Real(1.0));
	
	if(MRTSupported())
	{
		params->setNamedAutoConstant("far", GpuProgramParameters::ACT_FAR_CLIP_DISTANCE);
	}	
	individualVertexProgramParams(params);
}
Example #11
0
//  HUD utils
//---------------------------------------------------------------------------------------------------------------
void CHud::UpdMiniTer()
{
	MaterialPtr mm = MaterialManager::getSingleton().getByName("circle_minimap");
	Pass* pass = mm->getTechnique(0)->getPass(0);
	if (!pass)  return;
	try
	{	GpuProgramParametersSharedPtr par = pass->getFragmentProgramParameters();
		bool ter = app->scn->sc->ter;
		if (par->_findNamedConstantDefinition("showTerrain",false))
			par->setNamedConstant("showTerrain", pSet->mini_terrain && ter ? 1.f : 0.f);
		if (par->_findNamedConstantDefinition("showBorder",false))
			par->setNamedConstant("showBorder", pSet->mini_border && ter ? 1.f : 0.f);
		if (par->_findNamedConstantDefinition("square",false))
			par->setNamedConstant("square", pSet->mini_zoomed && ter ? 0.f : 1.f);
	}
	catch(...){  }
}
Example #12
0
void HDRListener::notifyMaterialSetup(uint32 pass_id, 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();
				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();
				GpuProgramParametersSharedPtr fparams =
					mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
				fparams->setNamedConstant("sampleOffsets", mBloomTexOffsetsVert[0], 15);
				fparams->setNamedConstant("sampleWeights", mBloomTexWeights[0], 15);
			}
			catch(...)
			{	}

			break;
		}
	}
}
	//---------------------------------------------------------------------
	void TerrainMaterialGeneratorA::SM2Profile::ShaderHelper::updateFpParams(
		const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const GpuProgramParametersSharedPtr& params)
	{
		params->setIgnoreMissingParams(true);
		// TODO - parameterise this?
		Vector4 scaleBiasSpecular(0.03, -0.04, 32, 1);
		params->setNamedConstant("scaleBiasSpecular", scaleBiasSpecular);

	}
Example #14
0
void DepthOfFieldEffect::notifyMaterialSetup(uint32 passId, MaterialPtr& material)
{
	switch (passId)
	{
	case BlurPass:
		{
			//float pixelSize[2] = {
			//	1.0f / (gEnv->ogreViewPort->getActualWidth() / BLUR_DIVISOR),
			//	1.0f / (gEnv->ogreViewPort->getActualHeight() / BLUR_DIVISOR)};

			// Adjust fragment program parameters
			Ogre::Vector3 ps = Ogre::Vector3(1.0f / (mWidth / BLUR_DIVISOR),1.0f / (mHeight / BLUR_DIVISOR), 1.0f);
			float pixelSize[3] = { ps.x, ps.y, ps.z };
			GpuProgramParametersSharedPtr fragParams = material->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
			if ((!fragParams.isNull())&&(fragParams->_findNamedConstantDefinition("pixelSize")))
				fragParams->setNamedConstant("pixelSize", pixelSize, 1, 3);

			break;
		}

	case OutputPass:
		{
			float pixelSizeScene[3] = {
				1.0f / mWidth,
				1.0f / mHeight,
				0};

			float pixelSizeBlur[3] = {
				1.0f / (mWidth / BLUR_DIVISOR),
				1.0f / (mHeight / BLUR_DIVISOR),
				0};

			// Adjust fragment program parameters
			GpuProgramParametersSharedPtr fragParams =
				material->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
			if ((!fragParams.isNull())&&(fragParams->_findNamedConstantDefinition("pixelSizeScene")))
				fragParams->setNamedConstant("pixelSizeScene", pixelSizeScene,1,3);
			if ((!fragParams.isNull())&&(fragParams->_findNamedConstantDefinition("pixelSizeBlur")))
				fragParams->setNamedConstant("pixelSizeBlur", pixelSizeBlur,1,3);

			break;
		}
	}
}
Example #15
0
HighLevelGpuProgramPtr ParticleMaterialGenerator::createSoftParticleVertexProgram()
{
	HighLevelGpuProgramManager& mgr = HighLevelGpuProgramManager::getSingleton();
	std::string progName = mDef->getName() + "_ambient_VP";

	HighLevelGpuProgramPtr ret = mgr.getByName(progName);
	if (!ret.isNull())
		mgr.remove(progName);

	ret = mgr.createProgram(progName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
		"cg", GPT_VERTEX_PROGRAM);

	ret->setParameter("profiles", "vs_4_0 vs_1_1 arbvp1");
	ret->setParameter("entry_point", "main_vp");

	StringUtil::StrStreamType sourceStr;
	
	sourceStr <<
	"void main_vp( 	float4 position 					: POSITION, \n"
	"	float4 color 						: COLOR,  \n"
	"	float2 texCoord 					: TEXCOORD0,  \n"
	"	out float4 oPosition			 	: POSITION,  \n"
	"	out float4 objectPos				: COLOR,  \n"
	"	out float4 oTexCoord				: TEXCOORD0,  \n"
	"	out float4 oVertexColour				: TEXCOORD1,  \n"
	"	out float4 oScreenPosition				: TEXCOORD2,  \n"
	"	out float4 oWorldPosition				: TEXCOORD3,  \n"
	"	uniform float enableFog,  \n"
	"	uniform float4 fogParams,  \n"
	"	uniform float4x4 wvpMat,  \n"
	"	uniform float4x4 wMat  \n"
	")  \n"
	"{  \n"
	"	oVertexColour = color;  \n"
	"	oPosition = mul(wvpMat, position);  \n"
	"	oWorldPosition = mul(wMat, position);  \n"
	"	oScreenPosition = oPosition; \n"
	"	oTexCoord = float4(texCoord.x, texCoord.y, 1, 1);  \n"
	"	objectPos = position;  \n"
	"	objectPos.w = enableFog * saturate(fogParams.x * (oPosition.z - fogParams.y) * fogParams.w);  \n"
	"} \n";
	
	ret->setSource(sourceStr.str());
	ret->load();
	
	// params
	GpuProgramParametersSharedPtr params = ret->getDefaultParameters();
	params->setIgnoreMissingParams(true);
	params->setNamedAutoConstant("wvpMat", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
	params->setNamedAutoConstant("wMat", GpuProgramParameters::ACT_WORLD_MATRIX);
	params->setNamedAutoConstant("fogParams", GpuProgramParameters::ACT_FOG_PARAMS);
	params->setNamedConstant("enableFog", mDef->mProps->fog ? Real(1.0) : Real(0.0));
	
	return ret;
}
Example #16
0
void MaterialFactory::setWind(bool wind)
{
	for (std::vector<std::string>::iterator it=windMtrs.begin();
		it != windMtrs.end(); ++it)
	{
		MaterialPtr mat = MaterialManager::getSingleton().getByName( (*it) );
		if (mat->getTechnique(0)->getPass(0)->hasVertexProgram())
		{
			GpuProgramParametersSharedPtr vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();
			vparams->setIgnoreMissingParams(true);
			vparams->setNamedConstant("enableWind", wind ? Real(1.0) : Real(0.0));
		}
	}
}
Example #17
0
void MaterialGenerator::individualVertexProgramParams(GpuProgramParametersSharedPtr params)
{
	//#ifndef _DEBUG
	params->setIgnoreMissingParams(true);
	//#endif
	
	if (needShadows())
	for (int i=0; i<mParent->getNumShadowTex(); ++i)
	{
		params->setNamedAutoConstant("texWorldViewProjMatrix"+toStr(i), GpuProgramParameters::ACT_TEXTURE_WORLDVIEWPROJ_MATRIX, i);
	}
	
	params->setNamedConstant("enableFog", mDef->mProps->fog ? Real(1.0) : Real(0.0));
}
Example #18
0
void SSAOListener::notifyMaterialRender(uint32 pass_id, MaterialPtr &mat)
{
	if (pass_id != 42) // not SSAO, return
		return;

	// this is the camera you're using
	#ifndef SR_EDITOR
	Camera *cam = mApp->mSplitMgr->mCameras.front();
	#else
	Camera *cam = mApp->mCamera;
	#endif

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

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

	// get the vertex shader parameters
	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 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());
}
	//-----------------------------------------------------------------------------------
	void PbsMaterial::updateTexturUnits(TextureUnitState* textureUnitState, GpuProgramParametersSharedPtr fragmentParams, SamplerContainer& s, int index)
	{
		if (s.textureType == TEX_TYPE_2D)
		{
			s.textureUnitState->setTexture(s.tex);
			s.textureUnitState->setTextureAddressingMode(s.textureAddressing.u, s.textureAddressing.v, TextureUnitState::TAM_WRAP);
		}
		else if (s.textureType == TEX_TYPE_CUBE_MAP)
		{
			s.textureUnitState->setCubicTexture(&s.tex, true);
			if (mFragmentDatablock.getLanguage() != "hlsl")
			{
				s.textureUnitState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
			}
		}
		s.textureUnitState->setTextureFiltering(TFO_TRILINEAR);
	
		if (s.hasIntensity)
		{
			fragmentParams->setNamedConstant("in_map_" + s.name + "_intensity", s.intensity);
		}

		if (s.hasMipmapCount)
		{
			fragmentParams->setNamedConstant("in_map_" + s.name + "_mipmapcount", s.mipmapCount);
		}

		if (s.hasBlendFactor1)
		{
			fragmentParams->setNamedConstant("in_blendfactor1_" + s.name, s.blendFactor1);
		}

		if (s.hasBlendFactor2)
		{
			fragmentParams->setNamedConstant("in_blendfactor2_" + s.name, s.blendFactor2);
		}
	}
Example #20
0
void FilmGrainListener::notifyMaterialRender(uint32 pass_id, MaterialPtr &mat)
{
	if(pass_id == 1)
	{
		float noiseIntensity = 0.1f;
		float exposure = 1-mApp->pSet->hdrParam3;
		Vector4  grainparams(1.0f / mViewportWidth, 1.0f / mViewportHeight, noiseIntensity, exposure);

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

		if (params->_findNamedConstantDefinition("grainparams"))
			params->setNamedConstant("grainparams", grainparams);
	}
}
Example #21
0
void MotionBlurListener::notifyMaterialRender(uint32 pass_id, MaterialPtr &mat)
{
	if (pass_id != 120)  return;
	//LogO("notifyMaterialRender");
	try
	{	mat->load();
		GpuProgramParametersSharedPtr fparams =
			mat->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
		fparams->setNamedConstant("blur", pApp->motionBlurIntensity);
	}
	catch (Exception& e)
	{
		LogO("Error setting motion blur");
	}
}
Example #22
0
void MaterialFactory::setSoftParticles(bool bEnable)
{
	if(MaterialGenerator::MRTSupported())
	{
		for (std::vector<std::string>::iterator it=softMtrs.begin();
			it != softMtrs.end(); ++it)
		{
			MaterialPtr mat = MaterialManager::getSingleton().getByName( (*it) );
			if (mat->getTechnique(0)->getPass(0)->hasFragmentProgram())
			{
				GpuProgramParametersSharedPtr vparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
				vparams->setNamedConstant("useSoftParticles", bEnable ? 1.0f: -1.0f);
			}
		}
	}
}
//-----------------------------------------------------------------------------
void GLSLESProgramProcessor::bindTextureSamplers(Program* pCpuProgram, GpuProgramPtr pGpuProgram)
{
	GpuProgramParametersSharedPtr pGpuParams = pGpuProgram->getDefaultParameters();
	const UniformParameterList& progParams = pCpuProgram->getParameters();
	UniformParameterConstIterator itParams;

	// Bind the samplers.
	for (itParams = progParams.begin(); itParams != progParams.end(); ++itParams)
	{
		const UniformParameterPtr pCurParam = *itParams;
		
		if (pCurParam->isSampler())
		{		
			pGpuParams->setNamedConstant(pCurParam->getName(), pCurParam->getIndex());						
		}		
	}
}
Example #24
0
	void CompositorWhiteoutListener::notifyMaterialRender( uint32 pass_id, MaterialPtr & mat )
	{
		// build a white blendcolor with alpha based on progress
		float alpha = 1.0f - OgreClient::Singleton->Data->Effects->Whiteout->Progress;
		float blendcolor[4];
		blendcolor[0] = 1.0f;  // r
		blendcolor[1] = 1.0f;  // g
		blendcolor[2] = 1.0f;  // b
		blendcolor[3] = alpha; // a

		// get shader parameters
		const GpuProgramParametersSharedPtr list = 
			mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();

		// set current blendcolor in shader
		list->setNamedConstant(SHADERBLENDCOLOR, blendcolor, 1);
	};
Example #25
0
void DepthOfFieldEffect::preViewportUpdate(const Ogre::RenderTargetViewportEvent& evt)
{

	float dofParams[4] = {mNearDepth, mFocalDepth, mFarDepth, mFarBlurCutoff};

	// Adjust fragment program parameters for depth pass
	GpuProgramParametersSharedPtr fragParams =
		mDepthTechnique->getPass(0)->getFragmentProgramParameters();
	if ((!fragParams.isNull())&&(fragParams->_findNamedConstantDefinition("dofParams")))
		fragParams->setNamedConstant("dofParams", dofParams,1,4);		

	evt.source->setVisibilityMask(~DEPTHMAP_DISABLED);

	// Add 'this' as a RenderableListener to replace the technique for all renderables
	RenderQueue* queue = evt.source->getCamera()->getSceneManager()->getRenderQueue();
	queue->setRenderableListener(this);
}
Example #26
0
	void CompositorPainListener::notifyMaterialRender( uint32 pass_id, MaterialPtr & mat )
	{
		// build a red blendcolor with alpha based on progress
		// we scale pain effect here from 30-0% blending
		float alpha = 0.3f - (0.3f * OgreClient::Singleton->Data->Effects->Pain->Progress);
		float blendcolor[4];
		blendcolor[0] = 1.0f;  // r
		blendcolor[1] = 0.0f;  // g
		blendcolor[2] = 0.0f;  // b
		blendcolor[3] = alpha; // a

		// get shader parameters
		const GpuProgramParametersSharedPtr list = 
			mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();

		// set current blendcolor in shader
		list->setNamedConstant(SHADERBLENDCOLOR, blendcolor, 1);
	};
//-----------------------------------------------------------------------------
void GLSLESProgramProcessor::bindTextureSamplers(Program* pCpuProgram, GpuProgramPtr pGpuProgram)
{
	GpuProgramParametersSharedPtr pGpuParams = pGpuProgram->getDefaultParameters();
	const UniformParameterList& progParams = pCpuProgram->getParameters();
	UniformParameterConstIterator itParams;

	// Bind the samplers.
	for (itParams = progParams.begin(); itParams != progParams.end(); ++itParams)
	{
		const UniformParameterPtr pCurParam = *itParams;
		
		if (pCurParam->isSampler())
		{
            // The optimizer may remove some unnecessary parameters, so we should ignore them
            pGpuParams->setIgnoreMissingParams(true);

            pGpuParams->setNamedConstant(pCurParam->getName(), pCurParam->getIndex());
		}
	}
}
//-------------------------------------------------------------------------------------------------------
//  utility
//-------------------------------------------------------------------------------------------------------
void CarModel::UpdateLightMap()
{
	MaterialPtr mtr;
	for (int i=0; i < NumMaterials; ++i)
	{
		mtr = MaterialManager::getSingleton().getByName(sMtr[i]);
		if (!mtr.isNull())
		{	Material::TechniqueIterator techIt = mtr->getTechniqueIterator();
			while (techIt.hasMoreElements())
			{	Technique* tech = techIt.getNext();
				Technique::PassIterator passIt = tech->getPassIterator();
				while (passIt.hasMoreElements())
				{	Pass* pass = passIt.getNext();
					if (pass->hasFragmentProgram())
					{
						GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
						params->setIgnoreMissingParams(true);  // don't throw exception if material doesnt use lightmap
						params->setNamedConstant("enableTerrainLightMap", bLightMapEnabled ? 1.f : 0.f);
	}	}	}	}	}
}
	//---------------------------------------------------------------------
	void TerrainMaterialGeneratorA::SM2Profile::ShaderHelper::defaultVpParams(
		const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog)
	{
		GpuProgramParametersSharedPtr params = prog->getDefaultParameters();
		params->setIgnoreMissingParams(true);
		params->setNamedAutoConstant("worldMatrix", GpuProgramParameters::ACT_WORLD_MATRIX);
		params->setNamedAutoConstant("viewProjMatrix", GpuProgramParameters::ACT_VIEWPROJ_MATRIX);
		params->setNamedAutoConstant("lodMorph", GpuProgramParameters::ACT_CUSTOM, 
			Terrain::LOD_MORPH_CUSTOM_PARAM);
		params->setNamedAutoConstant("fogParams", GpuProgramParameters::ACT_FOG_PARAMS);

		if (prof->isShadowingEnabled(tt, terrain))
		{
			uint numTextures = 1;
			if (prof->getReceiveDynamicShadowsPSSM())
			{
				numTextures = (uint)prof->getReceiveDynamicShadowsPSSM()->getSplitCount();
			}
			for (uint i = 0; i < numTextures; ++i)
			{
				params->setNamedAutoConstant("texViewProjMatrix" + StringConverter::toString(i), 
					GpuProgramParameters::ACT_TEXTURE_VIEWPROJ_MATRIX, i);
				if (prof->getReceiveDynamicShadowsDepth())
				{
					params->setNamedAutoConstant("depthRange" + StringConverter::toString(i), 
						GpuProgramParameters::ACT_SHADOW_SCENE_DEPTH_RANGE, i);
				}
			}
		}

		if (terrain->_getUseVertexCompression() && tt != RENDER_COMPOSITE_MAP)
		{
			Matrix4 posIndexToObjectSpace;
			terrain->getPointTransform(&posIndexToObjectSpace);
			params->setNamedConstant("posIndexToObjectSpace", posIndexToObjectSpace);
		}

		
		
	}
	//---------------------------------------------------------------------
	void TerrainMaterialGeneratorC::SM2Profile::ShaderHelper::defaultVpParams(
		const SM2Profile* prof, const Terrain* terrain, TechniqueType tt, const HighLevelGpuProgramPtr& prog)
	{
		GpuProgramParametersSharedPtr params = prog->getDefaultParameters();
		params->setIgnoreMissingParams(true);
		params->setNamedAutoConstant("worldMatrix", GpuProgramParameters::ACT_WORLD_MATRIX);
		params->setNamedAutoConstant("viewMatrix", GpuProgramParameters::ACT_WORLDVIEW_MATRIX);
		params->setNamedAutoConstant("viewProjMatrix", GpuProgramParameters::ACT_VIEWPROJ_MATRIX);
		params->setNamedAutoConstant("lodMorph", GpuProgramParameters::ACT_CUSTOM, 
			Terrain::LOD_MORPH_CUSTOM_PARAM);
		params->setNamedAutoConstant("fogParams", GpuProgramParameters::ACT_FOG_PARAMS);
 
		if (terrain->_getUseVertexCompression() && tt != RENDER_COMPOSITE_MAP)
		{
			Matrix4 posIndexToObjectSpace;
			terrain->getPointTransform(&posIndexToObjectSpace);
			params->setNamedConstant("posIndexToObjectSpace", posIndexToObjectSpace);
		}
 
 
 
	}