Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreSharedRuns.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreSharedRuns.h	(revision 2320)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreSharedRuns.h	(revision 2475)
@@ -218,4 +218,16 @@
 	void freeAllResources();
 
+	OgreRenderable* getRootRenderable()
+	{
+		if(!child1)//this is a root
+		{
+			std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
+			OgreRenderable* rend = (*it).first;
+			return rend; 
+		}
+		else
+			return ((OgreSharedRuns*)getRoot())->getRootRenderable();
+	}
+
 protected:
 	/**
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreRenderable.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreRenderable.h	(revision 2240)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreRenderable.h	(revision 2475)
@@ -134,4 +134,6 @@
 	*/
 	Renderable* getRenderable();
+
+	SceneNode* getParentSceneNode();
 	
 protected:
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.h	(revision 2397)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.h	(revision 2475)
@@ -70,4 +70,5 @@
 							int startTextureUnitID,
 							bool nearestLightsFromCamera,
+							bool bindToVertexShader,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
@@ -146,4 +147,5 @@
 	int startTextureUnitID;
 	bool nearestLightsFromCamera;
+	bool bindToVertexShader;
 };
 
@@ -180,4 +182,5 @@
 	int startTextureUnitID;
 	bool nearestLightsFromCamera;
+	bool bindToVertexShader;
 };
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCausticReceiverRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCausticReceiverRenderTechnique.h	(revision 2397)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCausticReceiverRenderTechnique.h	(revision 2475)
@@ -54,4 +54,5 @@
 							String casterCenterVariableName,
 							String attenuationVariableName,
+							bool bindDistanceMap,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
@@ -101,4 +102,6 @@
 	String casterCenterVariableName;
 	String attenuationVariableName;
+	bool bindDistanceMap;
+	bool bindAttenuation;
 };
 
@@ -128,4 +131,5 @@
 	String casterCenterVariableName;
 	String attenuationVariableName;
