Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h	(revision 1639)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreIlluminationManager.h	(revision 1670)
@@ -74,4 +74,5 @@
 	bool blurSM;
 	bool focusingSM;
+	String shadowMapMaterialName;
 	unsigned int phaseTextureSize;
 	std::map<RenderingRunType,float> maxRads;
@@ -315,4 +316,5 @@
 	void setFocusingSM(bool use){focusingSM = use;}
 	void setBlurShadowMap(bool use){blurSM = use;}
+	void setShadowMapMaterialName(String name){shadowMapMaterialName = name;}
 };
 
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreDepthShadowMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreDepthShadowMapRenderingRun.h	(revision 1628)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreDepthShadowMapRenderingRun.h	(revision 1670)
@@ -56,4 +56,5 @@
 	*/
 	Matrix4 getLightViewProjMatrix();
+	Real getLightFarPlane(){return lightFarPlane;}
 
 protected:	
@@ -84,4 +85,5 @@
 	Texture* depthMapTexture;
 	Texture* blurredDepthMapTexture;
+	Real lightFarPlane;
 	
 	//inherited
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.h	(revision 836)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.h	(revision 1670)
@@ -47,4 +47,10 @@
 							String shadowVertexProgram,
 							String shadowFragmentProgram,
+							bool setLightViewMatrix,
+							bool setLightViewProjMatrix,
+							bool setLightProjFarPlane,
+							String lightViewProjParamName,
+							String lightViewParamName,
+							String lightFarPlaneParamName,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
@@ -79,5 +85,11 @@
 		@breif new passes created by this technique
 	*/
-	std::vector<Pass*> passes;	
+	std::vector<Pass*> passes;
+	bool setLightViewMatrix;
+	bool setLightViewProjMatrix;
+	bool setLightProjFarPlane;
+	String lightViewProjParamName;
+	String lightViewParamName;
+	String lightFarPlaneParamName;
 };
 
@@ -98,4 +110,10 @@
 	String shadowVertexProgram;
 	String shadowFragmentProgram;
+	bool setLightViewMatrix;
+	bool setLightViewProjMatrix;
+	bool setLightProjFarPlane;
+	String lightViewProjParamName;
+	String lightViewParamName;
+	String lightFarPlaneParamName;
 
 };
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderingRun.cpp	(revision 1647)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderingRun.cpp	(revision 1670)
@@ -1,5 +1,4 @@
 #include "OgreRenderingrun.h"
 #include "OgreIlluminationManager.h"
-#include "OgreTerrainSceneManager.h"
 
 MovablePlane* OgreRenderingRun::fullScreenQuad = NULL;
@@ -163,10 +162,4 @@
 	SceneManager* sm = Ogre::Root::getSingleton()._getCurrentSceneManager();
 	
-	if(sm->getTypeName() == "TerrainSceneManager")
-	{
-		terrainMaterial = ((TerrainSceneManager*)sm)->getTerrainMaterial()->getName();
-		((TerrainSceneManager*)sm)->setCustomMaterial(materialName);
-	}
-
 	RenderQueue* rq = sm->getRenderQueue();
 	rq->clear();
@@ -187,8 +180,5 @@
 {
 	SceneManager* sm = Ogre::Root::getSingleton()._getCurrentSceneManager();
-	if(sm->getTypeName()== "TerrainSceneManager")
-		((TerrainSceneManager*)sm)->setCustomMaterial(terrainMaterial);
-	
-
+	
 	std::map<Renderable*, String>::iterator it = visibleObjects.begin();
 	std::map<Renderable*, String>::iterator itend = visibleObjects.end();
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp	(revision 1639)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp	(revision 1670)
@@ -20,5 +20,5 @@
 	
 	this->materialName = materialName;
-
+	lightFarPlane = 0;
 	createDepthMap();	
 }
@@ -320,5 +320,7 @@
 			if(!usefocusing)
 			{
-				depthMapCamera->setFarClipDistance(light->getAttenuationRange() );
+				lightFarPlane = light->getAttenuationRange();
+				depthMapCamera->setFarClipDistance(lightFarPlane);
+				
 			}
 			else
@@ -336,6 +338,7 @@
 					float farP= -1.5 * min.z;
 					if(farP < 0.2) farP = 0.2;
-					depthMapCamera->setFarClipDistance(farP);
-
+						depthMapCamera->setFarClipDistance(farP);
+					lightFarPlane = farP;
+				
 					Vector3 scale = (max - min);
 					scale *= 1.5; // just for safety
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreSceneCameraDepthRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreSceneCameraDepthRenderingRun.cpp	(revision 1425)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreSceneCameraDepthRenderingRun.cpp	(revision 1670)
@@ -58,5 +58,5 @@
 	rt->update();	
 
-	//rt->writeContentsToFile("cameraDepth.dds");
+	//rt->writeContentsToFile("cameraDepth.bmp");
 	
 	restoreMaterials();
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp	(revision 1628)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowRecieverRenderTechnique.cpp	(revision 1670)
@@ -8,4 +8,10 @@
 												String shadowVertexProgram,
 												String shadowFragmentProgram,
+												bool setLightViewMatrix,
+												bool setLightViewProjMatrix,
+												bool setLightProjFarPlane,
+												String lightViewProjParamName,
+												String lightViewParamName,
+												String lightFarPlaneParamName,
 												Pass* pass,
 												OgreRenderable* parentRenderable,
@@ -18,5 +24,10 @@
 	this->shadowVertexProgram = shadowVertexProgram ;
 	this->shadowFragmentProgram = shadowFragmentProgram;
