Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2832)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2833)
@@ -242,5 +242,4 @@
 static CGparameter sPositionsTexParam;
 static CGparameter sNormalsTexParam;
-//static CGparameter sNoiseTexParam;
 
 static CGparameter sColorsTexParamSsao;
@@ -250,11 +249,9 @@
 
 static CGparameter sModelViewProjMatrixParam;
-//static CGparameter sModelMatrixParam;
 static CGparameter sMaxDepthParam;
 static CGparameter sMaxDepthParamTex;
 
-//static CGparameter sSamplesParam; 
 static CGparameter sSamplesParamSsao; 
-static CGparameter sNoiseMultiplierParam;; 
+//static CGparameter sNoiseMultiplierParam;; 
 
 
@@ -538,5 +535,5 @@
 		sNormalsTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "normals");  
 		sNoiseTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "noiseTexture");
-		sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier");
+		//sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier");
 		
 		cgGLDisableTextureParameter(sNoiseTexParamSsao);
@@ -923,5 +920,5 @@
 	glLoadIdentity();
 
-	gluPerspective(fov, 1.0f / winAspectRatio, nearDist, myfar);
+	gluPerspective(fov, winAspectRatio, nearDist, myfar);
 
 	glMatrixMode(GL_MODELVIEW);
@@ -1397,10 +1394,10 @@
 	winHeight = h;
 
-	if (w) winAspectRatio = (float) h / (float) w;
+	if (w) winAspectRatio = (float) w / (float) h;
 
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
 
-	gluPerspective(fov, 1.0f / winAspectRatio, nearDist, myfar);
+	gluPerspective(fov, winAspectRatio, nearDist, myfar);
 
 	glMatrixMode(GL_MODELVIEW);
@@ -1921,5 +1918,5 @@
 		cgGLSetTextureParameter(sNoiseTexParamSsao, noiseTex);
 
-		cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(3.0f, 7.0f));
+		//cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(3.0f, 7.0f));
 	}
 	else
@@ -2051,18 +2048,18 @@
 {
 	// generates poisson distribution on disc
-	float factor = 1.0f;
-	float minDist = factor / (sqrt((float)NUM_SAMPLES) * 2.0f);
+	//float factor = 5.0f;
+	float minDist = 2.0f;//factor / sqrt((float)NUM_SAMPLES);
 
 	cout << "minDist= " << minDist << endl;
 
-	for (int i = 0; i < NUM_SAMPLES; i += 2)
-	{
-		int tries = 0;
+	for (int i = 0; i < NUM_SAMPLES * 2; i += 2)
+	{
+		int tries = 0, totalTries = 0;
 
 		// repeat until valid sample was found
 		while (1)
 		{
-
 			++ tries;
+			++ totalTries;
 
 			const float rx = RandomValue(-1, 1);
@@ -2093,5 +2090,5 @@
 			}
 
-			if (tries > 1000)
+			if (tries > 2000)
 			{
 				minDist *= 0.9f;
@@ -2099,5 +2096,5 @@
 			}
 		}
-		cout << "sample: " << samples[i] << " " << samples[i + 1] << " r: " << sqrt(samples[i] * samples[i]  + samples[i + 1] * samples[i + 1]) << " tries: " << tries << endl;
+		cout << "sample: " << samples[i] << " " << i /2 << " " << samples[i + 1] << " r: " << sqrt(samples[i] * samples[i]  + samples[i + 1] * samples[i + 1]) << " tries: " << totalTries << endl;
 	}
 
@@ -2112,14 +2109,17 @@
 {
 	float myfov = fov * M_PI / 180.0f;
-	const float h_far = 2.0f * tan(myfov / 2.0f);
-	const float w_far = h_far * texWidth / texHeight;
+
+	const float w_far = 2.0f * tan(myfov / 2.0f);
+	const float aspect = texWidth / texHeight;
+
+	const float h_far = w_far / aspect;
 
 	float t1 = h_far * 0.5f;
 	float t2 = w_far * 0.5f;
 
-	bl = Normalize(Vector3(-t1, -t2, 1.0f));
-	br = Normalize(Vector3( t1, -t2, 1.0f));
-	tl = Normalize(Vector3(-t1,  t2, 1.0f));
-	tr = Normalize(Vector3( t1,  t2, 1.0f));
+	bl = Normalize(-Vector3(-t1, -t2, 1.0f));
+	br = Normalize(-Vector3( t1, -t2, 1.0f));
+	tl = Normalize(-Vector3(-t1,  t2, 1.0f));
+	tr = Normalize(-Vector3( t1,  t2, 1.0f));
 
 	// normalize to 0 .. 1
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2832)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2833)
@@ -6,5 +6,5 @@
 //#define SAMPLE_INTENSITY 0.5f
 //#define SAMPLE_INTENSITY 1.1f
