Index: GTP/trunk/App/Demos/Illum/EnvMap/.matrix
===================================================================
--- GTP/trunk/App/Demos/Illum/EnvMap/.matrix	(revision 1488)
+++ GTP/trunk/App/Demos/Illum/EnvMap/.matrix	(revision 1534)
@@ -1,12 +1,12 @@
 
 World matrix:
-         1          0          0          0
-         0          1          0          0
-         0          0          1          0
-         0          0       6.82          1
+         1  -0.003845  -0.004636          0
+  0.004172     0.9974    0.07259          0
+  0.004345   -0.07261     0.9974          0
+-1.863e-009 -5.96e-008       6.82          1
 
 Camera position:
-         0          0      -6.82
+ 0.0316175  -0.495054   -6.80194
 
 Mesh position:
-      -1.4          0          0
+-0.0666665          0          0
Index: GTP/trunk/App/Demos/Illum/EnvMap/Parameters.h
===================================================================
--- GTP/trunk/App/Demos/Illum/EnvMap/Parameters.h	(revision 1488)
+++ GTP/trunk/App/Demos/Illum/EnvMap/Parameters.h	(revision 1534)
@@ -16,5 +16,6 @@
 	DIFFUSE_SPECULAR_CLASSIC,		///< Classic environment mapping technique.
 	DIFFUSE_SPECULAR_LOCALIZED,		///< Our proposal.
-	DIFFUSE_SPECULAR_LOCALIZED_5TEX	///< Our proposal, using 5 texel only.
+	DIFFUSE_SPECULAR_LOCALIZED_5TEX,	///< Our proposal, using 5 texel only.
+	DIFFUSE_SPECULAR_LOCALIZED_NEW		///< Our proposal.	
 } method_t;
 
Index: GTP/trunk/App/Demos/Illum/EnvMap/.params
===================================================================
--- GTP/trunk/App/Demos/Illum/EnvMap/.params	(revision 1488)
+++ GTP/trunk/App/Demos/Illum/EnvMap/.params	(revision 1534)
@@ -1,8 +1,8 @@
 47 version ----- RayTraceEffects: Saved parameters of the algorithm -----
 Bool values:
-0001
-(Help [F1]; [A]utoGenCubeMap; ; [F]ireballs; Multiple [O]bjects; Between [W]alls only; )
+0111
+(Help [F1]; [F]ireballs; Multiple [O]bjects; Between [W]alls only; )
 Float values:
-2 	(WhichMethod [Q,TAB], 0..2)
+3 	(WhichMethod [TAB,Q], 0..3)
 8 	(WhichMesh [Home,End], 0..9)
 34 	(Mesh size [Ins,Del], 0..100)
Index: GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.fx
===================================================================
--- GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.fx	(revision 1488)
+++ GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.fx	(revision 1534)
@@ -455,4 +455,196 @@
 }
 
+// Method #3
+
+/// \brief Calculates diffuse or specular contributions of the 5 "most important" texels of #SmallEnvironmentMap to the current point.
+/// For these texels, function GetContr(int,float3,float3,float3,float3) is called.
+float4 GetContibution(float3 L1, float3 L2, float3 L3, float3 L4, float3 pos, float3 N, float d)
+{
+	L1 = d * normalize(L1);
+	L2 = d * normalize(L2);
+	L3 = d *  normalize(L3);
+	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 kd = 0.3;	// 0.3
+	/*
+	float3 R;
+	R = cross(r1, r2);
+	float tri1 = asin(length(R)) * dot(R, N);
+	R = cross(r2, r3);
+	float tri2 = asin(length(R)) * dot(R, N);
+	R = cross(r3, r4);
+	float tri3 = asin(length(R)) * dot(R, N);
+	R = cross(r4, r1);
+	float tri4 = asin(length(R)) * dot(R, N);
+	*/
+	
+	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);
+	
+	return max(tri1 + tri2 + tri3 + tri4, 0);	
+	//return tri1 + tri2 + tri3 + tri4;	
+}
+
+float4 EnvMapDiffuseLocalizedNewPS( _EnvMapVS_output IN ) : COLOR			
+{		
+	float M = 4.0;																			
+	IN.View = -normalize( IN.View );												
+	IN.Normal = normalize( IN.Normal );												
+	IN.Position -= reference_pos.xyz;				
+	float3 pos = IN.Position.xyz;	
+	
+	//return	reference_pos;
+	//return  texCUBE(SmallEnvironmentMapSampler, pos);	
+												
+	float3 N =IN.Normal;																				
+	float3 R = -reflect( IN.View, IN.Normal );		
+													
+    float4 I = 0;									
+	float3 L1, L2, L3, L4, L;						
+	float4 Le;										
+	float d;										
+	float width = 1.0 / M;							
+	
+	for (int x = 0; x < M; x++)			
+	 for (int y = 0; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = (x + 0.5) * width;	// 0..1
+	    tpos.y = (y + 0.5) * width;	// 0..1
+	    
+	    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(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);
+		d = texCUBE(SmallEnvironmentMapSampler, L).a;	
+		
+		I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);			
+		//I += Le / 16.0;
+	 }																			
+			
+	for (int x = 0; x < M; x++)			
+	 for (int y = 0; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = (x + 0.5) * width;	// 0..1
+	    tpos.y = (y + 0.5) * 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(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);
+		d = texCUBE(SmallEnvironmentMapSampler, L).a;	
+		
+		I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);			
+		//I += Le / 16.0;
+	 }	
+	 
+	for (int x = 0; x < M; x++)			
+	 for (int y = 0; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = (x + 0.5) * width;	// 0..1
+	    tpos.y = (y + 0.5) * 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(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);
+		d = texCUBE(SmallEnvironmentMapSampler, L).a;	
+		
+		I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);			
+		//I += Le / 16.0;
+	 }		
+	 
+	for (int x = 0; x < M; x++)			
+	 for (int y = 0; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = (x + 0.5) * width;	// 0..1
+	    tpos.y = (y + 0.5) * 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(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);
+		d = texCUBE(SmallEnvironmentMapSampler, L).a;	
+		
+		I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);			
+		//I += Le / 16.0;
+	 }
+	 for (int x = 0; x < M; x++)			
+	 for (int y = 0; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = (x + 0.5) * width;	// 0..1
+	    tpos.y = (y + 0.5) * 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(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);
+		d = texCUBE(SmallEnvironmentMapSampler, L).a;	
+		
+		I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);			
+		//I += Le / 16.0;
+	 }
+	 
+	 for (int x = 0; x < M; x++)			
+	 for (int y = 0; y < M; y++)											
+	 {																
+		float2 p, tpos; 
+	    tpos.x = (x + 0.5) * width;	// 0..1
+	    tpos.y = (y + 0.5) * 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(texCUBE(SmallEnvironmentMapSampler, L).rgb, 1);
+		d = texCUBE(SmallEnvironmentMapSampler, L).a;	
+		
+		I += 0.5 * Le * GetContibution( L1, L2, L3, L4, pos, N, d);			
+		//I += Le / 16.0;
+	 }																					
+	return intensity * I;															
+}
+
 
 //--------------------------------------------------------------------------------------
