Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp	(revision 2321)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp	(revision 2333)
@@ -238,5 +238,5 @@
 		else
 		{			
-			Vector3 pos = light->getParentSceneNode()->getPosition();
+			Vector3 pos = light->getDerivedPosition();
 			Vector3 dir = sharedRuns->getRootPosition(ILLUMRUN_LIGHTVOLUME_MAP) - pos;
 			dir.normalise();
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMWeightComputeRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMWeightComputeRenderingRun.cpp	(revision 2321)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePMWeightComputeRenderingRun.cpp	(revision 2333)
@@ -4,4 +4,7 @@
 #include "OgreDepthShadowMapRenderingRun.h"
 
+Texture* OgrePMWeightComputeRenderingRun::weightTexture = 0;
+Texture* OgrePMWeightComputeRenderingRun::allWeightsTexture = 0;
+
 OgrePMWeightComputeRenderingRun::OgrePMWeightComputeRenderingRun(String name, String LightName)
 														   : OgreRenderingRun(1, 1)
@@ -19,46 +22,50 @@
 void OgrePMWeightComputeRenderingRun::createWeightMap()
 {
-	
-	unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
-	int width = entryPointCnt / 4096;
-	int height = 4096;
-	TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL", 
-																		"default",
-																		TEX_TYPE_2D,
-																		width,
-																		height,
-																		0,
-																		0,
-																		PF_FLOAT32_R,
-																		TU_RENDERTARGET);
-	 allWeightsTexture = texPtr.getPointer();
-	 //add viewport to rendertarget
-	 HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer();
-	 RenderTarget* rt = hpb->getRenderTarget();
-	 Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA"); 
-	 Viewport* v = rt->addViewport(wc);
-	 v->setOverlaysEnabled(false);
-	 rt->setAutoUpdated(false);
-
-	unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
-	width = clustercount;
-	height = 1;
-	texPtr = Ogre::TextureManager::getSingleton().createManual(name, 
-																"default",
-																TEX_TYPE_2D,
-																width,
-																height,
-																0,
-																0,
-																PF_FLOAT32_R,
-																TU_RENDERTARGET);
-	 weightTexture = texPtr.getPointer();
-	 //add viewport to rendertarget
-	 hpb = (weightTexture->getBuffer()).getPointer();
-	 rt = hpb->getRenderTarget();
-	 wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA"); 
-	 v = rt->addViewport(wc);
-	 v->setOverlaysEnabled(false);
-	 rt->setAutoUpdated(false);
+	if(allWeightsTexture == 0)
+	{
+		unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
+		int width = entryPointCnt / 4096;
+		int height = 4096;
+		TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name + "_ALL", 
+																			"default",
+																			TEX_TYPE_2D,
+																			width,
+																			height,
+																			0,
+																			0,
+																			PF_FLOAT16_RGBA,
+																			TU_RENDERTARGET);
+		allWeightsTexture = texPtr.getPointer();
+		//add viewport to rendertarget
+		HardwarePixelBuffer* hpb = (allWeightsTexture->getBuffer()).getPointer();
+		RenderTarget* rt = hpb->getRenderTarget();
+		Camera* wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_ALL_CAMERA"); 
+		Viewport* v = rt->addViewport(wc);
+		v->setBackgroundColour(ColourValue::Black);
+		v->setClearEveryFrame(false);
+		v->setOverlaysEnabled(false);
+		rt->setAutoUpdated(false);
+
+		unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
+		width = clustercount;
+		height = 1;
+		texPtr = Ogre::TextureManager::getSingleton().createManual(name, 
+																	"default",
+																	TEX_TYPE_2D,
+																	width,
+																	height,
+																	0,
+																	0,
+																	PF_FLOAT16_RGBA,
+																	TU_RENDERTARGET);
+		weightTexture = texPtr.getPointer();
+		//add viewport to rendertarget
+		hpb = (weightTexture->getBuffer()).getPointer();
+		rt = hpb->getRenderTarget();
+		wc = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA"); 
+		v = rt->addViewport(wc);
+		v->setOverlaysEnabled(false);
+		rt->setAutoUpdated(false);		
+	}
 }
 
@@ -83,7 +90,7 @@
 		GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
 			
-			Vector3 lightPos = light->getPosition();
-			Vector3 lightDir = light->getDirection();
-		//	Radian lightAngle = light->getSpotlightOuterAngle();
+			Vector3 lightPos = light->getDerivedPosition();
+			Vector3 lightDir = light->getDerivedDirection();
+			Radian lightAngle = light->getSpotlightOuterAngle();
 			
 			Fparams->setNamedConstant("nRadionColumns", col);
@@ -91,6 +98,13 @@
 			Fparams->setNamedConstant("lightDir", lightDir);
 			Fparams->setNamedConstant("lightPower", light->getPowerScale());
