Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3080)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3081)
@@ -6,10 +6,11 @@
 //-- ssao + gi parameters
 
-#define NUM_SAMPLES 8
-//#define NUM_SAMPLES 16
+//#define NUM_SAMPLES 8
+#define NUM_SAMPLES 16
 
 // for quadratic falloff
 //#define SAMPLE_INTENSITY 0.1f
-#define SAMPLE_INTENSITY 0.07f
+//#define SAMPLE_INTENSITY 0.07f
+#define SAMPLE_INTENSITY 0.03f
 
 #define SAMPLE_RADIUS 8e-1f
@@ -18,5 +19,6 @@
 #define DISTANCE_SCALE 5e-2f
 
-#define ILLUM_INTENSITY 8e-2f
+//#define ILLUM_INTENSITY 8e-2f
+#define ILLUM_INTENSITY 2e-2f
 
 #define VIEW_CORRECTION_SCALE 1.0f
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3034)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3081)
@@ -211,2 +211,90 @@
 }
 
+#if 0
+/** This shader computes the reprojection and stores reprojected color / depth values
+	as well as a boolean that 
+*/
+pixel (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, noise, 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
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3080)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3081)
@@ -20,4 +20,10 @@
 	float4 illum_col: COLOR0;
 };
+
+
+inline float occlusionPower(float radius, float dist)
+{
+	return 6.283185307179586476925286766559f * (1.0f - cos(asin(radius / dist)));
+}
 
 
@@ -106,7 +112,7 @@
 
 		float3 dirSample = samplePos - centerPosition;
-		const float magSample = length(dirSample);
+		const float lengthToSample = length(dirSample);
 		// normalize
-		dirSample /= magSample;
+		dirSample /= lengthToSample;
 
 		// angle between current normal and direction to sample controls AO intensity.
@@ -115,5 +121,6 @@
 		// the distance_scale offset is used to avoid singularity that occurs at global illumination when 
 		// the distance to a sample approaches zero
-		const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + magSample * magSample);
+		//const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f;
+		const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);
 
 #if 1
@@ -121,5 +128,5 @@
 		// => compensate for this (on the other hand, projected sampling area could be larger!)
 		const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal);
-		total_ao += cosAngle * intensity * viewCorrection;
+		total_ao += cosAngle * aoContrib * viewCorrection;
 #else
 		total_ao += cosAngle * intensity;
@@ -130,5 +137,5 @@
 }
 
-#pragma position_invariant main
+//#pragma position_invariant main
 
 /** The mrt shader for screen space ambient occlusion
@@ -188,8 +195,6 @@
 	// 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);
@@ -199,5 +204,4 @@
 	const float depthDif = projDepth - oldDepth;
 
-
 	//const float oldNumSamples = oldCol.y;
 	const float oldWeight = clamp(oldCol.y, 0, temporalCoherence);
@@ -208,8 +212,9 @@
 	//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 ((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)
@@ -224,5 +229,5 @@
 	{	
 		OUT.illum_col.x = ao.x;
-		newWeight = 0;
+		newWeight = .0f;
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3079)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3081)
@@ -604,5 +604,4 @@
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-	GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();
 
 	fbo->Bind();
@@ -724,5 +723,4 @@
 
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
-	GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();
 	
 	GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
@@ -774,5 +772,4 @@
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-	GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();
 
 	GLuint shadowTex = shadowMap->GetDepthTexture();
@@ -948,3 +945,32 @@
 
 
+/*
+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");
+}
+*/
+
+
+
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt	(revision 3013)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt	(revision 3081)
@@ -32,2 +32,46 @@
 
 
+
+ssao:
+
+1) implement bilateral filtering
+2) check physical properties 
+
+paper of 2007 arikan formula:
+
+SW(P, C, r) = 2 * pi * (1 - cos(asin (r / |PC|)))
+
+but not working properly!
+
+3) normal mapping
+
+
+problems:
+
+4) update of converged regions
+
+something could become visible 
+
+a) from outside
+b) from previously occluded regions
+
+a) could use ratio of samples outside current frame / last frame
+   but slows donw code
+
+5) dynamic objects:
+
+a) make ao stick on object: this should
+   be possible somehow, as the information is still available!!
+ 
+   tried to use difference of ao intensity between previous and
+   current frame to find out if pixel ao is not valid anymore.
+   but problems as some flickering was introduced while update of 
+   dynamic objects was not fast enough (annoying grey fade effect)
+
+b) fix the contact shadow on the floor:
+
+check when pixel not valid anymore: do that by checking for each
+sample if they were invalidated recently. if so, then invalidate
+current pixel ao. for each point, theoretically you don't have
+to compare the depth of the current pixel, but the depth of the
+samples taken for ao
