Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.hlsl	(revision 2040)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.hlsl	(revision 2054)
@@ -25,5 +25,5 @@
 
 	// iteration
-	for( int i = 0; i < SECANT_ITERATIONCOUNT; i++ )
+	for( int i = 0; i < SECANT_ITERATIONCOUNT ; i++ )
 	{
 		float llp = length( l ) / readDistanceCubeMap( mp, l);		// |l|/|l|
@@ -43,13 +43,14 @@
 }
 
-struct ShadedTex_OUT
+
+struct Shaded_OUT
 {
  float4 vPos : POSITION;
- float4 texCoord : TEXCOORD0;
- float4 wNormal : TEXCOORD1;
- float4 wPos    : TEXCOORD2;  
+ float4 wNormal : TEXCOORD0;
+ float4 wPos    : TEXCOORD1; 
 };
 
-float4 EnvMap_Default_PS(ShadedTex_OUT IN,
+
+float4 EnvMap_Default_PS(Shaded_OUT IN,
 						uniform samplerCUBE CubeMap : register(s0),
 						uniform float3 cameraPos) : COLOR0
@@ -62,5 +63,5 @@
 }
 
-float4  EnvMap_Localized_Reflection_PS( ShadedTex_OUT IN,
+float4  EnvMap_Localized_Reflection_PS( Shaded_OUT IN,
 										uniform samplerCUBE CubeMap : register(s0),
 										uniform samplerCUBE DistanceMap : register(s1),
@@ -82,5 +83,5 @@
 }
 
-float4  EnvMap_Localized_Refraction_PS( ShadedTex_OUT IN,
+float4  EnvMap_Localized_Refraction_PS( Shaded_OUT IN,
 										uniform samplerCUBE CubeMap : register(s0),
 										uniform samplerCUBE DistanceMap : register(s1),
@@ -111,5 +112,5 @@
 
 
-float4 EnvMap_LocalizedMetal_PS(  ShadedTex_OUT IN,
+float4 EnvMap_LocalizedMetal_PS(  Shaded_OUT IN,
 									uniform samplerCUBE CubeMap : register(s0),
 									uniform samplerCUBE DistanceMap : register(s1),
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.material	(revision 2040)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.material	(revision 2054)
@@ -140,5 +140,6 @@
 				update_interval		0
 				update_all_face true
-				distance_calc true 3.5					
+				distance_calc false					
+				face_angle_calc false
 			}
 			RenderTechnique DistanceCubeMap
@@ -146,5 +147,6 @@
 				update_interval		0
 				update_all_face true
-				distance_calc true 3.5						
+				distance_calc false
+				face_angle_calc false
 			}			
 		 }      
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPParticles/GTP_Sprite.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPParticles/GTP_Sprite.hlsl	(revision 2024)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPParticles/GTP_Sprite.hlsl	(revision 2054)
@@ -100,7 +100,8 @@
 	    uniform float nearplane,
 	    uniform float farplane,
-		uniform sampler2D colorTexture : register(s0),
-		uniform sampler2D DepthMap : register(s1),
-		uniform sampler2D PlanckMap : register(s2)
+            uniform float4 color,
+	    uniform sampler2D colorTexture : register(s0),
+	    uniform sampler2D DepthMap : register(s1),
+	    uniform sampler2D PlanckMap : register(s2)
 		) : COLOR
 {
@@ -137,5 +138,5 @@
 	Color.rgb = tex2D( PlanckMap, Color.aa).rgb;
 	
-	return Color; 
+	return Color * color; 
 }
 
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPParticles/GTP_Particles.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPParticles/GTP_Particles.material	(revision 2024)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPParticles/GTP_Particles.material	(revision 2054)
@@ -31,43 +31,44 @@
    technique 
    { 
-   	pass 
+    pass 
     {    
-         IllumTechniques
-		 { 
+        IllumTechniques
+	{ 
          	RenderTechnique SphericalBillboard
-		 	{
+	        {
 		  		texture_unit_id		1					
-		 	}
-		 }	  
-		 scene_blend src_alpha one
-		 //scene_blend src_alpha one_minus_src_alpha
-		 depth_write off
-		 depth_check off	
-		 vertex_program_ref GTP/Particles/SB_Sprite_VS
-	     {       
-	        param_named_auto worldView worldview_matrix
-		    param_named_auto Proj projection_matrix
-		    param_named_auto width viewport_width 	
-		    param_named_auto height viewport_height 
-		 } 
-		 fragment_program_ref  GTP/Particles/SB_Sprite_PS
-	     { 
-	        param_named_auto farplane far_clip_distance	  
-		    param_named_auto nearplane near_clip_distance
-		 }
-		 texture_unit
-		 {
-		   anim_texture smokealpha.tga 32 2.0
-		   //texture flare.png
-		 }
-		 //scene depth texture
-		 texture_unit
-		 {
-		   filtering none
-		 }	
-		 texture_unit
-		 {
-		   texture planck.tga
-		 }
+	 	}
+	}	  
+	scene_blend src_alpha one
+	//scene_blend src_alpha one_minus_src_alpha
+	depth_write off
+	depth_check off	
+	vertex_program_ref GTP/Particles/SB_Sprite_VS
+	{       
+	    param_named_auto worldView worldview_matrix
+	    param_named_auto Proj projection_matrix
+	    param_named_auto width viewport_width 	
+	    param_named_auto height viewport_height 
+	} 
+	fragment_program_ref  GTP/Particles/SB_Sprite_PS
+	{ 
+	    param_named_auto farplane far_clip_distance	  
+	    param_named_auto nearplane near_clip_distance
+            param_named color float4 3 3 3 1
+	 }
+	 texture_unit
+	 {
+	   anim_texture smokealpha.tga 32 2.0
+	   //texture flare.png
+	 }
+	 //scene depth texture
+	 texture_unit
+	 {
+	   filtering none
+	 }	
+	 texture_unit
+	 {
+	   texture planck.tga
+	 }
     }
    }
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.material	(revision 2040)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.material	(revision 2054)
@@ -40,9 +40,9 @@
      param_named_auto WorldView     worldview_matrix
      param_named_auto Proj          projection_matrix
-     param_named CauSpriteSize      float 20.0
+     param_named CauSpriteSize      float 20
    } 
    fragment_program_ref GTP/Caustic/CauCube_PointSprite_PS
    {
-     param_named CausticColor float4          0.7 0.7 0.5 0.15
+     param_named CausticColor float4          0.7 0.7 0.5 0.3
    }
    texture_unit
@@ -96,16 +96,14 @@
 			{
 				update_interval		0
-				update_all_face true
-				distance_calc true 3.5					
+				update_all_face true									
 			}
 			RenderTechnique DistanceCubeMap
 			{
 				update_interval		0
-				update_all_face true
-				distance_calc true 3.5						
+				update_all_face true										
 			}
 			RenderTechnique CausticCaster
 			{
-				attenuation	0
+				attenuation	1000
 				photonmap_resolution 32
 				caustic_cubemap_resolution 256
@@ -118,5 +116,5 @@
 			
 		 }      
-	     vertex_program_ref GTP/Basic/ShadedTex_VS
+	 vertex_program_ref GTP/Basic/ShadedTex_VS
      	 {       
             param_named_auto WorldViewProj worldviewproj_matrix 
@@ -124,5 +122,5 @@
     	    param_named_auto WorldInv inverse_world_matrix
      	 } 
