Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3081)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3082)
@@ -61,4 +61,66 @@
 	return samplePos;
 }
+
+
+/** This shader computes the reprojection and stores reprojected color / depth values
+	as well as a boolean that 
+*/
+pixel TemporalSmoothing(float currentPos,
+						float currentDepth,
+						uniform sampler2D oldTex)
+{
+
+	/////////////////
+	//-- compute reprojection for temporal smoothing
+
+
+	// reproject into old frame and calculate projected depth
+	float4 projPos = mul(oldModelViewProj, worldPos);
+	projPos /= projPos.w;
+	
+	// the current depth projected into the old frame
+	const float projDepth = projPos.z * precisionScale;
+	// fit from unit cube into 0 .. 1
+	const float2 tex = projPos.xy * 0.5f + 0.5f;
+	// retrieve the sample from the last frame
+	float4 oldCol = tex2D(oldTex, tex);
+
+	const float oldDepth = oldCol.z;
+	//const float depthDif = 1.0f - projDepth / oldDepth;
+	const float depthDif = projDepth - oldDepth;
+
+	//const float oldNumSamples = oldCol.y;
+	const float oldWeight = clamp(oldCol.y, 0, temporalCoherence);
+
+	float newWeight;
+
+	// the number of valid samples in this frame
+	//const float newNumSamples = ao.y;
+
+	if ((temporalCoherence > 0)
+		&& (tex.x >= 0.0f) && (tex.x < 1.0f)
+		&& (tex.y >= 0.0f) && (tex.y < 1.0f)
+		&& (abs(depthDif) < MIN_DEPTH_DIFF) 
+		// if visibility changed in the surrounding area we have to recompute
+		//&& (oldNumSamples > 0.8f * newNumSamples)
+		)
+	{
+		// increase the weight for convergence
+		newWeight = oldWeight + 1.0f;
+		OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight;
+		//if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0;
+	}
+	else
+	{	
+		OUT.illum_col.x = ao.x;
+		newWeight = .0f;
+	}
+
+	illum_col.y = newWeight;
+	illum_col.z = currentDepth;
+
+	return illum_col;
+}
+
 
 
@@ -159,9 +221,9 @@
 	pixel OUT;
 
-	float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0));
-	const float3 normal = normalize(norm.xyz);
-
-	/// reconstruct position from the eye space depth
-	float3 viewDir = IN.view;
+	const float3 normal = 
+		normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz);
+
+	// reconstruct position from the eye space depth
+	const float3 viewDir = IN.view;
 	const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w;
 	const float3 eyeSpacePos = -viewDir * eyeDepth;
@@ -185,53 +247,6 @@
 	/////////////////
 	//-- compute temporally smoothing
-
-
-	// reproject new frame into old one 
-	
-	// calculate projected depth
-	float4 projPos = mul(oldModelViewProj, worldPos);
-	projPos /= projPos.w;
-	
-	// the current depth projected into the old frame
-	const float projDepth = projPos.z * precisionScale;
-	// fit from unit cube into 0 .. 1
-	const float2 tex = projPos.xy * 0.5f + 0.5f;
-	// retrieve the sample from the last frame
-	float4 oldCol = tex2D(oldTex, tex);
-
-	const float oldDepth = oldCol.z;
-	//const float depthDif = 1.0f - projDepth / oldDepth;
-	const float depthDif = projDepth - oldDepth;
-
-	//const float oldNumSamples = oldCol.y;
-	const float oldWeight = clamp(oldCol.y, 0, temporalCoherence);
-
-	float newWeight;
-
-	// the number of valid samples in this frame
-	//const float newNumSamples = ao.y;
-
-	if ((temporalCoherence > 0)
-		&& (tex.x >= 0.0f) && (tex.x < 1.0f)
-		&& (tex.y >= 0.0f) && (tex.y < 1.0f)
-		&& (abs(depthDif) < MIN_DEPTH_DIFF) 
-		&& (abs(oldCol.x - ao.x) < 0.1f)
-		// if visibility changed in the surrounding area we have to recompute
-		//&& (oldNumSamples > 0.8f * newNumSamples)
-		)
-	{
-		// increase the weight for convergence
-		newWeight = oldWeight + 1.0f;
-		OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight;
-		//if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0;
-	}
-	else
-	{	
-		OUT.illum_col.x = ao.x;
-		newWeight = .0f;
-	}
-
-	OUT.illum_col.y = newWeight;
-	OUT.illum_col.z = currentDepth;
+	
+	OUT.illum_col = TemporalSmoothing(currentPos, currentDepth, oldTex);
 
 	return OUT;
