Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3108)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3115)
@@ -21,5 +21,5 @@
 
 //#define ILLUM_INTENSITY 8e-2f
-#define ILLUM_INTENSITY 2e-2f
+#define ILLUM_INTENSITY 5e-3f
 
 #define VIEW_CORRECTION_SCALE 1.0f
@@ -29,5 +29,5 @@
 //-- reprojection
 
-#define MIN_DEPTH_DIFF 5e-2f
+#define MIN_DEPTH_DIFF 2e-2f
 #define PRECISION_SCALE 1e-1f
 
@@ -58,5 +58,6 @@
 
 //#define NUM_SSAO_FILTERSAMPLES 28
-#define NUM_SSAO_FILTERSAMPLES 40
+//#define NUM_SSAO_FILTERSAMPLES 40
+#define NUM_SSAO_FILTERSAMPLES 100
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3114)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3115)
@@ -17,4 +17,5 @@
 
 static float sCurrentTimer = 0;
+static float sOldTimer = 0;
 static Matrix4x4 sCurrentViewMatrix = IdentityMatrix();
 static Vector3 sCurrentViewDir = Vector3::UNIT_Y();
@@ -158,4 +159,10 @@
 {
 	mTimerParam = idx;
+}
+
+
+void GPUProgramParameters::SetOldTimerParam(int idx)
+{
+	mOldTimerParam = idx;
 }
 
@@ -318,5 +325,6 @@
 	if (mTimerParam >= 0)
 		mProgram->SetValue1f(mTimerParam, sCurrentTimer);
-
+	if (mOldTimerParam >= 0)
+		mProgram->SetValue1f(mOldTimerParam, sOldTimer);
 	if (mViewDirParam >= 0)
 		mProgram->SetValue3f(mViewDirParam, sCurrentViewDir.x, sCurrentViewDir.y, sCurrentViewDir.z);
@@ -339,4 +347,5 @@
 {
 	static PerfTimer mytimer;
+	sOldTimer = sCurrentTimer;
 	sCurrentTimer = mytimer.Elapsedms(false) * M_PI / 180.0f;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg	(revision 3046)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg	(revision 3115)
@@ -10,6 +10,4 @@
 	
 	float4 color: COLOR;
-	//float4 color1: COLOR1;
-
 	float4 texCoord: TEXCOORD0;
 };
@@ -21,8 +19,11 @@
 	float4 texCoord: TEXCOORD0;    
 
-	float4 color: COLOR0;  
-	//float4 color1: COLOR1;  
-	float4 eyePos: TEXCOORD1; // eye position
+	float4 color: COLOR0; 
+	// eye position
+	float4 eyePos: TEXCOORD1; 
 	float4 normal: TEXCOORD2;
+
+	float4 worldPos: TEXCOORD3;
+	float4 oldWorldPos: TEXCOORD4;
 };
 
@@ -54,8 +55,8 @@
 	const float3 l = normalize(lightDir);
 
-	const float dif = max(.0f, dot(OUT.normal.xyz, l));
+	const float diffuse = max(.0f, dot(OUT.normal.xyz, l));
 
 	//OUT.color.xyz = IN.color.xyz * max(0, dot(OUT.normal.xyz, normalize(lightDir)));
-	OUT.color = glstate.material.ambient + glstate.material.front.diffuse * dif;
+	OUT.color = glstate.material.ambient + glstate.material.front.diffuse * diffuse;
 	OUT.color.w = IN.color.w;
 	return OUT;
@@ -72,5 +73,9 @@
 					 uniform float frequency,
 					 uniform float2 minMaxPos,
