Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.h	(revision 2848)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/LODInfo.h	(revision 2853)
@@ -10,4 +10,7 @@
 
 /** Class representing information about an LOD level.
+	The distance parameter indicates the distance where this
+	lod level is invoked - if the parameter value is smaller or equal 
+	than the distance to the view point.
 */
 struct LODLevel
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2838)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2853)
@@ -10,5 +10,5 @@
 //#define SAMPLE_INTENSITY 0.125f
 
-#define AREA_SIZE 5e-1f
+#define AREA_SIZE 9e-1f
 #define VIEW_CORRECTION_SCALE 0.3f
 #define DISTANCE_SCALE 1e-6f
@@ -254,7 +254,11 @@
 		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
 		(abs(depthDif)  < 8e-5f))
+	{
 		OUT.color = attenuated_color * expFactor + col1 * float4(1.0f - expFactor);
+	}
 	else
+	{
 		OUT.color = attenuated_color;
+	}
 
 	OUT.color.w = tex2D(colors, IN.texCoord.xy).w;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2852)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2853)
@@ -60,4 +60,5 @@
 	//-- load lod levels
 
+	// note: lods must be ordered from smallest distance to largest
 	int numLODs;
 	str.read(reinterpret_cast<char *>(&numLODs), sizeof(int));
@@ -65,11 +66,11 @@
 	for (int i = 0; i < numLODs; ++ i)
 	{
-		float distance;
-		str.read(reinterpret_cast<char *>(&distance), sizeof(float));
+		float dist;
+		str.read(reinterpret_cast<char *>(&dist), sizeof(float));
 
 		int numShapes;
 		str.read(reinterpret_cast<char *>(&numShapes), sizeof(int));
 
-		LODLevel *lodLevel = new LODLevel(distance);
+		LODLevel *lodLevel = new LODLevel(dist);
 
 		for (int j = 0; j < numShapes; ++ j)
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Plane3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Plane3.h	(revision 2782)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Plane3.h	(revision 2853)
@@ -16,6 +16,4 @@
 	Plane3() {}
 
-	//Plane3(const Vector3 &normal, float dist);
-
 	Plane3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
 
@@ -27,5 +25,5 @@
 		mD *= -1;
 	}
-	/** Get disance to point.
+	/** Get distance to a point.
 	*/
 	inline float Distance(const Vector3 &v) const 
@@ -73,7 +71,4 @@
 	Vector3 mNormal;
 	float mD;
