Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2872)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2873)
@@ -3,10 +3,10 @@
 // based on shader of Alexander Kusternig
 
-//#define NUM_SAMPLES 8
-#define NUM_SAMPLES 16
+#define NUM_SAMPLES 10
+//#define NUM_SAMPLES 16
 
 // rule of thumb: approx 1 / NUM_SAMPLES
-#define SAMPLE_INTENSITY 0.15
-//#define SAMPLE_INTENSITY 0.125f
+//#define SAMPLE_INTENSITY 0.15f
+#define SAMPLE_INTENSITY 0.2f
 
 #define AREA_SIZE 7e-1f
@@ -43,13 +43,4 @@
 
 
-/*float2 rotate(float2 pt, float2 n)
-{
-	float2 ptTransformed;
-	ptTransformed.x = n.r * pt.x - n.g * pt.y;
-	ptTransformed.y = n.g * pt.x + n.r * pt.y;
-
-	return ptTransformed;
-}*/
-
 
 /** The ssao shader returning the an intensity value between 0 and 1
@@ -74,17 +65,14 @@
 	float total_ao = 0.0;
 
-	const float areaSize = 5e-1f;
-
 	for (int i = 0; i < NUM_SAMPLES; i ++) 
 	{
 		float2 offset = samples[i];
 
-		//sample noisetex; r stores costheta, g stores sintheta
+		////////////////////
+		// add random noise: r stores costheta, g stores sintheta
+
 		//float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;
 		float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy;
 
-		// rotation
-		//float2 offsetTransformed = offset;
-		//float2 offsetTransformed = rotate(offset, mynoise);
 		float2 offsetTransformed = reflect(offset, mynoise);
 
@@ -117,70 +105,4 @@
 	return max(0.0f, 1.0f - total_ao);
 	//return dot(currentViewDir, currentNormal);
-}
-
-
-/** Computes ambient occlusion + diffuse reflections
-*/
-float4 globIllum(fragment IN,
-				 uniform sampler2D colors,
-				 uniform sampler2D positions,
-				 uniform sampler2D noiseTexture,
-				 uniform float2 samples[NUM_SAMPLES],
-				 uniform float3 currentNormal,
-				 uniform float3 currentViewDir,
-				 uniform float noiseMultiplier,
-				 uniform float4 centerPosition
-				 )
-{
-	// the w coordinate from the persp. projection
-	float w = centerPosition.w;
-
-	// Check in a circular area around the current position.
-	// Shoot vectors to the positions there, and check the angle to these positions.
-	// Summing up these angles gives an estimation of the occlusion at the current position.
-
-	// ao is in stored in the w
-	float4 total_color = float4(0, 0, 0, 1);
-
-	const float areaSize = 5e-1f;
-
-	for (int i = 0; i < NUM_SAMPLES; i ++) 
-	{
-		float2 offset = samples[i];
-
-		//sample noisetex; r stores costheta, g stores sintheta
-		float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy;
-
-		// rotation
-		float2 offsetTransformed = reflect(offset, mynoise);
-
-		// weight with projected coordinate to reach similar kernel size for near and far
-		float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w;
-
-		float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz;
-		float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, 1)).xyz;
-
-		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;
-
-		// Angle between current normal and direction to sample controls AO intensity.
-		float cos_angle = dot(direction_to_sample, currentNormal);
-		cos_angle = max(cos_angle, 0.0f);
-
-		// distance between current position and sample position controls AO intensity.
-		float distance_intensity = 
-			(SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample);
-
-		// if normal perpenticular to view dir, only half of the samples count
-		float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal));
-
-		total_color.w -= cos_angle * distance_intensity * view_correction;
-
-		const float scale_factor = 0.3f;
-		total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * scale_factor;
-	}
-
-	return saturate(total_color);
 }
 
@@ -220,10 +142,9 @@
 	const float currentDepth = currentCol.w;
 
-	//float4 new_col = (float4)ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition);
-	float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition); 
-	
+	const float ao = ssao(IN, positions, noiseTexture, samples, normal, viewDir, noiseMultiplier, centerPosition);
+		
 
 	/////////////////
-	//-- compute temporally smoothed value
+	//-- compute temporally smoothing
 
 	float4 realPos = centerPosition * maxDepth;
@@ -240,40 +161,21 @@
 	const float depthDif = 1.0f - newDepth / oldDepth;
 
+
 	if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 
 		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
-		(abs(depthDif)  < 1e-4f))
+		(abs(depthDif)  < 1e-3f))
 	{
-		OUT.illum_col = new_col * expFactor + oldCol * float4(1.0f - expFactor);
+		OUT.illum_col.x = ao * expFactor + oldCol.x * (1.0f - expFactor);
 	}
 	else
 	{
-		OUT.illum_col = new_col;
+		OUT.illum_col.x = ao;
 	}
 
-	//const float ao = OUT.illum_col.x;
-	const float ao = OUT.illum_col.w;
+	OUT.combined_col = currentCol * OUT.illum_col.x;
+	OUT.illum_col.w = currentDepth;
 
-	//OUT.combined_col = (currentCol + OUT.illum_col) * ao;
-	OUT.combined_col = currentCol * ao;
-
-	OUT.illum_col.w = currentDepth;
+	
 
 	return OUT;
 }
-
-/*
-pixel combined(fragment IN, 
-			   uniform sampler2D colors,
-			   uniform sampler2D ssaoTex
-		   )
-{
-	pixel OUT;
-
-	float4 col = tex2D(colors, IN.texCoord.xy);
-	float4 ao = tex2D(ssaoTex, IN.texCoord.xy);
-	//float4 illum = tex2D(ssaoTex, IN.texCoord.xy);
-
-	OUT.illum_col = col * ao;
-
-	return OUT;
-}*/
