Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h	(revision 2189)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h	(revision 2200)
@@ -34,4 +34,5 @@
     Vector3 position;
 	Vector3 normal;
+	float prob;
 };
 /**
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePMWeightComputeRenderingRun.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePMWeightComputeRenderingRun.h	(revision 2189)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePMWeightComputeRenderingRun.h	(revision 2200)
@@ -28,5 +28,5 @@
 		@brief returns the name of the camera depth texture
 	*/
-	String getPMWeightTetureName(){return name;}
+	String getPMWeightTetureName(){return weightTexture->getName();}
 	float* getWeights(){return weights;}
 	
@@ -45,4 +45,5 @@
 	*/
 	Texture* weightTexture;
+	Texture* allWeightsTexture;
 	
 	Light* light;
@@ -54,9 +55,3 @@
 	
 	inline void createWeightMap();
-
-	bool needUpdate(unsigned long frameNum )
-	{
-		return true;
-	}
-
 };
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePMEntryPointMapRenderingRun.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePMEntryPointMapRenderingRun.h	(revision 2189)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePMEntryPointMapRenderingRun.h	(revision 2200)
@@ -29,4 +29,5 @@
 	*/
 	String getEntryPointTextureName(){return name;}
+	String getClusterLengthTextureName(){return clusterLengthTexture->getName();}
 	
 protected:
@@ -39,4 +40,5 @@
 	*/
 	Texture* entryPointTexture;
+	Texture* clusterLengthTexture;
 	
 	//inherited
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgrePathMapRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgrePathMapRenderTechnique.h	(revision 2189)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgrePathMapRenderTechnique.h	(revision 2200)
@@ -57,4 +57,7 @@
 	Pass* pathMapPass;
 	PathMapClusters* clusters;	
+	Texture* weightIndexTexture;
+
+	void createWeightIndexTexture();
 };
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMWeightComputeRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMWeightComputeRenderingRun.cpp	(revision 2189)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMWeightComputeRenderingRun.cpp	(revision 2200)
@@ -22,5 +22,5 @@
 	int width = entryPointCnt / 4096;
 	int height = 4096;
-	TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name, 
+	TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL", 
 																		"default",
 																		TEX_TYPE_2D,
@@ -29,12 +29,33 @@
 																		0,
 																		0,
-																		PF_FLOAT32_R,
+																		PF_FLOAT32_RGBA,
 																		TU_RENDERTARGET);
+	 allWeightsTexture = texPtr.getPointer();
+	 //add viewport to rendertarget
+	 HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer();
+	 RenderTarget* rt = hpb->getRenderTarget();
+	 Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA"); 
+	 Viewport* v = rt->addViewport(wc);
+	 v->setOverlaysEnabled(false);
+	 rt->setAutoUpdated(false);
+
+	unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
+	width = clustercount;
+	height = 1;
+	texPtr = Ogre::TextureManager::getSingleton().createManual(name, 
+																"default",
+																TEX_TYPE_2D,
+																width,
+																height,
+																0,
+																0,
+																PF_FLOAT32_RGBA,
+																TU_RENDERTARGET);
 	 weightTexture = texPtr.getPointer();
 	 //add viewport to rendertarget
-	 HardwarePixelBuffer* hpb = (weightTexture->getBuffer()).getPointer();
-	 RenderTarget* rt = hpb->getRenderTarget();
-	 Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA"); 
-	 Viewport* v = rt->addViewport(wc);
+	 hpb = (weightTexture->getBuffer()).getPointer();
+	 rt = hpb->getRenderTarget();
+	 wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA"); 
+	 v = rt->addViewport(wc);
 	 v->setOverlaysEnabled(false);
 	 rt->setAutoUpdated(false);
@@ -45,64 +66,57 @@
 void OgrePMWeightComputeRenderingRun::updateFrame(unsigned long frameNum)
 {
-	switch(light->getType())
+	OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP, frameNum);
+	OgrePMEntryPointMapRenderingRun* PMEPrun = (OgrePMEntryPointMapRenderingRun*)
+		OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP)->asOgreRenderingRun();
+	unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
+	int col = entryPointCnt / 4096; 
+		
+	if(light->getType() == Light::LT_SPOTLIGHT)
 	{
-		case Light::LT_SPOTLIGHT:
+		MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights");
 
-			MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights");
-
-			GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
+		GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
 			
 			Vector3 lightPos = light->getPosition();
 			Vector3 lightDir = light->getDirection();
 		//	Radian lightAngle = light->getSpotlightOuterAngle();
-			unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
-			int col = entryPointCnt / 4096; 
-
+			
 			//Fparams->setNamedConstant("lightTransform", lightMatrix);
 			Fparams->setNamedConstant("nRadionColumns", col);
 			Fparams->setNamedConstant("lightPos", lightPos);
 			Fparams->setNamedConstant("lightDir", lightDir);
-
-			OgrePMEntryPointMapRenderingRun* PMEPrun = (OgrePMEntryPointMapRenderingRun*)
-					OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP)->asOgreRenderingRun();
+			
 			mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
 						PMEPrun->getEntryPointTextureName());
 				
