Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.cpp	(revision 2355)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.cpp	(revision 2366)
@@ -18,4 +18,6 @@
 												SceneBlendFactor passBlendingSRC,
 												SceneBlendFactor passBlendingDEST,
+												bool createNewPasses,
+												int startTextureUnitID,							
 												Pass* pass,
 												OgreRenderable* parentRenderable,
@@ -38,36 +40,40 @@
 	this->WorldParamName = WorldParamName;
 	this->WorldViewProjParamName = WorldViewProjParamName;
+	this->createNewPasses = createNewPasses;
+	this->startTextureUnitID = startTextureUnitID;
+							
+	if(createNewPasses)
+	{
+		//insert new passes
+		Ogre::Technique* techn = pass->getParent();
+		Technique::PassIterator it = techn->getPassIterator();
 		
-	//insert new passes
-	Ogre::Technique* techn = pass->getParent();
-	Technique::PassIterator it = techn->getPassIterator();
-	
-	int index = 0;
-	while(it.hasMoreElements())
-	{
-		if( it.getNext() == pass)
-			break;
+		int index = 0;
+		while(it.hasMoreElements())
+		{
+			if( it.getNext() == pass)
+				break;
+			index++;
+			it.moveNext();
+		}
+		
 		index++;
-		it.moveNext();
-	}
-	
-	index++;
-	for(int i = 0; i < maxlights; i++)
-	{
-		int lastpass = techn->getNumPasses();
-		Pass* newpass = techn->createPass();
-		passes.push_back(newpass);
-		
-		TextureUnitState* st = newpass->createTextureUnitState();		
-		st->setTextureFiltering(TFO_NONE);
-		st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
-		st->setTextureBorderColour(ColourValue::White);
-
-		newpass->setSceneBlending(passBlendingSRC, passBlendingDEST);
-		
-		newpass->setDepthBias(1);
-		techn->movePass(lastpass, index);			
-	}
-	
+		for(int i = 0; i < maxlights; i++)
+		{
+			int lastpass = techn->getNumPasses();
+			Pass* newpass = techn->createPass();
+			passes.push_back(newpass);
+			
+			TextureUnitState* st = newpass->createTextureUnitState();		
+			st->setTextureFiltering(TFO_NONE);
+			st->setTextureAddressingMode(TextureUnitState::TAM_BORDER);
+			st->setTextureBorderColour(ColourValue::White);
+
+			newpass->setSceneBlending(passBlendingSRC, passBlendingDEST);
+			
+			newpass->setDepthBias(1);
+			techn->movePass(lastpass, index);			
+		}
+	}	
 }
 
@@ -87,5 +93,5 @@
 	//fill passes
 	unsigned int l = 0;
