Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3083)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3084)
@@ -42,5 +42,7 @@
 #define MAX_LOD_LEVEL 10
 
-#define MIN_DEPTH_DIFF 1e-5f
+#define MIN_DEPTH_DIFF 1e-6f
+#define PRECISION_SCALE 1e-3f
+
 // burnout
 #define WHITE_LUMINANCE 3e4f
@@ -53,5 +55,4 @@
 #define NUM_SSAO_FILTERSAMPLES 100
 
-#define PRECISION_SCALE 1e-3f
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3046)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3084)
@@ -61,4 +61,5 @@
 }
 
+#pragma position_invariant fragtex
 
 pixel fragtex(fragin IN, 
@@ -90,4 +91,6 @@
 
 
+#pragma position_invariant frag
+
 pixel frag(fragin IN, uniform float4x4 viewMatrix)
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3083)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3084)
@@ -54,7 +54,4 @@
 								   float3 bl, float3 br, float3 tl, float3 tr)
 {
-	texcoord.x += 1.0f / 1024.0f; texcoord.y += 1.0f / 768.0f;
-
-	//const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w;
 	const float eyeSpaceDepth = tex2D(colors, texcoord).w;
 	float3 viewVec = Interpol(texcoord, bl, br, tl, tr);
@@ -77,5 +74,5 @@
 						 uniform float2 samples[NUM_SAMPLES],
 						 uniform sampler2D colors,
-						 uniform sampler2D noiseTexture,
+						 uniform sampler2D noiseTex,
 						 uniform float scaleFactor,
 						 uniform float3 bl,
@@ -83,5 +80,6 @@
 						 uniform float3 tl,
 						 uniform float3 tr, 
-						 float2 texcoord0
+						 float2 texcoord0,
+						 float3 eyePos
 						 )
 {
@@ -92,5 +90,8 @@
 
 	// reproject into old frame and calculate projected depth
-	float4 backProjPos = mul(oldModelViewProj, worldPos);
+	const float3 dummyPos = ReconstructSamplePos(colors, texcoord0, bl, br, tl, tr) + eyePos;
+	float4 backProjPos = mul(oldModelViewProj, float4(dummyPos, 1.0f));
+	//float4 backProjPos = mul(oldModelViewProj, worldPos);
+	
 	backProjPos /= backProjPos.w;
 	
@@ -106,5 +107,5 @@
 
 	//const float oldNumSamples = oldCol.y;
-	const float oldWeight = clamp(oldCol.y, 0, temporalCoherence);
+	const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence);
 	float newWeight;
 
@@ -115,12 +116,9 @@
 		const float2 offset = samples[i];
 
-		////////////////////
-		// add random noise: reflect around random normal vector (warning: slow!)
-
-		float2 mynoise = tex2D(noiseTexture, texcoord0).xy;
+		float2 mynoise = tex2D(noiseTex, texcoord0).xy;
 		const float2 offsetTransformed = myreflect(offset, mynoise);
 
-		const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor;
-		const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr);
+		const float2 texCoord = texcoord0;// + offsetTransformed * scaleFactor;
+		const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos;
 
 		// reproject into old frame and calculate projected depth
@@ -136,5 +134,4 @@
 
 		if (abs(dDiff) > 1e-5f) isValid = false;
-		//if (oldSample.y < oldWeight) isValid = false;
 	}
 
@@ -142,8 +139,8 @@
 	//const float newNumSamples = ao.y;
 
