Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3154)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3155)
@@ -11,8 +11,8 @@
 // for quadratic falloff
 //#define SAMPLE_INTENSITY 0.2f
-//#define SAMPLE_INTENSITY 0.07f
+#define SAMPLE_INTENSITY 0.07f
 
 //#define SAMPLE_INTENSITY 0.075f
-#define SAMPLE_INTENSITY 0.2f
+//#define SAMPLE_INTENSITY 0.2f
 
 #define SAMPLE_RADIUS 8e-1f
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg	(revision 3116)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg	(revision 3155)
@@ -75,6 +75,4 @@
 					 uniform float timer,
 					 uniform float oldTimer
-					 //uniform float4x4 modelMatrix,
-					 //uniform float4x4 oldModelMatrix
 					 )
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3154)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3155)
@@ -200,94 +200,4 @@
 }
 
-#if 0
-/** This shader computes the reprojection and stores reprojected color / depth values
-	as well as a boolean that 
-*/
-pixel Reproject(fragment IN, 
-				uniform sampler2D colors,
-				uniform sampler2D normals)
-{
-	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 float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w;
-	const float3 eyeSpacePos = -viewDir * eyeDepth;
-	const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f);
-
-
-	////////////////
-	//-- calculcate the current projected posiion (also used for next frame)
-	
-	float4 currentPos = mul(modelViewProj, worldPos);
-	
-	const float w = SAMPLE_RADIUS / currentPos.w;
-	currentPos /= currentPos.w;
-	
-	const float precisionScale = 1e-3f;
-	const float currentDepth = currentPos.z * precisionScale;
-
-	const float2 ao = ssao(IN, colors, noiseTex, samples, normal, 
-		                   eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir));
-
-
-	/////////////////
-	//-- 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;
-
-	return OUT;
-}
-
-#endif
-
 
 float4 Output(fragment IN, uniform sampler2D colors): COLOR
@@ -304,4 +214,129 @@
 	color.w /= length(IN.view);
 	
+	return color;
+}
+
+
+/** This shader computes the reprojection and checks
+	if the reprojected pixel from last frame is still
+	valid in the current frame
+	*/
+inline float PixelValid(sampler2D diffVals,
+						sampler2D oldTex,
+						float4 color,
+						float2 texCoord,
+						float3 viewDir,
+						float3 oldEyePos,
+						float4x4 modelViewProj,
+						float4x4 oldModelViewProj,
+						float3 oldbl,
+						float3 oldbr,
+						float3 oldtl,
+						float3 oldtr
+						)
+{
+	// reconstruct position from the eye space depth
+	const float eyeSpaceDepth = color.w;
+	const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f);
+
+	float3 diffVec = tex2Dlod(diffVals, float4(texCoord, 0, 0)).xyz;
+	
+
+	////////////////
+	//-- calculcate the current projected posiion (also used for next frame)
+	
+	float4 projPos = mul(modelViewProj, worldPos);
+	const float invw = 1.0f / projPos.w;
+	projPos *= invw;
+
+	// compute position from old frame for dynamic objects + translational portion
+	//const float3 translatedPos = diffVec - oldEyePos + worldPos.xyz;
+	const float3 translatedPos = worldPos.xyz;
+
+
+	/////////////////
+	//-- 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(oldModelViewProj, float4(translatedPos, 1.0f));
+	float4 backProjPos = mul(modelViewProj, float4(translatedPos, 1.0f));
+	backProjPos /= backProjPos.w;
+	
+	// fit from unit cube into 0 .. 1
+	//const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f;
+	const float2 oldTexCoords = texCoord;
+	// retrieve the sample from the last frame
+	const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f));
+
+	// calculate eye space position of sample in old frame
+	const float oldEyeSpaceDepth = oldPixel.w;
+
+	// vector from eye pos to old sample 
+	const float3 oldViewDir = viewDir;//Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr);
+	const float invLen = 1.0f / length(oldViewDir);
+	const float projectedEyeSpaceDepth = invLen * length(translatedPos);
+	
+	const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);
+
+	const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z;
+
+	//if (squaredLen < 1e-8f) // object not dynamic
+	//{}
+
+	float validPixel;
+
+	if (1
+		&& (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f)
+		&& (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f)
+		//&& (depthDif <= MIN_DEPTH_DIFF) 
+		&& (depthDif <= 9e-1f) 
+		)
+	{
+		validPixel = 0.0f;//5f;
+	}
+	else
+	{	
+		validPixel = 1.5f;
+	}
+
+	return depthDif;
+	//return validPixel;
+}
+
+
+float4 PrepareSsao(fragment IN,
+				   uniform sampler2D colorsTex,
+				   uniform sampler2D oldTex,
+				   uniform float4x4 modelViewProj,
+				   uniform float4x4 oldModelViewProj,
+				   uniform float3 oldEyePos,
+				   uniform float3 oldbl,
+				   uniform float3 oldbr,
+				   uniform float3 oldtl,
+				   uniform float3 oldtr,
+				   uniform sampler2D diffVals
+				   ): COLOR
+{   
+	//const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz);
+	const float3 viewDir = IN.view;
+	float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
+
+	// store scaled view vector so wie don't have to normalize for e.g., ssao
+	color.w /= length(IN.view);
+	//color.w = 1;
+
+	// do reprojection and filter out the pixels that are not save
+	float pValid = PixelValid(diffVals,
+		oldTex,
+		color, 
+		IN.texCoord,
+		viewDir,
+		oldEyePos,
+		modelViewProj,
+		oldModelViewProj,
+		oldbl, oldbr, oldtl, oldtr
+		);
+
+	color.x = pValid;
 	return color;
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3149)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3155)
@@ -78,6 +78,7 @@
 	average /= max(total_w, 1e-1f);
 
