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 2040)
@@ -0,0 +1,148 @@
+float4 readCubeMap(samplerCUBE cm, float3 coord)		
+{
+	float4 color = texCUBE( cm, float3(coord.xy, - coord.z) );
+	color.a = 1;
+	return color;
+}
+
+float readDistanceCubeMap(samplerCUBE dcm, float3 coord)		
+{
+	float dist = texCUBE(dcm, float3(coord.xy, - coord.z)).r;
+	if(dist == 0) dist = 1000; ///sky
+	return dist;
+}
+
+#define SECANT_ITERATIONCOUNT 2
+
+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 ShadedTex_OUT
+{
+ float4 vPos : POSITION;
+ float4 texCoord : TEXCOORD0;
+ float4 wNormal : TEXCOORD1;
+ float4 wPos    : TEXCOORD2;  
+};
+
+float4 EnvMap_Default_PS(ShadedTex_OUT IN,
+						uniform samplerCUBE CubeMap : register(s0),
+						uniform float3 cameraPos) : COLOR0
+{
+	float3 N = normalize(IN.wNormal.xyz);
+	float3 V = normalize(IN.wPos.xyz - cameraPos);
+	float3 R = reflect( V, N);	
+	
+	return readCubeMap(CubeMap, R );	
+}
+
+float4  EnvMap_Localized_Reflection_PS( ShadedTex_OUT IN,
+										uniform samplerCUBE CubeMap : register(s0),
+										uniform samplerCUBE DistanceMap : register(s1),
+										uniform float3 cameraPos,
+										uniform float3 lastCenter,		
+										uniform float sFresnel,
+										uniform float sRefraction ) :COLOR0
+{
+	float3 N = normalize(IN.wNormal.xyz);
+	float3 RR;	
+	float3 V = normalize(IN.wPos.xyz - cameraPos);
+	float3 cubePos = IN.wPos.xyz - lastCenter;
+	float3 R = reflect( V, N);	
+		
+	RR = R;
+	RR = Hit(cubePos, R, DistanceMap);
+	
+	return readCubeMap(CubeMap, RR );	
+}
+
+float4  EnvMap_Localized_Refraction_PS( ShadedTex_OUT IN,
+										uniform samplerCUBE CubeMap : register(s0),
+										uniform samplerCUBE DistanceMap : register(s1),
+										uniform float3 cameraPos,
+										uniform float3 lastCenter,		
+										uniform float sFresnel,
+										uniform float sRefraction ) :COLOR0
+{
+	float3 N = normalize(IN.wNormal.xyz);
+	float3 RR, TT;	
+	float3 V = normalize(IN.wPos.xyz - cameraPos);
+	float3 cubePos = IN.wPos.xyz - lastCenter;
+	float3 R = reflect( V, N);	
+	float3 T = refract(V, N, sRefraction);
+		
+	RR = R;	TT = T;
+	RR = Hit(cubePos, R, DistanceMap);
+	TT = Hit(cubePos, T, DistanceMap);
+	
+	float4 reflectcolor = readCubeMap(CubeMap, RR );		
+	float4 refractcolor = readCubeMap(CubeMap, TT );		
+	
+	float cos_theta = -dot(V, N);
+	float F = (sFresnel + pow(1 - cos_theta, 5.0f) * (1 - sFresnel));
+    	
+	return (F * reflectcolor + (1 - F) * refractcolor);	
+}
+
+
+float4 EnvMap_LocalizedMetal_PS(  ShadedTex_OUT IN,
+									uniform samplerCUBE CubeMap : register(s0),
+									uniform samplerCUBE DistanceMap : register(s1),
+									uniform float3 cameraPos,
+									uniform float3 lastCenter,
+									uniform float3 F0 ):COLOR0
+{	
+	float4 Color;
+	float3 N = normalize(IN.wNormal.xyz);
+	float3 RR;	
+	float3 V = normalize(IN.wPos.xyz - cameraPos);
+	float3 cubePos = IN.wPos.xyz - lastCenter;
+	float3 R = reflect( V, N);
+		
+	RR = R;	
+	RR = Hit(cubePos, R, DistanceMap);
+	Color = readCubeMap(CubeMap, RR );	
+	
+	float ctheta_in = dot(N, R);
+	float ctheta_out = dot(N, -V);
+
+	float3 F = 0;
+	
+	// compute F,P,G
+	//if ( ctheta_in > 0 && ctheta_out > 0 )
+	{
+		float3 H = normalize(R - V);	// felezõvektor
+		float cbeta  = dot(H,R);		
+		//F = ( (n-1)*(n-1) + pow(1-cbeta,5) * 4*n + k*k) / ( (n+1)*(n+1) + k*k );
+		//float3 F0 = ((n-1)*(n-1) + k*k) / ( (n+1)*(n+1) + k*k );
+		//float3 F1 = float3(1.0f,1.0f,1.0f) - F0;
+		F = F0 + (1 - F0) * pow(1 - cbeta, 5);
+	}
+		
+	return Color * float4(F,1);	
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.program
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.program	(revision 2040)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.program	(revision 2040)
@@ -0,0 +1,28 @@
+fragment_program GTP/EnvMap/Defaut_PS hlsl
+{
+	source GTPEnvMap.hlsl
+	entry_point EnvMap_Default_PS
+	target ps_2_0
+}
+
+fragment_program GTP/EnvMap/Localized_Reflection_PS hlsl
+{
+	source GTPEnvMap.hlsl
+	entry_point EnvMap_Localized_Reflection_PS
+	target ps_3_0
+} 
+
+fragment_program GTP/EnvMap/Localized_Refraction_PS hlsl
+{
+	source GTPEnvMap.hlsl
+	entry_point EnvMap_Localized_Refraction_PS
+	target ps_3_0
+}
+
+fragment_program GTP/EnvMap/Localized_Metal_PS hlsl
+{
+	source GTPEnvMap.hlsl
+	entry_point EnvMap_LocalizedMetal_PS
+	target ps_3_0
+} 
+
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 2040)
@@ -0,0 +1,231 @@
+material GTP/EnvMap/Default
+{
+   technique 
+   {   
+      pass 
+      { 
+		 IllumTechniques
+		 {
+			RenderTechnique ColorCubeMap
+			{
+				update_interval		1
+				update_all_face true
+				distance_calc false					
+				face_angle_calc false
+			}			
+		 }      
+	     vertex_program_ref GTP/Basic/ShadedTex_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/Defaut_PS
+     	 { 
+		    param_named_auto cameraPos camera_position            
+	     }		
+	     //Cube map of reflections	
+	     texture_unit
+	     {
+	    
+	     }	     
+	  }
+   }
+}
+
+material GTP/EnvMap/Localized_Reflector
+{
+   technique 
+   {   
+      pass 
+      { 
+		 IllumTechniques
+		 {
+			RenderTechnique ColorCubeMap
+			{
+				update_interval		0
+				update_all_face true
+				distance_calc true 3.5					
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		0
+				update_all_face true
+				distance_calc true 3.5						
+			}			
+		 }      
+	     vertex_program_ref GTP/Basic/ShadedTex_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_Reflection_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
+	     {
+	   
+	     }
+	  }
+   }
+}
+
+material GTP/EnvMap/Localized_Reflector_Refractor
+{
+   technique 
+   {   
+      pass 
+      { 
+		 IllumTechniques
+		 {
+			RenderTechnique ColorCubeMap
+			{
+				update_interval		0
+				update_all_face true
+				distance_calc true 3.5					
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		0
+				update_all_face true
+				distance_calc true 3.5						
+			}		
+		 }      
+	     vertex_program_ref GTP/Basic/ShadedTex_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.104
+            param_named sRefraction float 0.6667
+	     }		
+	     //Cube map for reflections and refractions	
+	     texture_unit
+	     {
+	    
+	     }
+	     //Cube map of distances
+	     texture_unit
+	     {
+	   
+	     }
+	  }
+   }
+}
+
+material GTP/EnvMap/Localized_Metal
+{
+   technique
+   {   
+      pass mainpass
+      { 
+		 IllumTechniques
+		 {
+			RenderTechnique ColorCubeMap
+			{
+				update_interval		0
+				update_all_face true
+				distance_calc true 3.5					
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		0
+				update_all_face true
+				distance_calc true 3.5						
+			}			
+		 }      
+	     vertex_program_ref GTP/Basic/ShadedTex_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_Metal_PS
+     	 { 
+		    param_named_auto cameraPos camera_position
+            param_named lastCenter float3 0 0 0
+            param_named F0 float3 1 1 1            
+	     }		
+	     //Cube map for reflections and refractions	
+	     texture_unit
+	     {
+	    
+	     }
+	     //Cube map of distances
+	     texture_unit
+	     {
+	   
+	     }
+	  }
+   }
+}
+
+material GTP/EnvMap/Gold : GTP/EnvMap/Localized_Metal
+{
+   technique
+   {   
+      pass mainpass
+      {
+        fragment_program_ref
+        {
+          param_named F0 float3 0.96 0.85 0.39
+        }
+      }
+   }
+}
+
+material GTP/EnvMap/Silver : GTP/EnvMap/Localized_Metal
+{
+   technique
+   {   
+      pass mainpass
+      {
+        fragment_program_ref
+        {
+          param_named F0 float3 0.97 0.95 0.9
+        }
+      }
+   }
+}
+
+material GTP/EnvMap/Copper : GTP/EnvMap/Localized_Metal
+{
+   technique
+   {   
+      pass mainpass
+      {
+        fragment_program_ref
+        {
+          param_named F0 float3 0.95 0.63 0.54
+        }
+      }
+   }
+}
+
+material GTP/EnvMap/Alu : GTP/EnvMap/Localized_Metal
+{
+   technique
+   {   
+      pass mainpass
+      {
+        fragment_program_ref
+        {
+          param_named F0 float3 0.9 0.92 0.92
+        }
+      }
+   }
+}
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 2040)
@@ -0,0 +1,145 @@
+material GTP/Caustic/PhotonMap_HitEnv
+{
+ 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/Caustic/PhotonMapHitEnv_PS
+   {
+     param_named_auto cameraPos camera_position
+     param_named lastCenter float3 0 0 0
+     param_named reflIndex float 0.85	
+   }
+   //cubemap of distances
+   texture_unit
+   {
+   
+   }
+  }
+ }
+}
+
+material GTP/Caustic/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 20.0
+   } 
+   fragment_program_ref GTP/Caustic/CauCube_PointSprite_PS
+   {
+     param_named CausticColor float4          0.7 0.7 0.5 0.15
+   }
+   texture_unit
+   {
+     vertex_texture true	 
+   }
+   texture_unit
+   {
+     texture PowerOfPhotonHitTexel.dds
+   }
+  }
+ }
+}
+
+material GTP/Caustic/CauCube_Triangles
+{
+ technique
+ {
+  pass
+  { 
+   cull_hardware none
+   scene_blend src_alpha one
+   depth_write off
+   vertex_program_ref GTP/Caustic/CauCube_Triangles_VS
+   {
+     param_named_auto WorldView      worldview_matrix
+     param_named_auto Proj           projection_matrix
+     param_named PhotonMapResolution float 32
+   } 
+   fragment_program_ref GTP/Caustic/CauCube_Triangles_PS
+   {
+     param_named CausticColor float4 0.7 0.7 0.5 1
+   }
+   texture_unit
+   {
+     vertex_texture true	 
+   }
+  }
+ }
+}
+
+material GTP/Caustic/Glass
+{
+   technique 
+   {   
+      pass 
+      { 
+		 IllumTechniques
+		 {
+			RenderTechnique ColorCubeMap
+			{
+				update_interval		0
+				update_all_face true
+				distance_calc true 3.5					
+			}
+			RenderTechnique DistanceCubeMap
+			{
+				update_interval		0
+				update_all_face true
+				distance_calc true 3.5						
+			}
+			RenderTechnique CausticCaster
+			{
+				attenuation	0
+				photonmap_resolution 32
+				caustic_cubemap_resolution 256
+				photon_map_material	GTP/Caustic/PhotonMap_HitEnv
+				caustic_map_material	GTP/Caustic/CauCube_PointSprite
+				//caustic_map_material	GTP/Caustic/CauCube_Triangles
+				//use_triangles	true
+				//blur_caustic_cubemap true				
+			}
+			
+		 }      
+	     vertex_program_ref GTP/Basic/ShadedTex_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.9
+	     }		
+	     //Cube map for reflections and refractions	
+	     texture_unit
+	     {
+	    
+	     }
+	     //Cube map of distances
+	     texture_unit
+	     {
+	   
+	     }
+	  }
+   }
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.program
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.program	(revision 2040)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.program	(revision 2040)
@@ -0,0 +1,41 @@
+fragment_program GTP/Caustic/PhotonMapHitEnv_PS hlsl
+{
+   source GTPCaustic.hlsl
+   entry_point PhotonMapHitEnvPS
+   target ps_3_0
+}
+
+vertex_program GTP/Caustic/CauCube_PointSprite_VS hlsl
+{
+   source GTPCaustic.hlsl
+   entry_point CauCube_PointSprite_VS
+   target vs_3_0
+}
+
+fragment_program GTP/Caustic/CauCube_PointSprite_PS hlsl
+{
+   source GTPCaustic.hlsl
+   entry_point CauCube_PointSprite_PS
+   target ps_3_0
+}
+
+vertex_program GTP/Caustic/CauCube_Triangles_VS hlsl
+{
+   source GTPCaustic.hlsl
+   entry_point CauCube_Triangles_VS
+   target vs_3_0
+}
+
+fragment_program GTP/Caustic/CauCube_Triangles_PS hlsl
+{
+   source GTPCaustic.hlsl
+   entry_point CauCube_Triangles_PS
+   target ps_3_0
+}
+
+fragment_program GTP/Caustic/GatherCaustic_Cube_PS hlsl
+{
+   source GTPCaustic.hlsl
+   entry_point GatherCaustic_Cube_PS
+   target ps_3_0
+}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.programs
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.programs	(revision 2024)
+++ 	(revision )
@@ -1,41 +1,0 @@
-fragment_program GTP/Caustic/PhotonMapHitEnv_PS hlsl
-{
-   source GTPCaustic.hlsl
-   entry_point PhotonMapHitEnvPS
-   target ps_3_0
-}
-
-vertex_program GTP/Caustic/CauCube_PointSprite_VS hlsl
-{
-   source GTPCaustic.hlsl
-   entry_point CauCube_PointSprite_VS
-   target vs_3_0
-}
-
-fragment_program GTP/Caustic/CauCube_PointSprite_PS hlsl
-{
-   source GTPCaustic.hlsl
-   entry_point CauCube_PointSprite_VS
-   target ps_3_0
-}
-
-vertex_program GTP/Caustic/CauCube_Triangles_VS hlsl
-{
-   source GTPCaustic.hlsl
-   entry_point CauCube_Triangles_VS
-   target vs_3_0
-}
-
-fragment_program GTP/Caustic/CauCube_Triangles_PS hlsl
-{
-   source GTPCaustic.hlsl
-   entry_point CauCube_Triangles_PS
-   target ps_3_0
-}
-
-fragment_program GTP/Caustic/GatherCaustic_Cube_PS hlsl
-{
-   source GTPCaustic.hlsl
-   entry_point GatherCaustic_Cube_PS
-   target ps_3_0
-}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.materials
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.materials	(revision 2024)
+++ 	(revision )
@@ -1,81 +1,0 @@
-material GTP/Caustic/PhotonMap_HitEnv
-{
- 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
-   } 
-   vertex_program_ref GTP/Caustic/PhotonMapHitEnv_PS
-   {
-     param_named_auto cameraPos camera_position
-     param_named float3 lastCenter 0 0 0
-     param_named float  reflIndex 0.85	
-   }
-  }
- }
-}
-
-material GTP/Caustic/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          proj_matrix
-     param_named CauSpriteSize      float 20.0
-   } 
-   vertex_program_ref GTP/Caustic/CauCube_PointSprite_PS
-   {
-     param_named CausticColor float4          0.7 0.7 0.5 0.15
-   }
-   texture_unit
-   {
-     vertex_texture true	 
-   }
-   texture_unit
-   {
-     texture PowerOfPhotonHitTexel.dds
-   }
-
-  }
- }
-}
-
-material GTP/Caustic/CauCube_Triangles
-{
- technique
- {
-  pass
-  { 
-   cull_hardware none
-   scene_blend src_alpha one
-   depth_write off
-   vertex_program_ref GTP/Caustic/CauCube_Triangles_VS
-   {
-     param_named_auto WorldView      worldview_matrix
-     param_named_auto Proj           proj_matrix
-     param_named PhotonMapResolution float 64
-   } 
-   vertex_program_ref GTP/Caustic/CauCube_Triangles_PS
-   {
-     param_named CausticColor float4 0.7 0.7 0.5 1
-   }
-   texture_unit
-   {
-     vertex_texture true	 
-   }
-  }
- }
-}
Index: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.material
===================================================================
--- GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.material	(revision 2024)
+++ GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.material	(revision 2040)
@@ -98,5 +98,5 @@
      param_named_auto WorldView     worldview_matrix
    } 
-   vertex_program_ref GTP/Basic/CDist
+   fragment_program_ref GTP/Basic/CDist_PS
    {	
    }   