-	for(unsigned int i = 0; i < passes.size(); i++)
+	for(unsigned int i = 0; i < maxlights; i++)
 	{
 		while(lights.size() != l && !lights.at(l)->getCastShadows())
@@ -108,33 +114,67 @@
 														.getPerLightRun(lights.at(l)->getName(), 
 														ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun();
-						
-				passes.at(i)->getTextureUnitState(0)->setTextureName(
+				
+				Pass* passToSet = this->pass;
+				int textureUnit = startTextureUnitID + i;
+				if(createNewPasses)
+				{
+					passToSet = passes.at(i);
+					passToSet->setActive(true);
+					textureUnit = 0;
+					passes.at(i)->setActive(true);
+				}
+				passToSet->getTextureUnitState(textureUnit)->setTextureName(
 					depthRun->getDepthMapTextureName());
 			
-				//TODO: ask programs from illummanager
-				passes.at(i)->setVertexProgram(shadowVertexProgram);
-				passes.at(i)->setFragmentProgram(shadowFragmentProgram);
+				if(createNewPasses)
+				{
+					//TODO: ask programs from illummanager
+					passes.at(i)->setVertexProgram(shadowVertexProgram);
+					passes.at(i)->setFragmentProgram(shadowFragmentProgram);
+				}
 		
-				GpuProgramParametersSharedPtr fpParams = passes.at(i)->getFragmentProgramParameters();
-				GpuProgramParametersSharedPtr vpParams = passes.at(i)->getVertexProgramParameters();
-
-		
-				vpParams->setNamedAutoConstant(WorldViewProjParamName,
-									GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);	
-				vpParams->setNamedAutoConstant(WorldParamName,
-									GpuProgramParameters::ACT_WORLD_MATRIX);
+				GpuProgramParametersSharedPtr fpParams = passToSet->getFragmentProgramParameters();
+				GpuProgramParametersSharedPtr vpParams = passToSet->getVertexProgramParameters();
+
+				String LightViewProjParamName = lightViewProjParamName;
+				String LightViewParamName = lightViewParamName;
+				String LightFarPlaneParamName = lightFarPlaneParamName;
+				if(!createNewPasses)
+				{
+					LightViewProjParamName += String("[") + StringConverter::toString(i) + String("]");
+					LightViewParamName += String("[") + StringConverter::toString(i) + String("]");
+					LightFarPlaneParamName += String("[") + StringConverter::toString(i) + String("]");
+				}
+				else
+				{
+					vpParams->setNamedAutoConstant(WorldViewProjParamName,
+										GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);	
+					vpParams->setNamedAutoConstant(WorldParamName,
+										GpuProgramParameters::ACT_WORLD_MATRIX);
+				}
 		
 				if(setLightViewProjMatrix)
-					vpParams->setNamedConstant(lightViewProjParamName, depthRun->getLightViewProjMatrix());
+				{
+					if(createNewPasses)
+					vpParams->setNamedConstant(LightViewProjParamName, depthRun->getLightViewProjMatrix());
+					else
+					fpParams->setNamedConstant(LightViewProjParamName, depthRun->getLightViewProjMatrix());
+				}
 				if(setLightViewMatrix)
-					vpParams->setNamedConstant(lightViewParamName, depthRun->getLightViewMatrix());
+				{
+					if(createNewPasses)
+					vpParams->setNamedConstant(LightViewParamName, depthRun->getLightViewMatrix());
+					else
+					fpParams->setNamedConstant(LightViewParamName, depthRun->getLightViewMatrix());
+				}
 				if(setLightProjFarPlane)
-					fpParams->setNamedConstant(lightFarPlaneParamName, depthRun->getLightFarPlane());
-				
-				
-				passes.at(i)->setActive(true);
-			
+				{
+					if(createNewPasses)
+					fpParams->setNamedConstant(LightFarPlaneParamName, depthRun->getLightFarPlane());
+					else
+					fpParams->setNamedConstant(LightFarPlaneParamName, depthRun->getLightFarPlane());
+				}
 		}	
-		else
+		else if(createNewPasses)
 			passes.at(i)->setActive(false);
 
@@ -282,5 +322,17 @@
 		  f->passBlendingDEST = convertBlendFactor(vecparams[1]) ;
 		}		
-	}	
+	}
+
+	void parseCreateNewPasses(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreDepthShadowReceiverRenderTechniqueFactory* f = (OgreDepthShadowReceiverRenderTechniqueFactory*) factory;
+		f->createNewPasses =  StringConverter::parseBool(params);
+	}
+	
+	void parseStartTexID(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreDepthShadowReceiverRenderTechniqueFactory* f = (OgreDepthShadowReceiverRenderTechniqueFactory*) factory;
+		f->startTextureUnitID =  StringConverter::parseInt(params);
+	}
 }
 
@@ -303,4 +355,6 @@
 	this->attributeParsers.insert(AttribParserList::value_type("light_farplane_param_name", (ILLUM_ATTRIBUTE_PARSER) parseLightFarPlaneParamName));
 	this->attributeParsers.insert(AttribParserList::value_type("pass_blending", (ILLUM_ATTRIBUTE_PARSER) parsePassBlending));
+	this->attributeParsers.insert(AttribParserList::value_type("new_passes", (ILLUM_ATTRIBUTE_PARSER) parseCreateNewPasses));
+	this->attributeParsers.insert(AttribParserList::value_type("start_tex_id", (ILLUM_ATTRIBUTE_PARSER) parseStartTexID));	
 }
 
@@ -325,5 +379,7 @@
 	passBlendingSRC = SBF_DEST_COLOUR;
 	passBlendingDEST = SBF_ZERO;
-
+	createNewPasses = true;
+	startTextureUnitID = 0;
+	
 	parseParams(params);
 
@@ -342,4 +398,6 @@
 												passBlendingSRC,
 												passBlendingDEST,
