Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/MetalTeapot.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/MetalTeapot.material	(revision 1859)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/MetalTeapot.material	(revision 1860)
@@ -89,5 +89,5 @@
     fragment_program_ref NormalDistancePS
     { 
-				
+		param_named refIndex float 1.6		
 	} 
   }
@@ -111,5 +111,5 @@
     fragment_program_ref NormalDistancePS
     { 
-				
+		param_named refIndex float 1.6		
 	} 
   }
@@ -134,4 +134,5 @@
       pass 
       { 
+        //cull_hardware none
 		IllumTechniques
 		{
@@ -194,5 +195,6 @@
 			//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 SingleBounce float 0.0
+			param_named refIndex float 1.6			
 		} 
 		
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapot.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapot.hlsl	(revision 1859)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapot.hlsl	(revision 1860)
@@ -312,10 +312,10 @@
 }
 
-float4 NormalDistancePS( VertOut IN):COLOR
+float4 NormalDistancePS( VertOut IN, uniform float refIndex):COLOR
 {
  
  float4 Color = float4(0, 0, 0, 0);
  //return Color;
- Color = float4(normalize(IN.mNormal), length(IN.cPos));
+ Color = float4(normalize(IN.mNormal) * refIndex, length(IN.cPos));
  return Color;
 }
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl	(revision 1859)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/MetalTeapotNew.hlsl	(revision 1860)
@@ -16,5 +16,5 @@
 #define MIN_LIN_ITERATIONCOUNT 6
 #define SECANT_ITERATIONCOUNT 1
-#define MAX_RAY_DEPTH 2
+#define MAX_RAY_DEPTH 5
 
 void linearSearch(  float3 x, float3 R, float3 N, samplerCUBE mp,
@@ -30,5 +30,5 @@
  float a = xm / Rm;
            
- bool undershoot = true, overshoot = false; 
+ bool undershoot = false, overshoot = false; 
  
  float dt =  length(x / xm - R / Rm) * MAX_LIN_ITERATIONCOUNT;
@@ -36,5 +36,5 @@
  dt = 1.0 / dt;
     
- float t = dt;
+ float t = 0.01;//dt;
  float pa;
  bool first = true;
@@ -64,10 +64,10 @@
  if(!overshoot)
   p = float3(0,0,0);
- else if(t == 2 * dt)
+/* else if(t == 2 * dt)
  {
 	 float3 hitp = pa * normalize(p);
     if(dot(normalize(hitp - x), N) < 0.1f)
 	   p = float3(0,0,0);
- }
+ }*/
 }
 
@@ -178,5 +178,6 @@
 							uniform samplerCUBE NormDistMap1 : register(s2),
 							uniform samplerCUBE NormDistMap2 : register(s3),
-							uniform float3 lastCenter)
+							uniform float3 lastCenter,
+							uniform float refIndex)
 {
  float4 Color = float4(1,1,1,1);
@@ -188,6 +189,13 @@
  
  V = normalize(V);
- float3 R = normalize(reflect( V, N));
- //float3 R = normalize(refract( V, N, 0.8));
+
+float3 R;	   
+if(refIndex > 100.0)
+    R = normalize(reflect( V, N));
+else
+{
+	refIndex = 1.0 / refIndex;
+    R = normalize(refract( V, N, refIndex));
+}
 			
  float3 Nl;
@@ -207,9 +215,10 @@
 							uniform samplerCUBE NormDistMap1 : register(s2),
 							uniform samplerCUBE NormDistMap2 : register(s3),
-							uniform float3 lastCenter)
+							uniform float3 lastCenter,
+							uniform float refIndex)
 {
 	 float4 I = float4(0,0,0,0);
 			
-	 float3 N = normalize(IN.mNormal);
+	 float3 N = normalize(IN.mNormal) * refIndex;
 	 float3 newTexCoord;	
 	 float3 x = IN.wPos - lastCenter;
@@ -222,6 +231,13 @@
 	 while(depth < MAX_RAY_DEPTH)
 	 {
-	   float3 R = normalize(reflect( V, N));
-	  // float3 R = normalize(refract( V, N, 0.8));
+	   float3 R;
+	   float refIndex = length(N);
+	   refIndex = 1.0 / refIndex;
+	   N = normalize(N);
+	   
+	   if(refIndex > 100.0)
+	    R = normalize(reflect( V, N));
+	   else
+	    R = normalize(refract( V, N, refIndex));
 				
 	   float3 Nl;
@@ -241,9 +257,11 @@
 	   N = normalize(Nl);
 	   V = R;
-	  // if(dot(N, V) > 0) N = -N;
+	   
+	  if(refIndex <= 100.0)
+	    if(dot(N, V) > 0) N = -N;
 	}
 	
-	/*if(I.a == 0)
-       I = readCubeMap(CubeMap, l);*/
+//	if(I.a == 0)
+ //      I = readCubeMap(CubeMap, l);
   
  	return I;
@@ -257,11 +275,12 @@
 							uniform samplerCUBE NormDistMap2 : register(s3),
 							uniform float3 lastCenter,
-							uniform float SingleBounce):COLOR
+							uniform float SingleBounce,
+							uniform float refIndex):COLOR
 {
 	float4 Color = 1.0;
 	if(SingleBounce == 1)
-	 Color = SingleReflectionPS(IN,cameraPos, CubeMap, DistanceMap, NormDistMap1,NormDistMap2,lastCenter);
+	 Color = SingleReflectionPS(IN,cameraPos, CubeMap, DistanceMap, NormDistMap1,NormDistMap2,lastCenter,refIndex);
 	else
-	 Color = MultipleReflectionPS(IN,cameraPos, CubeMap, DistanceMap, NormDistMap1,NormDistMap2,lastCenter);
+	 Color = MultipleReflectionPS(IN,cameraPos, CubeMap, DistanceMap, NormDistMap1,NormDistMap2,lastCenter,refIndex);
 	 
 	return Color;