-
-	//////////////////
-
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 2853)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 2853)
@@ -0,0 +1,79 @@
+#include "common.h"
+#include "SampleGenerator.h"
+#include "Halton.h"
+
+using namespace std;
+
+//SampleGenerator::SampleGenerator() {}
+
+SampleGenerator::SampleGenerator(int numSamples, float radius):
+mNumSamples(numSamples), mRadius(radius)
+{}
+
+
+PoissonDiscSampleGenerator::PoissonDiscSampleGenerator(int numSamples, float radius):
+SampleGenerator(numSamples, radius)
+{}
+
+
+void PoissonDiscSampleGenerator::Generate(Sample2 *samples) const
+{
+	static HaltonSequence halton;
+	float r[2];
+
+	// generates poisson distribution on disc
+	float minDist = 2.0f / sqrt((float)mNumSamples);
+
+	//cout << "minDist before= " << minDist << endl;
+
+	for (int i = 0; i < mNumSamples; ++ i)
+	{
+		int tries = 0, totalTries = 0;
+
+		// repeat until valid sample was found
+		while (1)
+		{
+			++ tries;
+			++ totalTries;
+
+			halton.GetNext(2, r);
+
+			const float rx = r[0] * 2.0f - 1.0f;
+			const float ry = r[1] * 2.0f - 1.0f;
+
+			// check if in disk, else exit early
+			if (rx * rx + ry * ry > 1)
+				continue;
+
+			bool sampleValid = true;
+
+			// check poisson property
+			for (int j = 0; ((j < i) && sampleValid); ++ j)
+			{
+				const float dist = 
+					sqrt((samples[j].x - rx) * (samples[j].x - rx) +
+					     (samples[j].y - ry) * (samples[j].y - ry));
+			
+				if (dist < minDist)
+					sampleValid = false;
+			}
+
+			if (sampleValid)
+			{
+				samples[i].x = rx;
+				samples[i].y = ry;
+				break;
+			}
+
+			if (tries > 2000)
+			{
+				minDist *= 0.9f;
+				tries = 0;
+			}
+		}
+		
+		//cout << "sample: " << samples[i].x << " " << i << " " << samples[i].y << " r: " << sqrt(samples[i].x * samples[i].x  + samples[i].y * samples[i].y) << " tries: " << totalTries << endl;
+	}
+
+	//cout << "minDist after= " << minDist << endl;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2848)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2853)
@@ -35,8 +35,9 @@
 	const Vector3 pos = GetCenter();
 
-	const float distance = SqrDistance(pos, viewPoint);
+	const float dist = SqrDistance(pos, viewPoint);
 
 	mCurrentLODLevel = 0;
 
+	// note: we assume that lods are ordered from smallest distance to largest
 	const int l = (int)mLODLevels.size();
 
@@ -45,5 +46,5 @@
 		LODLevel *lod = mLODLevels[i];
 
-		if (lod->GetSquaredDistance() > distance)
+		if (lod->GetSquaredDistance() > dist)
 			break;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h	(revision 2853)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h	(revision 2853)
@@ -0,0 +1,40 @@
+#ifndef __SAMPLEGENERATOR_H
+#define __SAMPLEGENERATOR_H
+
+
+/** Class that generates samples on a circle
+*/
+
+struct Sample2
+{
+	float x; 
+	float y;
+};
+
+
+class SampleGenerator
+{
+public:
+	
+	SampleGenerator(int numSamples, float radius);
+
+	virtual void Generate(Sample2 *samples) const = 0;
+
+protected:
+
+	SampleGenerator() {};
+
+	int mNumSamples;
+	float mRadius;
+};
+
+
+class PoissonDiscSampleGenerator: public SampleGenerator
+{
+public:
+	PoissonDiscSampleGenerator(int numSamples, float radius);
+
+	virtual void Generate(Sample2 *samples) const;
+};
+
+#endif
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2851)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2853)
@@ -31,4 +31,5 @@
 #include "Halton.h"
 #include "Transform3.h"
+#include "SampleGenerator.h"
 
 
@@ -188,5 +189,6 @@
 bool useFullScreen = false;
 
-float expFactor = 0.1f;
+// exp factor for ssao
+float expFactor = 0.05f;
 
 // ssao number of samples
@@ -376,6 +378,6 @@
 	glutInitWindowSize(winWidth, winHeight);
 	glutInit(&argc, argv);
-	//glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
-	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
+	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
+	//glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
 
 	//glutInitDisplayString("samples=2");
@@ -2041,5 +2043,5 @@
 	bool validIntersect = sceneQuery->CalcIntersection(playerPos);
 
-	if (validIntersect ) 
+	if (validIntersect) 
 		// && ((playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f))
 	{
@@ -2271,5 +2273,5 @@
 void GenerateSamples()
 {
-	static HaltonSequence halton;
+	/*static HaltonSequence halton;
 
 	float r[2];
@@ -2328,8 +2330,9 @@
 			}
 		}
-		//cout << "sample: " << samples[i] << " " << i / 2 << " " << samples[i + 1] << " r: " << sqrt(samples[i] * samples[i]  + samples[i + 1] * samples[i + 1]) << " tries: " << totalTries << endl;
-	}
-
-	//cout << "minDist after= " << minDist << endl;
+	}
+*/
+
+	static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f);
+	poisson.Generate((Sample2 *)samples);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2847)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2853)
@@ -284,4 +284,12 @@
 			</File>
 			<File
+				RelativePath=".\src\SampleGenerator.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\src\SampleGenerator.h"
+				>
+			</File>
+			<File
 				RelativePath=".\src\SceneQuery.cpp"
 				>