+												createNewPasses,
+												startTextureUnitID,
 												pass,
 												parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticReceiverRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticReceiverRenderTechnique.cpp	(revision 2299)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticReceiverRenderTechnique.cpp	(revision 2366)
@@ -11,4 +11,8 @@
 												SceneBlendFactor passBlendingSRC,
 												SceneBlendFactor passBlendingDEST,
+												bool createNewPasses,
+												int startTextureUnitID,
+												String casterCenterVariableName,
+												String attenuationVariableName,
 												Pass* pass,
 												OgreRenderable* parentRenderable,
@@ -23,46 +27,53 @@
 	this->causticVertexProgram = causticVertexProgram;
 	this->causticFragmentProgram = causticFragmentProgram;
-	
-	//insert new passes
-	Ogre::Technique* techn = pass->getParent();
-	Technique::PassIterator it = techn->getPassIterator();
-	
-	int index = 0;
-	while(it.hasMoreElements())
-	{
-		if( it.getNext() == pass)
-			break;
+	this->createNewPasses = createNewPasses;
+	this->startTextureUnitID = startTextureUnitID;
+	this->casterCenterVariableName = casterCenterVariableName;
+	this->attenuationVariableName = attenuationVariableName;
+	
+	if(createNewPasses)
+	{
+		//insert new passes
+		Ogre::Technique* techn = pass->getParent();
+		Technique::PassIterator it = techn->getPassIterator();
+		
+		int index = 0;
+		while(it.hasMoreElements())
+		{
+			if( it.getNext() == pass)
+				break;
+			index++;
+			it.moveNext();
+		}
+		
 		index++;
-		it.moveNext();
-	}
-	
-	index++;
-	for(int i = 0; i < maxcasters; i++)
-	{
-		int lastpass = techn->getNumPasses();
-		Pass* newpass = techn->createPass();
-		passes.push_back(newpass);
-
-		newpass->setVertexProgram(causticVertexProgram);
-		newpass->setFragmentProgram(causticFragmentProgram);
-		
-		GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer();
-		Vparams->setNamedAutoConstant("WorldViewProj",
-									GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
-		Vparams->setNamedAutoConstant("World",
-									GpuProgramParameters::ACT_WORLD_MATRIX);
-		GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer();
-		//Fparams->setNamedConstant("cubeMapCameraPosition", Vector3(0,0,0));
-
-		TextureUnitState* st = newpass->createTextureUnitState();
-		TextureUnitState* st2 = newpass->createTextureUnitState();
-
-		st->setTextureFiltering(TFO_BILINEAR);
-		st2->setTextureFiltering(TFO_BILINEAR);
-
-		newpass->setSceneBlending(passBlendingSRC, passBlendingDEST);
-		newpass->setDepthBias(1);		
-		
-		techn->movePass(lastpass, index);			
+		for(int i = 0; i < maxcasters; i++)
+		{
+			int lastpass = techn->getNumPasses();
+			Pass* newpass = techn->createPass();
+			passes.push_back(newpass);
+
+			newpass->setVertexProgram(causticVertexProgram);
+			newpass->setFragmentProgram(causticFragmentProgram);
+			
+			GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer();
+			Vparams->setNamedAutoConstant("WorldViewProj",
+										GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
+			Vparams->setNamedAutoConstant("World",
+										GpuProgramParameters::ACT_WORLD_MATRIX);
+			GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer();
+			//Fparams->setNamedConstant("cubeMapCameraPosition", Vector3(0,0,0));
+
+			TextureUnitState* st = newpass->createTextureUnitState();
+			TextureUnitState* st2 = newpass->createTextureUnitState();
+
+			st->setTextureFiltering(TFO_BILINEAR);
+			st2->setTextureFiltering(TFO_BILINEAR);
+
+			newpass->setSceneBlending(passBlendingSRC, passBlendingDEST);
+			newpass->setDepthBias(1);		
+			
+			techn->movePass(lastpass, index);			
+		}
 	}
 	
@@ -82,10 +93,10 @@
 				&causticCasters,
 				maxcasters);
+	
 	//fill passes
-	for(unsigned int i = 0; i < passes.size(); i++)
+	for(unsigned int i = 0; i < maxcasters; i++)
 	{
 		if(causticCasters.size() > i)
 		{
-			
 			//update caustic caster
 			causticCasters.at(i)->updateRun(ILLUMRUN_PHOTONMAP, frameNum);	
@@ -96,23 +107,33 @@
 				(OgreCausticCubeMapRenderingRun*) causticCasters.at(i)->
 					getRun(ILLUMRUN_CAUSTIC_CUBEMAP)->asOgreRenderingRun();
-			passes.at(i)->getTextureUnitState(0)->setTextureName(
+			
+			Pass* passToSet = this->pass;
+			int textureUnit = startTextureUnitID + i;
+			if(createNewPasses)
+			{
+				passToSet = passes.at(i);
+				passToSet->setActive(true);
+				textureUnit = 0;
+			}
+			
+			passToSet->getTextureUnitState(textureUnit)->setTextureName(
 				cauCubeRun->getCausticCubeMapTextureName());
-
-			OgreCubeMapRenderingRun* distCubeRun = 
-				(OgreCubeMapRenderingRun*) causticCasters.at(i)->
-					getRun(ILLUMRUN_DISTANCE_CUBEMAP)->asOgreRenderingRun();
-			passes.at(i)->getTextureUnitState(1)->setTextureName(
-				distCubeRun->getCubeMapTextureName());
-			
-			//set caster position
-			GpuProgramParameters* Fparams = passes.at(i)->getFragmentProgramParameters().getPointer();
-			Fparams->setNamedConstant("cubeMapCameraPosition",
-				causticCasters.at(i)->getRootPosition(ILLUMRUN_CAUSTIC_CUBEMAP));
-			Fparams->setNamedConstant("attenuation", cauCubeRun->getAttenuation());
-			passes.at(i)->setActive(true);
+	
+			//set caster position nad caustic attenuation
+			GpuProgramParameters* Fparams = passToSet->getFragmentProgramParameters().getPointer();
+			String centerVarName = casterCenterVariableName;
+			String attenuationVarName = attenuationVariableName;
+			if(!createNewPasses)
+			{
+				centerVarName += String("[") + StringConverter::toString(i) + String("]");
+				attenuationVarName += String("[") + StringConverter::toString(i) + String("]");
+			}
+			Fparams->setNamedConstant(centerVarName,
+										causticCasters.at(i)->getRootPosition(ILLUMRUN_CAUSTIC_CUBEMAP));
+			Fparams->setNamedConstant(attenuationVarName,
+										cauCubeRun->getAttenuation());			
 		}	
-		else
+		else if(createNewPasses)
 			passes.at(i)->setActive(false);
-
 	}
 }
@@ -201,6 +222,31 @@
 		  f->passBlendingDEST = convertBlendFactor(vecparams[1]) ;
 		}		
-	}	
-}
+	}
+
+	void parseCreateNewPasses(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory;
+		f->createNewPasses =  StringConverter::parseBool(params);
+	}
+	
+	void parseStartTexID(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory;
+		f->startTextureUnitID =  StringConverter::parseInt(params);
+	}
+	
+	void parseCenterVarName(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory;
+		f->casterCenterVariableName =  params;
+	}
+
+	void parseAttenuationVarName(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory;
+		f->attenuationVariableName =  params;
+	}
+}
+
 OgreCausticReceiverRenderTechniqueFactory::OgreCausticReceiverRenderTechniqueFactory()
 {
@@ -213,5 +259,8 @@
 	this->attributeParsers.insert(AttribParserList::value_type("fragment_program_name", (ILLUM_ATTRIBUTE_PARSER) parseFragmentProgram));
 	this->attributeParsers.insert(AttribParserList::value_type("pass_blending", (ILLUM_ATTRIBUTE_PARSER) parsePassBlending));
-	
+	this->attributeParsers.insert(AttribParserList::value_type("new_passes", (ILLUM_ATTRIBUTE_PARSER) parseCreateNewPasses));
+	this->attributeParsers.insert(AttribParserList::value_type("start_tex_id", (ILLUM_ATTRIBUTE_PARSER) parseStartTexID));
+	this->attributeParsers.insert(AttribParserList::value_type("center_var_name", (ILLUM_ATTRIBUTE_PARSER) parseCenterVarName));
+	this->attributeParsers.insert(AttribParserList::value_type("attenuation_var_name", (ILLUM_ATTRIBUTE_PARSER) parseAttenuationVarName));	
 }
 
