Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2974)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2975)
@@ -81,7 +81,9 @@
 	
 	OUT.color = col;
-	OUT.color.w = color.w;
-
-	// write out logaritmic luminance for tone mapping
+	
+
+	////////////
+	//-- write out logaritmic luminance for tone mapping
+
 	const float3 w = float3(0.299f, 0.587f, 0.114f);
 
@@ -89,7 +91,6 @@
 	float logLum = log(1e-5f + lum);
 
-	float invLogLumRange =  1 / (MAXLOGLUM + MINLOGLUM);
-	float logLumOffset = MINLOGLUM * invLogLumRange;
-	float logLumScaled = logLum * invLogLumRange + logLumOffset;
+	float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE;
+	float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset;
 
 	OUT.color.w = logLumScaled;
@@ -194,5 +195,7 @@
 	OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color;
 
-	// write out logaritmic luminance for tone mapping
+	////////////
+	//-- write out logaritmic luminance for tone mapping
+
 	const float3 w = float3(0.299f, 0.587f, 0.114f);
 
@@ -200,5 +203,8 @@
 	float logLum = log(1e-5f + lum);
 
-	OUT.color.w = 100;//logLum;
+	float logLumOffset = MINLOGLUM * INV_LOGLUM_RANGE;
+	float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset;
+
+	OUT.color.w = logLumScaled;
 	
 	return OUT;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 2974)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 2975)
@@ -90,8 +90,5 @@
 	// obtain new image key from highest mipmap level
 	float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, 99)).w;
-
-	float logLumRange = MAXLOGLUM + MINLOGLUM;
-	//float logLumOffset = MINLOGLUM * logLumRange;
-	float logLum = logLumScaled * logLumRange - MINLOGLUM;
+	float logLum = logLumScaled * LOGLUM_RANGE + MINLOGLUM;
 
 	float newImageKey = exp(logLum);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2974)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2975)
@@ -117,16 +117,12 @@
 
 	float4 norm = tex2D(normals, IN.texCoord.xy);
-	
-	// expand normal
 	float3 normal = normalize(norm.xyz);
-	
+
 	// a constant ambient term
 	const float amb = norm.w;
 	// the w coordinate from the persp. projection
 	float w = norm.w;
-
 	// the current world position
 	const float4 centerPosition = tex2D(positions, IN.texCoord.xy);
-	
 	// the current color
 	const float currentDepth = centerPosition.w;
@@ -141,5 +137,8 @@
 	realPos.w = 1.0f;
 
-	// reproject
+
+	///////////
+	//-- reprojection from new frame into old one
+
 	float4 oldPos = mul(oldModelViewProj, realPos);
 
@@ -161,11 +160,11 @@
 		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
 		(abs(depthDif) < 1e-3f) 
-		&& (oldNumSamples > ao.y - 1.5f) // check if something happened in the surrounding area
+		// check if visibility changed in the surrounding area:
+		// then we have to recompute
+		&& (oldNumSamples > ao.y - 1.5f) 
 		)
 	{
 		// increase the weight for convergence
 		newWeight = oldWeight + 1.0f;
-
-		//OUT.illum_col = (float4)ao * expFactor + oldCol.x * (1.0f - expFactor);
 		OUT.illum_col.xy = (ao.xy + oldCol.xy * oldWeight) / newWeight;
 
@@ -193,9 +192,9 @@
 
 	float4 col = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
-	float depth = tex2Dlod(positions, float4(IN.texCoord.xy, 0, 0)).w;
 	float4 ao = tex2D(ssaoTex, IN.texCoord.xy);
 
 	OUT.illum_col = col * ao.x;
-	OUT.illum_col.w = ao.w;
+	//OUT.illum_col.w = ao.w;
+	OUT.illum_col.w = col.w;
 
 	return OUT;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2974)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2975)
@@ -52,12 +52,10 @@
 				 uniform float2 samples[NUM_SAMPLES],
 				 uniform float3 currentNormal,
-				 uniform float3 currentViewDir,
-				 uniform float4 centerPosition
+				 uniform float4 centerPosition,
+				 float w
+				 //, uniform float3 currentViewDir
 				 )
 {
 	GiStruct gi;
-
-	// the w coordinate from the persp. projection
-	float w = centerPosition.w;
 
 	// Check in a circular area around the current position.
@@ -117,5 +115,5 @@
 	}
 
-	gi.illum = saturate(total_color);
+	gi.illum = total_color;
 	gi.ao = float2(max(0.0f, 1.0f - total_ao), numSamples);
 
@@ -143,23 +141,20 @@
 
 	float4 norm = tex2D(normals, IN.texCoord.xy);
-	
-	// the ambient term
+	float3 normal = normalize(norm.xyz);	
+	// something like a constant ambient term
 	const float amb = norm.w;
-
-	// expand normal
-	float3 normal = normalize(norm.xyz);
-
 	/// the current view direction
-	float3 viewDir;// = normalize(IN.view);
-
+	//float3 viewDir = normalize(IN.view);
+
+	// the w coordinate from the persp. projection
+	float w = norm.w;
 	// the current world position
 	const float4 centerPosition = tex2D(positions, IN.texCoord.xy);
-	
 	// the current color
 	const float4 currentCol = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
 	// the current depth is stored in the w component
-	const float currentDepth = currentCol.w;
-
-	GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, viewDir, centerPosition);
+	const float currentDepth = centerPosition.w;
+
+	GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w); //, viewDir);
 	
 
@@ -186,10 +181,13 @@
 
 	const float oldNumSamples = oldSsao.y;
+	const float oldAvgDepth = oldSsao.z;
 
 	if ((temporalCoherence > 0.0f) &&
 		(tex.x >= 0.0f) && (tex.x < 1.0f) && 
 		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
-		(abs(depthDif)  < 1e-3f)
-		&& (oldNumSamples > gi.ao.y - 1.5f) // check if something happened in the surrounding area
+		(abs(depthDif) < 1e-3f)
+		// check if something changed in the surrounding area
+		&& (oldNumSamples > 0.2 * gi.ao.y)
+		&& (oldAvgDepth / newAvgDepth > 0.99)
 		)
 	{
@@ -218,5 +216,5 @@
 			  uniform sampler2D ssaoTex,
 			  uniform sampler2D illumTex
-		   )
+			  )
 {
 	pixel OUT;
