Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/Diffuse.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/Diffuse.material	(revision 1735)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/Diffuse.material	(revision 1955)
@@ -183,4 +183,5 @@
 	entry_point DiffuseBumpPS
 	target ps_3_0
+	flow_control prefer
 } 
 
@@ -251,4 +252,5 @@
 	entry_point EnvMapDiffuseP2PPS
 	target ps_3_0
+	flow_control prefer
 } 
 
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/MetalTeapot.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/MetalTeapot.material	(revision 1929)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/MetalTeapot.material	(revision 1955)
@@ -185,5 +185,5 @@
 } 
 
-material MetalTeapotMultipleBounce
+material MetalTeapotMultipleBounce_0
 { 
    technique 
@@ -324,2 +324,110 @@
     }
 }
+
+
+
+
+material MetalTeapotMultipleBounce
+{ 
+   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 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 NormalDistanceCW
+				get_minmax true
+				min_var_name min2
+				max_var_name max2
+			}				
+		 }
+		 vertex_program_ref DefaultVS
+         {       
+            param_named_auto worldViewProj worldviewproj_matrix 
+    	    param_named_auto world world_matrix
+    	    param_named_auto worldview worldview_matrix
+    	    param_named_auto worldI inverse_world_matrix
+	    
+         } 
+		 fragment_program_ref 	MetalMultipleBouncePS
+         { 
+			param_named_auto cameraPos camera_position
+			//param_named n float3 0.21 0.96 1.17
+			//param_named k float3 4.16 2.57 2.32
+			param_named F0 float3 0.95 0.95 0.95
+			param_named SingleBounce float 0.0
+			param_named refIndex float 0.6667			
+		} 
+		
+		//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/programs/GameTools_PostProc.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_PostProc.hlsl	(revision 1683)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_PostProc.hlsl	(revision 1955)
@@ -119,5 +119,9 @@
 	
 	//Color = pow(Color * half4(1.05f, 0.97f, 1.27f, 1.0f), Gain);
-	return Color;
+	//return Color;
+	return float4(tex2D(GlobalLuminanceTexture, IN.texCoord).r,
+				  tex2D(GlobalLuminanceTexture, IN.texCoord).r,
+				  tex2D(GlobalLuminanceTexture, IN.texCoord).r,
+				  1);
 
 }
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl	(revision 1929)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl	(revision 1955)
@@ -85,5 +85,5 @@
  
  float minT = 0;
- float maxT = 0;	
+ float maxT = 0;
  {
   	float a = dot(R,R);
@@ -134,10 +134,9 @@
  float pa;
  float dt = (maxT - minT) / MAX_LIN_ITERATIONCOUNT;
- float t = minT;
+ dp = minT;
  //Linear iteration
- while(t <= maxT && !found)
+ while(dp <= maxT && !found)
  {
-   dp = t;
-   p = x + R * t;
+   p = x + R * dp;
    pa = readDistanceCubeMap(mp, p);
       
@@ -161,5 +160,5 @@
      shootL = 0;
       
-   t += dt;  
+   dp += dt;  
  }
 
@@ -228,5 +227,5 @@
     }
     else
-     Il = float4(0,0,0,1);
+     Il = float4(0,0,0,0);
  }
  else
@@ -243,8 +242,6 @@
      Il.rgb =  Nl.rgb = readCubeMap(mp2, p2).rgb;
      p = p2;
-    }
-    Il.a = 0;   
- }
- 
+    }    
+ } 
  return p;
 }
@@ -339,5 +336,4 @@
 	 float4 Irefl;
 	 int depth = 0;
-	
 	
 	 while(depth < MAX_RAY_DEPTH)
@@ -363,6 +359,6 @@
 	   
 	}
-/*	if(I.a == 0)
-	   I = readCubeMap(CubeMap, l);*/
+	if(I.a == 0)
+	   I = readCubeMap(CubeMap, l);
 	Irefl = I;
 	
@@ -416,5 +412,5 @@
  	return I;
 }
-
+/*
 float4 mainPS(VertOut IN,
 							uniform float3 cameraPos,
@@ -432,13 +428,13 @@
 {
    float2 miniMaxi1;
-   miniMaxi1.x = 1.0 / minmax.x / sqrt(2.0);
+   miniMaxi1.x = 1.0 / minmax.x;
    miniMaxi1.y = minmax.y;
    
    float2 miniMaxi2;
-   miniMaxi2.x = 1.0 / minmax1.x / sqrt(2.0);
+   miniMaxi2.x = 1.0 / minmax1.x;
    miniMaxi2.y = minmax1.y;
    
    float2 miniMaxi3;
-   miniMaxi3.x = 1.0 / minmax2.x / sqrt(2.0);
+   miniMaxi3.x = 1.0 / minmax2.x;
    miniMaxi3.y = minmax2.y;
 
@@ -450,3 +446,85 @@
 	 
 	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 = 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 Color = 1.0;
+	if(SingleBounce == 1)
+	 Color = SingleReflectionPS(IN,cameraPos, CubeMap, DistanceMap, NormDistMap1,NormDistMap2,lastCenter,refIndex, miniMaxi1, miniMaxi2, miniMaxi3);
+	else
+	 Color = MultipleReflectionPS(IN,cameraPos, CubeMap, DistanceMap, NormDistMap1,NormDistMap2,lastCenter,refIndex, miniMaxi1, miniMaxi2, miniMaxi3);
+	 
+	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 = min2.a;
+  miniMaxi1.y = max2.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, NormDistMap2, miniMaxi1, p, dl, dp, llp, ppp);
+  if( dot(p, p) != 0 )
+  {
+    secantSearch(x, R, NormDistMap2, dl, dp, llp, ppp, p);
+    I = readCubeMap(NormDistMap2, p);
+  }
+
+  //I = readCubeMap(NormDistMap1, R)+0.00000000001*x.x; 
+  return I;	
+}*/
