Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3136)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3137)
@@ -72,5 +72,4 @@
 	
 	OUT.color = col;
-	//OUT.color.xyz = normal * 0.5f + 0.5f;
 	// store scaled view vector so wie don't have to normalize for e.g., ssao
 	OUT.color.w = color.w;// / length(IN.view);
@@ -196,5 +195,5 @@
 	OUT.color = useShading ? (ambient + diffuse) * color : color;
 	// store scaled view vector from now on so wie don't have to normalize later (e.g., for ssao)
-	OUT.color.w = color.w / lenView;
+	//OUT.color.w = color.w / lenView;
 
 	return OUT;
@@ -294,5 +293,25 @@
 float4 Output(fragment IN, uniform sampler2D colors): COLOR
 {    
+	return tex2Dlod(colors, float4(IN.texCoord, 0, 0));
+}
+
+
+float4 ScaleDepth(fragment IN,
+				  uniform sampler2D colors): COLOR
+{    
+	float4 color = tex2Dlod(colors, 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);
+	
+	return color;
+}
+
+
+float4 DownSample(fragment IN,
+				  uniform sampler2D colors,
+				  uniform float2 downSampleOffs[NUM_DOWNSAMPLES]): COLOR
+{    
 	// let bilinear filtering do its work
-	return tex2Dlod(colors, float4(IN.texCoord, 0, 0));
-}
+	float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0));
+	return color;
+}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3135)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3137)
@@ -66,6 +66,8 @@
 float DiscontinuityFilter(float2 texCoord,
 						  float4 ao,
+						  float4 color,
 						  uniform sampler2D ssaoTex,
 						  uniform sampler2D normalsTex,
+						  uniform sampler2D colorsTex,
 						  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
 						  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
@@ -82,8 +84,10 @@
 	const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr);
 #else
+	//const float eyeSpaceDepth = color.w;
 	const float eyeSpaceDepth = ao.w;
 #endif
 
-	const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz);
+	const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz);
+	//const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz;
 
 	float4 aoSample;
@@ -95,10 +99,14 @@
 	float normalFactor;
 	float convergenceFactor;
+	float sampleDepth;
 
 	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
 	{
 		sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0);
+
+
 		aoSample = tex2Dlod(ssaoTex, sampleTexCoord);
 		sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz);
+		//sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz;
 
 #ifdef USE_POSITION
@@ -106,7 +114,9 @@
 		depthFactor = max(step(1.0f - 5e-1f, 1.0f - length(samplePos - centerPos)), 1e-3f);
 #else // use depth
-		depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f);
+		//sampleDepth = tex2Dlod(colorsTex, sampleTexCoord).w;
+		sampleDepth = aoSample.w;
+		depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth)), 1e-3f);
 #endif
-		normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f);
+		normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-3f);
 		convergenceFactor = min(100.0f, aoSample.y) * 0.01f;//max(step(18.5f, aoSample.y), 1e-3f);
 
@@ -176,5 +186,5 @@
 		//ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor  / (adaptFactor + ao.y), 0);
 
-		if (ao.y < 50.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, ao.z, bl, br, tl, tr);
+		if (ao.y < 50.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, ao.z, bl, br, tl, tr);
 		//ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0);
 	}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 3136)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 3137)
