Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h	(revision 874)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h	(revision 949)
@@ -139,7 +139,11 @@
 	void update(unsigned long frameNumber, RenderTarget* rt);
 	/**
-		@brief searches for RenderTechniques in materials and creates them.
+		@brief searches for RenderTechniques in materials and creates them for all objects.
 	*/
 	void initTechniques();
+	/**
+		@brief searches for RenderTechniques in materials and creates them for an Entity.
+	*/
+	void initTechniques(Entity* e);
 	/**
 		@brief Returns a pointer to the player camera.
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePhotonMapRenderingRun.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePhotonMapRenderingRun.h	(revision 790)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePhotonMapRenderingRun.h	(revision 949)
@@ -48,6 +48,8 @@
 	void refreshLight();
 
-	//inherited
+	
 	void distanceCubeMapChanged(RenderingRun* run);
+	
+	void distanceCubeMapUpdated(RenderingRun* run);
 	
 protected:	
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCausticCasterRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCausticCasterRenderTechnique.h	(revision 836)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCausticCasterRenderTechnique.h	(revision 949)
@@ -80,4 +80,6 @@
 	virtual void distanceCubeMapRunChanged(RenderingRun* run);
 	//inherited
+	void distanceCubeMapRunUpdated(RenderingRun* run);
+	//inherited
 	virtual RenderingRun* createPhotonMapRun();
 	//inherited
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp	(revision 808)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp	(revision 949)
@@ -78,5 +78,6 @@
 	static int framecount = 0;
 	String filename = "photon";
-	filename.append(StringConverter::toString(framecount));
+	filename.append(this->name);
+	//filename.append(StringConverter::toString(framecount));
 	filename.append(".png");
 	rt->writeContentsToFile(filename);
@@ -135,3 +136,13 @@
 	mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(cubemapname);
 }
+
+void OgrePhotonMapRenderingRun::distanceCubeMapUpdated(RenderingRun* run)
+{
+	Material* mat = (Material*) MaterialManager::getSingleton().getByName(materialName).getPointer();
+	OgreDistanceCubeMapRenderingRun* cuberun =(OgreDistanceCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	String cubemapname = cuberun->getDistanceCubeMapTextureName();
+	GpuProgramParametersSharedPtr fpParams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
+	Vector3 center = ((OgreSharedRuns*) sharedRuns)->getRootPosition(ILLUMRUN_DISTANCE_CUBEMAP);
+	fpParams->setNamedConstant("lastCenter",center);
+}
  
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCausticCubeMapRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCausticCubeMapRenderingRun.cpp	(revision 790)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCausticCubeMapRenderingRun.cpp	(revision 949)
@@ -21,4 +21,6 @@
 	this->materialName =  materialName;
 	this->photonMapTexId = photonMapTexId;
+
+	spriteSetName = name + String("_pixelSpriteSet");
 	
 	createCausticCubeMap();
@@ -40,4 +42,7 @@
 	String photonMapName = ((OgrePhotonMapRenderingRun*) run->asOgreRenderingRun())->getPhotonMapTextureName();
 	mat->getTechnique(0)->getPass(0)->getTextureUnitState(photonMapTexId)->setTextureName(photonMapName);
+
+	//rt = TextureManager::getSingleton().getByName(photonMapName);
+	LogManager::getSingleton().logMessage(LML_NORMAL, name + " map: " + photonMapName + " material: " + mat->getName());
 }
 
@@ -59,5 +64,5 @@
 	renderPixelSprites(materialName, rt, tex->getWidth(), tex->getHeight());
 
-	//rt->writeContentsToFile("caucube" + StringConverter::toString(facenum) + ".dds");
+	//rt->writeContentsToFile("caucube" + this->name + StringConverter::toString(facenum) + ".dds");
 }
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp	(revision 874)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp	(revision 949)
@@ -23,5 +23,11 @@
 {	
 	this->photonMapMaterialName = photonMapMaterialName;
-	this->causticMapMaterialName = causticMapMaterialName;
+	
+	String newMaterialName = causticMapMaterialName + parentRenderable->getName() + "_clone";
+	Material* mat = (Material*) MaterialManager::getSingleton().getByName(causticMapMaterialName).getPointer();
+	Material* newMat = mat->clone(newMaterialName).getPointer();
+	this->causticMapMaterialName = newMat->getName();
+	//this->causticMapMaterialName =causticMapMaterialName;
+		
 	this->photonMapTexID = photonMapTexID;
 	
@@ -63,5 +69,13 @@
 	}
 }
-
+void OgreCausticCasterRenderTechnique::distanceCubeMapRunUpdated(RenderingRun* run)
+{
+	if(useDistance)
+	{
+		OgrePhotonMapRenderingRun* photonrun = (OgrePhotonMapRenderingRun*) 
+					sharedRuns->getRun(ILLUMRUN_PHOTONMAP)->asOgreRenderingRun();
+		photonrun->distanceCubeMapUpdated(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP));
+	}
+}
 void OgreCausticCasterRenderTechnique::causticCubeMapRunChanged(RenderingRun* run)
 {
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp	(revision 836)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp	(revision 949)
@@ -54,5 +54,5 @@
 
 		newpass->setSceneBlending(SBT_MODULATE);
-		
+		newpass->setDepthBias(5);
 		techn->movePass(lastpass, index);			
 	}
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticRecieverRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticRecieverRenderTechnique.cpp	(revision 836)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticRecieverRenderTechnique.cpp	(revision 949)
@@ -58,4 +58,5 @@
 
 		newpass->setSceneBlending(SBF_DEST_COLOUR, SBF_ONE);
+		newpass->setDepthBias(5);
 		//newpass->setSceneBlending(SBT_ADD);
 		
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreSharedRuns.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreSharedRuns.cpp	(revision 790)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreSharedRuns.cpp	(revision 949)
@@ -36,5 +36,8 @@
 		sharedRuns[runType]->update(frameNum);
 	*/