-	if ((temporalCoherence > 0)
+	if ((temporalCoherence > 1e-6f)
 		&& (tex.x >= 0.0f) && (tex.x < 1.0f)
 		&& (tex.y >= 0.0f) && (tex.y < 1.0f)
-		//&& (abs(depthDif) < MIN_DEPTH_DIFF) 
+		&& (abs(depthDif) <= MIN_DEPTH_DIFF) 
 		// if visibility changed in the surrounding area we have to recompute
 		//&& (oldNumSamples > 0.8f * newNumSamples)
@@ -161,5 +158,7 @@
 		newWeight = .0f;
 	}
-
+	
+	//isValid = 0.0f;
+	//illum_col.y = isValid / 16.0f;
 	illum_col.y = newWeight;
 	illum_col.z = currentDepth;
@@ -173,5 +172,5 @@
 float2 ssao(fragment IN,
 			uniform sampler2D colors,
-			uniform sampler2D noiseTexture,
+			uniform sampler2D noiseTex,
 			uniform float2 samples[NUM_SAMPLES],
 			uniform float3 currentNormal,
@@ -189,6 +188,6 @@
 	// Summing up these angles gives an estimation of the occlusion at the current position.
 
-	float total_ao = 0.0;
-	float numSamples = 0;
+	float total_ao = .0f;
+	float numSamples = .0f;
 
 
@@ -199,7 +198,7 @@
 #if 1
 		////////////////////
-		// add random noise: reflect around random normal vector (warning: slow!)
-
-		float2 mynoise = tex2D(noiseTexture, IN.texCoord).xy;
+		//-- add random noise: reflect around random normal vector (rather slow!)
+
+		float2 mynoise = tex2D(noiseTex, IN.texCoord).xy;
 		const float2 offsetTransformed = myreflect(offset, mynoise);
 #else
@@ -250,5 +249,5 @@
 		   uniform sampler2D colors,
 		   uniform sampler2D normals,
-		   uniform sampler2D noise,
+		   uniform sampler2D noiseTex,
 		   uniform float2 samples[NUM_SAMPLES],
 		   uniform sampler2D oldTex,
@@ -280,10 +279,11 @@
 	float4 projPos = mul(modelViewProj, worldPos);
 	
-	const float w = SAMPLE_RADIUS / projPos.w;
-	projPos /= projPos.w;
+	float w = 1.0f / projPos.w;
+	projPos *= w;
+	w *= SAMPLE_RADIUS;
 	
 	const float currentDepth = projPos.z * PRECISION_SCALE;
 
-	const float2 ao = ssao(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir));
+	const float2 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir));
 
 
@@ -292,5 +292,5 @@
 	
 	OUT.illum_col = temporalSmoothing(projPos, worldPos, currentDepth, oldTex, oldModelViewProj, temporalCoherence, ao,
-		                              samples, colors, noise, w, bl, br, tl, tr, IN.texCoord);
+		                              samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyePos);
 
 	return OUT;
@@ -336,4 +336,5 @@
 	//OUT.illum_col = col * ao.x;
 	OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);
+	//OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);
 	OUT.illum_col.w = col.w;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3084)
@@ -89,5 +89,5 @@
 #if 1
 		////////////////////
-		// add random noise: reflect around random normal vector (warning: slow!)
+		// add random noiseTex: reflect around random normal vector (warning: slow!)
 		float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy).xy;
 		float2 offsetTransformed = myreflect(offset, mynoise);
@@ -151,5 +151,5 @@
 		   uniform sampler2D colors,
 		   uniform sampler2D normals,
-		   uniform sampler2D noise,
+		   uniform sampler2D noiseTex,
 		   uniform float2 samples[NUM_SAMPLES],
 		   uniform sampler2D oldSsaoTex,
@@ -187,10 +187,10 @@
 	currentPos /= currentPos.w;
 	
-	const float currentDepth = currentPos.z * 1e-3f;
+	const float currentDepth = currentPos.z * PRECISION_SCALE;
 
 	///////////
 	//-- compute color bleeding + ao
 
-	GiStruct gi = globIllum(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view));
+	GiStruct gi = globIllum(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view));
 	
 
@@ -204,5 +204,5 @@
 
 	// the current depth projected into the old frame
-	const float projDepth = projPos.z * 1e-3f;
+	const float projDepth = projPos.z * PRECISION_SCALE;
 
 	// fit from unit cube into 0 .. 1
@@ -223,5 +223,5 @@
 	//const float oldNumSamples = oldSsao.y;
 	
-	if (//(temporalCoherence > 0.0f) &&
+	if ((temporalCoherence > 1e-6f) &&
 		(tex.x >= 0.0f) && (tex.x < 1.0f) && 
 		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3081)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3084)
@@ -237,8 +237,4 @@
 mIllumFboIndex(0)
 {
-	// create noise texture for ssao
-	CreateNoiseTex2D(w, h);
-
-
 	///////////
 	//-- the flip-flop fbos
@@ -258,4 +254,7 @@
 
 	mFBOs.push_back(mDownSampleFbo);
+
+	// create noise texture for ssao
+	CreateNoiseTex2D(mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight());
 
 	InitCg();
@@ -298,5 +297,5 @@
 	sCgSsaoProgram->AddParameter("normals", i ++);
 	sCgSsaoProgram->AddParameter("oldTex", i ++);
-	sCgSsaoProgram->AddParameter("noise", i ++);
+	sCgSsaoProgram->AddParameter("noiseTex", i ++);
 	sCgSsaoProgram->AddParameter("eyePos", i ++);
 	sCgSsaoProgram->AddParameter("temporalCoherence", i ++);
@@ -312,5 +311,5 @@
 	sCgGiProgram->AddParameter("colors", i ++);
 	sCgGiProgram->AddParameter("normals", i ++);
-	sCgGiProgram->AddParameter("noise", i ++);
+	sCgGiProgram->AddParameter("noiseTex", i ++);
 	sCgGiProgram->AddParameter("oldSsaoTex", i ++);
 	sCgGiProgram->AddParameter("oldIllumTex", i ++);