@@ -23,5 +23,5 @@
 {
 	// center normal
-	const float3 centerNormal = normalize(tex2Dlod(normals, float4(IN.texCoords, 0, 0)).xyz);
+	const float3 centerNormal = tex2Dlod(normals, float4(IN.texCoords, 0, 0)).xyz;
 	// center color
 	const float4 centerColor = tex2Dlod(colors, float4(IN.texCoords, 0, 0));
@@ -37,8 +37,8 @@
 	float4 nd;
 
-	nd.x = dot(centerNormal, normalize(tex2Dlod(normals, float4(lt, 0, 0)).xyz));
-	nd.y = dot(centerNormal, normalize(tex2Dlod(normals, float4(rb, 0, 0)).xyz));
-	nd.z = dot(centerNormal, normalize(tex2Dlod(normals, float4(rt, 0, 0)).xyz));
-	nd.w = dot(centerNormal, normalize(tex2Dlod(normals, float4(lb, 0, 0)).xyz));
+	nd.x = dot(centerNormal, tex2Dlod(normals, float4(lt, 0, 0)).xyz);
+	nd.y = dot(centerNormal, tex2Dlod(normals, float4(rb, 0, 0)).xyz);
+	nd.z = dot(centerNormal, tex2Dlod(normals, float4(rt, 0, 0)).xyz);
+	nd.w = dot(centerNormal, tex2Dlod(normals, float4(lb, 0, 0)).xyz);
 
 	nd -= float4(barrier.x);
@@ -65,5 +65,5 @@
 	for (int i = 0; i < 4; ++ i)
 	{
-		dd = float4(depthVals[i * 2] + depthVals[i * 2 + 1]);
+		dd[i] = float4(depthVals[i * 2] + depthVals[i * 2 + 1]);
 	}
 
@@ -72,5 +72,6 @@
 	dd = step(dd, float4(0.0f));
 
-	const float de = saturate(dot(dd, weights.y));
+	//const float de = saturate(dot(dd, weights.y));
+	const float de = weights.y * dd.x + dd.y + dd.z + dd.w;
 
 
@@ -91,6 +92,6 @@
 
 	//float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f;
-	//float4 col = (s0 + s1 + s2 + s3) * 0.25f;
-	float4 col = float4(ne.x, ne.x, ne.x, 0);
+	float4 col = (s0 + s1 + s2 + s3) * 0.25f;
+	//float4 col = float4(ne.x, ne.x, ne.x, 0);
 	//float4 col = float4(de.x, de.x, de.x, 0);
 	//float4 col = float4(w, w, w, 0);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3132)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3137)
@@ -18,23 +18,4 @@
 	float4 col: COLOR0;
 };
-
- 
-
-float4 DownSample(frag IN,
-				  uniform sampler2D colors,
-				  uniform float2 downSampleOffs[NUM_DOWNSAMPLES]): COLOR
-{    
-	// let bilinear filtering do its work
-	return tex2Dlod(colors, float4(IN.texCoord, 0, 0));
-/*
-    float4 average = .0f;
-    for (int i = 0; i < NUM_DOWNSAMPLES; ++ i)
-    {
-		average += tex2Dlod(colors, float4(IN.texCoord + downSampleOffs[i], 0, 0));
-    }  
-	average *= 1.0f / (float)NUM_DOWNSAMPLES;
-
-    return average;*/
-}
 
 
@@ -154,5 +135,5 @@
 	float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset;
 
-	const float expFactor = 0.1f;
+	const float expFactor = 1e-2f;
 	// exponential smoothing of tone mapping over time
 	if (oldLogLum > 1e-3f) // check if loglum from last frame too small (=> tm too bright)
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3133)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3137)
@@ -118,5 +118,5 @@
 	reprojected color / depth values as well as a boolean that 
 */
-inline float3 temporalSmoothing(float4 worldPos,
+inline float2 temporalSmoothing(float4 worldPos,
 								float eyeSpaceDepth,
 								float2 texcoord0,
@@ -167,4 +167,5 @@
 	const float invLen = 1.0f / length(viewVec);
 	const float projectedEyeSpaceDepth = invLen * length(translatedPos);
+	//const float projectedEyeSpaceDepth = length(translatedPos);
 	
 	const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth);
@@ -238,5 +239,5 @@
 	//newWeight -= step(512.0f, newWeight) * 256.0f;
 
-	return float3(oldPixel.x, newWeight, eyeSpaceDepth);
+	return float2(oldPixel.x, newWeight);
 }
 
@@ -385,5 +386,5 @@
 	//-- compute temporal reprojection
 
-	float3 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
+	float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
 	                                        oldTex, oldModelViewProj, temporalCoherence,
 											colors, 
@@ -401,4 +402,5 @@
 	//const float newWeight = clamp(temporalVals.y, 1.0f, temporalCoherence);
 	const float newWeight = temporalVals.y;
+
 	//float2 noiseOffs = float2((temporalVals.y - 1)/ 139.0f, .0f);
 	float2 noiseOffs = float2(.0f);