+			Fparams->setNamedConstant("lightColor", light->getDiffuseColour());
 			Fparams->setNamedConstant("lightViewProj", SMrun->getLightViewProjMatrix());
 			Fparams->setNamedConstant("lightFarPlane", SMrun->getLightFarPlane());
+			Fparams->setNamedConstant("lightAttenuation", Vector4(light->getAttenuationRange(),
+																	light->getAttenuationConstant(),
+																	light->getAttenuationLinear(),
+																	light->getAttenuationQuadric()));
+			Fparams->setNamedConstant("lightAngleCos", Math::Cos(lightAngle.valueRadians()/2.0));			
+			Fparams->setNamedConstant("spotLightFalloff", light->getSpotlightFalloff());			
 			
 			mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
@@ -100,50 +114,66 @@
 				
 			RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget();
-			renderFullscreenQuad(mat->getName(), rt);
+			if(frameNum != rt->getLastFrameNumber())
+				rt->getViewport(0)->setClearEveryFrame(true);
+			else
+				rt->getViewport(0)->setClearEveryFrame(false);
+			
+				renderFullscreenQuad(mat->getName(), rt);
+			
 
 		//	rt->writeContentsToFile("allweights.bmp");
 		//	rt->writeContentsToFile("allweights.dds");
-			
-		/*	float* allweights = new float[entryPointCnt / 4096 * 4096];
-			PixelBox lockBox(entryPointCnt / 4096, 4096, 1, PF_FLOAT32_R, allweights);
-			allWeightsTexture->getBuffer()->blitToMemory(lockBox);
-
-			///////////////////DEBUG
-			static BillboardSet* entryPointBBSet = 0;
-			if(entryPointBBSet == 0)
-			{
-				SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
-				entryPointBBSet = sm->createBillboardSet("PATHMAP_ENTRYPOINTS", entryPointCnt);
-				entryPointBBSet->setBillboardType(BBT_POINT);
-				entryPointBBSet->setBillboardsInWorldSpace(true);
-				entryPointBBSet->setPointRenderingEnabled(true);
-				for(unsigned int i = 0; i < entryPointCnt; i++)
-				{
-					PathMapEntryPoint EP = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().at(i);
-					Vector3 billboardPosition = EP.position;
-					
-					float uCoord = allweights[i];
-					float  vCoord = 0;
-					//float uCoord = ((float) (i % col) + 0.5f) / (float) col;
-					//float vCoord = ((float)(i / col) + 0.5f) / 4096.0f;
-					entryPointBBSet->createBillboard(billboardPosition, ColourValue(uCoord, vCoord, 0, 0));
-				}
-				entryPointBBSet->setMaterialName("GTP/PM/EPBillboards");
-				MaterialPtr mater = MaterialManager::getSingleton().getByName("GTP/PM/EPBillboards");
-				mater->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(allWeightsTexture->getName());
-				sm->getRootSceneNode()->createChildSceneNode()->attachObject(entryPointBBSet);
-			}
-
-			delete[] allweights;*/
-
-/////////////////
+
 	}
-	else
+	else if(light->getType() == Light::LT_POINT)
 	{
-		///not implemented
+		OgreIlluminationManager::getSingleton().createPerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP);
+		OgreIlluminationManager::getSingleton().updatePerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP, frameNum);
+		OgreDepthShadowMapRenderingRun* SMrun = (OgreDepthShadowMapRenderingRun*) OgreIlluminationManager::getSingleton()
+			.getPerLightRun(light->getName(), ILLUMRUN_DEPTH_SHADOWMAP)->asOgreRenderingRun(); 
+		
+		MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_ComputeWeights_Point");
+		GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
+			
+			Vector3 lightPos = light->getDerivedPosition();
+			
+			Fparams->setNamedConstant("nRadionColumns", col);
+			Fparams->setNamedConstant("lightPos", lightPos);
+			Fparams->setNamedConstant("lightPower", light->getPowerScale());
+			Fparams->setNamedConstant("lightColor", light->getDiffuseColour());
+			Fparams->setNamedConstant("lightFarPlane", SMrun->getLightFarPlane());
+			Fparams->setNamedConstant("lightAttenuation", Vector4(light->getAttenuationRange(),
+																	light->getAttenuationConstant(),
+																	light->getAttenuationLinear(),
+																	light->getAttenuationQuadric()));
+
+			mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(
+						PMEPrun->getEntryPointTextureName());
+			mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName(
+						SMrun->getDepthMapTextureName());
+				
+			RenderTarget* rt = allWeightsTexture->getBuffer().getPointer()->getRenderTarget();
+			if(frameNum != rt->getLastFrameNumber())
+				rt->getViewport(0)->setClearEveryFrame(true);
+			else
+				rt->getViewport(0)->setClearEveryFrame(false);
+			
+				renderFullscreenQuad(mat->getName(), rt);
+			
 	}
 