-	return saturate(average );
+	return saturate(average);
 }
+
 
 /** Function combining image and indirect illumination buffer using a 
@@ -103,11 +104,12 @@
 		const float scaleFactor = 1.0f;
 		const float adaptFactor = 10.0f;
-		
 		const float scale =	adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y);
-			
-		ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale);
+
+		//ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale);
 	}
 
 	OUT.illum_col.xyz = col.xyz * ao.x;
+	
+	OUT.illum_col.xyz = float3(0, ao.x, 0);
 
 	//OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3151)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3155)
@@ -51,10 +51,8 @@
 
 // reconstruct world space position
-inline float3 ReconstructSamplePos(uniform sampler2D tex,
+inline float3 ReconstructSamplePos(float eyeSpaceDepth,
 								   float2 texcoord, 
 								   float3 bl, float3 br, float3 tl, float3 tr)
 {
-	const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w;
-	
 	float3 viewVec = Interpol(texcoord, bl, br, tl, tr);
 	float3 samplePos = -viewVec * eyeSpaceDepth;
@@ -117,5 +115,6 @@
 
 /** This shader computes the reprojection and stores 
-	reprojected color / depth values as well as a boolean that 
+	the ssao value of the old pixel as well as the
+	weight of the pixel in the new frame.
 */
 inline float2 temporalSmoothing(float4 worldPos,
@@ -140,5 +139,6 @@
 								float3 oldtl,
 								float3 oldtr,
-								float3 diffVec
+								float3 diffVec,
+								float pixelValid
 								)
 {
@@ -183,8 +183,8 @@
 #endif
 
-	float notValid = 0.5f;
+	//float pixelValid = 0.5f;
 	float overallDepth = 0;
 
-#if 1
+#if 0
 	const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z;
 
@@ -222,11 +222,11 @@
 		// if visibility changed in the surrounding area we have to recompute
 		//&& (oldNumSamples > 0.8f * newNumSamples)
-		//&& (notValid < 1.0f)
+		//&& (pixelValid < 1.0f)
 		)
 	{
 		// increase the weight for convergence
 		newWeight = oldWeight + 1.0f;
-		if (notValid > 1.0f) newWeight = 4.0f;
-		//if (notValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f);
+		if (pixelValid > 1.0f) newWeight = 4.0f;
+		//if (pixelValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f);
 	}
 	else
@@ -234,9 +234,4 @@
 		newWeight = 1.0f;
 	}
-
-	//if (oldPixel.y >= 2000)
-	//	newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50));
-	//if (newWeight >= 2000) newWeight = 1000;
-	//newWeight -= step(512.0f, newWeight) * 256.0f;
 
 	return float2(oldPixel.x, newWeight);
@@ -288,6 +283,10 @@
 
 		//if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples;
-		const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr);
+		float4 sampleColor = tex2Dlod(colors, float4(texcoord, 0, 0));
+
+		const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr);
 		const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz);
+
+		numSamples += sampleColor.x;
 
 
@@ -301,14 +300,7 @@
 
 		// angle between current normal and direction to sample controls AO intensity.
