Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2834)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2835)
@@ -241,6 +241,4 @@
 void InitFBO();
 
-void GenerateSamples();
-
 void CreateNoiseTex2D();
 
@@ -273,4 +271,5 @@
 static CGparameter sOldModelViewProjMatrixParam;
 static CGparameter sMaxDepthParam;
+static CGparameter sMaxDepthParamSsao;
 static CGparameter sMaxDepthParamTex;
 
@@ -443,5 +442,4 @@
 	// create noise texture for ssao
 	CreateNoiseTex2D();
-
 	// init render traverser
 	ResetTraverser();
@@ -561,12 +559,12 @@
 		sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier");
 		sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj");
-		
-		cgGLDisableTextureParameter(sNoiseTexParamSsao);
+		sMaxDepthParamSsao = cgGetNamedParameter(sCgSsaoProgram, "maxDepth");
+
+		cgGLSetParameter1f(sMaxDepthParamSsao, myfar / 10.0f);
 
 		sSamplesParamSsao = cgGetNamedParameter(sCgSsaoProgram, "samples");
 		sOldTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "oldTex");  
 
-		GenerateSamples();
-		cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples);
+		GenerateSamples(); cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples);
 	}
 	else
@@ -649,5 +647,5 @@
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer);
 	
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
 	int samples = 8;
 	//glEnable(GL_MULTISAMPLE_ARB);
@@ -658,10 +656,10 @@
 	glBindTexture(GL_TEXTURE_2D, colorsTex);
 
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
+	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0);
 
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -744,5 +742,5 @@
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer1);
 	
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer1);
 	
@@ -750,14 +748,17 @@
 	glBindTexture(GL_TEXTURE_2D, colorsTex1);
 
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
+	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex1, 0);
 
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
 
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+
 	PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
 
@@ -776,5 +777,5 @@
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer2);
 	
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer2);
 	
@@ -782,10 +783,15 @@
 	glBindTexture(GL_TEXTURE_2D, colorsTex2);
 
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
+	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex2, 0);
 
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -2319,6 +2325,6 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
-	//glTexImage2D(GL_RGBA, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, randomNormals);
-	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texWidth, texHeight, GL_RGB, GL_UNSIGNED_BYTE, randomNormals);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals);
+	//gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texWidth, texHeight, GL_RGB, GL_UNSIGNED_BYTE, randomNormals);
 
 	glBindTexture(GL_TEXTURE_2D, 0);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2834)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2835)
@@ -7,5 +7,5 @@
 //#define SAMPLE_INTENSITY 0.125f
 // rule of thumb: approx 1 / NUM_SAMPLES
-#define SAMPLE_INTENSITY 0.2 //0.0625f
+#define SAMPLE_INTENSITY 0.16 //0.0625f
 
 #define AREA_SIZE 5e-1f
@@ -76,9 +76,9 @@
 
 		//sample noisetex; r stores costheta, g stores sintheta
-		float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;
+		float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;
 
 		// rotation
 		//float2 offsetTransformed = offset;
-		float2 offsetTransformed = rotate(offset, noise);
+		float2 offsetTransformed = rotate(offset, mynoise);
 		//float2 offsetTransformed = reflect(offset, noise);
 
@@ -95,10 +95,6 @@
 		float cos_angle = dot(direction_to_sample, currentNormal);
 		cos_angle = max(cos_angle, 0.0f);
-		// take quadratic influence to sharpen contrast
-		//cos_angle *= cos_angle;
 
 		// distance between current position and sample position controls AO intensity.
-		//const float maxdist = 2e-1f;
-		//const float maxdist = 5e-1f;
 		const float distanceScale = 1e-6f;
 
@@ -107,6 +103,5 @@
 
 		// if normal perpenticular to view dir, only half of the samples count
-		float view_correction = (2.0f - dot(currentViewDir, currentNormal));
-		view_correction *= view_correction;
+		float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal));
 
 		total_ao += cos_angle * distance_intensity * view_correction;
@@ -144,8 +139,8 @@
 
 		//sample noisetex; r stores costheta, g stores sintheta
-		float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;
+		float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f;
 
 		// rotation
-		float2 offsetTransformed = rotate(offset, noise);
+		float2 offsetTransformed = rotate(offset, mynoise);
 
 		// weight with projected coordinate to reach similar kernel size for near and far
@@ -171,5 +166,4 @@
 		// if normal perpenticular to view dir, only half of the samples count
 		float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal));
-		//view_correction *= view_correction;
 
 		total_ao += cos_angle * distance_intensity * view_correction;
@@ -218,5 +212,6 @@
 				uniform float noiseMultiplier,
 				uniform sampler2D oldTex,
-				const uniform float4x4 oldModelViewProj
+				const uniform float4x4 oldModelViewProj,
+				uniform float maxDepth
 				)
 {
@@ -236,5 +231,5 @@
 
 	//float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition);
-	float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition);
+	float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
 	float ao = new_col.w;
 
@@ -244,5 +239,5 @@
 	//OUT.color = ao;
 	//OUT.color = ao * col; 
-	float4 dummy = centerPosition / 0.000487676f;
+	float4 dummy = centerPosition * maxDepth;
 	dummy.w = 1.0f;
 	float4 oldPos = mul(oldModelViewProj, dummy);
@@ -250,5 +245,5 @@
 	float newDepth = oldPos.z / oldPos.w;
  
-	const float x = 0.05f;
+	const float x = 0.1f;
 
 	float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f;
@@ -257,7 +252,8 @@
 	float oldDepth = col1.w;
 
-	if ((tex.x >= 0) && (tex.x <= 1) && (tex.y >= 0) && (tex.y <= 1) && (abs(newDepth - oldDepth) < 5e-4f))
+	if ((tex.x >= 0.0f) && (tex.x < 1.0f) && (tex.y >= 0.0f) && (tex.y < 1.0f) && (abs(newDepth - oldDepth) < 9e-4f))
 		OUT.color = attenuated_color * x + col1 * float4(1.0f - x);
-	else		OUT.color = attenuated_color;// * x + col1 * float4(1.0f - x);
+	else
+		OUT.color = attenuated_color;
 
 	//OUT.color = float4(centerPosition.w);
@@ -292,5 +288,5 @@
 	float4 col1 = tex2D(oldTex, IN.texCoord.xy);
 
-	const float x = 0.1f;
+	const float x = 0.01f;
 	OUT.color = col * x + col1 * float4(1.0f - x);
 
