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,