+	bool bindDistanceMap;
 };
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderable.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderable.cpp	(revision 1425)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderable.cpp	(revision 2475)
@@ -131,9 +131,17 @@
 	{
 	 case OGRE_RENDERABLETYPE_SUBENTITY:
+	 {
 		 parentEntity->getParentSceneNode()->_updateBounds();
 		 boundingBox = parentEntity->getWorldBoundingBox(true);
-		 boundingSphere = parentEntity->getWorldBoundingSphere(true);	
-		 break;
-	 case OGRE_RENDERABLETYPE_BILLBOARDSET:
+		 
+		 Vector3 center = (boundingBox.getMaximum() + boundingBox.getMaximum()) / 2.0;
+		 float radius = (center - boundingBox.getMaximum()).length();
+		 boundingSphere.setRadius(radius);
+		 boundingSphere.setCenter(center);
+		 //boundingSphere = parentEntity->getWorldBoundingSphere(true);	
+		 break;
+	 }
+	 case OGRE_RENDERABLETYPE_BILLBOARDSET:
+	 {
 		/* billboardSetRenderable->getParentSceneNode()->_updateBounds();
 		 boundingBox = billboardSetRenderable->getWorldBoundingBox(true);
@@ -144,4 +152,5 @@
 		 boundingSphere.setCenter( (boundingBox.getMaximum() + boundingBox.getMinimum()) / 2.0);
 		 break;
+	 }
 	default:
 		 OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
@@ -152,4 +161,24 @@
 }
 
+SceneNode* OgreRenderable::getParentSceneNode()
+{
+	switch(renderableType)
+	{
+	 case OGRE_RENDERABLETYPE_SUBENTITY:
+	 {
+		 return parentEntity->getParentSceneNode();		 
+	 }
+	 case OGRE_RENDERABLETYPE_BILLBOARDSET:
+	 {
+		 return parentParticleSystem->getParentSceneNode();
+	 }
+	 default:
+		 OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
+                "Unknown renderable type! Check RenderTechnique initializations!", 
+                "OgreRenderable::getParentSceneNode");
+	}
+	return 0;
+}
+
 Renderable* OgreRenderable::getRenderable()
 {
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp	(revision 2427)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp	(revision 2475)
@@ -137,4 +137,5 @@
 		restoreMaterials();
 
+	//	rt->writeContentsToFile(name+"_lightVolume.bmp");
 		//do blending
 	    rt = lightVolumeTexture2->getBuffer().getPointer()->getRenderTarget();
@@ -143,5 +144,5 @@
 		renderFullscreenQuad("GameTools/BlurLightVolume", rt);		
 
-
+	//	rt->writeContentsToFile(name+"_blurredlightVolume.bmp");
 	/*	
 		static int framecount = 0;
@@ -199,7 +200,9 @@
 void OgreLightVolumeRenderingRun::refreshLight()
 {
+	Vector3 center = sharedRuns->getRootPosition(ILLUMRUN_LIGHTVOLUME_MAP);
+			
 	SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
 	LightList list;
-	sm->_populateLightList(((OgreSharedRuns*)sharedRuns)->getRootPosition(ILLUMRUN_LIGHTVOLUME_MAP),100000, list);
+	sm->_populateLightList(center, 100000, list);
 	
 	light = *(list.begin());
@@ -226,5 +229,5 @@
 			lightVolumeCamera->setDirection( dir );
 			Real r = sharedRuns->getRootBoundingSphere(ILLUMRUN_LIGHTVOLUME_MAP).getRadius();
-			r += baseRad;
+			//r += baseRad;
 			systemRadius = r;
 			lightVolumeCamera->setPosition( sharedRuns->getRootPosition(ILLUMRUN_LIGHTVOLUME_MAP) - dir * r);
@@ -239,10 +242,17 @@
 		{			
 			Vector3 pos = light->getDerivedPosition();
-			Vector3 dir = sharedRuns->getRootPosition(ILLUMRUN_LIGHTVOLUME_MAP) - pos;
+			Vector3 dir = center - pos;
+			Real r = sharedRuns->getRootBoundingSphere(ILLUMRUN_LIGHTVOLUME_MAP).getRadius();
+			//r += baseRad;
+			Real d = dir.length();
 			dir.normalise();
-			Real r = sharedRuns->getRootBoundingSphere(ILLUMRUN_LIGHTVOLUME_MAP).getRadius();
-			r += baseRad;
-			lightVolumeCamera->setPosition( sharedRuns->getRootPosition(ILLUMRUN_LIGHTVOLUME_MAP) - dir * r);
-			lightVolumeCamera->lookAt( sharedRuns->getRootPosition(ILLUMRUN_LIGHTVOLUME_MAP) );			
+			/*float mindist = 1.5 * r;
+			if(d < mindist)
+			{
+				pos -= dir * (mindist - d) ;
+				d = mindist;
+			}*/
+			lightVolumeCamera->setPosition( center - dir * d);
+			lightVolumeCamera->lookAt( center );			
 			lightVolumeCamera->setProjectionType(PT_ORTHOGRAPHIC);
 			Matrix4 proj;
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.cpp	(revision 2460)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDepthShadowReceiverRenderTechnique.cpp	(revision 2475)
@@ -21,4 +21,5 @@
 												int startTextureUnitID,
 												bool nearestLightsFromCamera,
+												bool bindToVertexShader,
 												Pass* pass,
 												OgreRenderable* parentRenderable,
@@ -28,4 +29,5 @@
 							DepthShadowReceiverRenderTechnique(parentRenderable, parentTechniqueGroup)
 {
+	this->bindToVertexShader = bindToVertexShader;
 	this->passBlendingSRC = passBlendingSRC;
 	this->passBlendingDEST = passBlendingDEST;
@@ -99,5 +101,6 @@
 	Vector3 center = OgreIlluminationManager::getSingleton().getMainCamera()->getWorldPosition();
 	if(!nearestLightsFromCamera)
-		center = ((OgreSharedRuns*) sharedRuns)->getRootPosition();
+		center = ((OgreSharedRuns*) sharedRuns)->getRootRenderable()->getParentSceneNode()->_getDerivedPosition();
+		//center = ((OgreSharedRuns*) sharedRuns)->getRootPosition();
 	Root::getSingleton()._getCurrentSceneManager()->_populateLightList(
 							center,
@@ -149,4 +152,7 @@
 				GpuProgramParametersSharedPtr fpParams = passToSet->getFragmentProgramParameters();
 				GpuProgramParametersSharedPtr vpParams = passToSet->getVertexProgramParameters();
+				GpuProgramParametersSharedPtr variableSetParams = fpParams;
+				if(bindToVertexShader)
+					variableSetParams = vpParams;
 
 				String LightViewProjParamName = lightViewProjParamName;
@@ -165,5 +171,5 @@
 					vpParams->setNamedConstant(LightViewProjParamName, depthRun->getLightViewProjMatrix());
 					else
-					fpParams->setNamedConstant(LightViewProjParamName, depthRun->getLightViewProjMatrix());
+					variableSetParams->setNamedConstant(LightViewProjParamName, depthRun->getLightViewProjMatrix());
 				}
 				if(setLightViewMatrix)
@@ -172,5 +178,5 @@
 					vpParams->setNamedConstant(LightViewParamName, depthRun->getLightViewMatrix());
 					else
-					fpParams->setNamedConstant(LightViewParamName, depthRun->getLightViewMatrix());
+					variableSetParams->setNamedConstant(LightViewParamName, depthRun->getLightViewMatrix());
 				}
 				if(setLightProjFarPlane)
@@ -347,4 +353,9 @@
 		f->nearestLightsFromCamera = StringConverter::parseBool(params);
 	}
+	void parseBindToVertexShader(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreDepthShadowReceiverRenderTechniqueFactory* f = (OgreDepthShadowReceiverRenderTechniqueFactory*) factory;
+		f->bindToVertexShader = StringConverter::parseBool(params);
+	}
 }
 