-					 uniform float timer)
+					 uniform float timer,
+					 uniform float oldTimer
+					 //uniform float4x4 modelMatrix,
+					 //uniform float4x4 oldModelMatrix
+					 )
 {
 	vtxout OUT;
@@ -82,15 +87,21 @@
 	float factor = pos * pos * windStrength * sin(timer * frequency);
 
+	const float4 offs = float4(factor * windDir, 0);
+
 	// transform the vertex position into post projection space
 	OUT.position = mul(glstate.matrix.mvp, IN.position);
 	// displace the input position
-	OUT.position += float4(factor * windDir, 0);
+	OUT.position += offs;
 
 	// transform the vertex position into eye space
 	OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
-	OUT.eyePos += float4(factor * windDir, 0);
+	OUT.eyePos += offs;
 
 	OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
 	
+	// hack: no translational component anyway
+	OUT.oldWorldPos = float4(.0f);
+	OUT.worldPos = offs;
+
 	return OUT;
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3114)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3115)
@@ -66,23 +66,23 @@
 
 inline float ComputeDifference(float2 offset,
-							   uniform sampler2D oldTex,
-							   const uniform float4x4 oldModelViewProj,
-							   uniform sampler2D colors,
-							   uniform sampler2D noiseTex,
-							   uniform float scaleFactor,
-							   uniform float3 bl,
-							   uniform float3 br,
-							   uniform float3 tl,
-							   uniform float3 tr, 
+							   sampler2D oldTex,
+							   float4x4 oldModelViewProj,
+							   sampler2D colors,
+							   sampler2D noiseTex,
+							   float scaleFactor,
+							   float3 bl,
+							   float3 br,
+							   float3 tl,
+							   float3 tr, 
 							   float2 texcoord0,
 							   float3 oldEyePos,
-							   uniform float3 oldbl,
-							   uniform float3 oldbr,
-							   uniform float3 oldtl,
-							   uniform float3 oldtr,
+							   float3 oldbl,
+							   float3 oldbr,
+							   float3 oldtl,
+							   float3 oldtr,
 							   float eyeSpaceDepth
 							   )
 {
-	const float2 mynoise = tex2Dlod(noiseTex, texcoord0).xy;
+	const float2 mynoise = tex2Dlod(noiseTex, float4(texcoord0, 0, 0)).xy;
 
 	const float2 offsetTransformed = myreflect(offset, mynoise);
@@ -93,10 +93,9 @@
 	const float3 viewVec = Interpol(texCoord, bl, br, tl, tr);
 	const float3 samplePos = -viewVec * sampleEyeSpaceDepth;
-
 	const float3 translatedPos = samplePos - oldEyePos;
+
 	// reproject into old frame and calculate projected depth
 	float4 projPos = mul(oldModelViewProj, float4(translatedPos, 1.0f));
 	projPos /= projPos.w;
-
 	// fit from unit cube into 0 .. 1
 	const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f;
@@ -105,11 +104,12 @@
 
 	const float oldEyeSpaceDepth = oldPixel.w;
+	
+	// projected linear depth
 	const float3 oldViewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr);
-
 	const float invlen = 1.0f / length(oldViewVec);
-	const float projectedEyeSpaceDepth = length(translatedPos) * invlen;
-	
-	float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 
-		0 : abs(oldEyeSpaceDepth - projectedEyeSpaceDepth);
+	const float projectedEyeSpaceDepth = invlen * length(translatedPos);
+
+	float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 0 : 
+		abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);
 
 	return depthDif;
@@ -117,6 +117,6 @@
 
 
-/** This shader computes the reprojection and stores reprojected color / depth values
-	as well as a boolean that 
+/** This shader computes the reprojection and stores 
+	reprojected color / depth values as well as a boolean that 
 */
 inline float4 temporalSmoothing(float4 worldPos,
@@ -148,5 +148,5 @@
 
 	// compute position from old frame for dynamic objects + translational portion
-	const float3 translatedPt = worldPos.xyz - oldEyePos + diffVec;
+	const float3 translatedPos = worldPos.xyz - oldEyePos + diffVec;
 
 
@@ -155,5 +155,5 @@
 
 	// note: the old model view matrix only holds the view orientation part
-	float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f));
+	float4 backProjPos = mul(oldModelViewProj, float4(translatedPos, 1.0f));
 	backProjPos /= backProjPos.w;
 	
@@ -172,9 +172,7 @@
 	const float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr);
 	const float invLen = 1.0f / length(viewVec);
-	const float projectedEyeSpaceDepth = invLen * length(translatedPt);
-	
-	//const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth);
+	const float projectedEyeSpaceDepth = invLen * length(translatedPos);
+	
 	const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);
-	//const float depthDif = abs(projectedEyeSpaceDepth - oldEyeSpaceDepth ) / projectedEyeSpaceDepth;
 
 #else
@@ -182,6 +180,4 @@
 	const float oldDepth = oldPixel.w;
 	const float projectedDepth = projPos.z;
-	//const float projectedDepth = invW * worldPos.z;
-
 	// vector from eye pos to old sample 
 	const float depthDif = abs(projectedDepth - oldDepth);
@@ -189,23 +185,29 @@
 
 	float notValid = 0.5f;