@@ -418,7 +420,7 @@
 
 	OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight;
-	OUT.illum_col.y = temporalVals.y;
+	OUT.illum_col.y = newWeight;
 	OUT.illum_col.z = invw;
-	OUT.illum_col.w = temporalVals.z;
+	OUT.illum_col.w = eyeSpaceDepth;
 
 	return OUT;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3135)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3137)
@@ -88,6 +88,9 @@
 		resolution of fbo.
 	*/
-	void DownSample(FrameBufferObject *fbo, int bufferIdx,
-					FrameBufferObject *downSampleFbo, int downSampleBufferIdx);
+	void DownSample(FrameBufferObject *fbo,
+					int bufferIdx,
+					FrameBufferObject *downSampleFbo,
+					int downSampleBufferIdx,
+					ShaderProgram *program);
 
 	void DrawQuad(ShaderProgram *p);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3136)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3137)
@@ -58,4 +58,5 @@
 static ShaderProgram *sCgDownSampleProgram = NULL;
 static ShaderProgram *sCgSmoothSsaoProgram = NULL;
+static ShaderProgram *sCgScaleDepthProgram = NULL;
 
 
@@ -370,5 +371,6 @@
 	sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing");
 	sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap");
-	sCgDownSampleProgram = sm->CreateFragmentProgram("tonemap", "DownSample", "downSample");
+	sCgDownSampleProgram = sm->CreateFragmentProgram("deferred", "Output", "Output");
+	sCgScaleDepthProgram = sm->CreateFragmentProgram("deferred", "ScaleDepth", "ScaleDepth");
 	sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum");
 	sCgSmoothSsaoProgram = sm->CreateFragmentProgram("combineSsao", "smoothSsao", "smoothSsao");
@@ -425,6 +427,11 @@
 	/////////////////////
 
-	string downSampleParams[] = {"colors", "downSampleOffs"};
-	sCgDownSampleProgram->AddParameters(downSampleParams, 0, 2);
+	string downSampleParams[] = {"colors"};
+	sCgDownSampleProgram->AddParameters(downSampleParams, 0, 1);
+
+	/////////////////////
+
+	string scaleDepthParams[] = {"colors"};
+	sCgScaleDepthProgram->AddParameters(scaleDepthParams, 0, 1);
 
 	////////////
@@ -505,7 +512,8 @@
 	{
 		// downsample fbo buffers
-		DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0); // colors
-		DownSample(fbo, 1, mDownSampleFbo, 1); // normals
-		DownSample(fbo, 2, mDownSampleFbo, 2); // offsets
+		// colors
+		DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram);
+		DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals
+		DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets
 	}
 
@@ -952,24 +960,19 @@
 								  int bufferIdx,
 								  FrameBufferObject *downSampleFbo, 
-								  int downSampleBufferIdx)
-{
-	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(bufferIdx);
-	GLuint colorsTex = colorBuffer->GetTexture();
+								  int downSampleBufferIdx,
+								  ShaderProgram *program)
+{
+	ColorBufferObject *buffer = fbo->GetColorBuffer(bufferIdx);
+	GLuint tex = buffer->GetTexture();
 
 	glPushAttrib(GL_VIEWPORT_BIT);
 	glViewport(0, 0, downSampleFbo->GetWidth(), downSampleFbo->GetHeight());
 	
-	sCgDownSampleProgram->SetTexture(0, colorsTex);
-
-	const float filterWidth = 1.0f;
-	float downSampleOffsets[NUM_DOWNSAMPLES * 2];
-	//ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight(), filterWidth, NUM_DOWNSAMPLES);
-	
-	sCgDownSampleProgram->SetArray2f(1, (float *)downSampleOffsets, NUM_DOWNSAMPLES);
-
-	mDownSampleFbo->Bind();
+	downSampleFbo->Bind();
+
+	program->SetTexture(0, tex);
 	glDrawBuffers(1, mrt + downSampleBufferIdx);
 
-	DrawQuad(sCgDownSampleProgram);
+	DrawQuad(program);
 	
 	glPopAttrib();