@@ -370,4 +381,5 @@
 	this->attributeParsers.insert(AttribParserList::value_type("start_tex_id", (ILLUM_ATTRIBUTE_PARSER) parseStartTexID));	
 	this->attributeParsers.insert(AttribParserList::value_type("nearest_from_camera", (ILLUM_ATTRIBUTE_PARSER) parseNearestFromCamera));	
+	this->attributeParsers.insert(AttribParserList::value_type("bind_to_vertex_shader", (ILLUM_ATTRIBUTE_PARSER) parseBindToVertexShader));	
 }
 
@@ -394,6 +406,7 @@
 	createNewPasses = true;
 	startTextureUnitID = 0;
-	nearestLightsFromCamera = true;
-	
+	nearestLightsFromCamera = false;
+	bindToVertexShader = false;
+
 	parseParams(params);
 
@@ -415,4 +428,5 @@
 												startTextureUnitID,
 												nearestLightsFromCamera,
+												bindToVertexShader,
 												pass,
 												parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticReceiverRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticReceiverRenderTechnique.cpp	(revision 2366)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticReceiverRenderTechnique.cpp	(revision 2475)
@@ -15,4 +15,5 @@
 												String casterCenterVariableName,
 												String attenuationVariableName,
+												bool bindDistanceMap,
 												Pass* pass,
 												OgreRenderable* parentRenderable,
@@ -31,4 +32,8 @@
 	this->casterCenterVariableName = casterCenterVariableName;
 	this->attenuationVariableName = attenuationVariableName;
+	this->bindDistanceMap = bindDistanceMap;
+	bindAttenuation = false;
+	if(attenuationVariableName != "")
+		bindAttenuation = true;
 	
 	if(createNewPasses)