@@ -552,4 +744,9 @@
 TechniqueUsingCommonVS( EnvMapDiffuseLocalized16 );
 
+TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew );
+//TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew4 );
+//TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew8 );
+//TechniqueUsingCommonVS( EnvMapDiffuseLocalizedNew16 );
+
 #define ReduceTextureTechnique(M);									\
 	technique ReduceTexture##M										\
Index: GTP/trunk/App/Demos/Illum/EnvMap/Main.cpp
===================================================================
--- GTP/trunk/App/Demos/Illum/EnvMap/Main.cpp	(revision 1488)
+++ GTP/trunk/App/Demos/Illum/EnvMap/Main.cpp	(revision 1534)
@@ -199,5 +199,5 @@
 
 	// SLIDERS
-	pp.Add( iWhichMethod, "WhichMethod [TAB,Q]", 2, VK_TAB, 'Q', noconvert, OnChangeCubeMap );	
+	pp.Add( iWhichMethod, "WhichMethod [TAB,Q]", 3, VK_TAB, 'Q', noconvert, OnChangeCubeMap );	
 	pp.Add( iWhichMesh, "WhichMesh [Home,End]", 9, VK_HOME, VK_END, noconvert, OnChangeMesh );	
 	pp.Add( fMeshScale, "Mesh size [Ins,Del]", 100, VK_DELETE, VK_INSERT, noconvert, OnChangeMeshSize );	
@@ -700,4 +700,11 @@
 			else
 				txtHelper.DrawFormattedTextLine( L"Method : Our method (diffuse)"); 
+			break;
+		case DIFFUSE_SPECULAR_LOCALIZED_NEW:
+			if (pp.GetInt( iShininess ) > 0)
+				txtHelper.DrawFormattedTextLine( L"Method : Our method New (specular, s=%i)",
+					pp.GetInt( iShininess )); 
+			else
+				txtHelper.DrawFormattedTextLine( L"Method : Our method New (diffuse)"); 
 			break;
 		case DIFFUSE_SPECULAR_LOCALIZED_5TEX:
Index: GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.cpp
===================================================================
--- GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.cpp	(revision 1488)
+++ GTP/trunk/App/Demos/Illum/EnvMap/EnvMap.cpp	(revision 1534)
@@ -288,4 +288,8 @@
 			sprintf(techniqueName, "EnvMapDiffuseLocalized%i", LR_CUBEMAP_SIZE );
 			V( g_pEffect->SetTechnique( techniqueName ) );
+			break;
+		case DIFFUSE_SPECULAR_LOCALIZED_NEW:
+			sprintf(techniqueName, "EnvMapDiffuseLocalizedNew%i", LR_CUBEMAP_SIZE );
+			V( g_pEffect->SetTechnique( "EnvMapDiffuseLocalizedNew" ) );
 			break;
 		case DIFFUSE_SPECULAR_LOCALIZED_5TEX:
