Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3202)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3203)
@@ -7,9 +7,9 @@
 
 //#define NUM_SAMPLES 8
-#define NUM_SAMPLES 16
-//#define NUM_SAMPLES 24
+//#define NUM_SAMPLES 16
+#define NUM_SAMPLES 96
 
-//#define SAMPLE_INTENSITY 0.1f
-#define SAMPLE_INTENSITY 2.0f
+#define SAMPLE_INTENSITY 0.3f
+//#define SAMPLE_INTENSITY 2.0f
 
 #define SAMPLE_RADIUS 8e-1f
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3198)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3203)
@@ -194,5 +194,7 @@
 	const float m2 = min(texelCenterConv.z, texelCenterConv.w);
 
-	const float convergence = min(m1, m2);
+	const float minConvergence = min(m1, m2);
+
+	const float convergence = step(200.0f, minConvergence) * minConvergence;
 	//const float convergence = ao.y;
 
@@ -205,4 +207,5 @@
 		const float distanceScale = 1.0f;
 
+		// descend to zero filter size after reaching thres pixels
 		const float convergenceWeight = thres / (SSAO_FILTER_WIDTH - 1.0f);
 		const float convergenceScale = convergenceWeight / (convergence + convergenceWeight);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3199)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3203)
@@ -174,4 +174,5 @@
 	float total_ao = .0f;
 	float numSamples = .0f;
+	float validSamples = .0f;
 
 	for (int i = 0; i < NUM_SAMPLES; ++ i) 
@@ -233,5 +234,6 @@
 #endif
 		// check if the samples have been valid in the last frame
-		//numSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x;
+		validSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x;
+
 		++ numSamples;
 	}
@@ -239,5 +241,5 @@
 	total_ao /= numSamples;
 
-	return float3(max(0.0f, 1.0f - total_ao), .0f, numSamples);
+	return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples);
 }
 
@@ -287,5 +289,5 @@
 		const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor;
 
-		const float4 sampleColor = tex2Dlod(colors, float4(texcoord, 0, 0));
+		const float4 sampleColor = tex2Dlod(colors, float4(texcoord, .0f, .0f));
 		const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr);
 		
@@ -303,8 +305,4 @@
 		// angle between current normal and direction to sample controls AO intensity.
 		const float cosAngle = max(dot(dirSample, normal), .0f);
-	
-		// the distance_scale offset is used to avoid singularity that occurs at global illumination when 
-		// the distance to a sample approaches zero
-		//const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);
 		const float aoContrib = SAMPLE_INTENSITY / sqrLen;
 		//const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f;
@@ -321,9 +319,13 @@
 
 		// check if the samples have been valid in the last frame
-		validSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x;
+		// hack: the distance measure can fail in some cases => choose something different
+		const float tooFarAway = step(1.0f, lengthToSample);
+		validSamples += (1.0f - tooFarAway) * sampleColor.x;
 		//validSamples += sampleColor.x;
 
 		++ numSamples;
-		//if ((validSamples < 1.0f) && (newWeight > 20) && (numSamples >= 8)) break;
+
+		//if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break;
+		if ((validSamples < 1.0f) && (numSamples >= 8)) break;
 	}
 
@@ -401,6 +403,6 @@
 	if (eyeSpaceDepth < 1e10f)
 	{
-		//ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight);
-		ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);
+		ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight);
+		//ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);
 	}
 	else
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3202)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3203)
@@ -548,16 +548,4 @@
 	else
 	{
-		BvhNodeContainer::const_iterator nit, nit_end = nodes.end();
-
-		/*for (nit = nodes.begin(); nit != nit_end; ++ nit)
-		{
-			BvhNode *node = *nit;
-
-			for (int i = 0; i < node->mNumTestNodes; ++ i)
-			{
-				RenderBoundingBoxImmediate(mTestNodes[node->mTestNodesIdx + i]->GetBox());
-			}
-		}*/
-
 		renderedBoxes = PrepareBoundsWithDrawArrays(nodes);
 		RenderBoundsWithDrawArrays(renderedBoxes, state);
@@ -1315,15 +1303,8 @@
 	else
 	{
-		glPolygonMode(GL_FRONT, GL_LINE);
-		BvhNodeContainer nodes;
-		nodes.push_back(node);
-		int renderedBoxes = PrepareBoundsWithDrawArrays(nodes);
-		RenderBoundsWithDrawArrays(renderedBoxes, state);
-		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
-		/*for (int i = 0; i < node->mNumTestNodes; ++ i)
+		for (int i = 0; i < node->mNumTestNodes; ++ i)
 		{
 			RenderBoxForViz(mTestNodes[node->mTestNodesIdx + i]->GetBox());
-		}*/
+		}
 	}
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3197)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3203)
@@ -479,9 +479,9 @@
 	//-- load some dynamic stuff
 
-	resourceManager->mUseNormalMapping = true;
+	//resourceManager->mUseNormalMapping = true;
 	//resourceManager->mUseNormalMapping = false;
 
-	LoadModel("fisch.dem", dynamicObjects);
-	//LoadModel("hbuddha.dem", dynamicObjects);
+	//LoadModel("fisch.dem", dynamicObjects);
+	LoadModel("hbuddha.dem", dynamicObjects);
 	//LoadModel("venusm.dem", dynamicObjects);
 	//LoadModel("camel.dem", dynamicObjects);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt	(revision 3172)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt	(revision 3203)
@@ -104,2 +104,18 @@
 problem: 
 
+
+
+=========================
+
+1) ssao filter kernel: grows smaller too fast => flickering ... use
+adaptive number of samples instead of size?
+2) fix color bleeding
+3) fix ssao2 so that ssao contribution stays constant
+4) find physical expressions for constants in ssao
+5) retry normal discontinuity for ssao filter
+6) fix adaptive sampling for ssao and ssao2
+   a) sample adaptive if found invalid sample
+   b) sample adaptive if number of valid samples small?
+   
+   q: is it good to choose new weight as we do? (approx 4 frames)
+   or shouldn't we just completely reset sample?