@@ -228,4 +277,8 @@
 	passBlendingSRC = SBF_DEST_COLOUR;
 	passBlendingDEST = SBF_ONE;
+	createNewPasses = true;
+	startTextureUnitID = 0;
+	casterCenterVariableName = "cubeMapCameraPosition";
+	String attenuationVariableName = "attenuation";
 
 	parseParams(params);
@@ -237,4 +290,8 @@
 												passBlendingSRC,
 												passBlendingDEST,
+												createNewPasses,
+												startTextureUnitID,
+												casterCenterVariableName,
+												attenuationVariableName,
 												pass,
 												parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp	(revision 2333)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp	(revision 2366)
@@ -9,4 +9,6 @@
 												SceneBlendFactor passBlendingSRC,
 												SceneBlendFactor passBlendingDEST,
+												bool createNewPasses,
+												int startTextureUnitID,
 												Pass* pass,
 												OgreRenderable* parentRenderable,
@@ -17,30 +19,38 @@
 	this->passBlendingSRC = passBlendingSRC;
 	this->passBlendingDEST = passBlendingDEST;
+	this->createNewPasses = createNewPasses;
+	this->startTextureUnitID = startTextureUnitID;
 
 	this->clusters = OgreIlluminationManager::getSingleton().getPathMapClusters(parentRenderable->getName());
 	