+}
+
+void OgrePMWeightComputeRenderingRun::sumWeights(unsigned long frameNum)
+{
+	RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
+	if(frameNum == rt->getLastFrameNumber())return;
+	
+	unsigned int entryPointCnt = OgreIlluminationManager::getSingleton().getPathMapEntryPoints().size();
+	int col = entryPointCnt / 4096; 
 	unsigned int clustercount = OgreIlluminationManager::getSingleton().getPathMapClusterLengthsSize();
-
+	OgrePMEntryPointMapRenderingRun* PMEPrun = (OgrePMEntryPointMapRenderingRun*)
+	OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_PM_ENTRYPOINTMAP)->asOgreRenderingRun();
+	
 	MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/PathMap_SumWeights");
 	GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer();
@@ -157,15 +187,5 @@
 						allWeightsTexture->getName());
 	
-	RenderTarget* rt = weightTexture->getBuffer().getPointer()->getRenderTarget();
 	renderFullscreenQuad(mat->getName(), rt);
-
-	//rt->writeContentsToFile("weights.bmp");	
-	//rt->writeContentsToFile("weights.dds");
-/*
-	float* weights = new float[clustercount];
-	PixelBox lockBox(clustercount, 1, 1, PF_FLOAT32_R, weights);
-	weightTexture->getBuffer()->blitToMemory(lockBox);
-
-	delete[] weights;*/
 }
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp	(revision 2321)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp	(revision 2333)
@@ -100,5 +100,5 @@
 		if(light->getType() == Light::LT_DIRECTIONAL)
 		{
-			Vector3 dir = light->getDirection();
+			Vector3 dir = light->getDerivedDirection();
 			photonMapCamera->setDirection( dir );
 			Real r = sharedRuns->getRootBoundingSphere(ILLUMRUN_PHOTONMAP).getRadius();
@@ -113,5 +113,5 @@
 		else
 		{			
-			Vector3 pos = light->getParentSceneNode()->getPosition();
+			Vector3 pos = light->getDerivedPosition();
 			Vector3 dir = sharedRuns->getRootPosition(ILLUMRUN_PHOTONMAP) - pos;
 			Real r = sharedRuns->getRootBoundingSphere(ILLUMRUN_PHOTONMAP).getRadius();
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp	(revision 2321)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp	(revision 2333)
@@ -26,4 +26,12 @@
 void OgreDepthShadowMapRenderingRun::createDepthMap()
 {
+	if(light->getType() == Light::LT_POINT)
+	{
+		depthMapTexture = createCubeRenderTexture(name, light->getPosition(), resolutionX,PF_FLOAT16_RGBA,0,ColourValue::White);
+		if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType()))
+		blurredDepthMapTexture = createCubeRenderTexture(blurredname, light->getPosition(), resolutionX,PF_FLOAT16_RGBA,0,ColourValue::White);
+	}
+	else
+	{
 	
 		TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name, 
@@ -46,5 +54,5 @@
 		rt->setAutoUpdated(false);
 		
-		if(OgreIlluminationManager::getSingleton().getBlurShadowMap())
+		if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType()))
 		{
 			texPtr = Ogre::TextureManager::getSingleton().createManual(blurredname, 
@@ -64,4 +72,5 @@
 			rt->setAutoUpdated(false);
 		}
+	}
 }
 
@@ -72,5 +81,10 @@
 	if(light->getType() == Light::LT_POINT)
 	{
-		updateDepthMap();
+		//static int currentFace = 0;
+		//updateDepthCubeFace(currentFace);
+		//currentFace = (currentFace+1)%6;
+
+		for(int i = 0; i < 6 ; i++)
+			updateDepthCubeFace(i);
 	}
 	else
@@ -82,4 +96,28 @@
 void OgreDepthShadowMapRenderingRun::updateDepthCubeFace(int facenum)
 {
+	Vector3 lightpos = light->getDerivedPosition();			
+	
+	RenderTarget* rt = depthMapTexture->getBuffer(facenum, 0).getPointer()->getRenderTarget();	
+	Camera*  cam = 	rt->getViewport(0)->getCamera();
+	cam->setPosition(lightpos);	
+	cam->setFarClipDistance(lightFarPlane);
+
+	setMaterialForVisibles(materialName, cam, false);
+	rt->update();
+	restoreMaterials();
+
+	//rt->writeContentsToFile("shadowmap_" + StringConverter::toString(facenum) + ".dds");
+
+	if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType()))
+	{
+		rt = blurredDepthMapTexture->getBuffer(facenum, 0).getPointer()->getRenderTarget();
+		Material*  mat = (Material*) MaterialManager::getSingleton().getByName("GameTools/BlurCubeFace").getPointer();
+		mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(depthMapTexture->getName());
+		mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("face", facenum);
+		renderFullscreenQuad("GameTools/BlurCubeFace", rt);		
+		
+		//rt->writeContentsToFile("shadowmap_blurred_" + StringConverter::toString(facenum) + ".dds");
+	}
+	
 }
 
