Index: GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PRMDemo.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PRMDemo.material	(revision 2284)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PRMDemo.material	(revision 2337)
@@ -1,17 +1,2 @@
-vertex_program GTP/PathMap_VS hlsl
-{
-   source PathMap.hlsl
-   entry_point vsWalk
-   target vs_2_0   
-}
-
-fragment_program GTP/PathMap_PS hlsl
-{
-   source PathMap.hlsl
-   entry_point psWalk
-   target ps_3_0
-   flow_control prefer
-}
-
 material PRMDemo/Base
 {
@@ -131,123 +116,2 @@
   }
 }
-
-
-vertex_program GTP/PathMap_ComputeWeights_VS hlsl
-{
-   source PathMapWeightCompute.hlsl
-   entry_point vsComputeWeights
-   target vs_2_0   
-}
-
-fragment_program GTP/PathMap_ComputeWeights_PS hlsl
-{
-   source PathMapWeightCompute.hlsl
-   entry_point psComputeWeights
-   target ps_3_0   
-}
-
-material GTP/PathMap_ComputeWeights
-{
-	technique
-	{
-		pass
-		{
-			depth_check off
-			cull_harware none
-			vertex_program_ref GTP/PathMap_ComputeWeights_VS
-			{
-				
-			}
-			fragment_program_ref GTP/PathMap_ComputeWeights_PS
-			{
-			}
-			texture_unit //entrypoint texture
-			{
-				filtering off
-			}
-			texture_unit shadow_map //stores distances
-   			{
-     			
-    		}
-		}
-		
-	}
-}
-
-fragment_program GTP/PathMap_SumWeights_PS hlsl
-{
-   source PathMapWeightCompute.hlsl
-   entry_point psSumWeights
-   target ps_3_0
-   flow_control prefer     
-}
-
-material GTP/PathMap_SumWeights
-{
-	technique
-	{
-		pass
-		{
-			
-			depth_check off
-			cull_harware none
-			lighting off
-			vertex_program_ref GTP/PathMap_ComputeWeights_VS
-			{
-				
-			}
-			fragment_program_ref GTP/PathMap_SumWeights_PS
-			{
-			}
-			texture_unit //entrypoint texture
-			{
-				filtering none
-			}
-			texture_unit //entrypoint weight texture
-			{
-				filtering none
-			}
-			texture_unit //cluster length
-			{
-				filtering none
-			}
-		}
-		
-	}
-}
-
-vertex_program GTP/EPDisplayVS hlsl
-{
-   source PathMapWeightCompute.hlsl
-   entry_point EntryPointDisplayVS
-   target vs_2_0   
-}
-fragment_program GTP/EPDisplayPS hlsl
-{
-   source PathMapWeightCompute.hlsl
-   entry_point EntryPointDisplayPS
-   target ps_2_0   
-}
-
-material GTP/PM/EPBillboards
-{
- technique
- {
-   pass
-   {
-		polygon_mode points
-		point_size 10
-		vertex_program_ref GTP/EPDisplayVS
-		{
-			param_named_auto worldViewProj worldviewproj_matrix 	
-		}
-		fragment_program_ref GTP/EPDisplayPS
-		{
-		}
-    	texture_unit
-    	{  
-	    	filtering none   
-    	}
-   }
-  }
-}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PathMap.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PathMap.hlsl	(revision 2246)
+++ 	(revision )
@@ -1,56 +1,0 @@
-uniform float4x4 WorldViewProj;
-uniform float4 prmAtlasTilesHalfPixel;
-uniform sampler2D filteredAtlasSampler : register(s0);
-uniform sampler2D clusterWeightIndexSampler : register(s1);
-uniform sampler2D clusterWeightSampler : register(s2);
-uniform sampler2D colorSampler : register(s3);
-uniform float allClusterCount; 
-uniform float clusterCount;
-
-struct vsInputWalk
-{
-    float4 pos			: POSITION;
-    float2 tex			: TEXCOORD0;
-    float2 texAtlas		: TEXCOORD1;
-};
-
-struct vsOutputWalk
-{
-    float4 pos			: POSITION;
-    float2 tex			: TEXCOORD0;
-    float2 texAtlas		: TEXCOORD1;
-};
-
-
-vsOutputWalk vsWalk(vsInputWalk input)
-{
-	vsOutputWalk output = (vsOutputWalk)0;
-	output.pos = mul(WorldViewProj, input.pos);
-	output.tex = input.tex;
-	output.texAtlas = input.texAtlas;	
-	return output;
-}
-
-float4	psWalk(vsOutputWalk input) : COLOR
-{
-	int2 prmAtlasTiles = prmAtlasTilesHalfPixel.xy;
-	float2 atlasHalfPixel = prmAtlasTilesHalfPixel.zw;
-	
-	float3 col = 0;
-	for(int iCluster = 0; iCluster < 32; iCluster++)
-	{
-		float2 prmTexPos = float2(
-			(input.texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x,
-			1.0 - (input.texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y) + atlasHalfPixel;
-
-		float weightIndex = tex2D(clusterWeightIndexSampler, float2(((float)iCluster + 0.5) / clusterCount, 0.5)).r;
-		float weight = tex2D(clusterWeightSampler, float2((weightIndex + 0.5)/allClusterCount, 0.5)).r;
-		//weight = 0.0002 + 0.000000000001 * weight;
-		float3 val = tex2D(filteredAtlasSampler, prmTexPos).xyz;
-		col += val.xyz * weight;		
-	}
-	
-	float3 color = tex2D(colorSampler, input.tex).rgb;
-	return float4(col * color, 1);
-}
-
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PathMapWeightCompute.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PathMapWeightCompute.hlsl	(revision 2246)
+++ 	(revision )
@@ -1,125 +1,0 @@
-#define SAMPLECUTDIST2 0.01
-#define WEIGHTCUTOFF   0.01
-#define DIST_BIAS      0.005
-
-uniform int nRadionColumns;
-uniform float3 lightPos;
-uniform float3 lightDir;
-uniform float lightPower;
-uniform float clusterCount;
-uniform float4x4 lightViewProj;
-uniform float lightFarPlane;
-
-struct vsInputComputeWeights
-{
-    float4	pos			: POSITION;
-    float2	tex			: TEXCOORD0;
-};
-
-struct vsOutputComputeWeights
-{
-    float4	pos			: POSITION;
-    float2	tex			: TEXCOORD0;
-};
-
-vsOutputComputeWeights
-	vsComputeWeights(vsInputComputeWeights input)
-{
-    vsOutputComputeWeights output = (vsOutputComputeWeights)0;
-    output.pos = input.pos;
-    output.tex = (input.pos + 1.0) / 2.0;
-    //output.tex = input.tex;
-    output.tex.y = 1.0 - output.tex.y;
-   
-    return output;
-}
-
-float4 psComputeWeights(vsOutputComputeWeights input,
-						uniform sampler2D radionSampler : register(s0),
-						uniform sampler2D shadowMap : register(s1)) : COLOR0
-{
-	float dataColumnWidth = 1.0 / (float)nRadionColumns;
-	int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096;
-	int werx = bushIndex % nRadionColumns;
-	int wery = bushIndex / nRadionColumns;
-	float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
-	float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
-	dir = normalize(dir);
-	
-	float3 diff = lightPos - pos;
-	float dist2 = dot(diff, diff);
-	if(dist2 < SAMPLECUTDIST2)
-		dist2 = SAMPLECUTDIST2;
-	diff = normalize(diff);
-	float cosa = max(dot(lightDir, -diff), 0);
-	float cosb = max(dot(dir, diff), 0);	
-	
-	
-	float4 lightVPos = mul(lightViewProj, float4(pos,1));
-	float dist = sqrt(dist2) / lightFarPlane;
-	lightVPos /= lightVPos.w;
-	lightVPos.xy = (lightVPos.xy + 1.0) / 2.0;
-	lightVPos.y = 1.0 - lightVPos.y;
-	float storedDist = tex2D(shadowMap, lightVPos.xy).r;
-	dist -= DIST_BIAS;
-	float visibility = (dist <= storedDist);  	
-
-	//float visibility = 1;
-	//visibility = visibility * 0.00001 + 1.0;
-	
-	float4 ret = visibility * pow(cosa, 9) * cosb / dist2 * lightPower;
-	return ret;
-}
-
-float4 psSumWeights(vsOutputComputeWeights input,
-					uniform sampler2D radionSampler       : register(s0),
-					uniform sampler2D entryPointCountSampler : register(s1),
-					uniform sampler2D allWeightsSampler   : register(s2)) : COLOR0
-{
-	float halfPixel = 0.5 / clusterCount;
-	float iCluster = input.tex.x + halfPixel;
-	int entryPointCount = tex2D(entryPointCountSampler, float2(iCluster, 0.25));
-	int currentEntryPoint = tex2D(entryPointCountSampler, float2(iCluster, 0.75));
-	//sum entrypoint weights
-	float weight = 0;
-	float clusterRad = 0;
-	for(int i = 0; i < entryPointCount; i++)
-	{
-		
-		float dataColumnWidth = 1.0 / (float)nRadionColumns;
-		int werx = currentEntryPoint % nRadionColumns;
-		int wery = currentEntryPoint / nRadionColumns;
-		float2 coord1 = float2((werx + 0.5) * dataColumnWidth, (wery  + 0.5) / 4096.0);
-		float2 coord2 = coord1 + float2(0.25 * dataColumnWidth, 0);
-		float w = tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r;
-		float radrad = tex2Dlod(radionSampler, float4(coord1, 0, 0)).a;		
-		weight += w * radrad;		
-		clusterRad += radrad;
-		currentEntryPoint++;
-	}	
-	
-	if(clusterRad >= 0)
-		weight /= clusterRad;
-	else
-		weight = 0;
-   
-	return weight;
-}
-
-void EntryPointDisplayVS(float4 position :POSITION0,
-						 float4 color :COLOR0,
-						 uniform float4x4 worldViewProj,
-						 out float4 hPos:POSITION,
-						 out float2 texCoord: TEXCOORD0)
-{
-	hPos = mul(worldViewProj, position);
-	texCoord = color.xy;
-}
-
-float4 EntryPointDisplayPS(float2 texCoord : TEXCOORD0,
-							uniform sampler2D weightTexture : register(s0)):COLOR0
-{
-	//return texCoord.y;
-	return texCoord.r;
-}
-							 
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PRMDemo.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PRMDemo.material	(revision 2337)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PRMDemo.material	(revision 2337)
@@ -0,0 +1,171 @@
+vertex_program GTP/PathMap_VS hlsl
+{
+   source PathMap.hlsl
+   entry_point vsWalk
+   target vs_2_0   
+}
+
+fragment_program GTP/PathMap_PS hlsl
+{
+   source PathMap.hlsl
+   entry_point psWalk
+   target ps_3_0
+   flow_control prefer
+}
+
+vertex_program GTP/PathMap_ComputeWeights_VS hlsl
+{
+   source PathMapWeightCompute.hlsl
+   entry_point vsComputeWeights
+   target vs_2_0   
+}
+
+fragment_program GTP/PathMap_ComputeWeights_PS hlsl
+{
+   source PathMapWeightCompute.hlsl
+   entry_point psComputeWeights
+   target ps_3_0   
+}
+
+fragment_program GTP/PathMap_ComputeWeights_Point_PS hlsl
+{
+   source PathMapWeightCompute.hlsl
+   entry_point psComputeWeightsPoint
+   target ps_3_0   
+}
+
+material GTP/PathMap_ComputeWeights
+{
+	technique
+	{
+		pass
+		{
+			depth_check off
+			depth_write off
+			cull_hardware none
+			scene_blend add
+			vertex_program_ref GTP/PathMap_ComputeWeights_VS
+			{
+				
+			}
+			fragment_program_ref GTP/PathMap_ComputeWeights_PS
+			{
+			}
+			texture_unit //entrypoint texture
+			{
+				filtering none
+			}
+			texture_unit shadow_map //stores distances
+   			{
+     			
+    			}
+		}
+		
+	}
+}
+
+material GTP/PathMap_ComputeWeights_Point
+{
+	technique
+	{
+		pass
+		{
+			depth_check off
+			depth_write off
+			cull_hardware none
+			scene_blend add
+			vertex_program_ref GTP/PathMap_ComputeWeights_VS
+			{
+				
+			}
+			fragment_program_ref GTP/PathMap_ComputeWeights_Point_PS
+			{
+			}
+			texture_unit //entrypoint texture
+			{
+				filtering none
+			}
+			texture_unit shadow_map //stores distances
+   			{
+     			
+    			}
+		}
+		
+	}
+}
+
+fragment_program GTP/PathMap_SumWeights_PS hlsl
+{
+   source PathMapWeightCompute.hlsl
+   entry_point psSumWeights
+   target ps_3_0
+   flow_control prefer     
+}
+
+material GTP/PathMap_SumWeights
+{
+	technique
+	{
+		pass
+		{			
+			depth_check off
+			cull_hardware none
+			vertex_program_ref GTP/PathMap_ComputeWeights_VS
+			{
+				
+			}
+			fragment_program_ref GTP/PathMap_SumWeights_PS
+			{
+			}
+			texture_unit //entrypoint texture
+			{
+				filtering none
+			}
+			texture_unit //entrypoint weight texture
+			{
+				filtering none
+			}
+			texture_unit //cluster length
+			{
+				filtering none
+			}
+		}
+		
+	}
+}
+
+vertex_program GTP/EPDisplayVS hlsl
+{
+   source PathMapWeightCompute.hlsl
+   entry_point EntryPointDisplayVS
+   target vs_2_0   
+}
+fragment_program GTP/EPDisplayPS hlsl
+{
+   source PathMapWeightCompute.hlsl
+   entry_point EntryPointDisplayPS
+   target ps_2_0   
+}
+
+material GTP/PM/EPBillboards
+{
+ technique
+ {
+   pass
+   {
+		polygon_mode points
+		point_size 10
+		vertex_program_ref GTP/EPDisplayVS
+		{
+			param_named_auto worldViewProj worldviewproj_matrix 	
+		}
+		fragment_program_ref GTP/EPDisplayPS
+		{
+		}
+    	texture_unit
+    	{  
+	    	filtering none   
+    	}
+   }
+  }
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PathMapWeightCompute.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PathMapWeightCompute.hlsl	(revision 2337)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PathMapWeightCompute.hlsl	(revision 2337)
@@ -0,0 +1,175 @@
+#define SAMPLECUTDIST2 0.01
+#define WEIGHTCUTOFF   0.01
+#define DIST_BIAS      0.005
+
+uniform int nRadionColumns;
+uniform float3 lightPos;
+uniform float3 lightDir;
+uniform float lightPower;
+uniform float4 lightColor;
+uniform float clusterCount;
+uniform float4x4 lightViewProj;
+uniform float lightFarPlane;
+uniform float4 lightAttenuation;
+uniform float spotLightFalloff;
+uniform float lightAngleCos;
+
+struct vsInputComputeWeights
+{
+    float4	pos			: POSITION;
+    float2	tex			: TEXCOORD0;
+};
+
+struct vsOutputComputeWeights
+{
+    float4	pos			: POSITION;
+    float2	tex			: TEXCOORD0;
+};
+
+vsOutputComputeWeights
+	vsComputeWeights(vsInputComputeWeights input)
+{
+    vsOutputComputeWeights output = (vsOutputComputeWeights)0;
+    output.pos = input.pos;
+    output.tex = (input.pos + 1.0) / 2.0;
+    //output.tex = input.tex;
+    output.tex.y = 1.0 - output.tex.y;
+   
+    return output;
+}
+
+float4 psComputeWeights(vsOutputComputeWeights input,
+						uniform sampler2D radionSampler : register(s0),
+						uniform sampler2D shadowMap : register(s1)) : COLOR0
+{
+	float dataColumnWidth = 1.0 / (float)nRadionColumns;
+	int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096;
+	int werx = bushIndex % nRadionColumns;
+	int wery = bushIndex / nRadionColumns;
+	float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
+	float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
+	dir = normalize(dir);
+	
+	float3 diff = lightPos - pos;
+	float dist2 = dot(diff, diff);
+	float dist = sqrt(dist2);
+	diff = normalize(diff);
+	float cosb = max(dot(dir, diff), 0);	
+	
+	float visibility = 1;
+	float4 lightVPos = mul(lightViewProj, float4(pos,1));
+	
+	if( lightVPos.z > 0.0)
+	{
+		lightVPos /= lightVPos.w;
+		float d = length(lightVPos.xy);
+	
+		if(d <= 1.0)
+		{
+
+		float dist = sqrt(dist2); 
+		float distNorm = dist / lightFarPlane;
+		lightVPos.xy = (lightVPos.xy + 1.0) / 2.0;
+		lightVPos.y = 1.0 - lightVPos.y;
+		float storedDist = tex2D(shadowMap, lightVPos.xy).r;
+		dist -= DIST_BIAS;
+		visibility = (distNorm <= storedDist);  
+		
+		}
+	}
+	
+	float spotFalloff = (dot(normalize(-diff), normalize(lightDir)) - lightAngleCos) / (1.0 - lightAngleCos);
+	spotFalloff = pow(saturate(spotFalloff), spotLightFalloff);
+
+	
+	visibility *= spotFalloff / (lightAttenuation.y + dist * lightAttenuation.z + dist * dist * lightAttenuation.w);
+
+	
+	float4 ret = visibility * cosb * lightPower * lightColor;
+	return ret;
+}
+
+float4 psComputeWeightsPoint(vsOutputComputeWeights input,
+						uniform sampler2D radionSampler : register(s0),
+						uniform samplerCUBE shadowMap : register(s1)) : COLOR0
+{
+	float dataColumnWidth = 1.0 / (float)nRadionColumns;
+	int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096;
+	int werx = bushIndex % nRadionColumns;
+	int wery = bushIndex / nRadionColumns;
+	float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
+	float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
+	dir = normalize(dir);
+	
+	float3 diff = lightPos - pos;
+	float dist2 = dot(diff, diff);
+	float dist = sqrt(dist2);
+	diff = normalize(diff);
+	float cosb = max(dot(dir, diff), 0);	
+	
+	float visibility = 1;
+	float4 lightVPos = mul(lightViewProj, float4(pos,1));
+	
+	float distNorm = dist / lightFarPlane;
+	float storedDist = texCUBE(shadowMap, float3(-diff.xy, diff.z)).r;
+	dist -= DIST_BIAS;
+	visibility = (distNorm <= storedDist);  
+			
+	visibility *=  1.0 / (lightAttenuation.y + dist * lightAttenuation.z + dist * dist * lightAttenuation.w);
+	
+	float4 ret = visibility * cosb * lightPower * lightColor;
+	return ret;
+}
+
+float4 psSumWeights(vsOutputComputeWeights input,
+					uniform sampler2D radionSampler       : register(s0),
+					uniform sampler2D entryPointCountSampler : register(s1),
+					uniform sampler2D allWeightsSampler   : register(s2)) : COLOR0
+{
+	float halfPixel = 0.5 / clusterCount;
+	float iCluster = input.tex.x + halfPixel;
+	int entryPointCount = tex2D(entryPointCountSampler, float2(iCluster, 0.25));
+	int currentEntryPoint = tex2D(entryPointCountSampler, float2(iCluster, 0.75));
+	//sum entrypoint weights
+	float3 weight = 0;
+	float clusterRad = 0;
+	for(int i = 0; i < entryPointCount; i++)
+	{
+		
+		float dataColumnWidth = 1.0 / (float)nRadionColumns;
+		int werx = currentEntryPoint % nRadionColumns;
+		int wery = currentEntryPoint / nRadionColumns;
+		float2 coord1 = float2((werx + 0.5) * dataColumnWidth, (wery  + 0.5) / 4096.0);
+		float2 coord2 = coord1 + float2(0.25 * dataColumnWidth, 0);
+		float3 w = tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).rgb;
+		float radrad = tex2Dlod(radionSampler, float4(coord1, 0, 0)).a;		
+		weight += w * radrad;		
+		clusterRad += radrad;
+		currentEntryPoint++;
+	}	
+	
+	if(clusterRad >= 0)
+		weight /= clusterRad;
+	else
+		weight = 0;
+   
+	return float4(weight, 1);
+}
+
+void EntryPointDisplayVS(float4 position :POSITION0,
+						 float4 color :COLOR0,
+						 uniform float4x4 worldViewProj,
+						 out float4 hPos:POSITION,
+						 out float2 texCoord: TEXCOORD0)
+{
+	hPos = mul(worldViewProj, position);
+	texCoord = color.xy;
+}
+
+float4 EntryPointDisplayPS(float2 texCoord : TEXCOORD0,
+							uniform sampler2D weightTexture : register(s0)):COLOR0
+{
+	//return texCoord.y;
+	return texCoord.r;
+}
+							 
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PathMap.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PathMap.hlsl	(revision 2337)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPathMap/PathMap.hlsl	(revision 2337)
@@ -0,0 +1,62 @@
+uniform float4x4 WorldViewProj;
+uniform float4 prmAtlasTilesHalfPixel;
+uniform sampler2D filteredAtlasSampler : register(s0);
+uniform sampler2D clusterWeightIndexSampler : register(s1);
+uniform sampler2D clusterWeightSampler : register(s2);
+uniform sampler2D colorSampler : register(s3);
+uniform float allClusterCount; 
+uniform float clusterCount;
+
+struct vsInputWalk
+{
+    float4 pos			: POSITION;
+    float2 tex			: TEXCOORD1;
+    float2 texAtlas		: TEXCOORD2;
+};
+
+struct vsOutputWalk
+{
+    float4 pos			: POSITION;
+    float2 tex			: TEXCOORD0;
+    float2 texAtlas		: TEXCOORD1;
+};
+
+
+vsOutputWalk vsWalk(vsInputWalk input)
+{
+	vsOutputWalk output = (vsOutputWalk)0;
+	output.pos = mul(WorldViewProj, input.pos);
+	output.tex = input.tex;
+	output.texAtlas = input.texAtlas;	
+	return output;
+}
+
+float4	psWalk(vsOutputWalk input) : COLOR
+{
+	int2 prmAtlasTiles = prmAtlasTilesHalfPixel.xy;
+	float2 atlasHalfPixel = prmAtlasTilesHalfPixel.zw;
+	
+	float3 col = 0;
+	for(int iCluster = 0; iCluster < 32; iCluster++)
+	{
+		float2 prmTexPos = float2(
+			(input.texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x,
+			1.0 - (input.texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y) + atlasHalfPixel;
+
+		float weightIndex = tex2D(clusterWeightIndexSampler, float2(((float)iCluster + 0.5) / clusterCount, 0.5)).r;
+		float3 weight = tex2D(clusterWeightSampler, float2((weightIndex + 0.5)/allClusterCount, 0.5)).rgb;
+		//weight = 0.0002 + 0.000000000001 * weight;
+		float3 val = tex2D(filteredAtlasSampler, prmTexPos).xyz;
+		if(length(val - float3(1,1,1))== 0)
+		val = 0;
+		col += val.xyz * weight;		
+	}
+	
+	float3 color = tex2D(colorSampler, input.tex).rgb;
+
+	return float4(col * color, 1);
+
+
+	//return float4(col,1) * 0.0000000000001 + tex2D(filteredAtlasSampler, float2(input.texAtlas.x / 32.0, input.texAtlas.y));
+}
+
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.material	(revision 2301)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.material	(revision 2337)
@@ -117,4 +117,66 @@
 				use_triangles	true
 				blur_caustic_cubemap true				
+			}
+			
+		 }      
+	 vertex_program_ref GTP/Basic/Shaded_VS
+     	 {       
+            param_named_auto WorldViewProj worldviewproj_matrix 
+    	    param_named_auto World world_matrix
+    	    param_named_auto WorldInv inverse_world_matrix
+     	 } 
+	 fragment_program_ref GTP/EnvMap/Localized_Refraction_PS
+     	 { 
+		    param_named_auto cameraPos camera_position
+            param_named lastCenter float3 0 0 0
+            param_named sFresnel float 0.1
+<<<<<<< .mine
+            param_named sRefraction float 0.85
+=======
+            param_named sRefraction float 0.8
+>>>>>>> .r2314
+	     }		
+	     //Cube map for reflections and refractions	
+	     texture_unit
+	     {
+	    
+	     }
+	     //Cube map of distances
+	     texture_unit
+	     {
+	   	filtering none
+	     }
+	  }
+   }
+}
+
+material GTP/Caustic/Glass_PointSprite
+{
+   technique 
+   {   
+      pass 
+      { 
+		 IllumTechniques
+		 {
+			RenderTechnique ColorCubeMap
+			{
+				update_interval		0
+				update_all_face true									
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		0
+				update_all_face true										
+			}
+			RenderTechnique CausticCaster
+			{
+				attenuation	1000
+				update_interval	1
+				update_all_face true
+				photonmap_resolution 64
+				caustic_cubemap_resolution 256
+				photon_map_material	GTP/Caustic/PhotonMap_HitEnv
+				caustic_map_material	GTP/Caustic/CauCube_PointSprite
+				blur_caustic_cubemap false
 			}
 			
@@ -146,60 +208,2 @@
    }
 }
-
-material GTP/Caustic/Glass_PointSprite
-{
-   technique 
-   {   
-      pass 
-      { 
-		 IllumTechniques
-		 {
-			RenderTechnique ColorCubeMap
-			{
-				update_interval		0
-				update_all_face true									
-			}
-			RenderTechnique DistanceCubeMap
-			{
-				update_interval		0
-				update_all_face true										
-			}
-			RenderTechnique CausticCaster
-			{
-				attenuation	1000
-				update_interval	1
-				update_all_face true
-				photonmap_resolution 64
-				caustic_cubemap_resolution 256
-				photon_map_material	GTP/Caustic/PhotonMap_HitEnv
-				caustic_map_material	GTP/Caustic/CauCube_PointSprite
-				blur_caustic_cubemap false
-			}
-			
-		 }      
-	 vertex_program_ref GTP/Basic/Shaded_VS
-     	 {       
-            param_named_auto WorldViewProj worldviewproj_matrix 
-    	    param_named_auto World world_matrix
-    	    param_named_auto WorldInv inverse_world_matrix
-     	 } 
-	 fragment_program_ref GTP/EnvMap/Localized_Refraction_PS
-     	 { 
-		    param_named_auto cameraPos camera_position
-            param_named lastCenter float3 0 0 0
-            param_named sFresnel float 0.1
-            param_named sRefraction float 0.8
-	     }		
-	     //Cube map for reflections and refractions	
-	     texture_unit
-	     {
-	    
-	     }
-	     //Cube map of distances
-	     texture_unit
-	     {
-	   	filtering none
-	     }
-	  }
-   }
-}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuseSimple/GTPDiffuseSimpe.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuseSimple/GTPDiffuseSimpe.material	(revision 2337)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuseSimple/GTPDiffuseSimpe.material	(revision 2337)
@@ -0,0 +1,93 @@
+fragment_program GTP/Diffuse/ReduceCubeMapSimple_PS hlsl
+{
+	source GTPDiffuseSimple.hlsl
+	entry_point ReduceCubeMap_PS
+	target ps_3_0
+	//flow_control avoid
+}
+
+
+material GTP/Diffuse/ReduceCubeMap
+{
+ technique 
+ { 
+      pass 
+      { 
+         vertex_program_ref GTP/Basic/MPos_NoTransform_VS
+         {       
+           
+         } 
+	 fragment_program_ref GTP/Diffuse/ReduceCubeMapSimple_PS
+         { 
+		  param_named nFace int 0        
+         }
+         texture_unit
+	 {
+			
+	 }
+      }
+ }
+}
+
+fragment_program GTP/Diffuse/Poly2PointSimple_PS hlsl
+{
+	source GTPDiffuseSimple.hlsl
+	entry_point Diffuse_Poly2Point_PS
+	target ps_3_0
+	//flow_control prefer
+}
+
+
+material GTP/Diffuse/Poly2PointSimple
+{ 
+   technique 
+   { 
+      pass 
+      { 
+		
+		IllumTechniques
+		{
+			
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		1
+				update_all_face		false
+				distance_calc		false
+				face_angle_calc		false
+				resolution			64						
+			}
+			RenderTechnique ReducedColorCubeMap
+			{
+				update_interval		1
+				reduced_resolution 2
+				resolution 64
+				distance_calc false
+				face_angle_calc false
+				update_all_face		false
+			}
+		}      
+
+		vertex_program_ref GTP/Basic/Shaded_VS
+		{       
+			param_named_auto WorldViewProj worldviewproj_matrix 
+    		param_named_auto WorldInv      inverse_world_matrix  
+    		param_named_auto World         world_matrix
+        
+		} 
+		fragment_program_ref GTP/Diffuse/Poly2PointSimple_PS
+		{ 
+			param_named lastCenter float3 0 0 0
+		} 		
+		//Cube map for reflections and refractions	
+		texture_unit
+		{
+			
+		}
+		//Cube map of distances
+		texture_unit
+		 {
+		  
+		 }
+	 }
+   }
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuseSimple/GTPDiffuseSimple.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuseSimple/GTPDiffuseSimple.hlsl	(revision 2337)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuseSimple/GTPDiffuseSimple.hlsl	(revision 2337)
@@ -0,0 +1,154 @@
+
+#define CUBEMAP_SIZE 64
+#define REDUCED_CUBEMAP_SIZE 2
+#define RATE 32
+
+float4 readCubeMap(samplerCUBE cm, float3 coord)		
+{
+	float4 color = texCUBElod( cm, float4(coord.xy, -coord.z, 0) );
+	color.a = 1;
+	return color;
+}
+
+float readDistanceCubeMap(samplerCUBE dcm, float3 coord)		
+{
+	float dist = texCUBElod(dcm, float4(coord.xy, - coord.z, 0)).r;
+	if(dist == 0) dist = 1000000; ///sky
+	return dist;
+}
+
+////////////////////////////
+/// Reduce cube map shader
+///////////////////////////
+struct MPos_OUT
+{
+ float4 VPos : POSITION;
+ float4 MPos : TEXCOORD0;
+};
+
+float4 ReduceCubeMap_PS(MPos_OUT IN,
+						uniform int nFace,
+						uniform samplerCUBE EnvironmentMapSampler : register(s0) ) : COLOR
+{  
+   float4 color = 0;
+   float3 dir;
+  
+   for (int i = 0; i < RATE/2; i+=1)
+     for (int j = 0; j < RATE/2; j+=1)
+    {
+		float2 pos;
+		pos.x = IN.MPos.x + (4*i + 2)/(float)CUBEMAP_SIZE;
+		pos.y = IN.MPos.y - (4*j + 2)/(float)CUBEMAP_SIZE;	// y=-u
+
+		// "scrambling"
+		if (nFace == 0)	dir = float3(1, pos.y, -pos.x);
+		if (nFace == 1) dir = float3(-1, pos.y, pos.x);
+		if (nFace == 2) dir = float3(pos.x, 1, -pos.y);
+		if (nFace == 3) dir = float3(pos.x, -1, pos.y);
+		if (nFace == 4) dir = float3(pos.x, pos.y, 1);
+		if (nFace == 5) dir = float3(-pos.x, pos.y,-1);
+
+		color += texCUBE( EnvironmentMapSampler, dir);
+    }
+ 
+	return color / (RATE * RATE / 4.0);		
+}
+
+////////////////
+/// Diffuse
+///////////////
+
+/// Polygon to point form factor
+
+float4 Poly2Point_Contr(float3 L, float3 L1, float3 L2, float3 L3, float3 L4, float3 pos, float3 N, samplerCUBE cubemap)
+{
+	float d;
+	//d = texCUBE(cubemap, L).a;	
+	d = readDistanceCubeMap(cubemap, L1);	
+	L1 = d * normalize(L1);
+	d = readDistanceCubeMap(cubemap, L2);	
+	L2 = d * normalize(L2);
+	d = readDistanceCubeMap(cubemap, L3);	
+	L3 = d * normalize(L3);
+	d = readDistanceCubeMap(cubemap, L4);	
+	L4 = d * normalize(L4);
+		
+	
+    float3 r1 = normalize(L1 - pos);    
+    float3 r2 = normalize(L2 - pos);
+    float3 r3 = normalize(L3 - pos);
+    float3 r4 = normalize(L4 - pos);
+  /*     	
+	float tri1 = acos(dot(r1, r2)) * dot(cross(r1, r2), N);
+	float tri2 = acos(dot(r2, r3)) * dot(cross(r2, r3), N);
+	float tri3 = acos(dot(r3, r4)) * dot(cross(r3, r4), N);
+	float tri4 = acos(dot(r4, r1)) * dot(cross(r4, r1), N);
+  */
+  float3 crossP = cross(r1, r2);
+  float r = length(crossP);
+  float dd = dot(r1,r2);
+  float tri1 = acos(dd) * dot(crossP/r, N);
+  
+  crossP = cross(r2, r3);
+  r = length(crossP);
+  dd = dot(r1,r2);
+  float tri2 = acos(dd) * dot(crossP/r, N);
+  
+  crossP = cross(r3, r4);
+  r = length(crossP);
+  dd = dot(r1,r2);
+  float tri3 = acos(dd) * dot(crossP/r, N);
+  
+  crossP = cross(r4, r1);
+  r = length(crossP);
+  dd = dot(r1,r2);
+  float tri4= acos(dd) * dot(crossP/r, N);
+  
+  
+	return max(tri1 + tri2 + tri3 + tri4, 0);	
+	//return tri1 + tri2 + tri3 + tri4;	
+}
+
+struct Shaded_OUT
+{
+ float4 vPos : POSITION;
+ float4 wNormal : TEXCOORD0;
+ float4 wPos    : TEXCOORD1; 
+};
+
+float4 Diffuse_Poly2Point_PS( Shaded_OUT IN,
+           						uniform float3 lastCenter,
+           						uniform samplerCUBE SmallEnvMapSampler : register(s0),
+          						uniform samplerCUBE DistanceEnvMapSampler : register(s1)
+            ) : COLOR0
+{
+    float M = REDUCED_CUBEMAP_SIZE;
+	
+    float3 N = IN.wNormal.xyz;
+    N = normalize( N ); 
+    float3 pos = IN.wPos.xyz - lastCenter;
+    
+    float4 I = 0;									
+    float4 Le;										
+    
+    Le = float4(readCubeMap(SmallEnvMapSampler, float3(1,0,0)).rgb, 1);		
+    I += 0.5 * Le * Poly2Point_Contr( float3(1,0,0), float3(1,-0.5,0.5), float3(1,-0.5,-0.5), float3(1,0.5,-0.5), float3(1,0.5,0.5), pos, N, DistanceEnvMapSampler);		
+
+    Le = float4(readCubeMap(SmallEnvMapSampler, float3(-1,0,0)).rgb, 1);		
+    I += 0.5 * Le * Poly2Point_Contr( float3(-1,0,0), float3(-1,-0.5,-0.5), float3(-1,-0.5,0.5), float3(-1,0.5,0.5), float3(-1,0.5,-0.5), pos, N, DistanceEnvMapSampler);					
+   
+     Le = float4(readCubeMap(SmallEnvMapSampler, float3(0,1,0)).rgb, 1);		
+    I += 0.5 * Le * Poly2Point_Contr( float3( 0,1,0), float3( -0.5,1,0.5), float3(0.5,1,0.5), float3(0.5,1,-0.5), float3(-0.5,1,-0.5), pos, N, DistanceEnvMapSampler);	
+	
+    Le = float4(readCubeMap(SmallEnvMapSampler, float3(0,-1,0)).rgb, 1);		
+    I += 0.5 * Le * Poly2Point_Contr( float3( 0,-1,0), float3( -0.5,-1,-0.5), float3(0.5,-1,-0.5), float3(0.5,-1,0.5), float3(-0.5,-1,0.5), pos, N, DistanceEnvMapSampler);	
+
+    Le = float4(readCubeMap(SmallEnvMapSampler, float3(0,0,1)).rgb, 1);		
+    I += 0.5 * Le * Poly2Point_Contr( float3( 0,0,1), float3( -0.5,-0.5,1), float3(0.5,-0.5,1), float3(0.5,0.5,1), float3(-0.5,0.5,1), pos, N, DistanceEnvMapSampler);	
+
+    Le = float4(readCubeMap(SmallEnvMapSampler, float3(0,0,-1)).rgb, 1);		
+    I += 0.5 * Le * Poly2Point_Contr( float3( 0,0,-1), float3( 0.5,-0.5,-1), float3(-0.5,-0.5,-1), float3(-0.5,0.5,-1), float3(0.5,0.5,-1), pos, N, DistanceEnvMapSampler);	
+
+    float kd = 0.32;																		
+	return kd * I;
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.hlsl	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.hlsl	(revision 2337)
@@ -6,5 +6,5 @@
 float4 readCubeMap(samplerCUBE cm, float3 coord)		
 {
-	float4 color = texCUBElod( cm, float4(coord.xy, -coord.z, 1) );
+	float4 color = texCUBElod( cm, float4(coord.xy, -coord.z, 0) );
 	color.a = 1;
 	return color;
@@ -13,5 +13,5 @@
 float readDistanceCubeMap(samplerCUBE dcm, float3 coord)		
 {
-	float dist = texCUBElod(dcm, float4(coord.xy, - coord.z, 1)).r;
+	float dist = texCUBElod(dcm, float4(coord.xy, - coord.z, 0)).r;
 	if(dist == 0) dist = 1000000; ///sky
 	return dist;
@@ -26,5 +26,5 @@
  float4 MPos : TEXCOORD0;
 };
-
+/*
 float4 ReduceCubeMap_PS(MPos_OUT IN,
 						uniform int nFace,
@@ -54,5 +54,33 @@
 	return color / (RATE * RATE);		
 }
-
+*/
+
+float4 ReduceCubeMap_PS(MPos_OUT IN,
+						uniform int nFace,
+						uniform samplerCUBE EnvironmentMapSampler : register(s0) ) : COLOR
+{  
+   float4 color = 0;
+   float3 dir;
+  
+   for (int i = 0; i < RATE/2; i+=1)
+     for (int j = 0; j < RATE/2; j+=1)
+    {
+		float2 pos;
+		pos.x = IN.MPos.x + (4*i + 2)/(float)CUBEMAP_SIZE;
+		pos.y = IN.MPos.y - (4*j + 2)/(float)CUBEMAP_SIZE;	// y=-u
+
+		// "scrambling"
+		if (nFace == 0)	dir = float3(1, pos.y, -pos.x);
+		if (nFace == 1) dir = float3(-1, pos.y, pos.x);
+		if (nFace == 2) dir = float3(pos.x, 1, -pos.y);
+		if (nFace == 3) dir = float3(pos.x, -1, pos.y);
+		if (nFace == 4) dir = float3(pos.x, pos.y, 1);
+		if (nFace == 5) dir = float3(-pos.x, pos.y,-1);
+
+		color += texCUBE( EnvironmentMapSampler, dir);
+    }
+ 
+	return color / (RATE * RATE / 4.0);		
+}
 
 ////////////////
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.program
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.program	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.program	(revision 2337)
@@ -4,5 +4,5 @@
 	entry_point Diffuse_Poly2Point_PS
 	target ps_3_0
-	flow_control prefer
+	//flow_control prefer
 }
 
@@ -28,4 +28,4 @@
 	entry_point ReduceCubeMap_PS
 	target ps_3_0
-	flow_control prefer
+	//flow_control avoid
 }
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Phong.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Phong.hlsl	(revision 2294)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Phong.hlsl	(revision 2337)
@@ -115,5 +115,5 @@
   OUT.hPos = OUT.hPosition = mul(worldViewProj, position);
   OUT.wPos = mul(worldView, position).xyz;  
-  OUT.mNormal = mul(normal, worldViewI).xyz;
+  OUT.mNormal = normal;//mul(normal, worldViewI).xyz;
   //OUT.mNormal = normal;
   OUT.texCoord = texCoord;  
@@ -165,5 +165,4 @@
 	
     float3 N = IN.mNormal;
-    //float3 N = mul(worldViewIT, IN.mNormal);
     N = normalize( N ); 
     float3 pos = IN.wPos;
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl	(revision 2311)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl	(revision 2337)
@@ -106,5 +106,4 @@
     float4 pos = (IN.LightVPos / IN.LightVPos.w);
   	float d = length(pos.xy);
-    light = saturate((1.0 - d)/0.05);		
     if(d <= 1.0)
     {
@@ -126,7 +125,30 @@
     }
   }
-  else
-   light = 0;	
 	
   return shadowColor + (1 - shadowColor) * light;
 }
