Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2819)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2820)
@@ -145,9 +145,13 @@
 bool eightKeyPressed = false;
 
-static Vector3 samples[32];
-GLubyte *randomNormals;
+GLubyte *randomNormals = NULL;
 
 PerfTimer frameTimer, algTimer;
-	
+
+
+#define NUM_SAMPLES 8
+
+static float samples[NUM_SAMPLES * 2];
+
 
 // function forward declarations
@@ -201,4 +205,7 @@
 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br);
 
+void GenerateSamples();
+
+
 GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT};
 
@@ -222,5 +229,6 @@
 static CGparameter sMaxDepthParamTex;
 
-const static float radius = 1e-3f;
+static CGparameter sSamplesParam; 
+
 
 
@@ -461,4 +469,7 @@
 		sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals");  
 		sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture");
+
+		sSamplesParam = cgGetNamedParameter(sCgSSAOProgram, "samples");
+		cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);
 	}
 	else
@@ -1690,17 +1701,18 @@
 void GenerateSamples()
 {
-	// fill an n * n * 2 array with uniformly distributed spherical samples
-	for (int i = 0; i < 32; ++ i)
+	float scale = 1.0f / (float)NUM_SAMPLES;
+
+	// fill an array with uniformly distributed spherical samples
+	for (int i = 0; i < NUM_SAMPLES; ++ i)
 	{
 		// create stratified samples over sphere
-		const float rx = RandomValue(0, 1);
-		const float ry = RandomValue(0, 1);
-		//const float l = RandomValue(0, 1);
+		const float rx = ((float)i + RandomValue(0, 1)) * scale;
 
 		const float theta = 2.0f * acos(sqrt(1.0f - rx));
-		const float phi = 2.0f * M_PI * ry;
-
-		samples[i] = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
-		cout << samples[i] << endl;
+		
+		samples[i + 0] = cos(theta);
+		samples[i + 1] = sin(theta);
+
+		cout << samples[i] << " " << samples[i + 1] << endl;
 	}
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2819)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2820)
@@ -1,6 +1,7 @@
-#define SAMPLES	24
-
+#define NUM_SAMPLES 8
+#define SAMPLE_INTENSITY 0.6
+#define AREA_SIZE 3e-1f
 // kustls magic sample positions
-static const float2 samples[SAMPLES] =
+/*static const float2 samples[NUM_SAMPLES] =
 {
   {-0.326212f, -0.405805f},
@@ -28,5 +29,5 @@
   {0.32194f, 0.932615f},
   {0.791559f, 0.597705f}
-};
+};*/
 
 
@@ -60,5 +61,6 @@
 	   uniform sampler2D positions,
 	   uniform sampler2D normals,
-	   uniform sampler2D noiseTexture				
+	   uniform sampler2D noiseTexture,
+	   uniform float2 samples[NUM_SAMPLES]
 	   )
 {
@@ -79,8 +81,8 @@
 
   //const float areaSize = 5e-1f;
-  const float areaSize = 3e-1f;
-  const float sampleIntensity = 0.2f;
+  //const float areaSize = 3e-1f;
+  //const float sampleIntensity = 0.2f;
   
-  for (int i = 0; i < SAMPLES; i ++) {
+  for (int i = 0; i < NUM_SAMPLES; i ++) {
     float2 offset = samples[i];
     
@@ -95,5 +97,5 @@
 		
     // weight with projected coordinate to reach similar kernel size for near and far
-    float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * w;
+    float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w;
     
     float3 sample_position = tex2D(positions, texcoord).xyz;
@@ -101,5 +103,5 @@
     float3 vector_to_sample = sample_position - centerPosition.xyz;
     float length_to_sample = length(vector_to_sample);
-    float3 direction_to_sample = vector_to_sample / (length_to_sample + 1e-9f);
+    float3 direction_to_sample = vector_to_sample / length_to_sample;
     
     // Angle between current normal and direction to sample controls AO intensity.
@@ -115,5 +117,5 @@
     distance_intensity = max(distance_intensity, 0.0f);
     
-    total_ao += cos_angle * sampleIntensity * distance_intensity;
+    total_ao += cos_angle * SAMPLE_INTENSITY * distance_intensity;
   }
 	
@@ -122,12 +124,9 @@
 
 
-pixel main(fragment IN, 
-	   uniform sampler2D colors,
-           uniform sampler2D positions,
-           uniform sampler2D normals,
-	   uniform sampler2D noiseTexture)
+float4 shade(fragment IN, 
+	     uniform sampler2D colors,
+	     uniform sampler2D positions,
+	     uniform sampler2D normals)
 {
-  pixel OUT;
-
   float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f);
   float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f);
@@ -152,8 +151,22 @@
   float diffuse = diffuseLight + diffuseLight2;
 
-  //float ao = ssao(IN, positions, normals, noiseTexture);
-  float ao = 1.0f;
-  //OUT.color = ao; 
-  OUT.color = ao * (ambient + diffuse) * color;
+  return (ambient + diffuse) * color;
+}
+
+
+pixel main(fragment IN, 
+	   uniform sampler2D colors,
+           uniform sampler2D positions,
+           uniform sampler2D normals,
+	   uniform sampler2D noiseTexture,
+	   uniform float2 samples[NUM_SAMPLES])
+{
+  pixel OUT;
+
+  float4 col = Shade(IN, positions, normals);
+  float ao = ssao(IN, positions, normals, noiseTexture, samples);
+  //float ao = 1.0f;
+  OUT.color = ao * col; 
+  //OUT.color = ao * (ambient + diffuse) * color;
   //OUT.color = (ambient + diffuse) * color;
       