@@ -93,5 +131,5 @@
 	restoreMaterials();
 	
-	if(OgreIlluminationManager::getSingleton().getBlurShadowMap())
+	if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType()))
 	{
 		rt = blurredDepthMapTexture->getBuffer().getPointer()->getRenderTarget();
@@ -108,5 +146,5 @@
 const String& OgreDepthShadowMapRenderingRun::getDepthMapTextureName()
 {
-		if(OgreIlluminationManager::getSingleton().getBlurShadowMap())
+		if(OgreIlluminationManager::getSingleton().getBlurShadowMap(light->getType()))
 			return blurredname;
 
@@ -119,6 +157,6 @@
 	if(light!= 0)
 	{
-		bool uselispsm = OgreIlluminationManager::getSingleton().getUseLISPSM();
-		bool usefocusing = OgreIlluminationManager::getSingleton().getFocusingShadowMap();
+		bool uselispsm = OgreIlluminationManager::getSingleton().getUseLISPSM(light->getType());
+		bool usefocusing = OgreIlluminationManager::getSingleton().getFocusingShadowMap(light->getType());
 		if(light->getType() == Light::LT_DIRECTIONAL)
 		{
@@ -129,6 +167,6 @@
 			frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix());
 
-			Vector3 lightpos = light->getParentSceneNode()->getWorldPosition();
-			Vector3 lightdir = light->getDirection();
+			Vector3 lightpos = light->getDerivedPosition();
+			Vector3 lightdir = light->getDerivedDirection();
 			lightdir.normalise();		
 			
@@ -234,6 +272,6 @@
 			frun->setCameraMatrices(viewcam->getViewMatrix(), viewcam->getProjectionMatrix());
 
-			Vector3 lightpos = light->getParentSceneNode()->getWorldPosition ();
-			Vector3 lightdir = light->getDirection();
+			Vector3 lightpos = light->getDerivedPosition();
+			Vector3 lightdir = light->getDerivedDirection();
 			lightdir.normalise();		
 			Radian lightangle = light->getSpotlightOuterAngle();
@@ -359,22 +397,6 @@
 		else//point light
 		{
-	/*		Vector3 pos = light->getParentNode()->getWorldPosition();
-			Vector3 dir = -pos;
-			depthMapCamera->setDirection( dir );
-			depthMapCamera->setPosition(pos);
-			depthMapCamera->setProjectionType(PT_PERSPECTIVE);
-			depthMapCamera->setFOVy(Radian(Degree(140)));
-			depthMapCamera->setNearClipDistance(1);
-			// depthMapCamera->setFarClipDistance(200);
-	
-			//OGRE_EXCEPT(0, "NOT implemented for Pointlight", "OgreDepthShadowMapRenderingRun::refreshLight");
-		*/	
-			/*Vector3 pos = light->getParentNode()->getWorldPosition();
-			Vector3 dir = -pos;
-			depthMapCamera->setDirection( dir );
-			depthMapCamera->setPosition(pos);
-			depthMapCamera->setProjectionType(PT_ORTHOGRAPHIC);
-			depthMapCamera->*/
-			
+			lightFarPlane = light->getAttenuationRange();
+			//no other adjustment needed			
 		}
 	}
@@ -383,10 +405,18 @@
 Matrix4 OgreDepthShadowMapRenderingRun::getLightViewMatrix()
 {
-	return depthMapCamera->getViewMatrix();
+	Camera* cam = depthMapCamera;
+	if(light->getType() == Light::LT_POINT)
+	 cam = depthMapTexture->getBuffer(4, 0).getPointer()->getRenderTarget()->getViewport(0)->getCamera();	
+	
+	return cam->getViewMatrix();
 }
 
 Matrix4 OgreDepthShadowMapRenderingRun::getLightViewProjMatrix()
 {
-	return depthMapCamera->getProjectionMatrixWithRSDepth() * depthMapCamera->getViewMatrix();
+	Camera* cam = depthMapCamera;
+	if(light->getType() == Light::LT_POINT)
+	 cam = depthMapTexture->getBuffer(4, 0).getPointer()->getRenderTarget()->getViewport(0)->getCamera();	
+	
+	return cam->getProjectionMatrixWithRSDepth() * cam->getViewMatrix();
 }
 
