Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 3102)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 3109)
@@ -127,6 +127,10 @@
 	Vector3 mCenter;
 
+	int mId;
+
 	static bool sUseLODs;
+	static int sCurrentId;
 };
+
 
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3109)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3109)
@@ -0,0 +1,101 @@
+#include "../shaderenv.h"
+
+
+struct fragment
+{
+	float2 texCoord: TEXCOORD0; 
+	float3 view: TEXCOORD1;
+};
+
+
+struct pixel
+{
+	float4 illum_col: COLOR0;
+};
+
+
+
+float Filter(float2 texCoord, 
+			 uniform sampler2D ssaoTex,
+			 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
+			 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES])
+{
+	float average = .0f;
+	float w = .0f;
+
+	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
+	{
+		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x;
+		w += filterWeights[i];
+	}
+
+	average *= 1.0f / (float)w;
+
+	return average;
+}
+
+
+float BilateralFilter(float2 texCoord,
+					  float4 ao,
+					  uniform sampler2D ssaoTex,
+					  uniform sampler2D normalsTex,
+					  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
+					  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES])
+{
+	float average = .0f;
+	float total_w = .0f;
+
+	//const float eyeSpaceDepth = ao.w;
+	const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz);
+
+	float4 aoSample;
+	float3 sampleNorm;
+	float w;
+
+	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
+	{
+		float4 offs = float4(texCoord + filterOffs[i], 0, 0);
+		aoSample = tex2Dlod(ssaoTex, offs);
+		//aoSample = tex2D(ssaoTex, texCoord + filterOffs[i]);
+		//float sampleEyeSpaceDepth = aoSample.w;
+		//factor = abs(eyeSpaceDepth - sampleEyeSpaceDepth) / eyeSpaceDepth;
+		sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz);
+		//sampleNorm = tex2Dlod(normalsTex, offs).xyz;
+
+		w = filterWeights[i] * max(dot(sampleNorm, norm), .0f);
+
+		average += w * aoSample.x;
+		total_w += w;
+	}
+
+	average *= 1.0f / max(total_w, 1e-5f);
+
+	return average;
+}
+
+
+pixel combine(fragment IN, 
+			  uniform sampler2D colorsTex,
+			  uniform sampler2D ssaoTex,
+			  uniform sampler2D normalsTex,
+			  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
+			  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]
+			  )
+{
+	pixel OUT;
+
+	float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
+	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
+
+	//if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
+	//if (ao.y < 10.0f) ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights);
+
+	//OUT.illum_col = col * ao.x;
+	//OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w);
+	OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
+	//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;
+
+	return OUT;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3108)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3109)
@@ -125,43 +125,48 @@
 								uniform float4x4 oldModelViewProj,
 								uniform float temporalCoherence,
-								uniform float2 samples[NUM_SAMPLES],
 								uniform sampler2D colors,
-								uniform sampler2D noiseTex,
-								float scaleFactor,
 								uniform float3 bl,
 								uniform float3 br,
 								uniform float3 tl,
 								uniform float3 tr, 
+								float invW,
+								float3 projPos,
+								float4x4 inverseModelTrafo,
+								float id,
+								uniform sampler2D noiseTex,
+								uniform float2 samples[NUM_SAMPLES],
+								float scaleFactor,
 								uniform float3 oldbl,
 								uniform float3 oldbr,
 								uniform float3 oldtl,
-								uniform  float3 oldtr,
-								float invW,
-								float3 projPos
-								//,const uniform float4x4 inverseModelTrafo
-								//, float id
-						 )
+								uniform  float3 oldtr
+								)
 {
 	float4 illum_col;
 
+	////////////
+	//-- dynamic objects
+	
+	float4x4 trafo;
+	
+	if (id > 20) trafo = oldModelViewProj;
+	else trafo = inverseModelTrafo * oldModelViewProj;
+
+	// compute translational portion
+	const float3 translatedPt = worldPos.xyz - oldEyePos;
+
 	/////////////////
-	//-- compute reprojection for temporal smoothing
-
-	//float4x4 trafo;
-	// dynamic object
-	//if (id > 20) trafo = oldModelViewProj;
-	//else trafo = inverseModelTrafo * oldModelViewProj;
-
-	const float3 translatedPt = worldPos.xyz - oldEyePos;
-
-	// reproject into old frame and calculate texture position of sample in old frame
-	float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f));
+	//-- reproject into old frame and calculate texture position of sample in old frame
+
+	// note: the old model view matrix only holds the view orientation part
+	float4 backProjPos = mul(trafo, float4(translatedPt, 1.0f));
 	backProjPos /= backProjPos.w;
+	
 	// fit from unit cube into 0 .. 1
 	const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f;
 	
-
 	// retrieve the sample from the last frame
 	const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f));
+
 
 #if USE_EYESPACE_DEPTH
@@ -171,11 +176,10 @@
 	// vector from eye pos to old sample 
 	const float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr);
-	const float invlen = 1.0f / length(viewVec);
-	const float projectedEyeSpaceDepth = invlen * length(translatedPt);
+	const float invLen = 1.0f / length(viewVec);
+	const float projectedEyeSpaceDepth = invLen * length(translatedPt);
 	
 	//const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth);
-	//const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);
-
-	const float depthDif = abs(projectedEyeSpaceDepth - oldEyeSpaceDepth ) / projectedEyeSpaceDepth;
+	const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);
+	//const float depthDif = abs(projectedEyeSpaceDepth - oldEyeSpaceDepth ) / projectedEyeSpaceDepth;
 
 #else
@@ -345,5 +349,7 @@
 		   uniform float3 oldbr,
 		   uniform float3 oldtl,
-		   uniform float3 oldtr
+		   uniform float3 oldtr,
+		   uniform sampler2D attribs,
+		   uniform float4x4 inverseModelTrafo
 		   )
 {
@@ -377,8 +383,10 @@
 	//-- compute temporally smoothing
 
+	float id = tex2Dlod(attribs, float4(IN.texCoord, 0, 0)).x;
+
 	OUT.illum_col = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, ao, IN.texCoord, oldEyePos,
 		                              oldTex, oldModelViewProj, temporalCoherence,
-		                              samples, colors, noiseTex, w, bl, br, tl, tr,
-									  oldbl, oldbr, oldtl, oldtr, scaleFactor, projPos);
+		                              colors, w, bl, br, tl, tr, projPos, inverseModelTrafo, id,
+									  noiseTex, samples, scaleFactor, oldbl, oldbr, oldtl, oldtr);
 
 	//OUT.illum_col.xyz = normal * 0.5f + 0.5f;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3102)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3109)
@@ -15,9 +15,10 @@
 {
 
+int SceneEntity::sCurrentId = 0;
 bool SceneEntity::sUseLODs = true;
 
 
 SceneEntity::SceneEntity(Transform3 *trafo): 
-mTransform(trafo), mCurrentLODLevel(0), mLODLastUpdated(-1)
+mTransform(trafo), mCurrentLODLevel(0), mLODLastUpdated(-1), mId(sCurrentId ++)
 {
 	mBox.Initialize();
