Index: trunk/BUTE/src/IlluminationManager.cpp
===================================================================
--- trunk/BUTE/src/IlluminationManager.cpp	(revision 124)
+++ trunk/BUTE/src/IlluminationManager.cpp	(revision 124)
@@ -0,0 +1,341 @@
+#include "Ogre.h"
+#include "OgreEffectWrapper.h"
+#include "ManagedOgreRenderTexturePass.h"
+#include "FinalRenderingRun.h"
+#include "illuminationmanager.h"
+
+void IlluminationManager::render(RenderTarget* rt, CubeMapFaces cf)
+{
+	static std::vector<bool> entityVisibilityList;
+	static std::vector<bool> billboardVisibilityList;
+
+	RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
+	SceneManager* sceneManager = Root::getSingleton().getSceneManager(ST_GENERIC);
+
+	const ColourValue& backgroundColour = rt->getViewport(0)->getBackgroundColour();
+
+	//save visibility (entities)
+	//set all invisible (entities)
+	{
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			Entity* entity = ei.getNext();
+			entityVisibilityList.push_back(entity->isVisible());
+			entity->setVisible(false);
+		}
+	}
+	//save visibility (billboardsets)
+	//set all invisible (billboardsets)
+	{
+		SceneManager::BillboardSetIterator bi = sceneManager->getBillboardSetIterator();
+		while(bi.hasMoreElements())
+		{
+			BillboardSet* billboard = bi.getNext();
+			billboardVisibilityList.push_back(billboard->isVisible());
+			billboard->setVisible(false);
+		}
+	}
+
+	//foreach entity prerender
+	if(performPreRenderStep)
+	{
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			UserDefinedObject* pudo = ei.getNext()->getUserObject();
+			OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does not contain a valid MultipleUserDefinedObject.");
+			pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
+			OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does not contain a valid EntityRenderingObject.");
+			EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
+			FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
+
+			fRun->setVisible(true);
+			fRun->preRender(rt, cf);
+			fRun->setVisible(false);
+		}
+	}
+
+	//foreach entity render
+	{
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			UserDefinedObject* pudo = ei.getNext()->getUserObject();
+			OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
+			pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
+			OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
+			EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
+			FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
+
+			fRun->setVisible(true);
+			fRun->renderSingleEntity(rt, cf);
+			fRun->setVisible(false);
+		}
+	}
+
+	//foreach entity postrender
+	if(performPostRenderStep)
+	{
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			UserDefinedObject* pudo = ei.getNext()->getUserObject();
+			OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
+			pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
+			OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
+			EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
+			FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
+
+			fRun->setVisible(true);
+			fRun->postRender(rt, cf);
+			fRun->setVisible(false);
+		}
+	}
+
+	//foreach image based lighting directional light sample
+	if(performImageBasedLighting)
+	{
+		imageLightingSamplesRun.rewind();
+		while(imageLightingSamplesRun.renderNextDepthMaps())
+		{
+			//foreach entity postrender
+			{
+				SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+				while(ei.hasMoreElements())
+				{
+					UserDefinedObject* pudo = ei.getNext()->getUserObject();
+					OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
+					pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
+					OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
+					EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
+					FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
+
+					fRun->setVisible(true);
+					fRun->postRender(rt, cf);
+					fRun->setVisible(false);
+				}
+			}
+		}
+	}
+
+	//restore visibility (billboardsets)
+	{
+		unsigned int elementNumber = 0;
+		SceneManager::BillboardSetIterator bi = sceneManager->getBillboardSetIterator();
+		while(bi.hasMoreElements())
+		{
+			BillboardSet* billboard = bi.getNext();
+			billboard->setVisible(billboardVisibilityList.at(elementNumber++));
+		}
+		billboardVisibilityList.clear();
+	}
+
+	//render billboardsets
+
+
+	//restore visibility (entities)
+	{
+		unsigned int elementNumber = 0;
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			Entity* entity = ei.getNext();
+			entity->setVisible(entityVisibilityList.at(elementNumber++));
+		}
+		entityVisibilityList.clear();
+	}
+}
+
+void IlluminationManager::updateStaticLightData()
+{
+	RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
+	SceneManager* sceneManager = Root::getSingleton().getSceneManager(ST_GENERIC);
+
+
+	SceneManager::LightIterator li = sceneManager->getLightIterator();
+	bool pointLightUpdated[32];
+	bool spotLightUpdated[32];
+	bool directionalLightUpdated[32];
+	for(unsigned int i=0; i<32; i++)
+	{
+		pointLightUpdated[i] = spotLightUpdated[i] = directionalLightUpdated[i] = false;
+	}
+	while(li.hasMoreElements())
+	{
+		Light* light = li.getNext();
+		if(light->getType() == Light::LT_POINT && computePointLightShadows)
+		{
+			bool newLight = true;
+			for(unsigned int il=0; il < nPointLights; il++)
+			{
+				if(pointLights[il]->ogreLight == light)
+				{
+					pointLights[il]->update();
+					pointLightUpdated[il] = true;
+					newLight = false;
+					break;
+				}
+			}
+			if(newLight)
+			{
+				OgreAssert(nPointLights < 32, "More than 32 lights!");
+				if(nPointLights < nAllocatedPointLights)
+				{
+					pointLights[nPointLights]->ogreLight = light;
+					pointLights[nPointLights]->preProcRun.setLight(light);
+					nPointLights++;
+				}
+				else
+				{
+					pointLights[nPointLights] = new PointLightPreProcData();
+					pointLights[nPointLights]->ogreLight = light;
+					pointLights[nPointLights]->preProcRun.setLight(light);
+					nPointLights++;
+					nAllocatedPointLights++;
+				}
+			}
+		}
+		else if(light->getType() == Light::LT_SPOTLIGHT && computeSpotLightShadows)
+		{
+			bool newLight = true;
+			for(unsigned int il=0; il < nSpotLights; il++)
+			{
+				if(spotLights[il]->ogreLight == light)
+				{
+					spotLights[il]->update();
+					spotLightUpdated[il] = true;
+					newLight = false;
+					break;
+				}
+			}
+			if(newLight)
+			{
+				OgreAssert(nSpotLights < 32, "More than 32 lights!");
+				if(nSpotLights < nAllocatedSpotLights)
+				{
+					spotLights[nSpotLights]->ogreLight = light;
+					spotLights[nSpotLights]->preProcRun.setLight(light);
+					nSpotLights++;
+				}
+				else
+				{
+					spotLights[nSpotLights] = new SpotLightPreProcData();
+					spotLights[nSpotLights]->ogreLight = light;
+					spotLights[nSpotLights]->preProcRun.setLight(light);
+					nSpotLights++;
+					nAllocatedSpotLights++;
+				}
+			}
+		}
+		else if(light->getType() == Light::LT_DIRECTIONAL && computeDirectionalLightShadows)
+		{
+			bool newLight = true;
+			for(unsigned int il=0; il < nDirectionalLights; il++)
+			{
+				if(directionalLights[il]->ogreLight == light)
+				{
+					directionalLights[il]->update();
+					directionalLightUpdated[il] = true;
+					newLight = false;
+					break;
+				}
+			}
+			if(newLight)
+			{
+				OgreAssert(nDirectionalLights < 32, "More than 32 lights!");
+				if(nDirectionalLights < nAllocatedDirectionalLights)
+				{
+					directionalLights[nDirectionalLights]->ogreLight = light;
+					directionalLights[nDirectionalLights]->preProcRun.setLight(light);
+					nDirectionalLights++;
+				}
+				else
+				{
+					directionalLights[nDirectionalLights] = new DirectionalLightPreProcData();
+					directionalLights[nDirectionalLights]->ogreLight = light;
+					directionalLights[nDirectionalLights]->preProcRun.setLight(light);
+					nDirectionalLights++;
+					nAllocatedDirectionalLights++;
+				}
+			}
+		}
+	}
+	//dump unused lights
+}
+
+void IlluminationManager::update(unsigned long frameNumber, RenderTarget* rt, CubeMapFaces cf)
+{
+	RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
+	SceneManager* sceneManager = Root::getSingleton().getSceneManager(ST_GENERIC);
+
+
+	//update static light data
+
+
+	//foreach entity render VRM
+	{
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			UserDefinedObject* pudo = ei.getNext()->getUserObject();
+			OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
+			pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
+			OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
+			EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
+			FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
+
+			eObject->updateVRM(frameNumber);
+		}
+	}
+	//foreach entity render caustic map
+	{
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			UserDefinedObject* pudo = ei.getNext()->getUserObject();
+			OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
+			pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
+			OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
+			EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
+			FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
+
+			eObject->updateCausticMap(frameNumber);
+		}
+	}
+
+	//foreach entity render PRM
+	{
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			UserDefinedObject* pudo = ei.getNext()->getUserObject();
+			OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
+			pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
+			OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
+			EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
+			FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
+
+			eObject->updatePRM(frameNumber);
+		}
+	}
+
+	//foreach entity render environment map cubes
+	{
+		SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
+		while(ei.hasMoreElements())
+		{
+			UserDefinedObject* pudo = ei.getNext()->getUserObject();
+			OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
+			pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
+			OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
+			EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
+			FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
+
+			eObject->updateEnvironmentCubes(frameNumber);
+		}
+	}
+
+	renderSystem->clearFrameBuffer(0, rt->getViewport(0)->getBackgroundColour());
+	render(rt, cf);
+}
Index: trunk/BUTE/src/RenderingType.cpp
===================================================================
--- trunk/BUTE/src/RenderingType.cpp	(revision 124)
+++ trunk/BUTE/src/RenderingType.cpp	(revision 124)
@@ -0,0 +1,6 @@
+#include "RenderingType.h"
+
+
+const RenderingType RenderingType::LAMBERTSHADING;
+
+const RenderingType RenderingType::TEXTUREDLAMBERTSHADING;
Index: trunk/BUTE/src/MultipleUserDefinedObject.cpp
===================================================================
--- trunk/BUTE/src/MultipleUserDefinedObject.cpp	(revision 124)
+++ trunk/BUTE/src/MultipleUserDefinedObject.cpp	(revision 124)
@@ -0,0 +1,5 @@
+#include "Ogre.h"
+#include "multipleuserdefinedobject.h"
+
+const long MultipleUserDefinedObject::multipleUserDefinedObjectTypeId(-3);
+const String MultipleUserDefinedObject::multipleUserDefinedObjectTypeName("MultipleUserDefinedObject");
Index: trunk/BUTE/src/EntityRenderingObject.cpp
===================================================================
--- trunk/BUTE/src/EntityRenderingObject.cpp	(revision 124)
+++ trunk/BUTE/src/EntityRenderingObject.cpp	(revision 124)
@@ -0,0 +1,146 @@
+#include "Ogre.h"
+#include "RenderingType.h"
+#include "OgreEffectWrapper.h"
+#include "ManagedOgreRenderTexturePass.h"
+#include "FinalRenderingRun.h"
+#include "entityrenderingobject.h"
+
+#include "LightMapFinalRenderingRun.h"
+
+const long EntityRenderingObject::entityRenderingObjectTypeId(-2);
+const String EntityRenderingObject::entityRenderingObjectTypeName("EntityRenderingObject");
+
+EntityRenderingObject::EntityRenderingObject(Entity* owner, unsigned long startFrame, const RenderingType& renderingType )
+{
+	this->startFrame = startFrame;
+
+	if(renderingType.diffuseShaded &&
+		!renderingType.diffuseTextured )
+		finalRenderingRun = new LightMapFinalRenderingRun(owner);
+
+	//for all possible per entity preComputingRuns
+	if(finalRenderingRun->getLightMapUpdateInterval() != 0)
+	{
+		lightMapRun = new LightMapRun(
+				renderingType.lightMapResolutionX,
+				renderingType.lightMapResolutionY,
+				renderingType.lightMapNumberOfMipmapLevels, 
+				renderingType.lightMapLOD,
+				owner);
+		finalRenderingRun->setLightMapTexture(lightMapRun->getResultTextureName());
+	}
+	else
+		lightMapRun = NULL;
+
+	if(finalRenderingRun->getVRMUpdateInterval() != 0)
+	{
+		vrmRun = new VRMRun(
+			owner,
+			renderingType.vrmMapResolutionX,
+			renderingType.vrmMapResolutionY
+			);
+		finalRenderingRun->setVRMTexture(vrmRun->getResultTextureName());
+	}
+	else
+		vrmRun = NULL;
+
+	if(finalRenderingRun->getCausticMapUpdateInterval() != 0)
+	{
+		causticMapRun = new CausticMapRun(owner, renderingType.causticMapResolutionX, renderingType.causticMapResolutionY);
+		finalRenderingRun->setCausticMapTexture(causticMapRun->getResultTextureName());
+	}
+	else
+		vrmRun = NULL;
+
+	if(finalRenderingRun->getPRMUpdateInterval() != 0)
+	{
+		prmRun = new PRMRun(
+			owner,
+			renderingType.prmResolution,
+			renderingType.prmNEntryPoints,
+			renderingType.prmNClusters,
+			renderingType.prmTileSize
+			);
+		finalRenderingRun->setPRMTexture(prmRun->getResultTextureName());
+		finalRenderingRun->setEntryPointsTexture(prmRun->getEntryPointsTextureName());
+		finalRenderingRun->setNEntryPoints(prmRun->getNEntryPoints());
+		finalRenderingRun->setNClusters(prmRun->getNClusters());
+		finalRenderingRun->setTileSize(prmRun->getTileSize());
+	}
+	else
+		prmRun = NULL;
+
+	if(finalRenderingRun->getDiffuseEnvironmentUpdateInterval() != 0)
+	{
+		diffuseEnvironmentRun = new DiffuseEnvironmentMapRun(owner, renderingType.diffuseEnvironmentMapResolution);
+		finalRenderingRun->setDiffuseEnvironmentTextureCube(diffuseEnvironmentRun->getResultTextureName());
+	}
+	else
+		diffuseEnvironmentRun = NULL;
+
+	if(finalRenderingRun->getSpecularEnvironmentUpdateInterval() != 0)
+	{
+		specularEnvironmentRun = new SpecularEnvironmentMapRun(owner, renderingType.specularEnvironmentMapResolution);
+		finalRenderingRun->setSpecularEnvironmentTextureCube(specularEnvironmentRun->getResultTextureName());
+	}
+	else
+		specularEnvironmentRun = NULL;
+
+	if(finalRenderingRun->getFresnelEnvironmentUpdateInterval() != 0)
+	{
+		fresnelEnvironmentRun = new FresnelEnvironmentMapRun(owner, renderingType.fresnelEnvironmentMapResolution);
+		finalRenderingRun->setFresnelEnvironmentTextureCube(fresnelEnvironmentRun->getResultTextureName());
+	}
+	else
+		fresnelEnvironmentRun = NULL;
+
+}
+
+/**
+	perform preproc necessary in this frame
+*/
+void EntityRenderingObject::updateLightMap(long frameCount)
+{
+	if(finalRenderingRun->getLightMapUpdateInterval() != 0 &&
+		((frameCount - startFrame)  % finalRenderingRun->getLightMapUpdateInterval()) == 0 )
+		lightMapRun->update();
+}
+
+void EntityRenderingObject::updateVRM(long frameCount)
+{
+	if(finalRenderingRun->getVRMUpdateInterval() != 0 &&
+		((frameCount - startFrame)  % finalRenderingRun->getVRMUpdateInterval()) == 0 )
+		vrmRun->update();		
+}
+
+void EntityRenderingObject::updateCausticMap(long frameCount)
+{
+	if(finalRenderingRun->getCausticMapUpdateInterval() != 0 &&
+		((frameCount - startFrame)  % finalRenderingRun->getCausticMapUpdateInterval()) == 0 )
+		causticMapRun->update();		
+}
+
+void EntityRenderingObject::updatePRM(long frameCount)
+{
+	if(finalRenderingRun->getPRMUpdateInterval() != 0 &&
+		((frameCount - startFrame)  % finalRenderingRun->getPRMUpdateInterval()) == 0 )
+		prmRun->update();
+}
+
+void EntityRenderingObject::updateEnvironmentCubes(long frameCount)
+{
+	if(finalRenderingRun->getDiffuseEnvironmentUpdateInterval() != 0 &&
+		((frameCount - startFrame)  % finalRenderingRun->getDiffuseEnvironmentUpdateInterval()) == 0 )
+		diffuseEnvironmentRun->update();
+	if(finalRenderingRun->getSpecularEnvironmentUpdateInterval() != 0 &&
+		((frameCount - startFrame)  % finalRenderingRun->getSpecularEnvironmentUpdateInterval()) == 0 )
+		specularEnvironmentRun->update();
+	if(finalRenderingRun->getFresnelEnvironmentUpdateInterval() != 0 &&
+		((frameCount - startFrame)  % finalRenderingRun->getFresnelEnvironmentUpdateInterval()) == 0 )
+		fresnelEnvironmentRun->update();
+}
+
+EntityRenderingObject::~EntityRenderingObject(void)
+{
+	delete finalRenderingRun;
+}
Index: trunk/BUTE/src/ManagedOgreRenderTexturePass.cpp
===================================================================
--- trunk/BUTE/src/ManagedOgreRenderTexturePass.cpp	(revision 124)
+++ trunk/BUTE/src/ManagedOgreRenderTexturePass.cpp	(revision 124)
@@ -0,0 +1,137 @@
+#include "Ogre.h"
+#include <vector>
+#include <cmath> 
+#include "OgreEffectWrapper.h"
+#include "ManagedOgreRenderTexturePass.h"
+
+
+const char* ManagedOgreRenderTexturePass::noRenderTargetName="NO_RENDER_TEXTURE";
+MovablePlane* ManagedOgreRenderTexturePass::fullScreenQuad=NULL;
+Entity* ManagedOgreRenderTexturePass::fullScreenQuadEntity=NULL;
+SceneNode* ManagedOgreRenderTexturePass::fullScreenQuadSceneNode=NULL;
+
+ManagedOgreRenderTexturePass::ManagedOgreRenderTexturePass(
+			
+			Root* mRoot, const String& renderTextureName,unsigned int width,unsigned int height,
+		 	TextureType texType , PixelFormat internalFormat, 
+			const NameValuePairList *miscParams,bool fullScreenQuadRenderer
+			
+			){
+	
+	this->mRoot=mRoot;
+	renderSystem=mRoot->getRenderSystem();
+	mSceneMgr=mRoot->getSceneManager(ST_GENERIC);
+	if(renderTextureName!=noRenderTargetName){
+		renderTexture=renderSystem->createRenderTexture(renderTextureName,width,height,texType,internalFormat,miscParams);
+		this->addRenderTarget(renderTexture);
+	}
+	if(!fullScreenQuad){
+		createFullScreenQuad();
+	}
+	this->fullScreenQuadRenderer=fullScreenQuadRenderer;
+	effectWrapper=new EffectWrapper();
+}
+
+void ManagedOgreRenderTexturePass::createFullScreenQuad(){
+	fullScreenQuad=new MovablePlane(Vector3::UNIT_Y,0.0f);
+	MeshManager::getSingleton().createPlane("FullScreenQuad", 
+        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
+        *fullScreenQuad, 1, 1, 
+        1, 1, true, 1, 1, 1, Vector3::UNIT_Z);
+	this->fullScreenQuadEntity=mSceneMgr->createEntity("FullScreenQuad","FullScreenQuadEntity");
+	SceneNode* rootNode = mSceneMgr->getRootSceneNode();
+	fullScreenQuadSceneNode=rootNode->createChildSceneNode();
+	mPlaneNode->attachObject(fullScreenQuadEntity);
+    mPlaneNode->attachObject(fullScreenQuad);
+	//camera setup.
+}
+
+void ManagedOgreRenderTexturePass::entityMaterialSetup(){
+	SceneManager::EntityIterator entityIterator=mSceneMgr->getEntityIterator();
+	while(entityIterator.hasMoreElements()){
+		Entity* entity=entityIterator.getNext();
+		entity->setMaterialName(this->effectWrapper->getMaterial()->getName());
+		if(fullScreenQuadRenderer){
+			entityVisibilityList.push_back(entity->isVisible());
+			entity->setVisible(false);
+		}
+	}
+	if(fullScreenQuadRenderer){
+		this->fullScreenQuadSceneNode->setVisible(true);
+	}
+}
+
+void ManagedOgreRenderTexturePass::entityMaterialCleanup(){
+	if(fullScreenQuadRenderer){
+		SceneManager::EntityIterator entityIterator=mSceneMgr->getEntityIterator();
+		int elementNumber=0;
+		while(entityIterator.hasMoreElements()){
+			Entity* entity=entityIterator.getNext();
+			entity->setVisible(entityVisibilityList.at(elementNumber));
+			elementNumber++;
+		}
+		entityVisibilityList.clear();
+		this->fullScreenQuadSceneNode->setVisible(false);
+	}
+}
+
+void ManagedOgreRenderTexturePass::update(NameValuePairList* startParams,NameValuePairList* endParams){
+	onRenderStart(startParams);
+	entityMaterialSetup();
+	RenderTarget* rt=renderTargets.at(0);
+	Matrix4* worldMatrices=new Matrix4[rt->getViewport(0)->getCamera()->getNumWorldTransforms()];
+	rt->getViewport(0)->getCamera()->getWorldTransforms(worldMatrices);
+	Matrix4 viewMatrix=renderTexture->getViewport(0)->getCamera()->getViewMatrix();
+	Matrix4 projMatrix=renderTexture->getViewport(0)->getCamera()->getProjectionMatrix();
+	std::vector<Viewport*> viewports;
+	std::vector<RenderTarget*>::iterator rtIterator;
+	for(rtIterator=renderTargets.begin();rtIterator!=renderTargets.end();rtIterator++){
+		viewports.push_back((*rtIterator)->getViewport(0));
+	}
+	Matrix4 worldMatrix = Matrix4::IDENTITY;
+	for(int i=0;i<rt->getViewport(0)->getCamera()->getNumWorldTransforms();i++){
+		worldMatrix = worldMatrix * worldMatrices[i];
+	}
+	delete[] worldMatrices;
+	mRoot->getSceneManager(ST_GENERIC)->manualRender(effectWrapper->getMaterial()->getTechnique(0)->getPass(0),viewports,this->cubeMapFaces,worldMatrix,viewMatrix,projMatrix,true);
+	entityMaterialCleanup();
+	onRenderEnd(endParams);
+}
+
+bool ManagedOgreRenderTexturePass::changeTexture(const String& textureName, unsigned short textureUnit){
+	this->effectWrapper->SetTexture(textureUnit,textureName);
+	return false;
+}
+
+bool ManagedOgreRenderTexturePass::changeMaterial(String& materialName, StringVector& newTextureNames,bool useOldTextureNames){
+	effectWrapper->createMaterial(materialName);
+	this->effectWrapper->getMaterial()->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
+	std::vector<TextureUnitState*>::iterator iter;
+	for(iter=usedTextureUnitStates.begin();iter<usedTextureUnitStates.end();iter++){
+		usedTextureUnitStates.erase(iter);
+	}
+	if(!useOldTextureNames){
+		textureNames=newTextureNames;
+	}
+	std::vector<String>::iterator iter2;
+	int i=0;
+	for(iter2=textureNames.begin();iter2<textureNames.end();iter2++){
+		TextureUnitState* t = this->effectWrapper->getMaterial()->getTechnique(0)->getPass(0)->createTextureUnitState((*iter2),i);
+		i++;
+		usedTextureUnitStates.push_back(t);
+	}
+	return true;
+}
+
+void ManagedOgreRenderTexturePass::oneTimeRenderToTextureSetup(String& materialName,StringVector& textureNames){
+	std::vector<String>::iterator iter;
+	this->effectWrapper->getMaterial()->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
+	int i=0;
+	for(iter=textureNames.begin();iter<textureNames.end();iter++){
+		TextureUnitState* t = this->effectWrapper->getMaterial()->getTechnique(0)->getPass(0)->createTextureUnitState((*iter),i);
+		i++;
+		usedTextureUnitStates.push_back(t);
+	}
+	effectWrapper->createMaterial(materialName);
+}
+
Index: trunk/BUTE/src/PreComputingRun.cpp
===================================================================
--- trunk/BUTE/src/PreComputingRun.cpp	(revision 124)
+++ trunk/BUTE/src/PreComputingRun.cpp	(revision 124)
@@ -0,0 +1,3 @@
+#include "Ogre.h"
+#include "precomputingrun.h"
+
Index: trunk/BUTE/src/RenderingRun.cpp
===================================================================
--- trunk/BUTE/src/RenderingRun.cpp	(revision 124)
+++ trunk/BUTE/src/RenderingRun.cpp	(revision 124)
@@ -0,0 +1,3 @@
+#include "Ogre.h"
+#include "renderingrun.h"
+
Index: trunk/BUTE/src/OgreEffectWrapper.cpp
===================================================================
--- trunk/BUTE/src/OgreEffectWrapper.cpp	(revision 124)
+++ trunk/BUTE/src/OgreEffectWrapper.cpp	(revision 124)
@@ -0,0 +1,312 @@
+#include "Ogre.h"
+#include "OgreEffectWrapper.h"
+
+
+EffectWrapper::EffectWrapper(){
+	numberOfCurrentTechnique=-1;
+	numberOfCurrentPass=-1;
+	fragmentProgramParams=false;
+	vertexProgramParams=false;
+	shadowCasterParams=false;
+	shadowReceiverParams=false;
+	canSetNewTechnique=true;
+	this->material.setNull();
+}
+
+EffectWrapper::EffectWrapper(Material* material){
+	numberOfCurrentTechnique=-1;
+	numberOfCurrentPass=-1;
+	fragmentProgramParams=false;
+	vertexProgramParams=false;
+	shadowCasterParams=false;
+	shadowReceiverParams=false;
+	canSetNewTechnique=true;
+	this->material.bind(material);
+}
+
+
+
+EffectWrapper::~EffectWrapper(){
+
+}
+
+//D3D Effect framework style.
+
+bool EffectWrapper::SetFloat(const String& name, float value){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetFloatArray(const String& name,const float* value, size_t count){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetInt(const String& name, int value){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetIntArray(const String& name,const int* value, size_t count){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetDoubleArray(const String& name, double* value, size_t count){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value,count);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetMatrix(const String& name, Matrix4& value){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetMatrixArray(const String& name, Matrix4* value, size_t numEntries){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value,numEntries);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value,numEntries);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value,numEntries);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value,numEntries);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetMatrixTranspose(const String& name, Matrix4& value){
+	if(validateSet()){
+		return false;
+	}
+	Matrix4 transposeValue=value;
+	transposeValue.transpose();
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,transposeValue);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,transposeValue);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,transposeValue);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,transposeValue);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetMatrixTransposeArray(const String& name, Matrix4* value, size_t numEntries){
+	if(validateSet()){
+		return false;
+	}
+	Matrix4* transposeValues=new Matrix4[numEntries];
+	for(unsigned int i=0;i<numEntries;i++){
+		transposeValues[i]=value[i];
+		transposeValues[i].transpose();
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,transposeValues,numEntries);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,transposeValues,numEntries);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,transposeValues,numEntries);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,transposeValues,numEntries);
+	}
+	delete[] transposeValues;
+	return true;
+}
+
+bool EffectWrapper::SetTexture(int textureUnit,const String& textureName){
+	material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->createTextureUnitState()->setTextureName(textureName);
+	return(true);
+}
+
+//Ogre style.
+
+bool EffectWrapper::SetVector4(const String& name,const Vector4 &vec){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,vec);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,vec);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,vec);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,vec);
+	}
+	return true;
+}
+
+bool EffectWrapper::SetVector3(const String& name,const Vector3 &vec){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,vec);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,vec);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,vec);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,vec);
+	}
+	return(true);
+}
+
+bool EffectWrapper::SetReal(const String& name, Real value){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value);
+	}
+	return(true);
+}
+
+bool EffectWrapper::SetColourValue(const String& name, const ColourValue &colour){
+	if(validateSet()){
+		return false;
+	}
+	if(vertexProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,colour);
+	}
+	if(fragmentProgramParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,colour);
+	}
+	if(shadowCasterParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,colour);
+	}
+	if(shadowReceiverParams){
+		material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,colour);
+	}
+	return(true);
+}
+
+bool EffectWrapper::SetTechniqueToUse(int numberOfTechnique){
+	if(canSetNewTechnique){
+		if(GetNumTechniques()>numberOfTechnique){
+			this->numberOfCurrentTechnique=numberOfTechnique;
+			return true;
+		}
+		else{
+			return false;
+		}
+	}
+	return false;
+}
+
+MaterialPtr& EffectWrapper::getMaterial(){
+	return material;
+}
Index: trunk/BUTE/src/FinalRenderingRun.cpp
===================================================================
--- trunk/BUTE/src/FinalRenderingRun.cpp	(revision 124)
+++ trunk/BUTE/src/FinalRenderingRun.cpp	(revision 124)
@@ -0,0 +1,5 @@
+#include "Ogre.h"
+#include "OgreEffectWrapper.h"
+#include "ManagedOgreRenderTexturePass.h"
+#include "finalrenderingrun.h"
+