@@ -66,8 +71,10 @@
 
 			TextureUnitState* st = newpass->createTextureUnitState();
-			TextureUnitState* st2 = newpass->createTextureUnitState();
-
 			st->setTextureFiltering(TFO_BILINEAR);
-			st2->setTextureFiltering(TFO_BILINEAR);
+			if(bindDistanceMap)
+			{
+				TextureUnitState* st2 = newpass->createTextureUnitState();
+				st2->setTextureFiltering(TFO_BILINEAR);
+			}
 
 			newpass->setSceneBlending(passBlendingSRC, passBlendingDEST);
@@ -109,5 +116,6 @@
 			
 			Pass* passToSet = this->pass;
-			int textureUnit = startTextureUnitID + i;
+			int p = bindDistanceMap?i*2:i;
+			int textureUnit = startTextureUnitID + p;
 			if(createNewPasses)
 			{
@@ -119,4 +127,13 @@
 			passToSet->getTextureUnitState(textureUnit)->setTextureName(
 				cauCubeRun->getCausticCubeMapTextureName());
+			if(bindDistanceMap)
+			{
+				OgreCubeMapRenderingRun* distCubeRun = 
+				(OgreCubeMapRenderingRun*) causticCasters.at(i)->
+					getRun(ILLUMRUN_DISTANCE_CUBEMAP)->asOgreRenderingRun();
+				if(distCubeRun)
+				passToSet->getTextureUnitState(textureUnit + 1)->setTextureName(
+					distCubeRun->getCubeMapTextureName());
+			}
 	
 			//set caster position nad caustic attenuation
@@ -126,9 +143,10 @@
 			if(!createNewPasses)
 			{
-				centerVarName += String("[") + StringConverter::toString(i) + String("]");
-				attenuationVarName += String("[") + StringConverter::toString(i) + String("]");
+				centerVarName += StringConverter::toString(i+1);
+				attenuationVarName += StringConverter::toString(i+1);
 			}
 			Fparams->setNamedConstant(centerVarName,
 										causticCasters.at(i)->getRootPosition(ILLUMRUN_CAUSTIC_CUBEMAP));
+			if(bindAttenuation)
 			Fparams->setNamedConstant(attenuationVarName,
 										cauCubeRun->getAttenuation());			
@@ -247,4 +265,10 @@
 		f->attenuationVariableName =  params;
 	}
+
+	void parseBindDistanceMap(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCausticReceiverRenderTechniqueFactory* f = (OgreCausticReceiverRenderTechniqueFactory*) factory;
+		f->bindDistanceMap =  StringConverter::parseBool(params);
+	}
 }
 
@@ -263,4 +287,5 @@
 	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));	
+	this->attributeParsers.insert(AttribParserList::value_type("bind_distance_map", (ILLUM_ATTRIBUTE_PARSER) parseBindDistanceMap));	
 }
 
@@ -280,5 +305,6 @@
 	startTextureUnitID = 0;
 	casterCenterVariableName = "cubeMapCameraPosition";
-	String attenuationVariableName = "attenuation";
+	attenuationVariableName = "";
+	bindDistanceMap = false;
 
 	parseParams(params);
@@ -294,4 +320,5 @@
 												casterCenterVariableName,
 												attenuationVariableName,
+												bindDistanceMap,
 												pass,
 												parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp	(revision 2460)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgrePathMapRenderTechnique.cpp	(revision 2475)
@@ -144,8 +144,8 @@
 	LightList lights;
 	SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
-	sm->_populateLightList(OgreIlluminationManager::getSingleton().getMainCamera()->getPosition(), 1000, lights);
+	sm->_populateLightList(OgreIlluminationManager::getSingleton().getMainCamera()->getWorldPosition(), 1000, lights);
 
 	int found = 0;
-	for(int i = 0 ; found < 5 && i < lights.size(); i++)
+	for(int i = 0 ; found < 2 && i < lights.size(); i++)
 	{
 		if(lights.at(i)->isAttached())