-		//const float cosAngle = max(-dot(sampleNormal, normal), .0f);
-		//const float cosAngle = .5f - dot(sampleNormal, normal) * 0.5f;
 		float cosAngle = .5f + dot(sampleNormal, -normal) * 0.5f;
-
-		float dirAngle = dot(dirSample, normal);
-
-		cosAngle *= step(0.0f, dirAngle);
-
-		//cosAngle *= step(0.5f, cosAngle);
-		//const float cosAngle = .5f * dot(sampleNormal, normal) + 1.0f;
+		// use binary decision to cull samples that are behind current shading point
+		cosAngle *= step(0.0f, dot(dirSample, normal));
 	
 		// the distance_scale offset is used to avoid singularity that occurs at global illumination when 
@@ -374,7 +366,9 @@
 		const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor;
 
-		//if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples;
-		const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr);
+		float4 sampleColor = tex2Dlod(colors, float4(texcoord, 0, 0));
+		const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr);
 		
+		numSamples += sampleColor.x;
+
 
 		////////////////
@@ -454,4 +448,17 @@
 
 	
+	float2 ao;
+
+	// 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));
+		//ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);
+	}
+	else
+	{
+		 ao = float2(1.0f, 0);
+	}
+
 	/////////////////
 	//-- compute temporal reprojection
@@ -467,5 +474,6 @@
 											scaleFactor, 
 											oldbl, oldbr, oldtl, oldtr,
-											diffVec
+											diffVec,
+											ao.y
 											);
 
@@ -473,18 +481,6 @@
 	const float newWeight = temporalVals.y;
 
-	float2 ao;
-
-	// 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));
-		ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);
-	}
-	else
-	{
-		 ao = float2(1.0f, 0);
-	}
-
-	OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight;
+
+	OUT.illum_col.x = ao.y;//(ao.x + oldSsao * (newWeight - 1.0f)) / newWeight;
 	OUT.illum_col.y = newWeight;
 	OUT.illum_col.z = invw;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3148)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3155)
@@ -107,4 +107,7 @@
 	void FlipFbos(FrameBufferObject *fbo);
 
+	void PrepareSsao(FrameBufferObject *fbo);
+
+
 
 	////////////
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3153)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3155)
@@ -471,9 +471,9 @@
 	//-- load some dynamic stuff
 
-	resourceManager->mUseNormalMapping = true;
-	//resourceManager->mUseNormalMapping = false;
-
-	LoadModel("fisch.dem", dynamicObjects);
-	//LoadModel("hbuddha.dem", dynamicObjects);
+	//resourceManager->mUseNormalMapping = true;
+	resourceManager->mUseNormalMapping = false;
+
+	//LoadModel("fisch.dem", dynamicObjects);
+	LoadModel("hbuddha.dem", dynamicObjects);
 	//LoadModel("venusm.dem", dynamicObjects);
 	//LoadModel("camel.dem", dynamicObjects);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3151)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3155)
@@ -58,4 +58,5 @@
 static ShaderProgram *sCgDownSampleProgram = NULL;
 static ShaderProgram *sCgScaleDepthProgram = NULL;
+static ShaderProgram *sCgPrepareSsaoProgram = NULL;
 
 
@@ -291,6 +292,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);
@@ -373,4 +374,5 @@
 	sCgScaleDepthProgram = sm->CreateFragmentProgram("deferred", "ScaleDepth", "ScaleDepth");
 	sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum");
+	sCgPrepareSsaoProgram = sm->CreateFragmentProgram("deferred", "PrepareSsao", "PrepareSsao");
 
 
@@ -410,5 +412,7 @@
 	////////////////
 
-	string combineSsaoParams[] = {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights", "bl", "br", "tl", "tr"};
+	string combineSsaoParams[] = 
+		{"colorsTex", "normalsTex", "ssaoTex", "filterOffs", 
+		 "filterWeights", "bl", "br", "tl", "tr"};
 	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9);
 
@@ -439,9 +443,17 @@
 	////////////////
 
+	
+	string prepareSsaoParams[] = 
+		{"colorsTex", "oldTex", "modelViewProj", "oldModelViewProj", "oldEyePos", 
+		 "oldbl", "oldbr", "oldtl", "oldtr", "diffVals"};
+
+	sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 10);
+
+
+	////////////////
+
 
 	const float filterWidth = 100.0f;
-	//const float filterWidth = 1000.0f;
-
-#if 1
+
 	PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f);
 	poisson.Generate((float *)ssaoFilterOffsets);
@@ -461,12 +473,5 @@
 		ssaoFilterOffsets[2 * i + 1] *= yoffs;
 	}