-			RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
+			RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget();
 			renderFullscreenQuad(mat->getName(), rt);
 
-			//rt->writeContentsToFile("focusingmap.dds");
-		
-		
-			break;		
+			rt->writeContentsToFile("allweights.bmp");			
+			rt->writeContentsToFile("allweights.dds");
+	}
+	else
+	{
+		///not implemented
 	}
 
 	unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
-	if(weights == 0)
-		weights = new float[clustercount];
+
+	MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_SumWeights");
+	GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
+	Fparams->setNamedConstant("nRadionColumns", col);
+	Fparams->setNamedConstant("clusterCount", (float) clustercount);
+	mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
+						PMEPrun->getEntryPointTextureName());
+	mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
+						PMEPrun->getClusterLengthTextureName());
+	mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName(
+						allWeightsTexture->getName());
 	
-	unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
-	int width = entryPointCnt / 4096;
-	int height = 4096;
-	unsigned int buffersize = width * height;
-	float* allEntryWeights = new float[buffersize];
-	PixelBox lockBox(width, height, 1, PF_FLOAT32_R, allEntryWeights);
-	weightTexture->getBuffer()->blitToMemory(lockBox);	
+	RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
+	renderFullscreenQuad(mat->getName(), rt);
 
-	int iRadion = 0;
-	for(int iCluster=0; iCluster < clustercount; iCluster++)
-	{
-		weights[iCluster] = 0.0;
-		for(int clusterSummer=0;
-			clusterSummer < OgreIlluminationManager::getSingleton().getPathMapClusterLength(iCluster);
-			clusterSummer++, iRadion++)
-		{
-			weights[iCluster] += allEntryWeights[iRadion];			
-		}
-		if(weights[iCluster] <= 0)
-			weights[iCluster] /= OgreIlluminationManager::getSingleton().getPathMapClusterLength(iCluster); //(double)clusterLenghts[iCluster];
-		else
-			weights[iCluster] = 0.0f;		
-	}
+	rt->writeContentsToFile("weights.bmp");	
+	rt->writeContentsToFile("weights.dds");	
 }
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMEntryPointMapRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMEntryPointMapRenderingRun.cpp	(revision 2189)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMEntryPointMapRenderingRun.cpp	(revision 2200)
@@ -43,9 +43,40 @@
 		tm[i].dir[1] = EP->normal.y;
 		tm[i].dir[2] = EP->normal.z;
-		tm[i].dir[3] = 1.0;
+		tm[i].dir[3] = EP->prob;
 	}	
 
 	PixelBox lockBox(width, height, 1, PF_FLOAT32_RGBA, tm);
 	entryPointTexture->getBuffer()->blitFromMemory(lockBox);
+
+	delete[] tm;
+
+	int clusterCount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
+	width = clusterCount;
+	height = 2;
+	texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_CL", 
+																		"default",
+																		TEX_TYPE_2D,
+																		width,
+																		height,
+																		0,
+																		0,
+																		PF_FLOAT32_R,
+																		TU_RENDERTARGET);
+	clusterLengthTexture = texPtr.getPointer();
+
+	float* data = new float[clusterCount * 2];
+	unsigned int entryPointCount = 0;
+	for(int i = 0; i < clusterCount; i++)
+	{
+		unsigned int clusterSize = OgreIlluminationManager::getSingleton().getPathMapClusterLength(i);
+		data[i] = clusterSize;//clustercount
+		data[clusterCount + i] = entryPointCount;
+		entryPointCount += clusterSize;
+	}
+
+	PixelBox lockBox2(width, height, 1, PF_FLOAT32_R, data);
+	clusterLengthTexture->getBuffer()->blitFromMemory(lockBox2);
+
+	delete[] data;
 }
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp	(revision 2027)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp	(revision 2200)
@@ -30,5 +30,5 @@
 	this->blurCauCubeMap = blurCauCubeMap;
 	