-	getRun(runType)->update(frameNum);
+	RenderingRun* run = getRun(runType);
+	
+	if(run->update(frameNum))
+		runUpdated(runType, run);
 }
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp	(revision 874)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp	(revision 949)
@@ -158,4 +158,60 @@
 }
 
+void OgreIlluminationManager::initTechniques(Entity* e)
+{
+	OgreSharedRuns* sharedruns = 0;
+	
+	for(unsigned int s = 0; s < e->getNumSubEntities(); s++)
+	{
+		SubEntity* sube = e->getSubEntity(s);
+
+		Material* mat = sube->getMaterial().getPointer();
+		
+		OgreRenderable* rend = 0;	
+		OgreTechniqueGroup* group = 0;
+	
+		for(unsigned int t = 0 ; t < mat->getNumTechniques() ; t++)
+		{
+			Technique* tech = mat->getTechnique(t);
+
+			for(unsigned int p = 0; p< tech->getNumPasses(); p++)
+			{
+				Pass* pass = tech->getPass(p);
+
+				std::vector<IllumTechniqueParams*>& techniques = pass->getIllumTechniques();
+				std::vector<IllumTechniqueParams*>::iterator i = techniques.begin(); 
+				std::vector<IllumTechniqueParams*>::iterator iend = techniques.end();
+				
+				while( i != iend)
+				{
+					IllumTechniqueParams* params = *i;
+					
+					if(rend == 0)
+					{
+						rend = new OgreRenderable(e, s);
+						group = new OgreTechniqueGroup();
+						sube->setRenderTechniqueGroup(group);							
+						
+						if( sharedruns == 0)
+						{									
+							sharedruns  = new OgreSharedRuns();
+							addSharedRuns(sharedruns);
+						}
+
+						group->addSharedRun(sharedruns);
+						sharedruns->addRenderable(rend);
+						sharedruns->updateBounds();
+					}
+					
+					createTechnique(params, pass, rend, sharedruns); 
+
+					i++;
+				}
+			}
+		}
+	}
+
+		
+}
 
 void OgreIlluminationManager::initTechniques()
@@ -170,5 +226,5 @@
 			Entity* e = (Entity*) o;
 
-			OgreSharedRuns* sharedruns = 0;
+		/*	OgreSharedRuns* sharedruns = 0;
 			
 			for(unsigned int s = 0; s < e->getNumSubEntities(); s++)
@@ -222,4 +278,6 @@
 			}
 
+		*/
+			initTechniques(e);
 		}
 	}
Index: GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/CausticCasterRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/CausticCasterRenderTechnique.h	(revision 780)
+++ GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/CausticCasterRenderTechnique.h	(revision 949)
@@ -36,5 +36,6 @@
 	//inherited
 	void runChanged(RenderingRunType runType, RenderingRun* run);
-
+	//inherited
+	virtual void runUpdated(RenderingRunType runType, RenderingRun* run);
 	
 protected:
@@ -84,4 +85,10 @@
 	virtual void distanceCubeMapRunChanged(RenderingRun* run) = 0;
 	/**
+			@brief Called if the updated run is a DistanceCubeMapRenderingRun.
+
+			@param run pointer to the updated DistanceCubeMapRenderingRun
+	*/	
+	virtual void distanceCubeMapRunUpdated(RenderingRun* run) = 0;
+	/**
 			@brief Creates a PhotonMapRenderingRun.
 
Index: GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRun.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRun.h	(revision 874)
+++ GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRun.h	(revision 949)
@@ -27,11 +27,13 @@
 		@brief Calls updateFrame() if the run needs update according to its starting frame and update interval and has not been allready updated in this frame.			
 	*/
-	void update(unsigned long frameNum)
+	bool update(unsigned long frameNum)
 	{
-		if(needUpdate(frameNum))
+		bool needupdate = needUpdate(frameNum);
+		if(needupdate)
 		{
 			updateFrame(frameNum);
 			lastupdated = frameNum;			
 		}
+		return needupdate;
 	}
 	
Index: GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/CausticCasterRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/CausticCasterRenderTechnique.cpp	(revision 780)
+++ GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/CausticCasterRenderTechnique.cpp	(revision 949)
@@ -33,5 +33,10 @@
 		distanceCubeMapRunChanged(run);	
 }
- 
+
+void CausticCasterRenderTechnique::runUpdated(RenderingRunType runType, RenderingRun* run)
+{
+	if(runType == ILLUMRUN_DISTANCE_CUBEMAP)
+		distanceCubeMapRunUpdated(run);
+}
 
 