+	Pass* passToSet = pass;
+
 	//insert new pass
-	Ogre::Technique* techn = pass->getParent();
-	Technique::PassIterator it = techn->getPassIterator();
-	
-	int index = 0;
-	while(it.hasMoreElements())
-	{
-		if( it.getNext() == pass)
-			break;
-		index++;
-		it.moveNext();
-	}
-	
-	Pass* newpass = pathMapPass = techn->createPass();
-	
-	newpass->setVertexProgram("GTP/PathMap_VS");
-	newpass->setFragmentProgram("GTP/PathMap_PS");
-	
-	//bind vertex program parameters
-	GpuProgramParameters* Vparams = newpass->getVertexProgramParameters().getPointer();
-	Vparams->setNamedAutoConstant("WorldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);	
+	if(createNewPasses)
+	{
+		Ogre::Technique* techn = pass->getParent();
+		Technique::PassIterator it = techn->getPassIterator();
+		
+		int index = 0;
+		while(it.hasMoreElements())
+		{
+			if( it.getNext() == pass)
+				break;
+			index++;
+			it.moveNext();
+		}
+		
+		Pass* newpass = pathMapPass = passToSet = techn->createPass();
+		
+		newpass->setVertexProgram("GTP/PathMap_VS");
+		newpass->setFragmentProgram("GTP/PathMap_PS");
+
+		GpuProgramParameters* Vparams = passToSet->getVertexProgramParameters().getPointer();
+		Vparams->setNamedAutoConstant("WorldViewProj", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
+	}
+
 	//bind fragment program parameters
-	GpuProgramParameters* Fparams = newpass->getFragmentProgramParameters().getPointer();
+	GpuProgramParameters* Fparams = passToSet->getFragmentProgramParameters().getPointer();
+	
 	int prmxres = clusters->pathMapResolution * clusters->count;
 	int prmyres = clusters->pathMapResolution;
@@ -55,5 +65,5 @@
 	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);
@@ -61,31 +71,44 @@
 	Fparams->setNamedConstant("clusterCount", (float) clusters->count);
 	
-	TextureUnitState* st = newpass->createTextureUnitState();		
-	st->setTextureFiltering(TFO_BILINEAR);
-	st->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
-	st->setTextureBorderColour(ColourValue::Green);
-	st->setTextureName(clusters->pathMapTextureFilename);
-
+	TextureUnitState* st1;//path map texture
+	TextureUnitState* st2;//weight index texture
+	TextureUnitState* st3;//weight texture
+			
 	createWeightIndexTexture();
 	
-	st = newpass->createTextureUnitState();		
-	st->setTextureFiltering(TFO_NONE);
-	st->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
-	st->setTextureBorderColour(ColourValue::Red);
-	st->setTextureName(weightIndexTexture->getName());
-
-	st = newpass->createTextureUnitState();		
-	st->setTextureFiltering(TFO_NONE);
-	st->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
-	st->setTextureBorderColour(ColourValue::Blue);
-
-	st = newpass->createTextureUnitState();		
-	st->setTextureFiltering(TFO_BILINEAR);
-	st->setTextureAddressingMode(TextureUnitState::TAM_WRAP);
-	st->setTextureBorderColour(ColourValue::Blue);
-	st->setTextureName(pass->getTextureUnitState(0)->getTextureName());
-	
-	newpass->setSceneBlending(passBlendingSRC, passBlendingDEST);
-	newpass->setDepthBias(1);
+	if(createNewPasses)
+	{
+		st1 = passToSet->createTextureUnitState();		
+		st1->setTextureFiltering(TFO_BILINEAR);
+		st1->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
+		st1->setTextureBorderColour(ColourValue::Green);
+
+		st2 = passToSet->createTextureUnitState();		
+		st2->setTextureFiltering(TFO_NONE);
+		st2->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
+		st2->setTextureBorderColour(ColourValue::Red);
+
+		st3 = passToSet->createTextureUnitState();		
+		st3->setTextureFiltering(TFO_NONE);
+		st3->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
+		st3->setTextureBorderColour(ColourValue::Blue);
+
+		TextureUnitState* st4 = passToSet->createTextureUnitState();		
+		st4->setTextureFiltering(TFO_BILINEAR);
+		st4->setTextureAddressingMode(TextureUnitState::TAM_WRAP);
+		st4->setTextureBorderColour(ColourValue::Blue);
+		st4->setTextureName(pass->getTextureUnitState(0)->getTextureName());
+
+		passToSet->setSceneBlending(passBlendingSRC, passBlendingDEST);
+		passToSet->setDepthBias(1);
+	}
+	else
+	{
+		st1 = pass->getTextureUnitState(startTextureUnitID);
+		st2 = pass->getTextureUnitState(startTextureUnitID + 1);
+		st3 = pass->getTextureUnitState(startTextureUnitID + 2);
+	}
+	st1->setTextureName(clusters->pathMapTextureFilename);		
+	st2->setTextureName(weightIndexTexture->getName());				
 }
 