-
-	/*
-	for (int i = 0; i < NUM_SAMPLES; ++ i) 
+	//float overallDepth = 0;
+	const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z;
+
+	if (squaredLen < 1e-8f) // object not dynamic
 	{
-		float sampleDif = ComputeDifference(samples[i],
-			                  oldTex,
-							  oldModelViewProj,
-							  colors,
-							  noiseTex,
-							  scaleFactor,
-							  bl, br, tl, tr, 
-							  texcoord0,
-							  oldEyePos,
-							  oldbl, oldbr, oldtl, oldtr,
-							  eyeSpaceDepth);
-
-		if (sampleDif >= 5e-2f) ++ notValid;
-	}
-	*/
+		for (int i = 0; i < NUM_SAMPLES; ++ i) 
+		{
+			float sampleDif = ComputeDifference(samples[i],
+												oldTex,
+												oldModelViewProj,
+												colors,
+												noiseTex,
+												scaleFactor,
+												bl, br, tl, tr, 
+												texcoord0,
+												oldEyePos,
+												oldbl, oldbr, oldtl, oldtr,
+												eyeSpaceDepth
+												);
+			//overallDepth += sampleDif;
+
+			if (sampleDif >= MIN_DEPTH_DIFF) ++ notValid;
+		}
+	}
+
 
 	// the number of valid samples in this frame
@@ -243,7 +245,7 @@
 	illum_col.w = projectedDepth;
 #endif
-
+	//overallDepth = clamp(overallDepth*1e3, 0, 1);
 	illum_col.z = invW;
-	//illum_col.x = length(diffVec*50.0f);
+	//illum_col.x = overallDepth;
 
 	return illum_col;
@@ -370,7 +372,8 @@
 	// note: this should be done with the stencil buffer
 	if (eyeSpaceDepth < 1e10f)
+	{
 		ao = ssao(IN, colors, noiseTex, samples, normal, 
 		          eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir));
-
+	}
 
 	//float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz;
@@ -409,5 +412,5 @@
 	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
 	{	
-		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x;
+		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x;
 		w += filterWeights[i];
 	}
@@ -434,8 +437,8 @@
 	//	ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z);
 
-	//OUT.illum_col = col * ao.x;
+	OUT.illum_col = col * ao.x;
 	//OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w);
 	//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 = float4(ao.x, 0, 0, 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);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3114)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3115)
@@ -168,4 +168,5 @@
 					{
 						tech->SetVertexProgram(sTreeAnimationProgramMrt);
+						vtxParams->SetOldTimerParam(5);
 					}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3114)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3115)
@@ -72,4 +72,6 @@
 	*/
 	void SetTimerParam(int idx);
+
+	void SetOldTimerParam(int idx);
 	/** This parameter is connected to the current view matrix
 		that is updated once per frame.
@@ -195,4 +197,5 @@
 
 	int mTimerParam;
+	int mOldTimerParam;
 	int mViewDirParam;
 	int mLightDirParam;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3114)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3115)
@@ -41,5 +41,5 @@
 	mIsIdentity = false;
 	mOldMatrix = mMatrix;
-	mMatrix = mMatrix * trafo;
+	mMatrix = trafo * mMatrix;
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3114)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3115)
@@ -905,9 +905,5 @@
 		buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters();
 
-	static Matrix4x4 oldTrafo;
-
-	oldTrafo = buddha->GetTransform()->GetMatrix();
-	//vtxParams->SetMatrix(2, oldTrafo);
-
+	Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix();
 	Vector3 buddhaPos = motionPath->GetCurrentPosition();
 	Matrix4x4 trafo = TranslationMatrix(buddhaPos);
@@ -915,5 +911,7 @@
 	buddha->GetTransform()->SetMatrix(trafo);
 
-	//vtxParams->SetMatrix(1, buddha->GetTransform()->GetMatrix());
+	Matrix4x4 rotMatrix = RotationZMatrix(M_PI * 1e-3f);
+
+	dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix);
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3113)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3115)
@@ -259,9 +259,6 @@
 	//-- the flip-flop fbos
 
-	const int dsw = w / 2;
-	const int dsh = h / 2;
-
-	//const int dsw = w;
-	//const int dsh = h;
+	const int dsw = w / 2; const int dsh = h / 2;
+	//const int dsw = w; const int dsh = h;
 
 	mIllumFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3066)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3115)
@@ -12,5 +12,6 @@
 camPosition=483.398f 242.364f 186.078f
 camDirection=1 0 0
-lightDirection=-0.8f 1.0f -0.7f
+#lightDirection=-0.8f 1.0f -0.7f
+lightDirection=-0.3f 0.2f -0.7f
 #lightDirection=0.0f 0.0f -1.0f
 useFullScreen=0
@@ -24,5 +25,5 @@
 
 # ssao temporal coherence factor
-tempCohFactor=50.0f
-
+tempCohFactor=100.0f
+# tone mapping
 useHDR=0