-	String newMaterialName = causticMapMaterialName + parentRenderable->getName() + "_clone";
+	String newMaterialName = causticMapMaterialName + "_clone_" + parentRenderable->getName();
 	Material* mat = (Material*) MaterialManager::getSingleton().getByName(causticMapMaterialName).getPointer();
 	Material* newMat = mat->clone(newMaterialName).getPointer();
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp	(revision 2189)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp	(revision 2200)
@@ -50,10 +50,27 @@
 	Vector4 pathMapParameters(prmnt[0],prmnt[1],halfPixel[0],halfPixel[1]);
 	Fparams->setNamedConstant("prmAtlasTilesHalfPixel",pathMapParameters);
-    		
+    unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
+	Fparams->setNamedConstant("allClusterCount", (float) clustercount);
+	PathMapClusters* clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentOgreRenderable->getName());
+	Fparams->setNamedConstant("clusterCount", (float) clusters->count);
+	
 	TextureUnitState* st = newpass->createTextureUnitState();		
 	st->setTextureFiltering(TFO_BILINEAR);
 	st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
+	st->setTextureBorderColour(ColourValue::Green);
+	st->setTextureName(clusters->pathMapTextureFilename);
+
+	createWeightIndexTexture();
+	
+	st = newpass->createTextureUnitState();		
+	st->setTextureFiltering(TFO_NONE);
+	st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
+	st->setTextureBorderColour(ColourValue::Red);
+	st->setTextureName(weightIndexTexture->getName());
+
+	st = newpass->createTextureUnitState();		
+	st->setTextureFiltering(TFO_NONE);
+	st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
 	st->setTextureBorderColour(ColourValue::Blue);
-	st->setTextureName(clusters->pathMapTextureFilename);
 	
 	//newpass->setSceneBlending(SBT_MODULATE);
@@ -70,4 +87,27 @@
 }
 
+void OgrePathMapRenderTechnique::createWeightIndexTexture()
+{
+	PathMapClusters* clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentOgreRenderable->getName());
+	int width = clusters->count / 4;
+	TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(this->parentOgreRenderable->getName() + "_PMWeightIndexTexture", 
+																		"default",
+																		TEX_TYPE_1D,
+																		width,
+																		1,
+																		0,
+																		0,
+																		PF_FLOAT32_RGBA,
+																		TU_DYNAMIC_WRITE_ONLY);
+	weightIndexTexture = texPtr.getPointer();
+
+	float *weightIndices = new float[clusters->count];
+	PixelBox lockBox(width, 1, 1, PF_FLOAT32_RGBA, weightIndices);
+	for(int j = 0; j< clusters->count; j++)
+			weightIndices[j] = clusters->clusters[j];
+	weightIndexTexture->getBuffer()->blitFromMemory(lockBox);
+	delete[] weightIndices;
+}
+
 void OgrePathMapRenderTechnique::update(unsigned long frameNum)
 {	
@@ -76,6 +116,6 @@
 	sm->_populateLightList(Vector3(0,0,0), 1000, lights); //TODO
 //TODO set weights
-	PathMapClusters* clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentOgreRenderable->getName());
-	float *actualWeights = new float[clusters->count];//TODO = 0
+	
+	
 	for(int i = 0 ; i < 1; i++)
 	{
@@ -86,13 +126,7 @@
 			OgreIlluminationManager::getSingleton().getPerLightRun(lightName, ILLUMRUN_PM_WEIGHTMAP)->asOgreRenderingRun();
 
-		float* weights = PMWeightRun->getWeights();
-		
-		for(int j = 0; j< clusters->count; j++)
-			actualWeights[j] = weights[clusters->clusters[j]];
-				
+		TextureUnitState* st =pathMapPass->getTextureUnitState(2);
+		st->setTextureName(PMWeightRun->getPMWeightTetureName());				
 	}
-
-	GpuProgramParameters* Fparams = pathMapPass->getFragmentProgramParameters().getPointer();
-	Fparams->setNamedConstant("weights", actualWeights, clusters->count);
 }
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp	(revision 2189)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp	(revision 2200)
@@ -224,8 +224,8 @@
 						sharedruns->updateBounds();
 					}
-					String newMaterialName = mat->getName() + rend->getName() + "_clone";
+					String newMaterialName = mat->getName() + "_clone_" + rend->getName();
 					Material* newMat = mat->clone(newMaterialName).getPointer();
-					mat = newMat;
 					rend->setMaterialName(newMaterialName);
+					mat = sube->getMaterial().getPointer();
 					break;
 				}