@@ -131,5 +154,13 @@
 	}
 	OgrePMWeightComputeRenderingRun::sumWeights(frameNum);
-	TextureUnitState* st = pathMapPass->getTextureUnitState(2);
+
+	Pass* passToSet = pass;
+	int textureUnitID = startTextureUnitID + 2;
+	if(createNewPasses)
+	{
+		passToSet = pathMapPass;
+		textureUnitID = 2;
+	}
+	TextureUnitState* st = passToSet->getTextureUnitState(textureUnitID);
 	st->setTextureName(OgrePMWeightComputeRenderingRun::getPMWeightTextureName());
 }
@@ -200,5 +231,17 @@
 		  f->passBlendingDEST = convertBlendFactor(vecparams[1]) ;
 		}		
-	}	
+	}
+
+	void parseCreateNewPasses(String& params, RenderTechniqueFactory* factory)
+	{
+		OgrePathMapRenderTechniqueFactory* f = (OgrePathMapRenderTechniqueFactory*) factory;
+		f->createNewPasses =  StringConverter::parseBool(params);
+	}
+	
+	void parseStartTexID(String& params, RenderTechniqueFactory* factory)
+	{
+		OgrePathMapRenderTechniqueFactory* f = (OgrePathMapRenderTechniqueFactory*) factory;
+		f->startTextureUnitID =  StringConverter::parseInt(params);
+	}
 }
 
@@ -208,4 +251,6 @@
 	using namespace PathMapParsers;
 	this->attributeParsers.insert(AttribParserList::value_type("pass_blending", (ILLUM_ATTRIBUTE_PARSER) parsePassBlending));
+	this->attributeParsers.insert(AttribParserList::value_type("new_passes", (ILLUM_ATTRIBUTE_PARSER) parseCreateNewPasses));
+	this->attributeParsers.insert(AttribParserList::value_type("start_tex_id", (ILLUM_ATTRIBUTE_PARSER) parseStartTexID));	
 }
 
@@ -218,4 +263,6 @@
 	passBlendingSRC = SBF_ONE;
 	passBlendingDEST = SBF_ONE;
+	createNewPasses = true;
+	startTextureUnitID = 0;
 
 	parseParams(params);
@@ -224,4 +271,6 @@
 												passBlendingSRC,
 												passBlendingDEST,
+												createNewPasses,
+												startTextureUnitID,
 												pass,
 												parentRenderable,
