Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3309)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3310)
@@ -48,5 +48,5 @@
 	weight of the pixel in the new frame.
 */
-inline float2 temporalSmoothing(float4 worldPos,
+inline float3 temporalSmoothing(float4 worldPos,
 								float eyeSpaceDepth,
 								float2 texcoord0,
@@ -96,4 +96,5 @@
 	// the weight of the accumulated samples from the previous frames
 	float w;
+	float idx;
 
 	//////////////
@@ -108,11 +109,13 @@
 		// pixel valid => retrieve the convergence weight
 		w = oldPixel.y;
+		idx = oldPixel.z;
 	}
 	else
 	{	
-		w = 0.0f;
-	}
-
-	return float2(ssao, w);
+		w = .0f;
+		idx = .0f;
+	}
+
+	return float3(ssao, w, idx);
 }
 
@@ -141,4 +144,5 @@
 	float numSamples = .0f;
 	float validSamples = .0f;
+
 
 	for (int i = 0; i < NUM_PRECOMPUTED_SAMPLES; ++ i) 
@@ -247,13 +251,15 @@
 		//-- (affects performance for some reason!)
 
-		if (convergence < SSAO_CONVERGENCE_THRESHOLD)
+		if (1)//convergence < SSAO_CONVERGENCE_THRESHOLD)
 		{
 			float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy;
 			//offset = myreflect(samples[i], mynoise);
-			offset = myrotate(samples[i + idx], mynoise.x);
+			offset = myrotate(samples[i], mynoise.x);
+			//offset = myrotate(samples[i + idx], mynoise.x);
 		}
 		else
 		{
-			offset = samples[i + idx];
+			//offset = samples[i + idx];
+			offset = samples[i];
 		}
 		
@@ -382,5 +388,5 @@
 	//-- compute temporal reprojection
 
-	float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
+	float3 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
 	                                        oldTex, oldModelViewProj, 
 											colors, 
@@ -394,6 +400,6 @@
 	float oldWeight = temporalVals.y;
 
-	float usedWeight = min(temporalCoherence, abs(oldWeight));
-	int idx = (int)oldWeight % (int)temporalCoherence;
+	int idx = (int)temporalVals.z;
+		//min(0, (int)oldWeight % max((int)temporalCoherence, 1));
 
 	float3 ao;
@@ -402,5 +408,7 @@
 	if (eyeSpaceDepth < DEPTH_THRESHOLD)
 	{
-		ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), usedWeight, sampleIntensity, isMovingObject, idx);
+		ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, 
+			      scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, 
+				  sampleIntensity, isMovingObject, idx);
 		//ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity);
 	}
@@ -428,22 +436,30 @@
 		if (ao.y > completelyResetThres) 
 		{
-			oldWeight = .0f; 
+			oldWeight = .0f;
+			idx = .0f;
 		}
 		else if (ao.y > partlyResetThres)
 		{
 			oldWeight = min(oldWeight, 4.0f * newWeight);
-			//oldWeight = .0f; 
+			idx = oldWeight;
 		}
 	}
+
+	float usedWeight = min(temporalCoherence, oldWeight);
+
 
 	//////////
 	//-- blend ao between old and new samples (and avoid division by zero)
 
-	OUT.illum_col.x = ao.x * newWeight + oldSsao * usedWeight;
-	OUT.illum_col.x /= (newWeight + usedWeight);
+	OUT.illum_col.x = ao.x * newWeight;// + oldSsao * usedWeight;
+	OUT.illum_col.x /= max(newWeight + usedWeight, 1);
+
+	//if (oldWeight >= 10000) oldWeight = 1000;
 
 	// the new weight for the next frame
 	//const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence);
-	const float combinedWeight = newWeight + oldWeight;
+	float combinedWeight = newWeight + oldWeight;
+
+	clamp(combinedWeight, 0, 1000);
 
 	OUT.illum_col.y = combinedWeight;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3306)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3310)
@@ -114,4 +114,42 @@
 }
 
+
+/** In between step that only filters in one direction
+*/
+pixel FilterSsaoHalfRes(fragment IN, 
+						uniform sampler2D colorsTex,
+						uniform sampler2D ssaoTex,
+						uniform float3 bl,
+						uniform float3 br,
+						uniform float3 tl,
+						uniform float3 tr,
+						uniform float2 res
+						 )
+{
+	pixel OUT;
+
+	const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w;
+
+	OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
+	// compute minimal convergence for savetly reasons, write it out
+	const float convergence = ComputeConvergenceHalfRes(ssaoTex, IN.texCoord, res * 0.5f);
+	OUT.illum_col.y = convergence;
+
+	const float2 xyStep = float2(1.0f / res.x, 0);
+
+	// filter reaches size 1 pixel when sample size reaches threshold 
+	// afterwards we do not use the filter anymore
+
+	// filter up to a certain convergance value and leave out background (sky) by checking depth
+	if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD))
+	{
+		// the filtered ssao value
+		//OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
+	}
+
+	return OUT;
+}
+
+
 /** In between step that only filters in one direction
 */
@@ -137,5 +175,5 @@
 	// afterwards we do not use the filter anymore
 
-	float2 xyStep = float2(1.0f / res.x, 0);
+	const float2 xyStep = float2(1.0f / res.x, 0);
 
 	// filter up to a certain convergance value and leave out background (sky) by checking depth
@@ -149,39 +187,4 @@
 }
 
-/** In between step that only filters in one direction
-*/
-pixel FilterSsaoHalfRes(fragment IN, 
-						uniform sampler2D colorsTex,
-						uniform sampler2D ssaoTex,
-						uniform float3 bl,
-						uniform float3 br,
-						uniform float3 tl,
-						uniform float3 tr,
-						uniform float2 res
-						 )
-{
-	pixel OUT;
-
-	const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w;
-
-	OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
-	// compute minimal convergence for savetly reasons, write it out
-	const float convergence = ComputeConvergenceHalfRes(ssaoTex, IN.texCoord, res * 0.5f);
-	OUT.illum_col.y = convergence;
-
-	const float2 xyStep = float2(1.0f / res.x, 0);
-
-	// filter reaches size 1 pixel when sample size reaches threshold 
-	// afterwards we do not use the filter anymore
-
-	// filter up to a certain convergance value and leave out background (sky) by checking depth
-	if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD))
-	{
-		// the filtered ssao value
-		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
-	}
-
-	return OUT;
-}
 
 /** Function combining image and indirect illumination buffer using a 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3309)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3310)
@@ -208,5 +208,5 @@
 	case DeferredRenderer::SAMPLING_QUADRATIC:
 		{
-			static QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
+			QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
 			//static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f);
 			g.Generate((float *)samples2);
@@ -741,5 +741,5 @@
 	sCgSsaoProgram->SetTexture(i ++, noiseTex2D);
 
-	sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0);
+	sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : .0f);
 	
 	if (/*mUseTemporalCoherence || */mRegenerateSamples)
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3309)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3310)
@@ -106,5 +106,5 @@
 ssaoSampleIntensity=0.8f
 # ssao temporal coherence factor
-tempCohFactor=150.0f
+tempCohFactor=100.0f
 # ssao filter radius
 ssaoFilterRadius=12.0f