-#define SAMPLE_INTENSITY 0.7f
+#define SAMPLE_INTENSITY 0.25f
 #define AREA_SIZE 5e-1f
 
@@ -14,4 +14,5 @@
   float4 pos: WPOS; // normalized screen position
   float4 texCoord: TEXCOORD0; 
+  float3 view: COLOR0;
 };
 
@@ -51,5 +52,5 @@
 	   uniform float2 samples[NUM_SAMPLES],
 	   uniform float3 currentNormal,
-	   uniform float noiseMultiplier)
+	   uniform float3 currentViewDir)
 {
   // the current world position
@@ -72,5 +73,5 @@
     
     //sample noisetex; r stores costheta, g stores sintheta
-    float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;
+    float2 noise = tex2D(noiseTexture, IN.texCoord.xy * 7.1f).xy * 2.0f - 1.0f;
 	
     // rotation
@@ -98,11 +99,12 @@
     //const float maxdist = 5e-1f;
     const float distanceScale = 1e-6f;
-    //float distance_intensity = maxdist - length_to_sample;
-    float distance_intensity = (SAMPLE_INTENSITY * distanceScale) / (distanceScale + length_to_sample * length_to_sample);
-    //distance_intensity = max(distance_intensity, 0.0f);
-    // quadratic influence
-    //distance_intensity *= distance_intensity;
-    
-    total_ao += cos_angle * distance_intensity;
+
+    float distance_intensity = 
+      (SAMPLE_INTENSITY * distanceScale) / (distanceScale + length_to_sample * length_to_sample);
+
+    // if normal perpenticular to view dir, only half of the samples count
+    float view_correction = (2.0f - dot(currentViewDir, currentNormal));
+
+    total_ao += cos_angle * distance_intensity * view_correction;
   }
 	
@@ -133,5 +135,6 @@
   float diffuseLight2 = max(dot(normal, light2), 0.0f);
 
-  float diffuse = diffuseLight + diffuseLight2;
+  //float diffuse = diffuseLight + diffuseLight2;
+  float diffuse = diffuseLight;
 
   return (ambient + diffuse) * color * (1.0f - amb) + amb * color;
@@ -140,10 +143,9 @@
 
 pixel main_ssao(fragment IN, 
-	       uniform sampler2D colors,
-	       uniform sampler2D positions,
-	       uniform sampler2D normals,
-	       uniform sampler2D noiseTexture,
-	       uniform float2 samples[NUM_SAMPLES],
-	       uniform float noiseMultiplier)
+		uniform sampler2D colors,
+		uniform sampler2D positions,
+		uniform sampler2D normals,
+		uniform sampler2D noiseTexture,
+		uniform float2 samples[NUM_SAMPLES])
 {
   pixel OUT;
@@ -154,7 +156,8 @@
   // expand normal
   normal = normalize(normal * 2.0f - 1.0f);
+  float3 viewDir = normalize(IN.view * 2.0f - float(1.0f));
 
   float4 col = shade(IN, colors, positions, normal, amb);
-  float ao = ssao(IN, positions, noiseTexture, samples, normal, noiseMultiplier);
+  float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir);
   
    //OUT.color = ao;
@@ -175,6 +178,7 @@
   float amb = normal.w;
 
+  //OUT.color.xyz = IN.view;
   // expand normal
-  normal = normalize(normal * 2.0f - 1.0f);
+  normal = normalize(normal * 2.0f - float4(1.0f));
   
   float4 col = shade(IN, colors, positions, normal.xyz, amb);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2822)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2833)
@@ -91,5 +91,5 @@
   pix.col = diffuse;
   pix.pos = IN.worldPos * maxDepth;
-  pix.norm.xyz = IN.normal * 0.5f + 0.5f;
+  pix.norm.xyz = IN.normal * 0.5f + float4(0.5f);
   // hack: squeeze some information about ambient into the texture
   pix.norm.w = ambient.x;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2825)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2833)
@@ -179,7 +179,7 @@
 		texcoords = NULL;
 	}
-
-	//return new Geometry(vertices, normals, texcoords, vertexCount, true);
-	return new Geometry(vertices, normals, texcoords, vertexCount, false);
+	
+
+	return new Geometry(vertices, normals, texcoords, vertexCount, true);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2829)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2833)
@@ -174,8 +174,8 @@
 	float z_far = mFar;
 
-	const float h_near = 2.0f * tan(mFovy / 2) * z_near;
-	const float w_near = h_near * GetAspect();
-	const float h_far = 2.0f * tan(mFovy / 2) * z_far;
-	const float w_far = h_far * GetAspect();
+	const float w_near = 2.0f * tan(mFovy / 2) * z_near;
+	const float h_near = w_near / GetAspect();
+	const float w_far = 2.0f * tan(mFovy / 2) * z_far;
+	const float h_far = w_far / GetAspect();
 
 	const Vector3 view = GetDirection();