-
+	this->setLightViewMatrix = setLightViewMatrix;
+	this->setLightViewProjMatrix = setLightViewProjMatrix;
+	this->setLightProjFarPlane = setLightProjFarPlane;
+	this->lightViewProjParamName = lightViewProjParamName;
+	this->lightViewParamName = lightViewParamName;
+	this->lightFarPlaneParamName = lightFarPlaneParamName;
 		
 	//insert new passes
@@ -57,4 +68,5 @@
 		newpass->setSceneBlending(SBT_MODULATE);
 		//newpass->setSceneBlending(SBF_ONE, SBF_ZERO);
+
 		newpass->setDepthBias(1);
 		techn->movePass(lastpass, index);			
@@ -108,5 +120,11 @@
 			
 				//fpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix()); 
-				vpParams->setNamedConstant("lightViewProj", depthRun->getLightViewProjMatrix());
+				if(setLightViewProjMatrix)
+					vpParams->setNamedConstant(lightViewProjParamName, depthRun->getLightViewProjMatrix());
+				if(setLightViewMatrix)
+					vpParams->setNamedConstant(lightViewParamName, depthRun->getLightViewMatrix());
+				if(setLightProjFarPlane)
+					fpParams->setNamedConstant(lightFarPlaneParamName, depthRun->getLightFarPlane());
+				
 				
 				passes.at(i)->setActive(true);
@@ -139,4 +157,31 @@
 		OgreDepthShadowRecieverRenderTechniqueFactory* f = (OgreDepthShadowRecieverRenderTechniqueFactory*) factory;
 		f->shadowFragmentProgram =  params;
+	}
+
+	void parseSetLightViewProj(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreDepthShadowRecieverRenderTechniqueFactory* f = (OgreDepthShadowRecieverRenderTechniqueFactory*) factory;
+		StringVector vecparams = StringUtil::split(params, " \t");
+		f->setLightViewProjMatrix = StringConverter::parseBool(vecparams[0]);
+		if(f->setLightViewProjMatrix && vecparams.size() > 1)
+			f->lightViewProjParamName =  vecparams[1];
+	}
+
+	void parseSetLightView(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreDepthShadowRecieverRenderTechniqueFactory* f = (OgreDepthShadowRecieverRenderTechniqueFactory*) factory;
+		StringVector vecparams = StringUtil::split(params, " \t");
+		f->setLightViewMatrix = StringConverter::parseBool(vecparams[0]);
+		if(f->setLightViewMatrix && vecparams.size() > 1)
+			f->lightViewParamName =  vecparams[1];
+	}
+
+	void parseSetLightFarPlane(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreDepthShadowRecieverRenderTechniqueFactory* f = (OgreDepthShadowRecieverRenderTechniqueFactory*) factory;
+		StringVector vecparams = StringUtil::split(params, " \t");
+		f->setLightProjFarPlane = StringConverter::parseBool(vecparams[0]);
+		if(f->setLightProjFarPlane && vecparams.size() > 1)
+			f->lightFarPlaneParamName =  vecparams[1];
 	}
 }
@@ -151,4 +196,7 @@
 	this->attributeParsers.insert(AttribParserList::value_type("vertex_program_name", (ILLUM_ATTRIBUTE_PARSER) parseVertexProgram));
 	this->attributeParsers.insert(AttribParserList::value_type("fragment_program_name", (ILLUM_ATTRIBUTE_PARSER) parseFragmentProgram));
+	this->attributeParsers.insert(AttribParserList::value_type("set_light_viewproj", (ILLUM_ATTRIBUTE_PARSER) parseSetLightViewProj));
+	this->attributeParsers.insert(AttribParserList::value_type("set_light_view", (ILLUM_ATTRIBUTE_PARSER) parseSetLightView));
+	this->attributeParsers.insert(AttribParserList::value_type("set_light_farplane", (ILLUM_ATTRIBUTE_PARSER) parseSetLightFarPlane));
 }
 
@@ -163,4 +211,10 @@
 	shadowVertexProgram = "GameTools/ShadowMap/ShadowVS";
 	shadowFragmentProgram = "GameTools/ShadowMap/ShadowPS";
+	setLightViewMatrix = false;
+	setLightViewProjMatrix = true;
+	setLightProjFarPlane = false;
+	lightViewProjParamName = "lightViewProj";
+	lightViewParamName = "lightView";
+	lightFarPlaneParamName = "lightFarPlane";
 
 	parseParams(params);
@@ -170,4 +224,10 @@
 												shadowVertexProgram,
 												shadowFragmentProgram,
+												setLightViewMatrix ,
+												setLightViewProjMatrix,
+												setLightProjFarPlane,
+												lightViewProjParamName,
+												lightViewParamName,
+												lightFarPlaneParamName,
 												pass,
 												parentRenderable,
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp	(revision 1639)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreIlluminationManager.cpp	(revision 1670)
@@ -86,5 +86,6 @@
 	blurSM = false;
 	focusingSM = true;
-	
+	shadowMapMaterialName = "GameTools/ShadowMapDepth";
+
 	for(int i = 0; i < RUN_TYPE_COUNT; i++)
 	{
@@ -605,5 +606,5 @@
 				shadowMapSize,
 				shadowMapSize,
-				"GameTools/ShadowMapDepth" //TODO
+				shadowMapMaterialName //TODO
 				);
 			runs->addRun(ILLUMRUN_DEPTH_SHADOWMAP, run);