-#else
-	//ComputeSampleOffsets(ssaoFilterOffsets, mWidth, mHeight, sqrt(NUM_SSAO_FILTERSAMPLES), NUM_SSAO_FILTERSAMPLES); 
-	ComputeSampleOffsets(ssaoFilterOffsets, mWidth, mHeight, filterWidth, NUM_SSAO_FILTERSAMPLES); 
-	//cout<<"ssao filter size: " << NUM_SSAO_FILTERSAMPLES << endl;
-	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
-		ssaoFilterWeights[i] = 1.0f;
-
-#endif
+
 
 	/////////
@@ -507,5 +512,6 @@
 		// downsample fbo buffers
 		// colors
-		DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram);
+		//DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram);
+		PrepareSsao(fbo);
 		DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals
 		DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets
@@ -601,5 +607,4 @@
 	
 	if (mUseTemporalCoherence || mRegenerateSamples)
-	//if (mRegenerateSamples)
 	{
 		mRegenerateSamples = false;
@@ -946,4 +951,53 @@
 
 
+void DeferredRenderer::PrepareSsao(FrameBufferObject *fbo)
+{
+	GLuint colorsTex, diffVals, oldTex;
+
+	colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+	//normalsTex = fbo->GetColorBuffer(1)->GetTexture();
+	diffVals = fbo->GetColorBuffer(2)->GetTexture();
+	//diffVals = mDownSampleFbo->GetColorBuffer(2)->GetTexture();
+
+	// flip flop between illumination buffers
+	oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
+
+	int i = 0;
+
+	sCgPrepareSsaoProgram->SetTexture(i ++, colorsTex);
+	//sCgSsaoProgram->SetTexture(i ++, normalsTex);
+	sCgPrepareSsaoProgram->SetTexture(i ++, oldTex);
+	
+	sCgPrepareSsaoProgram->SetMatrix(i ++, mProjViewMatrix);
+	sCgPrepareSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix);
+
+	for (int j = 0; j < 4; ++ j, ++ i)
+		sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z);
+
+	Vector3 de;
+	de.x = mOldEyePos.x - mEyePos.x;
+	de.y = mOldEyePos.y - mEyePos.y; 
+	de.z = mOldEyePos.z - mEyePos.z;
+
+	sCgPrepareSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z);
+
+	sCgPrepareSsaoProgram->SetTexture(i ++, diffVals);
+
+
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight());
+	
+	mDownSampleFbo->Bind();
+
+	glDrawBuffers(1, mrt + 0);
+
+	DrawQuad(sCgPrepareSsaoProgram);
+	
+	glPopAttrib();
+	PrintGLerror("prepareSsao");
+}
+
+
+
 void DeferredRenderer::DownSample(FrameBufferObject *fbo, 
 								  int bufferIdx,
@@ -1009,32 +1063,4 @@
 
 
-/*
-void DeferredRenderer::BackProject(FrameBufferObject *fbo)
-{
-	// back project new frame into old one and check
-	// if pixel still valid. store this property with ssao texture or even 
-	// betteer with color / depth texture. This way
-	// we can sample this property together with the color / depth
-	// values and we do not require additional texture lookups
-	fbo->Bind();
-
-	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
-	//GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
-
-	// overwrite old color texture
-	//colorBufferIdx = 3 - colorBufferIdx;
-	//glDrawBuffers(1, mrt + colorBufferIdx);
-	//glDrawBuffers(1, mrt + colorBufferIdx);
-
-	sCgCombineSsaoProgram->SetTexture(0, colorsTex);
-	//sCgCombineSsaoProgram->SetTexture(1, ssaoTex);
-
-	DrawQuad(sCgBackProjectProgram);
-	
-	PrintGLerror("combine ssao");
-}
-*/
-
-
 void DeferredRenderer::InitFrame()
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp	(revision 3153)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp	(revision 3155)
@@ -23,5 +23,5 @@
 	}
 	
-	std::cin.get();
+	//std::cin.get();
 	cout << "conversion successful" << endl;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3154)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3155)
@@ -176,6 +176,6 @@
 
 		ambient.x = ambient.y = ambient.z = 0.2f;
-		//diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f;
-		diffuse.x = diffuse.y = diffuse.z = 1.0f;
+		diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f;
+		//diffuse.x = diffuse.y = diffuse.z = 1.0f;
 		spec.x = spec.y = spec.z = .0f;
 		emm = spec;
