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,