+
+
+float4 shadowMapDist_POINT_Variance(LightCPos_OUT IN,
+                              uniform float lightFarPlane,
+                              uniform samplerCUBE shadowMap) : COLOR
+{
+  float4 light = float4(1,1,1,1);
+  
+  float dist = length(IN.LightCPos.xyz) / lightFarPlane;
+  float4 storedDist = texCUBE(shadowMap, float3(IN.LightCPos.xy, -IN.LightCPos.z));
+  dist -= DIST_BIAS_VSM;
+  float lit_factor = light * (dist <= storedDist.r);	
+    	 
+  float M1 = storedDist.r;
+  float M2 = storedDist.g;
+  float v2 = min(max(M2 - M1 * M1, 0.0) +  DIST_EPSILON, 1.0);
+  float m_d = M1 - dist;
+  float pmax = v2 / (v2 + m_d * m_d);
+						
+  // Adjust the light color based on the shadow attenuation
+  light = max(lit_factor, pmax);    	
+  	
+  
+  return (shadowColor + (1 - shadowColor) * light);
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program	(revision 2294)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program	(revision 2337)
@@ -193,4 +193,11 @@
    source GTPShadowMap_PS.hlsl
    entry_point shadowMapDist_Variance
+   target ps_2_0
+}
+
+fragment_program GTP/Basic/SM/Dist_POINT_VSM_PS hlsl
+{
+   source GTPShadowMap_PS.hlsl
+   entry_point shadowMapDist_POINT_Variance
    target ps_2_0
 }