-	     fragment_program_ref GTP/EnvMap/Localized_Refraction_PS
+	 fragment_program_ref GTP/EnvMap/Localized_Refraction_PS
      	 { 
 		    param_named_auto cameraPos camera_position
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.hlsl	(revision 2024)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.hlsl	(revision 2054)
@@ -256,9 +256,11 @@
 
 	if(mydist > dist + EPSILON) caustic = 0;
-	//caustic.rgb *= max(attenuation - mydist, 0.0) / attenuation;
+	
+        caustic.rgb *= max(attenuation - mydist, 0.0) / attenuation;
 			
 	Color = caustic;
-	Color += attenuation;
-	Color.a = 1;	
+	//Color += attenuation * 0.000000000001;
+	Color.a = 1;
+
 	return Color;
 }
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 2054)
@@ -0,0 +1,416 @@
+
+#define CUBEMAP_SIZE 128
+#define REDUCED_CUBEMAP_SIZE 4
+#define RATE 32
+
+float4 readCubeMap(samplerCUBE cm, float3 coord)		
+{
+	float4 color = texCUBElod( cm, float4(coord.xy, -coord.z, 1) );
+	color.a = 1;
+	return color;
+}
+
+float readDistanceCubeMap(samplerCUBE dcm, float3 coord)		
+{
+	float dist = texCUBElod(dcm, float4(coord.xy, - coord.z, 1)).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; i++)
+     for (int j = 0; j < RATE; j++)
+    {
+		float2 pos;
+		pos.x = IN.MPos.x + (2*i + 1)/(float)CUBEMAP_SIZE;
+		pos.y = IN.MPos.y - (2*j + 1)/(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);		
+}
+
+
+////////////////
+/// 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).r;	
+	L1 = d * normalize(L1);
+	d = readDistanceCubeMap(cubemap, L2).r;	
+	L2 = d * normalize(L2);
+	d = readDistanceCubeMap(cubemap, L3).r;	
+	L3 = d * normalize(L3);
+	d = readDistanceCubeMap(cubemap, L4).r;	
+	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;									
+	float3 L1, L2, L3, L4, L;						
+	float4 Le;										
+	float width = 1.0 / M;							
+	float width2 = width * 2;
+	float d; 
+	
+	for (float x = 1; x < M; x++)			
+	 for (float y = 1; y < M; y++)										
+	 {																
+		float2 p, tpos; 
+	    tpos.x = x * width;
+	    tpos.y = y * width;
+	    
+	    p = tpos.xy;    
+	    p = 2.0 * p - 1.0; //-1..1
+	    	    	    
+		L1 = float3(p.x - width, p.y - width, 1);	
+		L2 = float3(p.x + width, p.y - width, 1);	
+		L3 = float3(p.x + width, p.y + width, 1);	
+		L4 = float3(p.x - width, p.y + width, 1);
+		L = float3(p.x, p.y, 1);
+		Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1);
+		
+		I += 0.5 * Le * Poly2Point_Contr( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);			
+			
+	}																			
+	
+	for (float x = 1; x < M; x++)			
+	 for (float y = 1; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = x * width;	// 0..1
+	    tpos.y = y * width;	// 0..1
+	    
+	    p = tpos.xy;    
+	    p = 2.0 * p - 1.0; //-1..1
+	    	    	    
+		L4 = float3(p.x - width, p.y - width, -1);	
+		L3 = float3(p.x + width, p.y - width, -1);	
+		L2 = float3(p.x + width, p.y + width, -1);	
+		L1 = float3(p.x - width, p.y + width, -1);
+		L = float3(p.x, p.y, -1);
+		Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1);
+		
+		I += 0.5 * Le * Poly2Point_Contr( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);			
+	 }	
+	 
+	for (float x = 1; x < M; x++)			
+	 for (float y = 1; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = x * width;	// 0..1
+	    tpos.y = y * width;	// 0..1
+	    
+	    p = tpos.xy;    
+	    p = 2.0 * p - 1.0; //-1..1
+	    	    	    
+		L4 = float3(p.x - width, 1, p.y - width);
+		L3 = float3(p.x + width, 1, p.y - width);	
+		L2 = float3(p.x + width, 1, p.y + width);	
+		L1 = float3(p.x - width, 1, p.y + width);			
+		L = float3(p.x, 1, p.y);
+		Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1);
+		
+		I += 0.5 * Le * Poly2Point_Contr( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);			
+	 }		
+	 
+	for (float x = 1; x < M; x++)			
+	 for (float y = 1; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = x * width;	// 0..1
+	    tpos.y = y * width;	// 0..1
+	    
+	    p = tpos.xy;    
+	    p = 2.0 * p - 1.0; //-1..1
+	    	    	    
+		L1 = float3(p.x - width, -1, p.y - width);
+		L2 = float3(p.x + width, -1, p.y - width);	
+		L3 = float3(p.x + width, -1, p.y + width);	
+		L4 = float3(p.x - width, -1, p.y + width);			
+		L = float3(p.x, -1, p.y);
+		Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1);
+		
+		I += 0.5 * Le * Poly2Point_Contr( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);			
+	 }
+	 
+	 for (float x = 1; x < M; x++)			
+	 for (float y = 1; y < M; y++)										
+		{																
+		float2 p, tpos; 
+	    tpos.x = x * width;	// 0..1
+	    tpos.y = y * width;	// 0..1
+	    
+	    p = tpos.xy;    
+	    p = 2.0 * p - 1.0; //-1..1
+	    	    	    
+		L1 = float3(1, p.x - width, p.y - width);
+		L2 = float3(1, p.x + width, p.y - width);	
+		L3 = float3(1, p.x + width, p.y + width);	
+		L4 = float3(1, p.x - width, p.y + width);	
+		L = float3(1, p.x, p.y);
+		Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1);
+		
+		I += 0.5 * Le * Poly2Point_Contr( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);			
+	}
+	 
+	for (float x = 1; x < M; x++)			
+	 for (float y = 1; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = x * width;	// 0..1
+	    tpos.y = y * width;	// 0..1
+	    
+	    p = tpos.xy;    
+	    p = 2.0 * p - 1.0; //-1..1
+	    	    	    
+		L4 = float3(-1, p.x - width, p.y - width);
+		L3 = float3(-1, p.x + width, p.y - width);	
+		L2 = float3(-1, p.x + width, p.y + width);	
+		L1 = float3(-1, p.x - width, p.y + width);	
+		L = float3(-1, p.x, p.y);
+		Le = float4(readCubeMap(SmallEnvMapSampler, L).rgb, 1);
+		
+		I += 0.5 * Le * Poly2Point_Contr( L, L1, L2, L3, L4, pos, N, DistanceEnvMapSampler);				
+	 }
+	 float kd = 0.32;																		
+	return kd * I;
+}
+
+/// Point to point form factor
+
+float4 Point2Point_Contr(float3 N, float3 Nl, float3 pos, float3 L, samplerCUBE cubemap, samplerCUBE distmap)
+{
+	Nl = normalize(Nl);
+	L = normalize(L);
+	float4 Le = readCubeMap(cubemap, L);
+	float d = readDistanceCubeMap(distmap, L);
+	float3 Lpos = L * d;
+	float3 Ldir = Lpos - pos;
+	float dist = 4 * dot(Ldir, Ldir);
+	Ldir = normalize(Ldir);
+		
+	return Le * (max(dot(N, Ldir),0) * dot(Nl, -1 * Ldir)) / dist;	
+}
+
+float4 Diffuse_Point2Point_PS( Shaded_OUT IN,
+							uniform float3 lastCenter,
+							uniform samplerCUBE SmallEnvMapSampler : register(s0),
+							uniform samplerCUBE DistanceEnvMapSampler : register(s1)) : COLOR			
+{		
+	float M = REDUCED_CUBEMAP_SIZE;
+	
+    float3 N = IN.wNormal.xyz;
+    N = normalize( N ); 
+    float3 pos = IN.wPos.xyz - lastCenter;																		
+													
+    float4 I = 0;									
+	float3 L;						
+	float4 Le;										
+	float width = 1.0 / M;
+	float d;	
+	
+	float kd = 1.0;																		
+		
+	for (float x = 0.5; x < M; x++)			
+	 for (float y = 0.5; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = x * width;
+	    tpos.y = y * width;
+	    
+	    p = tpos.xy;    
+	    p = 2.0 * p - 1.0; //-1..1
+	    	    	    
+		I += Point2Point_Contr(N, float3(0,0,-1), pos, float3(p.x, p.y, 1), SmallEnvMapSampler, DistanceEnvMapSampler);
+		I += Point2Point_Contr(N, float3(0,0,1), pos, float3(-p.x, p.y, -1), SmallEnvMapSampler, DistanceEnvMapSampler);
+		I += Point2Point_Contr(N, float3(-1,0,0), pos, float3(1, p.y, -p.x), SmallEnvMapSampler, DistanceEnvMapSampler);
+		I += Point2Point_Contr(N, float3(1,0,0), pos, float3(-1, p.y, p.x), SmallEnvMapSampler, DistanceEnvMapSampler);
+		I += Point2Point_Contr(N, float3(0,-1,0), pos, float3(p.x, 1, -p.y), SmallEnvMapSampler, DistanceEnvMapSampler);
+		I += Point2Point_Contr(N, float3(0,1,0), pos, float3(p.x, -1, p.y), SmallEnvMapSampler, DistanceEnvMapSampler);
+	}
+																		
+	return kd * I;															
+}
+
+/// Disc to point form factor
+
+float4 Disc2Point_Contr(float3 L, float3 pos, float3 N, float3 V, samplerCUBE SmallEnvMapSampler, samplerCUBE DistanceEnvMapSampler)	// Phong-Blinn
+// L: a hossza lényeges (az egységkocka faláig ér)
+{
+   	float mindist = 1.0;
+    
+	float kd = 0.3;	// 0.3
+	float ks = 0;	// 0.5
+	float shininess = 10;
+	
+	float l = length(L);
+	L = normalize(L);
+
+	//dw
+	float dw = 4 / (REDUCED_CUBEMAP_SIZE*REDUCED_CUBEMAP_SIZE*l*l*l + 4/3.1416f);
+	//Lin
+	float4 Lin = readCubeMap(SmallEnvMapSampler, L);
+	//r
+	float doy = readDistanceCubeMap(DistanceEnvMapSampler, L);
+	float dxy = length(L * doy - pos);
+	
+	dxy = max(mindist, dxy);
+		
+
+	//dws
+	float dws = (doy*doy * dw) / (dxy*dxy*(1 - dw/3.1416f) + doy*doy*dw/3.1416f);	// localization:
+	//float dws = dw;
+	
+	//L = L * doy - pos;	// L: x->y, az objektumtól induljon, ne a középpontból
+	L = normalize(L);
+	float3 H = normalize(L + V);	// felezõvektor
+
+	float a = kd * max(dot(N,L),0) + 
+			  ks * pow(max(dot(N,H),0), shininess); // diffuse + specular
+
+	// 1.: eddigi
+	//return Lin * a * dws;
+	
+	float ctheta_in = dot(N,L);
+	float ctheta_out = dot(N,V);	
+	
+	return Lin * a * dws;		
+}
+
+float4 Diffuse_Disc2Point_PS(Shaded_OUT IN,
+							uniform float3 lastCenter,
+							uniform float3 cameraPos,
+							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 V = normalize(IN.wPos.xyz - cameraPos); 
+    float3 pos = IN.wPos.xyz - lastCenter;																		
+													
+    float4 I = 0;									
+	float3 L;						
+	float4 Le;										
+	float width = 1.0 / M;
+	float d;	
+			
+	for (float x = 0.5; x < M; x++)			
+	 for (float y = 0.5; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = x * width;
+	    tpos.y = y * width;
+	    
+	    p = tpos.xy;    
+	    p = 2.0 * p - 1.0; //-1..1
+	    
+	    float3 L;
+	    
+		L = float3(p.x, p.y, 1);
+		I += Disc2Point_Contr( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler);
+		
+		L = float3(p.x, p.y, -1);
+		I += Disc2Point_Contr( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler);
+		
+		L = float3(p.x, 1, p.y);
+		I += Disc2Point_Contr( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler);
+		
+		L = float3(p.x, -1, p.y);
+		I += Disc2Point_Contr( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler);
+		
+		L = float3(1, p.x, p.y);
+		I += Disc2Point_Contr( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler);
+		
+		L = float3(-1, p.x, p.y);
+		I += Disc2Point_Contr( L, pos, N, V, SmallEnvMapSampler, DistanceEnvMapSampler);
+	}
+	float kd = 1.0;
+	return kd * I;
+}
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 2054)
@@ -0,0 +1,31 @@
+fragment_program GTP/Diffuse/Poly2Point_PS hlsl
+{
+	source GTPDiffuse.hlsl
+	entry_point Diffuse_Poly2Point_PS
+	target ps_3_0
+	flow_control prefer
+}
+
+fragment_program GTP/Diffuse/Point2Point_PS hlsl
+{
+	source GTPDiffuse.hlsl
+	entry_point Diffuse_Point2Point_PS
+	target ps_3_0
+	//flow_control prefer
+}
+
+fragment_program GTP/Diffuse/Disc2Point_PS hlsl
+{
+	source GTPDiffuse.hlsl
+	entry_point Diffuse_Disc2Point_PS
+	target ps_3_0
+	//flow_control prefer
+}  
+
+fragment_program GTP/Diffuse/ReduceCubeMap_PS hlsl
+{
+	source GTPDiffuse.hlsl
+	entry_point ReduceCubeMap_PS
+	target ps_3_0
+	flow_control prefer
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.material	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/diffuse/GTPDiffuse.material	(revision 2054)
@@ -0,0 +1,185 @@
+material GTP/Diffuse/ReduceCubeMap
+{
+ technique 
+ { 
+      pass 
+      { 
+         vertex_program_ref GTP/Basic/MPos_NoTransform_VS
+         {       
+           
+         } 
+	 	 fragment_program_ref GTP/Diffuse/ReduceCubeMap_PS
+         { 
+		  param_named nFace int 0        
+         }
+         texture_unit
+		 {
+			
+		 }
+      }
+ }
+}
+
+material GTP/Diffuse/Poly2Point
+{ 
+   technique 
+   { 
+      pass 
+      { 
+		
+		IllumTechniques
+		{
+			
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		1
+				update_all_face		false
+				distance_calc		false
+				face_angle_calc		false
+				resolution			128						
+			}
+			RenderTechnique ReducedColorCubeMap
+			{
+				update_interval		1
+				reduced_resolution 4
+				resolution 128
+				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/Poly2Point_PS
+		{ 
+			param_named lastCenter float3 0 0 0
+		} 		
+		//Cube map for reflections and refractions	
+		texture_unit
+		{
+			
+		}
+		//Cube map of distances
+		texture_unit
+		 {
+		  
+		 }
+	 }
+   }
+}
+
+
+material GTP/Diffuse/Point2Point
+{ 
+   technique 
+   { 
+      pass 
+      { 
+		
+		IllumTechniques
+		{
+			
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		1
+				update_all_face		false
+				distance_calc		false
+				face_angle_calc		false
+				resolution			128						
+			}
+			RenderTechnique ReducedColorCubeMap
+			{
+				update_interval		1
+				reduced_resolution 4
+				resolution 128
+				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/Point2Point_PS
+		{ 
+			param_named lastCenter float3 0 0 0
+		} 		
+		//Cube map for reflections and refractions	
+		texture_unit
+		{
+			
+		}
+		//Cube map of distances
+		texture_unit
+		 {
+		  
+		 }
+	 }
+   }
+}
+
+material GTP/Diffuse/Disc2Point
+{ 
+   technique 
+   { 
+      pass 
+      { 
+		
+		IllumTechniques
+		{
+			
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		1
+				update_all_face		false
+				distance_calc		false
+				face_angle_calc		false
+				resolution			128						
+			}
+			RenderTechnique ReducedColorCubeMap
+			{
+				update_interval		1
+				reduced_resolution 4
+				resolution 128
+				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/Disc2Point_PS
+		{ 
+		    param_named_auto cameraPos camera_position
+			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/multibounce/multipleReflectionMinMax/GTPMultipleReflectionMinMax.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleReflectionMinMax/GTPMultipleReflectionMinMax.material	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleReflectionMinMax/GTPMultipleReflectionMinMax.material	(revision 2054)
@@ -0,0 +1,106 @@
+fragment_program GTP/MultiBounce/Reflection_MinMax_PS hlsl
+{
+	
+	source GTPMultipleReflection_MinMax.hlsl
+    entry_point MultipleReflectionPS
+	target ps_3_0
+	flow_control prefer
+}
+
+material GTP/MultiBounce/Reflector_MinMax
+{ 
+   technique 
+   { 
+      pass 
+      { 
+        //cull_hardware none
+		IllumTechniques
+		{
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+								
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				resolution 1024
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+				get_minmax true
+				min_var_name min
+				max_var_name max				
+			}
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				layer 1
+				texture_unit_id 2
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+				render_env false
+				render_self true
+				self_material GTP/MultiBounce/NormalDistanceCCW
+				get_minmax true
+				min_var_name min1
+				max_var_name max1			
+			}
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				layer 2
+				texture_unit_id 3
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+				render_env false
+				render_self true
+				self_material GTP/MultiBounce/NormalDistanceCW
+				get_minmax true
+				min_var_name min2
+				max_var_name max2
+			}				
+		 }
+		 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/MultiBounce/Reflection_MinMax_PS
+         { 
+			param_named_auto cameraPos camera_position						
+		 } 
+		
+		//Cube map of environment
+		texture_unit
+		{
+			//filtering none
+		}
+		//Cube map of environment distances
+		texture_unit
+		{
+			filtering none
+		}
+		
+		//Cube map of reflective object's normals and distances CCW
+		texture_unit
+		{
+			filtering none
+		}		
+		//Cube map of reflective object's normals and distances CW
+		texture_unit
+		{
+			filtering none
+		}
+	  }
+    }
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection.hlsl	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection.hlsl	(revision 2054)
@@ -0,0 +1,349 @@
+float4 readCubeMap(samplerCUBE cm, float3 coord)		
+{
+	float4 color = texCUBElod( cm, float4(coord.xy, - coord.z,0) );
+	return color;
+}
+
+float readDistanceCubeMap(samplerCUBE dcm, float3 coord)		
+{
+	float dist = texCUBElod(dcm, float4(coord.xy, - coord.z,0)).a;
+	return dist;
+}
+
+#define MAX_LIN_ITERATIONCOUNT 30  //80
+#define MIN_LIN_ITERATIONCOUNT 20  //60
+#define SECANT_ITERATIONCOUNT 1
+#define MAX_RAY_DEPTH 2
+
+void linearSearch(  float3 x, float3 R, float3 N, samplerCUBE mp,
+                    out float3 p,
+                    out float dl,
+                    out float dp,
+                    out float llp,
+                    out float ppp)
+{
+ float3 Ra = abs(R), xa = abs(x);
+ float xm =  max(max(xa.x,xa.y),xa.z);
+ float Rm = max(max(Ra.x,Ra.y),Ra.z);
+ float a = xm / Rm;
+ 
+ int shootL = 0, shootP = 0;          
+ bool found = false; 
+ 
+ float dt =  length(x / xm - R / Rm) * MAX_LIN_ITERATIONCOUNT;
+ dt = max(dt, MIN_LIN_ITERATIONCOUNT);
+ dt = 1.0 / dt;
+    
+ float t = 0.01;//dt;
+ float pa;
+ 
+ //Linear iteration
+ while(t <= 1.0 && !found)
+ {
+   dp = a * t / (1 - t);
+   p = x + R * dp;
+   pa = readDistanceCubeMap(mp, p);
+      
+   if(pa > 0)
+   {
+    ppp = length(p) / pa;
+    if(ppp < 1)
+      shootP = -1;
+    else 
+      shootP = 1;      
+    if(shootL * shootP == -1)
+      found = true;
+    else
+    {
+      shootL = shootP;
+      dl = dp;
+      llp = ppp;
+    }
+   }
+   else
+     shootL = 0;
+      
+   t += dt;  
+ }
+
+ if(!found)
+  p = float3(0,0,0);
+}
+
+
+void secantSearch(float3 x, float3 R, samplerCUBE mp, 
+	               float dl,
+	               float dp,
+	               float llp,
+	               float ppp,
+	               out float3 p)
+{
+  for(int i= 0; i < SECANT_ITERATIONCOUNT; i++)
+  {
+   float dnew;
+   dnew = dl + (dp - dl) * (1 - llp) / (ppp - llp);
+   p = x + R * dnew;
+   half pppnew = length(p) / readDistanceCubeMap(mp, p);
+   if(pppnew < 1)
+   {
+    llp = pppnew;
+    dl = dnew;
+   }
+   else
+   {
+    ppp = pppnew;
+    dp = dnew;
+   }
+  }
+}
+
+float3 Hit(float3 x, float3 R, float3 N, 
+           samplerCUBE mp1,
+           samplerCUBE mp2,
+           samplerCUBE mp3Color,
+           samplerCUBE mp3Dist,
+           out float4 Il, out float3 Nl)
+{
+ float dl1 = 0, dp1, llp1, ppp1;
+ float3 p1;
+ linearSearch(x, R, N, mp1, p1, dl1, dp1, llp1, ppp1);
+ float dl2 = 0, dp2, llp2, ppp2;
+ float3 p2;
+ linearSearch(x, R, N, mp2, p2, dl2, dp2, llp2, ppp2);
+ 
+ bool valid1 = dot(p1,p1) != 0;
+ bool valid2 = dot(p2,p2) != 0;
+		
+ float dl, dp, llp, ppp;
+ float3 p;
+ 
+ if(!valid1 && ! valid2)
+ {
+    linearSearch(x, R, N, mp3Dist, p, dl, dp, llp, ppp);
+    Il.a = 1; 
+    secantSearch(x, R, mp3Dist, dl, dp, llp, ppp, p);
+    Il.rgb =  Nl.rgb = readCubeMap(mp3Color, p).rgb;  
+ }
+ else
+ {
+    if( !valid2 || (valid1 && dp1 < dp2))
+    {
+     secantSearch(x, R, mp1, dl1, dp1, llp1, ppp1, p1);
+     Il.rgb =  Nl.rgb = readCubeMap(mp1, p1).rgb;
+     p = p1;
+    }
+    else
+    {
+     secantSearch(x, R, mp2, dl2, dp2, llp2, ppp2, p2);
+     Il.rgb =  Nl.rgb = readCubeMap(mp2, p2).rgb;
+     p = p2;
+    }
+    Il.a = 0;   
+ }
+ 
+ return p;
+}
+
+struct Shaded_OUT
+{
+ float4 vPos : POSITION;
+ float4 wNormal : TEXCOORD0;
+ float4 wPos    : TEXCOORD1; 
+};
+
+float4 MultipleReflectionPS(Shaded_OUT IN,
+							uniform samplerCUBE CubeMap : register(s0),
+							uniform samplerCUBE DistanceMap : register(s1),
+							uniform samplerCUBE NormDistMap1 : register(s2),
+							uniform samplerCUBE NormDistMap2 : register(s3),
+							uniform float3 cameraPos,
+							uniform float3 lastCenter) : COLOR0
+{	
+	 float4 I = float4(0,0,0,0);
+			
+	 float3 N = normalize(IN.wNormal.xyz);
+	 float3 x = IN.wPos.xyz - lastCenter;
+	 float3 V  = (IN.wPos.xyz - cameraPos);
+	 
+	 V = normalize(V);
+	 float3 l;
+
+		
+	//return readCubeMap(NormDistMap2, x).a /2.0 + 0.000000000001 * x.x;
+	  
+	 int depth = 0;
+	
+	 while(depth < MAX_RAY_DEPTH)
+	 {
+	   float3 R;  
+	   R = normalize(reflect( V, N));	  
+	  	
+	   float3 Nl;
+	   float4 Il = 0;
+	   l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl);
+	   if(Il.a == 0)
+	   {	   
+		  depth += 1;		 
+	   }
+	   else
+	   {
+		   I = Il;
+		   depth = MAX_RAY_DEPTH;
+	   }
+	   x = l;	   
+	   N = Nl;
+	   V = R;   
+	   
+	}
+	if(I.a == 0)
+	   I = readCubeMap(CubeMap, l);
+	
+	return I;
+}
+
+float4 MultipleRefractionPS(Shaded_OUT IN,
+							uniform samplerCUBE CubeMap : register(s0),
+							uniform samplerCUBE DistanceMap : register(s1),
+							uniform samplerCUBE NormDistMap1 : register(s2),
+							uniform samplerCUBE NormDistMap2 : register(s3),
+							uniform float3 cameraPos,
+							uniform float3 lastCenter,
+							uniform float sFresnel,
+							uniform float refIndex ) : COLOR0
+{
+	 float4 I = float4(0,0,0,0);
+			
+	 float3 N = normalize(IN.wNormal.xyz);
+	 float3 x = IN.wPos.xyz - lastCenter;
+	 float3 V  = (IN.wPos.xyz - cameraPos);
+	  V = normalize(V);
+	 
+	 float F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel);	 
+	
+	 float3 l;
+	 float4 Irefl;
+	 int depth = 0;
+	
+	 while(depth < MAX_RAY_DEPTH)
+	 {
+	    float3 R;  
+	   R = normalize(reflect( V, N));	  
+	  	
+	   float3 Nl;
+	   float4 Il;
+	   l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl);
+	   if(Il.a == 0)
+	   {
+		   depth += 1;		 
+	   }
+	   else
+	   {
+		   I = Il;
+		   depth = MAX_RAY_DEPTH;
+	   }
+	   x = l;	   
+	   N = Nl;
+	   V = R;   
+	   
+	}
+	if(I.a == 0)
+	   I = readCubeMap(CubeMap, l);
+	Irefl = I;
+	
+	{
+	float4 Irefr;
+	N = normalize(IN.wNormal.xyz);
+	x = IN.wPos.xyz - lastCenter;
+	V  = (IN.wPos.xyz - cameraPos);
+	depth = 0;
+	
+	while(depth < MAX_RAY_DEPTH)
+	{
+	  float3 R;  
+	  
+	  float ri = refIndex;
+	 
+	  if(dot(V,N) > 0)
+	  {
+		ri = 1.0 / ri;
+		N = -N;	    
+	  }
+	  R = refract( V, N, ri);
+	  if(dot(R,R) == 0) R = reflect( V, N); 
+					
+	  float3 Nl;
+	  float4 Il;
+	  l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl);
+	  if(Il.a == 0)
+	  {
+		   depth += 1;		 
+	  }
+	  else
+	  {
+		   I = Il;
+		   depth = MAX_RAY_DEPTH;
+	  }
+	  x = l;	   
+	  N = normalize(Nl);
+	  V = R;	   	   
+	}
+	
+	if(I.a == 0)
+	   I = readCubeMap(CubeMap, l);
+	Irefr = I;
+	    
+	I = Irefl * F + (1.0 - F) * Irefr;	
+    }
+ 	return I;
+}
+
+float4 MultipleRefractionPhotonMap_PS(Shaded_OUT IN,
+									uniform samplerCUBE DistanceMap : register(s0),
+									uniform samplerCUBE NormDistMap1 : register(s1),
+									uniform samplerCUBE NormDistMap2 : register(s2),
+									uniform float3 cameraPos,
+									uniform float3 lastCenter,
+									uniform float refIndex) : COLOR0
+{
+	float4 I = float4(0,0,0,0);
+		 
+	float3 N = normalize(IN.wNormal.xyz);
+	float3 x = IN.wPos.xyz - lastCenter;
+	float3 V  = (IN.wPos.xyz - cameraPos);
+	V = normalize(V);
+	float3 l;
+	int depth = 0;
+		
+	while(depth < MAX_RAY_DEPTH)
+	{
+	  float3 R;  
+	  
+	  float ri = refIndex;
+	 
+	  if(dot(V,N) > 0)
+	  {
+		ri = 1.0 / ri;
+		N = -N;	    
+	  }
+	  R = refract( V, N, ri);
+	  if(dot(R,R) == 0) R = reflect( V, N); 
+					
+	  float3 Nl;
+	  float4 Il;
+	  l = Hit(x, R, N, NormDistMap1, NormDistMap2, DistanceMap, DistanceMap, Il, Nl);
+	  if(Il.a == 0)
+	  {
+		   depth += 1;		 
+	  }
+	  else
+	  {
+		   I = Il;
+		   depth = MAX_RAY_DEPTH;
+	  }
+	  x = l;	   
+	  N = normalize(Nl);
+	  V = R;	   	   
+	}
+	
+	return float4(l,1);
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.program
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.program	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.program	(revision 2054)
@@ -0,0 +1,8 @@
+
+fragment_program GTP/MultiBounce/NormalDistancePS hlsl
+{
+	source MultiBounceShared.hlsl
+	entry_point NormalDistancePS
+	target ps_2_0
+} 
+
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleReflection/GTPMultipleReflection.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleReflection/GTPMultipleReflection.material	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleReflection/GTPMultipleReflection.material	(revision 2054)
@@ -0,0 +1,97 @@
+fragment_program GTP/MultiBounce/Reflection_PS hlsl
+{
+	
+	source GTPMultipleReflection.hlsl
+    entry_point MultipleReflectionPS
+	target ps_3_0
+	flow_control prefer
+}
+
+material GTP/MultiBounce/Reflector
+{ 
+   technique 
+   { 
+      pass 
+      { 
+        //cull_hardware none
+		IllumTechniques
+		{
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+								
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				resolution 1024
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true				
+			}
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				layer 1
+				texture_unit_id 2
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+				render_env false
+				render_self true
+				self_material GTP/MultiBounce/NormalDistanceCCW				
+			}
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				layer 2
+				texture_unit_id 3
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+				render_env false
+				render_self true
+				self_material GTP/MultiBounce/NormalDistanceCW			
+			}				
+		 }
+		 vertex_program_ref GTP/Basic/Shaded_CPos_VS
+    	 {       
+       	 	param_named_auto WorldViewProj worldviewproj_matrix 
+    		param_named_auto World         world_matrix
+    		param_named_auto WorldInv inverse_world_matrix  
+   		 }
+		 fragment_program_ref GTP/MultiBounce/Reflection_PS
+         { 
+			param_named_auto cameraPos camera_position						
+		 } 
+		
+		//Cube map of environment
+		texture_unit
+		{
+			//filtering none
+		}
+		//Cube map of environment distances
+		texture_unit
+		{
+			filtering none
+		}
+		
+		//Cube map of reflective object's normals and distances CCW
+		texture_unit
+		{
+			filtering none
+		}		
+		//Cube map of reflective object's normals and distances CW
+		texture_unit
+		{
+			filtering none
+		}
+	  }
+    }
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction2L/GTPMultipleRefraction2L.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction2L/GTPMultipleRefraction2L.hlsl	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction2L/GTPMultipleRefraction2L.hlsl	(revision 2054)
@@ -0,0 +1,278 @@
+float4 readCubeMap(samplerCUBE cm, float3 coord)		
+{
+	float4 color = texCUBElod( cm, float4(coord.xy, - coord.z,0) );
+	return color;
+}
+
+float readDistanceCubeMap(samplerCUBE dcm, float3 coord)		
+{
+	float dist = texCUBElod(dcm, float4(coord.xy, - coord.z,0)).a;
+	return dist;
+}
+
+#define MAX_LIN_ITERATIONCOUNT 2  //80
+#define MIN_LIN_ITERATIONCOUNT 1  //60
+#define SECANT_ITERATIONCOUNT 1
+#define MAX_RAY_DEPTH 2
+
+void linearSearch(  float3 x, float3 R, float3 N, samplerCUBE mp,
+                    out float3 p,
+                    out float dl,
+                    out float dp,
+                    out float llp,
+                    out float ppp)
+{
+ float3 Ra = abs(R), xa = abs(x);
+ float xm =  max(max(xa.x,xa.y),xa.z);
+ float Rm = max(max(Ra.x,Ra.y),Ra.z);
+ float a = xm / Rm;
+ 
+ int shootL = 0, shootP = 0;          
+ bool found = false; 
+ 
+ float dt =  length(x / xm - R / Rm) * MAX_LIN_ITERATIONCOUNT;
+ dt = max(dt, MIN_LIN_ITERATIONCOUNT);
+ dt = 1.0 / dt;
+    
+ float t = 0.01;//dt;
+ float pa;
+ 
+ //Linear iteration
+ while(t <= 1.0 && !found)
+ {
+   dp = a * t / (1 - t);
+   p = x + R * dp;
+   pa = readDistanceCubeMap(mp, p);
+      
+   if(pa > 0)
+   {
+    ppp = length(p) / pa;
+    if(ppp < 1)
+      shootP = -1;
+    else 
+      shootP = 1;      
+    if(shootL * shootP == -1)
+      found = true;
+    else
+    {
+      shootL = shootP;
+      dl = dp;
+      llp = ppp;
+    }
+   }
+   else
+     shootL = 0;
+      
+   t += dt;  
+ }
+
+ if(!found)
+  p = float3(0,0,0);
+}
+
+
+void secantSearch(float3 x, float3 R, samplerCUBE mp, 
+	               float dl,
+	               float dp,
+	               float llp,
+	               float ppp,
+	               out float3 p)
+{
+  for(int i= 0; i < SECANT_ITERATIONCOUNT; i++)
+  {
+   float dnew;
+   dnew = dl + (dp - dl) * (1 - llp) / (ppp - llp);
+   p = x + R * dnew;
+   half pppnew = length(p) / readDistanceCubeMap(mp, p);
+   if(pppnew < 1)
+   {
+    llp = pppnew;
+    dl = dnew;
+   }
+   else
+   {
+    ppp = pppnew;
+    dp = dnew;
+   }
+  }
+}
+/*
+float3 Hit(float3 x, float3 R, float3 N, 
+           samplerCUBE mp1,
+           samplerCUBE mp3Color,
+           samplerCUBE mp3Dist,
+           out float4 Il, out float3 Nl)
+{
+ float dl1 = 0, dp1, llp1, ppp1;
+ float3 p1;
+ linearSearch(x, R, N, mp1, p1, dl1, dp1, llp1, ppp1);
+ 
+ bool valid1 = dot(p1,p1) != 0;
+ 		
+ float dl, dp, llp, ppp;
+ float3 p;
+ 
+ if(!valid1)
+ {
+    linearSearch(x, R, N, mp3Dist, p, dl, dp, llp, ppp);
+    Il.a = 1; 
+    secantSearch(x, R, mp3Dist, dl, dp, llp, ppp, p);
+    Il.rgb =  Nl.rgb = readCubeMap(mp3Color, p).rgb;  
+ }
+ else
+ {
+    secantSearch(x, R, mp1, dl1, dp1, llp1, ppp1, p1);
+    Il.rgb =  Nl.rgb = readCubeMap(mp1, p1).rgb;
+    p = p1;    
+    Il.a = 0;   
+ }
+ 
+ return p;
+}*/
+
+float3 Hit( float3 x, float3 R, samplerCUBE mp )
+{
+	float rl = readDistanceCubeMap( mp, R);				// |r|
+	
+	float ppp = length( x ) /  readDistanceCubeMap( mp, x);			// |p|/|p|
+	float dun = 0, pun = ppp, dov = 0, pov = 0;
+	float dl = rl * ( 1 - ppp );							// eq. 2
+	float3 l = x + R * dl;									// ray equation
+
+	// iteration
+	for( int i = 0; i < SECANT_ITERATIONCOUNT ; i++ )
+	{
+		float llp = length( l ) / readDistanceCubeMap( mp, l);		// |l|/|l|
+		if ( llp < 0.999f )									// undershooting
+		{
+			dun = dl; pun = llp;							// last undershooting
+			dl += ( dov == 0 ) ? rl * ( 1 - llp ) :			// eq. 2
+				( dl - dov ) * ( 1 - llp ) / ( llp - pov );	// eq. 3
+		} else if ( llp > 1.001f )							// overshooting
+		{
+			dov = dl; pov = llp;							// last overshooting
+			dl += ( dl -dun ) * ( 1 - llp ) / ( llp - pun );// eq. 3
+		}
+		l = x + R * dl;										// ray equation
+	}
+	return l;												// computed hit point
+}
+
+
+struct Shaded_OUT
+{
+ float4 vPos : POSITION;
+ float4 wNormal : TEXCOORD0;
+ float4 wPos    : TEXCOORD1; 
+};
+
+
+float4 MultipleRefractionPS(Shaded_OUT IN,
+							uniform samplerCUBE CubeMap : register(s0),
+							uniform samplerCUBE DistanceMap : register(s1),
+							uniform samplerCUBE NormDistMap1 : register(s2),
+							uniform float3 cameraPos,
+							uniform float3 lastCenter,
+							uniform float sFresnel,
+							uniform float refIndex ) : COLOR0
+{
+	 float4 I = float4(0,0,0,0);
+			
+	 float3 N = normalize(IN.wNormal.xyz);
+	 float3 x = IN.wPos.xyz - lastCenter;
+	 float3 V  = (IN.wPos.xyz - cameraPos);
+	  V = normalize(V);
+	 
+	 float F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel);	 
+	
+	 float3 l;	 
+	 float ri = refIndex;
+	 float3 R;
+	 
+	 if(dot(V,N) > 0)
+	 {
+		ri = 1.0 / refIndex;
+		N = -N;	    
+	 }
+	 float4 Irefr = 0;
+	 R = refract( V, N, ri);
+	 if(dot(R,R) != 0)
+	 {
+	   R = refract( V, N, ri);
+	   l = Hit(x, R, DistanceMap);
+	   x = l;	   
+	   N = readCubeMap(NormDistMap1, l).rgb;
+	   V = R;
+	   
+	   if(dot(V,N) > 0)
+	   {
+		ri = 1.0 / refIndex;
+		N = -N;	    
+	   }
+	   R = refract( V, N, ri);	   
+	   if(dot(R,R) != 0)
+	   {
+		 l = Hit(x, R, DistanceMap);
+		 Irefr =  readCubeMap(CubeMap, l); 
+	   }	   
+	 }
+	 
+	 N = normalize(IN.wNormal.xyz);
+	 V  = normalize(IN.wPos.xyz - cameraPos);
+	 x = IN.wPos.xyz - lastCenter;
+	 R = reflect( V, N); 
+	 l = Hit(x, R, DistanceMap);
+	 float4 Irefl = readCubeMap(CubeMap, l);
+	 
+	 I = F * Irefl + (1 - F) * Irefr;    
+	
+ 	return I;
+}
+
+float4 MultipleRefractionPhotonMap_PS(Shaded_OUT IN,
+									uniform samplerCUBE DistanceMap : register(s0),
+									uniform samplerCUBE NormDistMap1 : register(s1),
+									uniform float3 cameraPos,
+									uniform float3 lastCenter,
+									uniform float refIndex) : COLOR0
+{
+	float4 I = float4(0,0,0,0);
+		 
+	float3 N = normalize(IN.wNormal.xyz);
+	float3 x = IN.wPos.xyz - lastCenter;
+	float3 V  = (IN.wPos.xyz - cameraPos);
+	V = normalize(V);
+	
+	float3 l = 0;	 
+	float ri = refIndex;
+	float3 R;
+	 
+	 if(dot(V,N) > 0)
+	 {
+		ri = 1.0 / refIndex;
+		N = -N;	    
+	 }
+	 float4 Irefr = 0;
+	 R = refract( V, N, ri);
+	 if(dot(R,R) != 0)
+	 {
+	   R = refract( V, N, ri);
+	   l = Hit(x, R, DistanceMap);
+	   x = l;	   
+	   N = readCubeMap(NormDistMap1, l).rgb;
+	   V = R;
+	   
+	   if(dot(V,N) > 0)
+	   {
+		ri = 1.0 / refIndex;
+		N = -N;	    
+	   }
+	   R = refract( V, N, ri);	   
+	   if(dot(R,R) != 0)
+	   {
+		 l = Hit(x, R, DistanceMap);		 
+	   }	   
+	 }
+	 	 
+	return float4(l,1);
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction2L/GTPMultipleRefraction2L.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction2L/GTPMultipleRefraction2L.material	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction2L/GTPMultipleRefraction2L.material	(revision 2054)
@@ -0,0 +1,166 @@
+fragment_program GTP/MultiBounce/Refraction2L_PS hlsl
+{
+	
+	source GTPMultipleRefraction2L.hlsl
+    entry_point MultipleRefractionPS
+	target ps_3_0
+	flow_control prefer
+}
+
+fragment_program GTP/MultiBounce/PhotonMap2L_PS hlsl
+{
+	
+	source GTPMultipleRefraction2L.hlsl
+    entry_point MultipleRefractionPhotonMap_PS
+	target ps_3_0
+	flow_control prefer
+}
+
+material GTP/MultiBounce/PhotonMap2L
+{
+ technique
+ {
+  pass
+  {   
+   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/MultiBounce/PhotonMap2L_PS
+   {
+     param_named_auto cameraPos camera_position
+     param_named lastCenter float3 0 0 0
+     param_named refIndex float 0.77	
+   }
+   //cubemap of distances
+   texture_unit
+   {
+   
+   }
+   texture_unit
+   {
+    texture object_SE_0_COLORCUBEMAP_L1
+   }
+  }
+ }
+}
+
+material GTP/MultiBounce/CauCube_PointSprite
+{
+ technique
+ {
+  pass
+  { 
+   cull_hardware none
+   scene_blend src_alpha one
+   depth_check off
+   point_sprites on
+   vertex_program_ref GTP/Caustic/CauCube_PointSprite_VS
+   {
+     param_named_auto WorldView     worldview_matrix
+     param_named_auto Proj          projection_matrix
+     param_named CauSpriteSize      float 15
+   } 
+   fragment_program_ref GTP/Caustic/CauCube_PointSprite_PS
+   {
+     param_named CausticColor float4          0.8 0.8 0.8 0.5
+   }
+   texture_unit
+   {
+     vertex_texture true	 
+   }
+   texture_unit
+   {
+     texture PowerOfPhotonHitTexel.dds
+   }
+  }
+ }
+}
+
+
+//object_SE_0_DISTANCECUBEMAP_L1
+
+material GTP/MultiBounce/Refractor2L
+{ 
+   technique 
+   { 
+      pass 
+      { 
+        //cull_hardware none
+		IllumTechniques
+		{
+			RenderTechnique CausticCaster
+			{
+				attenuation	1000
+				photonmap_resolution 32
+				caustic_cubemap_resolution 256
+				photon_map_material	GTP/MultiBounce/PhotonMap2L
+				caustic_map_material	GTP/MultiBounce/CauCube_PointSprite
+				//caustic_map_material	GTP/Caustic/CauCube_Triangles
+				//use_triangles	true
+				//blur_caustic_cubemap true				
+			}
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				update_interval		1
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+								
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				resolution 1024
+				update_interval		1
+				distance_calc false
+				face_angle_calc false
+				update_all_face true				
+			}
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				layer 1
+				texture_unit_id 2
+				update_interval		1
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+				render_env false
+				render_self true
+				self_material GTP/MultiBounce/NormalDistanceCCW				
+			}				
+		 }
+		 vertex_program_ref GTP/Basic/Shaded_CPos_VS
+    	 {       
+       	 	param_named_auto WorldViewProj worldviewproj_matrix 
+    		param_named_auto World         world_matrix
+    		param_named_auto WorldInv inverse_world_matrix  
+   		 }
+		 fragment_program_ref GTP/MultiBounce/Refraction2L_PS
+         { 
+			param_named_auto cameraPos camera_position						
+			param_named refIndex float 0.77
+			param_named sFresnel float 0.04
+		 } 
+		
+		//Cube map of environment
+		texture_unit
+		{
+			//filtering none
+		}
+		//Cube map of environment distances
+		texture_unit
+		{
+			filtering none
+		}		
+		//Cube map of reflective object's normals and distances CCW
+		texture_unit
+		{
+			filtering none
+		}		
+	  }
+    }
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction/GTPMultipleRefraction.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction/GTPMultipleRefraction.material	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction/GTPMultipleRefraction.material	(revision 2054)
@@ -0,0 +1,99 @@
+fragment_program GTP/MultiBounce/Refraction_PS hlsl
+{
+	
+	source GTPMultipleReflection.hlsl
+    entry_point MultipleRefractionPS
+	target ps_3_0
+	flow_control prefer
+}
+
+material GTP/MultiBounce/Refractor
+{ 
+   technique 
+   { 
+      pass 
+      { 
+        //cull_hardware none
+		IllumTechniques
+		{
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+								
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				resolution 1024
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true				
+			}
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				layer 1
+				texture_unit_id 2
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+				render_env false
+				render_self true
+				self_material GTP/MultiBounce/NormalDistanceCCW				
+			}
+			RenderTechnique ColorCubeMap
+			{
+				resolution 1024
+				layer 2
+				texture_unit_id 3
+				update_interval		0
+				distance_calc false
+				face_angle_calc false
+				update_all_face true
+				render_env false
+				render_self true
+				self_material GTP/MultiBounce/NormalDistanceCW			
+			}				
+		 }
+		 vertex_program_ref GTP/Basic/Shaded_CPos_VS
+    	 {       
+       	 	param_named_auto WorldViewProj worldviewproj_matrix 
+    		param_named_auto World         world_matrix
+    		param_named_auto WorldInv inverse_world_matrix  
+   		 }
+		 fragment_program_ref GTP/MultiBounce/Refraction_PS
+         { 
+			param_named_auto cameraPos camera_position						
+			param_named refIndex float 0.77
+			param_named sFresnel float 0.04
+		 } 
+		
+		//Cube map of environment
+		texture_unit
+		{
+			//filtering none
+		}
+		//Cube map of environment distances
+		texture_unit
+		{
+			filtering none
+		}
+		
+		//Cube map of reflective object's normals and distances CCW
+		texture_unit
+		{
+			filtering none
+		}		
+		//Cube map of reflective object's normals and distances CW
+		texture_unit
+		{
+			filtering none
+		}
+	  }
+    }
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.material	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.material	(revision 2054)
@@ -0,0 +1,96 @@
+material GTP/MultiBounce/NormalDistanceCW
+{
+ technique 
+ { 
+  pass 
+  { 
+    cull_hardware clockwise
+    
+	vertex_program_ref GTP/Basic/Shaded_CPos_VS
+    {       
+        param_named_auto WorldViewProj worldviewproj_matrix 
+    	param_named_auto World world_matrix
+    	param_named_auto WorldView worldview_matrix
+    	param_named_auto WorldInv inverse_world_matrix   
+    }
+    fragment_program_ref GTP/MultiBounce/NormalDistancePS
+    { 
+			
+	} 
+  }
+ }
+}
+
+material GTP/MultiBounce/NormalDistanceCCW
+{
+ technique 
+ { 
+  pass 
+  { 
+    cull_hardware anticlockwise
+	vertex_program_ref GTP/Basic/Shaded_CPos_VS
+    {       
+        param_named_auto WorldViewProj worldviewproj_matrix 
+    	param_named_auto World world_matrix
+    	param_named_auto WorldView worldview_matrix
+    	param_named_auto WorldInv inverse_world_matrix 
+    }
+    fragment_program_ref GTP/MultiBounce/NormalDistancePS
+    { 
+		
+	} 
+  }
+ }
+}
+
+material GTP/MultiBounce/DistanceMinMaxCW
+{
+ technique 
+ { 
+  pass 
+  { 
+    cull_hardware clockwise
+    scene_blend_op max
+    depth_check off
+    polygon_mode points
+    
+    vertex_program_ref GTP/Basic/Shaded_CPos_VS
+    {       
+        param_named_auto WorldViewProj worldviewproj_matrix 
+	param_named_auto World         world_matrix
+	param_named_auto WorldView     worldview_matrix
+    	param_named_auto WorldInv      inverse_world_matrix    
+    }
+    fragment_program_ref GTP/MultiBounce/DistanceMinMaxPS
+    { 			
+    } 
+  }
+ }
+}
+
+material GTP/MultiBounce/DistanceMinMaxCCW
+{
+ technique 
+ { 
+  pass 
+  { 
+    cull_hardware anticlockwise
+    scene_blend_op max
+    depth_check off
+    polygon_mode points
+        
+    vertex_program_ref GTP/Basic/Shaded_CPos_VS
+    {       
+        param_named_auto WorldViewProj worldviewproj_matrix 
+	param_named_auto World         world_matrix
+	param_named_auto WorldView     worldview_matrix
+    	param_named_auto WorldInv      inverse_world_matrix    
+    }
+    fragment_program_ref GTP/MultiBounce/DistanceMinMaxPS
+    { 		
+	} 
+  }
+ }
+}
+
+
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection_MinMax.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection_MinMax.hlsl	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection_MinMax.hlsl	(revision 2054)
@@ -0,0 +1,452 @@
+float4 readCubeMap(samplerCUBE cm, float3 coord)		
+{
+	float4 color = texCUBElod( cm, float4(coord.xy, - coord.z,0) );
+	return color;
+}
+
+float readDistanceCubeMap(samplerCUBE dcm, float3 coord)		
+{
+	float dist = texCUBElod(dcm, float4(coord.xy, - coord.z,0)).a;
+	return dist;
+}
+
+#define MAX_LIN_ITERATIONCOUNT 30  //80
+#define MIN_LIN_ITERATIONCOUNT 25  //60
+#define SECANT_ITERATIONCOUNT 1
+#define MAX_RAY_DEPTH 2
+
+void linearSearch(  float3 x, float3 R, float3 N, samplerCUBE mp,
+					float2 minMax,					
+                    out float3 p,
+                    out float dl,
+                    out float dp,
+                    out float llp,
+                    out float ppp)
+{
+ 
+ int shootL = 0, shootP = 0;          
+ bool found = false; 
+ 
+ float min = minMax.x;
+ float max = minMax.y;
+ 
+ float minT = 0;
+ float maxT = 0;
+ {
+  	float a = dot(R,R);
+	float b = 2 * dot(R, x);
+	float c = dot(x,x) - min * min; 
+	float c2 = dot(x,x) - max * max; 
+	
+	float dis = b*b - 4*a*c;
+	float dis2 = b*b - 4*a*c2;
+	
+	float t1 = (-b + sqrt(dis))/ 2.0 * a;
+	float t2 = (-b - sqrt(dis))/ 2.0 * a;
+    float t3 = (-b + sqrt(dis2))/ 2.0 * a;
+	float t4 = (-b - sqrt(dis2))/ 2.0 * a;
+	
+	int numvalids = 0;
+	if(t1 > 0)
+	{
+	 numvalids++;
+	 if(t1 > maxT)maxT = t1;
+	 if(t1 < minT || minT == 0)minT = t1;
+	}
+	if(t2 > 0)
+	{
+	 numvalids++;
+	 if(t2 > maxT)maxT = t2;
+	 if(t2 < minT || minT == 0)minT = t2;
+	}
+	if(t3 > 0)
+	{
+	 numvalids++;
+	 if(t3 > maxT)maxT = t3;
+	 if(t3 < minT || minT == 0)minT = t3;
+	}
+	if(t4 > 0)
+	{
+	 numvalids++;
+	 if(t4 > maxT)maxT = t4;
+	 if(t4 < minT || minT == 0)minT = t4;
+	}
+	
+	if(numvalids % 2 == 1)
+	 minT = 0.01;
+	if(numvalids == 0)
+	 minT = maxT + 1.0;	
+ }
+ 
+ int iterationNeeded = MAX_LIN_ITERATIONCOUNT;// + (dot(normalize(x), R) + 1.0) / 2.0 * (MAX_LIN_ITERATIONCOUNT - MIN_LIN_ITERATIONCOUNT);
+ float pa;
+ float dt = (maxT - minT) / (float) iterationNeeded ;
+ dp = minT;
+ //Linear iteration
+ while(dp <= maxT && !found)
+ {
+   p = x + R * dp;
+   pa = readDistanceCubeMap(mp, p);
+      
+   if(pa > 0)
+   {
+    ppp = length(p) / pa;
+    if(ppp < 1)
+      shootP = -1;
+    else 
+      shootP = 1;      
+    if(shootL * shootP == -1)
+      found = true;
+    else
+    {
+      shootL = shootP;
+      dl = dp;
+      llp = ppp;
+    }
+   }
+   else
+     shootL = 0;
+      
+   dp += dt;  
+ }
+
+ if(!found)
+  p = float3(0,0,0);
+}
+
+
+void secantSearch(float3 x, float3 R, samplerCUBE mp, 
+	               float dl,
+	               float dp,
+	               float llp,
+	               float ppp,
+	               out float3 p)
+{
+  for(int i= 0; i < SECANT_ITERATIONCOUNT; i++)
+  {
+   float dnew;
+   dnew = dl + (dp - dl) * (1 - llp) / (ppp - llp);
+   p = x + R * dnew;
+   half pppnew = length(p) / readDistanceCubeMap(mp, p);
+   if(pppnew < 1)
+   {
+    llp = pppnew;
+    dl = dnew;
+   }
+   else
+   {
+    ppp = pppnew;
+    dp = dnew;
+   }
+  }
+}
+
+
+float3 Hit(float3 x, float3 R, float3 N, 
+           samplerCUBE mp1,
+           samplerCUBE mp2,
+           samplerCUBE mp3Color,
+           samplerCUBE mp3Dist,
+           float2 minMax,
+           float2 minMax1,
+		   float2 minMax2,		   
+           out float4 Il, out float3 Nl)
+{
+ float dl1 = 0, dp1, llp1, ppp1;
+ float3 p1;
+ linearSearch(x, R, N, mp1, minMax1, p1, dl1, dp1, llp1, ppp1);
+ float dl2 = 0, dp2, llp2, ppp2;
+ float3 p2;
+ linearSearch(x, R, N, mp2, minMax2, p2, dl2, dp2, llp2, ppp2);
+ 
+ bool valid1 = dot(p1,p1) != 0;
+ bool valid2 = dot(p2,p2) != 0;
+		
+ float dl, dp, llp, ppp;
+ float3 p;
+ 
+ if(!valid1 && ! valid2)
+ {
+    linearSearch(x, R, N, mp3Dist, minMax, p, dl, dp, llp, ppp);
+    if(dot(p,p) != 0)
+    {
+     Il.a = 1;    
+     secantSearch(x, R, mp3Dist, dl, dp, llp, ppp, p);
+     Il.rgb =  Nl.rgb = readCubeMap(mp3Color, p).rgb;  
+    }
+    else
+     Il = float4(0,0,0,0);
+ }
+ else
+ {
+    if( !valid2 || (valid1 && dp1 < dp2))
+    {
+     secantSearch(x, R, mp1, dl1, dp1, llp1, ppp1, p1);
+     Il.rgb =  Nl.rgb = readCubeMap(mp1, p1).rgb;
+     p = p1;
+    }
+    else
+    {
+     secantSearch(x, R, mp2, dl2, dp2, llp2, ppp2, p2);
+     Il.rgb =  Nl.rgb = readCubeMap(mp2, p2).rgb;
+     p = p2;
+    }    
+ } 
+ return p;
+}
+
+struct Shaded_OUT
+{
+ float4 vPos : POSITION;
+ float4 wNormal : TEXCOORD0;
+ float4 wPos    : TEXCOORD1; 
+};
+
+
+float4 MultipleReflectionPS(Shaded_OUT IN,
+							uniform samplerCUBE CubeMap : register(s0),
+							uniform samplerCUBE DistanceMap : register(s1),
+							uniform samplerCUBE NormDistMap1 : register(s2),
+							uniform samplerCUBE NormDistMap2 : register(s3),
+							uniform float3 cameraPos,
+							uniform float3 lastCenter,
+							uniform float4 min,
+							uniform float4 min1,
+							uniform float4 min2,
+							uniform float4 max,
+							uniform float4 max1,
+							uniform float4 max2) : COLOR0
+{
+	float2 miniMaxi1;
+    miniMaxi1.x = min.a;
+    miniMaxi1.y = max.a;
+   
+    float2 miniMaxi2;
+    miniMaxi2.x = min1.a;
+    miniMaxi2.y = max1.a;
+   
+    float2 miniMaxi3;
+    miniMaxi3.x = min2.a;
+    miniMaxi3.y = max2.a;
+	 		
+	 float3 N = normalize(IN.wNormal.xyz);
+	 float3 x = IN.wPos.xyz - lastCenter;
+	 float3 V  = (IN.wPos.xyz - cameraPos);
+		 
+	 float4 I = float4(0,0,0,0);
+	 V = normalize(V);
+	 float3 l;
+	 int depth = 0;
+	
+	 while(depth < MAX_RAY_DEPTH)
+	 {
+	   float3 R;  
+	   R = normalize(reflect( V, N));	  
+	  	
+	   float3 Nl;
+	   float4 Il;
+	   l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, miniMaxi1, miniMaxi2, miniMaxi3, Il, Nl);
+	   if(Il.a == 0)
+	   {
+		   depth += 1;		 
+	   }
+	   else
+	   {
+		   I = Il;
+		   depth = MAX_RAY_DEPTH;
+	   }
+	   x = l;	   
+	   N = Nl;
+	   V = R;   
+	   
+	}
+	if(I.a == 0)
+	   I = readCubeMap(CubeMap, l);
+	
+	return I;
+}
+
+float4 MultipleRefractionPS(Shaded_OUT IN,
+							uniform samplerCUBE CubeMap : register(s0),
+							uniform samplerCUBE DistanceMap : register(s1),
+							uniform samplerCUBE NormDistMap1 : register(s2),
+							uniform samplerCUBE NormDistMap2 : register(s3),
+							uniform float3 cameraPos,
+							uniform float3 lastCenter,
+							uniform float refIndex,
+							//uniform float sFresnel, //0.04 
+							uniform float4 min,
+							uniform float4 min1,
+							uniform float4 min2,
+							uniform float4 max,
+							uniform float4 max1,
+							uniform float4 max2) : COLOR0
+{
+	float2 miniMaxi1;
+    miniMaxi1.x = min.a;
+    miniMaxi1.y = max.a;
+   
+    float2 miniMaxi2;
+    miniMaxi2.x = min1.a;
+    miniMaxi2.y = max1.a;
+   
+    float2 miniMaxi3;
+    miniMaxi3.x = min2.a;
+    miniMaxi3.y = max2.a;
+
+	 float4 I = float4(0,0,0,0);
+			
+	 float3 N = normalize(IN.wNormal.xyz);
+	 float3 x = IN.wPos.xyz - lastCenter;
+	 float3 V  = (IN.wPos.xyz - cameraPos);
+	 
+	 float sFresnel = 0.04;
+	 float F = sFresnel + pow(1 - dot(N, -V), 5) * (1 - sFresnel);
+	 
+	 V = normalize(V);
+	 float3 l;
+	 float4 Irefl;
+	 int depth = 0;
+	
+	 while(depth < MAX_RAY_DEPTH)
+	 {
+	    float3 R;  
+	   R = normalize(reflect( V, N));	  
+	  	
+	   float3 Nl;
+	   float4 Il;
+	   l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, miniMaxi1, miniMaxi2, miniMaxi3, Il, Nl);
+	   if(Il.a == 0)
+	   {
+		   depth += 1;		 
+	   }
+	   else
+	   {
+		   I = Il;
+		   depth = MAX_RAY_DEPTH;
+	   }
+	   x = l;	   
+	   N = Nl;
+	   V = R;   
+	   
+	}
+	if(I.a == 0)
+	   I = readCubeMap(CubeMap, l);
+	Irefl = I;
+	
+	{
+	float4 Irefr;
+	N = normalize(IN.wNormal.xyz);
+	x = IN.wPos.xyz - lastCenter;
+	V  = (IN.wPos.xyz - cameraPos);
+	V = normalize(V);
+	depth = 0;
+	
+	while(depth < MAX_RAY_DEPTH)
+	{
+	  float3 R;  
+	  
+	  float ri = refIndex;
+	 
+	  if(dot(V,N) > 0)
+	  {
+		ri = 1.0 / ri;
+		N = -N;	    
+	  }
+	  R = refract( V, N, ri);
+	  if(dot(R,R) == 0) R = reflect( V, N); 
+					
+	  float3 Nl;
+	  float4 Il;
+	  l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, miniMaxi1, miniMaxi2, miniMaxi3, Il, Nl);
+	  if(Il.a == 0)
+	  {
+		   depth += 1;		 
+	  }
+	  else
+	  {
+		   I = Il;
+		   depth = MAX_RAY_DEPTH;
+	  }
+	  x = l;	   
+	  N = normalize(Nl);
+	  V = R;	   	   
+	}
+	
+	if(I.a == 0)
+	   I = readCubeMap(CubeMap, l);
+	Irefr = I;
+	    
+	I = Irefl * F + (1.0 - F) * Irefr;
+    }
+ 	return I;
+}
+
+float4 MultipleRefractionPhotonMap_PS(Shaded_OUT IN,
+									uniform samplerCUBE DistanceMap : register(s0),
+									uniform samplerCUBE NormDistMap1 : register(s1),
+									uniform samplerCUBE NormDistMap2 : register(s2),
+									uniform float3 cameraPos,
+									uniform float3 lastCenter,
+									uniform float refIndex,
+									uniform float4 min,
+									uniform float4 min1,
+									uniform float4 min2,
+									uniform float4 max,
+									uniform float4 max1,
+									uniform float4 max2) : COLOR0
+{
+	float2 miniMaxi1;
+    miniMaxi1.x = min.a;
+    miniMaxi1.y = max.a;
+   
+    float2 miniMaxi2;
+    miniMaxi2.x = min1.a;
+    miniMaxi2.y = max1.a;
+   
+    float2 miniMaxi3;
+    miniMaxi3.x = min2.a;
+    miniMaxi3.y = max2.a;
+
+	float4 I = float4(0,0,0,0);
+		 
+	float3 N = normalize(IN.wNormal.xyz);
+	float3 V  = (IN.wPos.xyz - cameraPos);
+	float3 x = IN.wPos.xyz - lastCenter;
+	V = normalize(V);
+	float3 l;
+	int depth = 0;
+	
+	while(depth < MAX_RAY_DEPTH)
+	{
+	  float3 R;  
+	  
+	  float ri = refIndex;
+	 
+	  if(dot(V,N) > 0)
+	  {
+		ri = 1.0 / ri;
+		N = -N;	    
+	  }
+	  R = refract( V, N, ri);
+	  if(dot(R,R) == 0) R = reflect( V, N); 
+					
+	  float3 Nl;
+	  float4 Il;
+	  l = Hit(x, R, N, NormDistMap1, NormDistMap2, DistanceMap, DistanceMap, miniMaxi1, miniMaxi2, miniMaxi3, Il, Nl);
+	  if(Il.a == 0)
+	  {
+		   depth += 1;		 
+	  }
+	  else
+	  {
+		   I = Il;
+		   depth = MAX_RAY_DEPTH;
+	  }
+	  x = l;	   
+	  N = normalize(Nl);
+	  V = R;	   	   
+	}
+	
+	return float4(l,1);
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.hlsl	(revision 2054)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/MultiBounceShared.hlsl	(revision 2054)
@@ -0,0 +1,15 @@
+struct Shaded_CPos_OUT
+{
+ float4 vPos : POSITION;
+ float4 wNormal : TEXCOORD0;
+ float4 wPos    : TEXCOORD1; 
+ float4 CPos    : TEXCOORD2;
+};
+
+
+float4 NormalDistancePS( Shaded_CPos_OUT IN):COLOR
+{ 
+ float4 Color = float4(0, 0, 0, 0);
+ Color = float4(normalize(IN.wNormal.xyz), length(IN.CPos.xyz));
+ return Color;
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material	(revision 1671)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material	(revision 2054)
@@ -192,4 +192,8 @@
 					set_light_farplane true
 				}
+				RenderTechnique CausticReciever
+				{
+					max_caster_count	3
+				}	
 			}
 			
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/GameTools.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/GameTools.material	(revision 2030)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/GameTools.material	(revision 2054)
@@ -261,19 +261,21 @@
    technique 
    { 
-      scene_blend none
-
-      pass 
-      { 
-		cull_hardware anticlockwise
-		//cull_hardware none
+      
+      pass 
+      { 
+	scene_blend none
+
+	cull_hardware anticlockwise
+	//cull_hardware none
+	//cull_hardware clockwise
 		
-		vertex_program_ref GameTools/ShadowMap/DistVS
+	vertex_program_ref GameTools/ShadowMap/DistVS
         {       
           param_named_auto worldViewProj worldviewproj_matrix
           param_named_auto worldView worldview_matrix          
-	    } 
-		fragment_program_ref  GameTools/ShadowMap/DistPS
+        } 
+	fragment_program_ref  GameTools/ShadowMap/DistPS
         { 
-			param_named_auto farPlane far_clip_distance
+	  param_named_auto farPlane far_clip_distance
         }
         
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/kupola.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/kupola.material	(revision 1691)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/kupola.material	(revision 2054)
@@ -11,8 +11,8 @@
 		{
 			
-			//RenderTechnique CausticReciever
-			//{
-			//	max_caster_count	10
-			//}
+			RenderTechnique CausticReciever
+			{
+				max_caster_count	10
+			}
 			//RenderTechnique DepthShadowReciever
 			//{
@@ -65,8 +65,8 @@
 			{
 				
-				//RenderTechnique CausticReciever
-				//{
-				//	max_caster_count	10
-				//}
+				RenderTechnique CausticReciever
+				{
+					max_caster_count	10
+				}
 				//RenderTechnique DepthShadowReciever
 				//{
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/colorcube.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/colorcube.material	(revision 1862)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/colorcube.material	(revision 2054)
@@ -6,10 +6,26 @@
 		{
 			//lighting off
-			
+			IllumTechniques
+			{
+				
+				RenderTechnique CausticReciever
+				{
+					max_caster_count	10					
+				}				
+				RenderTechnique DepthShadowReciever
+				{
+				   max_light_count 1
+				   vertex_program_name GameTools/ShadowMap/ShadowDistVS
+				   fragment_program_name GameTools/ShadowMap/ShadowDistPS
+				   set_light_view true
+				   set_light_farplane true
+				}
+			}
+
 			texture_unit
 			{
 				texture roomc.PNG
 				tex_coord_set 0
-				colour_op replace
+				colour_op modulate
 			}
 		}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_DepthShadow.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_DepthShadow.hlsl	(revision 1691)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_DepthShadow.hlsl	(revision 2054)
@@ -113,4 +113,5 @@
 
 
+
 VS_OUT_SHADOW distShadowVS(float4 position : POSITION,	
 							uniform float4x4 worldViewProj,
@@ -128,5 +129,5 @@
 }
 
-
+/*
 float4 distShadowPS(VS_OUT_SHADOW IN,
 					uniform float4x4 lightViewProj,
@@ -173,6 +174,42 @@
 	
 	return shadow + (1 - shadow) * light;
-}
-
+}*/
+
+float4 distShadowPS(VS_OUT_SHADOW IN,
+					uniform float4x4 lightViewProj,
+					uniform float lightFarPlane,
+					uniform sampler2D depthShadowMap : register(s0)
+					):COLOR
+{	
+	float bias = 0.001;
+	float epsilon = 0.001;
+	float4 light = float4(1,1,1,1);
+	float4 shadow = float4(0.85,0.85,0.85,1);
+	
+	if(IN.lPosition.z > 0.0)
+	{
+		float4 pos = (IN.lPosition / IN.lPosition.w);
+		
+		float d = length(pos.xy);
+			
+		light = saturate((1.0 - d)/0.05);
+		
+		if(d <= 1.0)
+		{
+			float dist = length(IN.lVPosition.xyz) / lightFarPlane;
+			pos.xy = (pos.xy + 1.0) / 2.0;
+			pos.y = 1.0 - pos.y;
+			float4 storedDist = tex2D(depthShadowMap, pos.xy);
+			
+    		light = storedDist.r + dist*0.000000000001;
+    	
+		}
+		
+	}
+	else
+		light = 0;	
+	
+	return shadow + (1 - shadow) * light;
+}
 
 /*
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl	(revision 2024)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl	(revision 2054)
@@ -413,5 +413,5 @@
  	return I;
 }
-
+/*
 float4 mainPS(VertOut IN,
 							uniform float3 cameraPos,
@@ -448,6 +448,6 @@
    return Color;
 }
-
-/*
+*/
+
 float4 mainPS(VertOut IN,
 							uniform float3 cameraPos,
@@ -486,49 +486,3 @@
 	 
 	return Color;
-}*/
-
-/*
-float4 mainPS(VertOut IN,
-							uniform float3 cameraPos,
-							uniform samplerCUBE CubeMap : register(s0),
-							uniform samplerCUBE DistanceMap : register(s1),
-							uniform samplerCUBE NormDistMap1 : register(s2),
-							uniform samplerCUBE NormDistMap2 : register(s3),
-							uniform float3 lastCenter,
-							uniform float SingleBounce,
-							uniform float refIndex,
-							uniform float4 min,
-							uniform float4 min1,
-							uniform float4 min2,
-							uniform float4 max,
-							uniform float4 max1,
-							uniform float4 max2
-							):COLOR
-{
-  float2 miniMaxi1;
-  miniMaxi1.x = min1.a;
-  miniMaxi1.y = max1.a;
-   
-  float4 I = float4(0,0,0,0);
-		
-  float3 N = normalize(IN.mNormal);
-  float3 x = IN.wPos - lastCenter;
-  float3 V  = normalize(IN.wPos - cameraPos);
-  float3 R = normalize(reflect(V, N)); 
-	 
-  float3 p;
-  float dl, dp, llp, ppp;   
-  linearSearch( x, R, N, NormDistMap1, miniMaxi1, p, dl, dp, llp, ppp);
-  if( dot(p, p) != 0 )
-  {
-    //secantSearch(x, R, NormDistMap1, dl, dp, llp, ppp, p);
-    I = readCubeMap(NormDistMap1, p);
-  }
-<<<<<<< .mine
-I = max1 + 0.0000000000001 *x.x;
-=======
- I = max1 + 0.000000001 * x.x;
->>>>>>> .r1994
-  //I = readCubeMap(NormDistMap1, R)+0.00000000001*x.x; 
-  return I;	
-}*/
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Diffuse.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Diffuse.hlsl	(revision 1929)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Diffuse.hlsl	(revision 2054)
@@ -1,3 +1,5 @@
 float REDUCED_CUBEMAP_SIZE;
+int CUBEMAP_SIZE = 128;
+int RATE = 32;
 
 float4 readCubeMap(samplerCUBE cm, float3 coord)		
@@ -13,4 +15,44 @@
 	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
+{  
+   RATE = 32;
+   CUBEMAP_SIZE = 128;
+   float4 color = 0;
+   float3 dir;
+  
+   for (int i = 0; i < RATE; i++)
+     for (int j = 0; j < RATE; j++)
+    {
+		float2 pos;
+		pos.x = IN.mPos.x + (2*i + 1)/(float)CUBEMAP_SIZE;
+		pos.y = IN.mPos.y - (2*j + 1)/(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);		
 }
 
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program	(revision 2024)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program	(revision 2054)
@@ -50,4 +50,18 @@
    entry_point VPos
    target vs_1_1
+}
+
+vertex_program GTP/Basic/MPos_VS hlsl
+{
+   source GTPBasic_VS.hlsl
+   entry_point MPos
+   target vs_1_1
+}   
+
+vertex_program GTP/Basic/MPos_NoTransform_VS hlsl
+{
+   source GTPBasic_VS.hlsl
+   entry_point MPos_NoTransform
+   target vs_1_1
 }   
 
@@ -56,4 +70,11 @@
    source GTPBasic_VS.hlsl
    entry_point CPos
+   target vs_1_1
+}
+
+vertex_program GTP/Basic/Shaded_CPos_VS hlsl
+{
+   source GTPBasic_VS.hlsl
+   entry_point Shaded_CPos_VS
    target vs_1_1
 }
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic_VS.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic_VS.hlsl	(revision 2024)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic_VS.hlsl	(revision 2054)
@@ -153,4 +153,26 @@
 }
 
+struct MPos_OUT
+{
+ float4 VPos : POSITION;
+ float4 MPos : TEXCOORD0;
+};
+
+MPos_OUT MPos(float4 position : POSITION0,
+              uniform float4x4 WorldViewProj)
+{
+ MPos_OUT OUT;
+ OUT.VPos = mul(WorldViewProj, position);
+ OUT.MPos = position;
+ return OUT;
+}
+
+MPos_OUT MPos_NoTransform(float4 position : POSITION0)
+{
+ MPos_OUT OUT;
+ OUT.VPos = position;
+ OUT.MPos = position;
+ return OUT;
+}
 
 struct CPos_OUT
@@ -168,4 +190,27 @@
  OUT.CPos = mul(WorldView, position);
  return OUT;
+}
+
+struct Shaded_CPos_OUT
+{
+ float4 vPos : POSITION;
+ float4 wNormal : TEXCOORD0;
+ float4 wPos    : TEXCOORD1; 
+ float4 CPos    : TEXCOORD2;
+};
+
+Shaded_CPos_OUT Shaded_CPos_VS(float4 position : POSITION,
+                               float4 normal : NORMAL,
+                               uniform float4x4 WorldViewProj,
+                               uniform float4x4 World,
+		                       uniform float4x4 WorldView,
+                               uniform float4x4 WorldInv)
+{
+ Shaded_CPos_OUT OUT;
+ OUT.vPos = mul(WorldViewProj, position);
+ OUT.wPos = mul(World, position);
+ OUT.CPos = mul(WorldView, position);
+ OUT.wNormal = mul(normal, WorldInv);
+ return OUT; 
 }
 
