Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2848)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2865)
@@ -90,5 +90,7 @@
 	*/
 	Vector3 GetCenter() const;
-
+	/** If false, the highest (most detailed) LOD level is used for all entities.
+	*/
+	static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; }
 
 
@@ -119,4 +121,6 @@
 	/// the center of gravity of this scene entity
 	Vector3 mCenter;
+
+	static bool sUseLODs;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp	(revision 2850)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp	(revision 2865)
@@ -92,7 +92,7 @@
 	}
 
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage);
-	
-	if (mUseMipMap)
+	if (!mUseMipMap)
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage);
+	else	
 		gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, mImage);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2863)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2865)
@@ -7,10 +7,10 @@
 
 // rule of thumb: approx 1 / NUM_SAMPLES
-//#define SAMPLE_INTENSITY 0.2
-#define SAMPLE_INTENSITY 0.125f
+#define SAMPLE_INTENSITY 0.17
+//#define SAMPLE_INTENSITY 0.125f
 
 #define AREA_SIZE 9e-1f
 //#define VIEW_CORRECTION_SCALE 0.3f
-#define VIEW_CORRECTION_SCALE 1.0f
+#define VIEW_CORRECTION_SCALE 0.5f
 #define DISTANCE_SCALE 1e-6f
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2851)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2865)
@@ -73,21 +73,23 @@
 			  uniform float4 diffuse)
 {
-  pixel pix;
-      
-  pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy);
-  pix.pos = IN.worldPos * maxDepth;
-  pix.norm.xyz = IN.normal * 0.5f + 0.5f;
+	pixel pix;
 
-  // hack: squeeze some information about ambient into the texture
-  pix.norm.w = ambient.x;
-  // hack: store projection coordinate for scaling ssao
-  pix.pos.w = IN.projPos.w;
+	pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy);
+	pix.pos = IN.worldPos * maxDepth;
+	pix.norm.xyz = IN.normal * 0.5f + 0.5f;
 
-  if (pix.col.w < 0.5f)
-	  discard;
+	// hack: squeeze some information about ambient into the texture
+	pix.norm.w = ambient.x;
+	// hack: store projection coordinate for scaling ssao
+	pix.pos.w = IN.projPos.w;
 
-  pix.col.w = IN.mypos.z / IN.mypos.w;
+	// account for alpha blending
+	if (pix.col.w < 0.5f)
+		discard;
 
-  return pix;
+	// write the depth
+	pix.col.w = IN.mypos.z / IN.mypos.w;
+
+	return pix;
 }
 
@@ -98,14 +100,14 @@
 	   uniform float4 diffuse)
 {
-  pixel pix;
-      
-  pix.col = diffuse;
-  pix.pos = IN.worldPos * maxDepth;
-  pix.norm.xyz = IN.normal * 0.5f + float3(0.5f);
-  // hack: squeeze some information about ambient into the texture
-  pix.norm.w = ambient.x;
-  pix.pos.w = IN.mypos.w;
-  pix.col.w = IN.mypos.z / IN.mypos.w;
+	pixel pix;
 
-  return pix;
+	pix.col = diffuse;
+	pix.pos = IN.worldPos * maxDepth;
+	pix.norm.xyz = IN.normal * 0.5f + float3(0.5f);
+	// hack: squeeze some information about ambient into the texture
+	pix.norm.w = ambient.x;
+	pix.pos.w = IN.mypos.w;
+	pix.col.w = IN.mypos.z / IN.mypos.w;
+
+	return pix;
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 2864)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 2865)
@@ -1,70 +1,83 @@
 struct v2p
 {
-	float tc0: TEXCOORD0; // Center
-	float tc1: TEXCOORD1; // Center
-	float tc2: TEXCOORD2; // Center
-	float tc3: TEXCOORD3; // Center
-	float tc4: TEXCOORD4; // Center
-	float tc5: TEXCOORD5; // Center
-	float tc6: TEXCOORD6; // Center
-}
+	float2 c:  TEXCOORD0; // center
+	float2 lt: TEXCOORD1; // left top
+	float2 rb: TEXCOORD2; // right bottom
+	float2 rt: TEXCOORD3; // right top
+	float2 lb: TEXCOORD4; // left bottom
+	float4 lr: TEXCOORD5; // left / right
+	float4 tb: TEXCOORD6; // top / bottom
+};
+
+//uniform sampler2D s_distort;
+uniform float4 e_barrier = float4(5e-5, 5e-5, 0, 0);
+uniform float4 e_weights = float4(1.0f, 1.0f, 1.0f, 1.0f); // x = normal, y = depth
+uniform float4 e_kernel = float4(0.3f, 1.0f, 1.0f, 1.0f); // x = normal, y = depth
 
 
-uniform sampler2D s_distort;
-uniform hlf4 e_barrier;
-uniform half4 e_weights;
-uniform half4 e_kernel;
+float4 main(v2p IN, 
+			uniform sampler2D colors,
+			uniform sampler2D normals
+			): COLOR
+{
+	// normal discontinuity filter
+	float3 nc = (float3)tex2D(normals, IN.c.xy);
 
-half4 main(v2p) : COLOR
-{
-
-
-	// discontinuity filter
-	/*float nc = tex1D(s_normal, I.tc0);
-	float nd;
-
-	nd.x = dot(nc, float3(tex2D(s_normal, I.tc1));
-	nd.y = dot(nc, float3(tex2D(s_normal, I.tc2));
-	nd.z = dot(nc, float3(tex2D(s_normal, I.tc3));
-	nd.w = dot(nc, float3(tex2D(s_normal, I.tc4));
+	float4 nd;
+	nd.x = dot(nc, float3(tex2D(normals, IN.lt.xy)));
+	nd.y = dot(nc, float3(tex2D(normals, IN.rb.xy)));
+	nd.z = dot(nc, float3(tex2D(normals, IN.rt.xy)));
+	nd.w = dot(nc, float3(tex2D(normals, IN.lb.xy)));
 
 	nd -= e_barrier.x;
-	nd = max(0, nd);
+	nd = step(0, nd);
 
 	float ne = saturate(dot(nd, e_weights.x));
 
-	float 4 tc5r = = I.tc5.wzyx;
-	float 4 tc6r = = I.tc6.wzyx;
-*/
+	// opposite coordinates
+	float4 lrr = IN.lr.wzyx;
+	float4 tbr = IN.tb.wzyx;
 
+	// depth filter: compute gradient difference:
+	// (c - sample) + (c - opposite sample)
+
+	float4 dc = float4(tex2D(colors, IN.c).w);
+
+	float pos_lt = (float)tex2D(colors, IN.lt.xy).w;
+	float pos_rb = (float)tex2D(colors, IN.rb.xy).w;
+
+	float pos_lb = (float)tex2D(colors, IN.lb.xy).w;
+	float pos_rt = (float)tex2D(colors, IN.rt.xy).w;
+
+	float pos_l = (float)tex2D(colors, IN.lr.xy).w;
+	float pos_r = (float)tex2D(colors, lrr.xy).w;
+
+	float pos_t = (float)tex2D(colors, IN.tb.xy).w;
+	float pos_b = (float)tex2D(colors, tbr.xy).w;
+
+	float4 dd;
+
+	dd.x = pos_lt + pos_rb;
+	dd.y = pos_lb + pos_rt;
+	dd.z = pos_l + pos_r;
+	dd.w = pos_t + pos_b;
+
+	dd = abs(2.0f * dc - dd) - e_barrier.y;
+	dd = step(dd, 0);
+	float de = saturate(dot(dd, e_weights.y));
+
+	// weight: 0 = no aa, 1 = full antialiasing
+	float w = (1.0f - de * ne) * e_kernel.x;
+
+	// smoothed color
+	// (a - c) * w + c = a * w + c * (1 - w)
+	float2 offset = IN.c.xy * (1.0f - w);
+
+	float4 s0 = tex2D(colors, offset + IN.lt.xy * w);
+	float4 s1 = tex2D(colors, offset + IN.rb.xy * w);
+	float4 s2 = tex2D(colors, offset + IN.rt.xy * w);
+	float4 s3 = tex2D(colors, offset + IN.lb.xy * w);
+
+	return (s0 + s1 + s2 + s3) / 4.0f;
+	//return float4(w);
 }
-
-
-
-
-struct fragment
-{
-  float4 pos: WPOS; // normalized screen position
-  float4 texCoord: TEXCOORD0; 
-};
-
-struct pixel
-{
-  float4 color: COLOR0;
-};
-
-
-pixel main(fragment IN, 
-	   uniform sampler2D colorsTex1,
-           uniform sampler2D colorsTex2)
-{
-  pixel OUT;
-  
-  float4 col1 = tex2D(colorsTex1, IN.texCoord.xy);
-  float4 col2 = tex2D(colorsTex2, IN.texCoord.xy);
-  
-  const float x = 0.5f;
-  OUT.color = col1 * x + col2 * (1.0f - x);
-
-  return OUT;
-}
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 2865)
@@ -23,5 +23,5 @@
 
 	// generates poisson distribution on disc
-	float minDist = 2.0f / sqrt((float)mNumSamples);
+	float minDist = 4.0f / sqrt((float)mNumSamples);
 
 	//cout << "minDist before= " << minDist << endl;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2863)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2865)
@@ -30,4 +30,9 @@
 static CGparameter sNoiseMultiplierParam;
 static CGparameter sExpFactorParam;
+static CGprogram sCgAntiAliasingProgram;
+
+static CGparameter sColorsTexAntiAliasingParam;
+static CGparameter sNormalsTexAntiAliasingParam;
+
 
 static GLuint noiseTex;
@@ -133,4 +138,23 @@
 		cerr << "ssao program failed to load" << endl;
 
+	sCgAntiAliasingProgram = 
+		cgCreateProgramFromFile(context, 
+								CG_SOURCE,
+								"src/shaders/antialiasing.cg", 
+								RenderState::sCgFragmentProfile,
+								"main",
+								NULL);
+
+	if (sCgAntiAliasingProgram != NULL)
+	{
+		cgGLLoadProgram(sCgAntiAliasingProgram);
+
+		sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");  
+		sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals");
+	}
+	else
+		cerr << "antialiasing program failed to load" << endl;
+
+
 	PrintGLerror("init");
 }
@@ -151,5 +175,6 @@
 	ComputeSsao(fbo, expFactor);
 	// the second pass just renders the combined solution
-	DisplayTexture();
+	//DisplayTexture();
+	AntiAliasing(fbo);
 }
 
@@ -213,5 +238,5 @@
 
 
-	GenerateSamples(); 
+	//GenerateSamples(); 
 	cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);
 
@@ -259,5 +284,5 @@
 
 
-void SsaoShader::DisplayTexture()
+/*void SsaoShader::DisplayTexture()
 {
 	glEnable(GL_TEXTURE_2D);
@@ -300,5 +325,5 @@
 
 	PrintGLerror("ssao second pass");
-}
+}*/
 
 
@@ -370,3 +395,91 @@
 
 
+
+static void SetVertex(float x, float y, float x_offs, float y_offs)
+{
+	glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center
+	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top
+	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom
+	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top
+	glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom
+
+	glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right
+	glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom
+
+	glVertex3f(x - 0.5f, y - 0.5f, -0.5f);
+}
+
+
+void SsaoShader::AntiAliasing(FrameBufferObject *fbo)
+{
+	GLuint colorsTex = mNewFbo->GetColorBuffer(0)->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
+
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, mWidth, mHeight);
+
+	glDisable(GL_ALPHA_TEST);
+	glDisable(GL_TEXTURE_2D);
+	glDisable(GL_LIGHTING);
+	
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	const float offs = 0.5f;
+	
+	glOrtho(-offs, offs, -offs, offs, 0, 1);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
+
+	cgGLBindProgram(sCgAntiAliasingProgram);
+
+	cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex);
+	cgGLEnableTextureParameter(sColorsTexAntiAliasingParam);
+
+	cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex);
+	cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam);
+	
+	glColor3f(1.0f, 1.0f, 1.0f);
+
+	float offs2 = 0.5f;
+
+	glBegin(GL_QUADS);
+
+	// the neighbouring texels
+	float x_offs = 1.0f / mWidth;
+	float y_offs = 1.0f / mHeight;
+
+	SetVertex(0, 0, x_offs, y_offs);
+	SetVertex(1, 0, x_offs, y_offs);
+	SetVertex(1, 1, x_offs, y_offs);
+	SetVertex(0, 1, x_offs, y_offs);
+
+	glEnd();
+
+	cgGLDisableTextureParameter(sColorsTexAntiAliasingParam);
+	cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam);
+
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
+	
+	glEnable(GL_LIGHTING);
+	glDisable(GL_TEXTURE_2D);
+	
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+
+	glMatrixMode(GL_MODELVIEW);
+	glPopMatrix();
+
+	glPopAttrib();
+
+	PrintGLerror("deferred shading");
+}
+
+
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h	(revision 2861)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h	(revision 2865)
@@ -38,6 +38,11 @@
 protected:
 
+	void FirstPass(FrameBufferObject *fbo);
+	void AntiAliasing(FrameBufferObject *fbo);
+
 	int mWidth;
 	int mHeight;
+
+	FrameBufferObject *mFbo;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2853)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2865)
@@ -18,4 +18,6 @@
 {
 
+bool SceneEntity::sUseLODs = true;
+
 
 SceneEntity::SceneEntity(Transform3 *trafo): 
@@ -33,9 +35,11 @@
 void SceneEntity::UpdateLODs(const Vector3 &viewPoint)
 {
+	mCurrentLODLevel = 0;
+
+	if (!sUseLODs) return;
+
 	const Vector3 pos = GetCenter();
 
 	const float dist = SqrDistance(pos, viewPoint);
-
-	mCurrentLODLevel = 0;
 
 	// note: we assume that lods are ordered from smallest distance to largest
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2863)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2865)
@@ -50,5 +50,6 @@
 	void ComputeSsao(FrameBufferObject *fbo, float expFactor);
 
-	void DisplayTexture();
+	//void DisplayTexture();
+	void AntiAliasing(FrameBufferObject *fbo);
 
 	void CreateNoiseTex2D();
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2864)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2865)
@@ -124,5 +124,5 @@
 bool showHelp = false;
 bool showStatistics = false;
-bool showOptions = false;
+bool showOptions = true;
 bool showBoundingVolumes = false;
 bool visMode = false;
@@ -164,4 +164,7 @@
 
 bool useFullScreen = false;
+
+bool useLODs = true;
+
 
 static Matrix4x4 matProjectionView = IdentityMatrix();
@@ -291,7 +294,10 @@
 		env.GetVectorParam(string("camDirection"), camDir);
 
+		env.GetBoolParam(string("useLODs"), useLODs);
+
 		//env.GetStringParam(string("modelPath"), model_path);
 		//env.GetIntParam(string("numSssaoSamples"), numSsaoSamples);
 
+		cout << "*********** parameters ***************" << endl;
 		cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; 
 		cout << "maxBatchSize: " << maxBatchSize << endl;
@@ -303,4 +309,5 @@
 		cout << "winHeight: " << winHeight << endl;
 		cout << "useFullScreen: " << useFullScreen << endl;
+		cout << "useLODs: " << useLODs << endl;
 		cout << "camPosition: " << camPos << endl;
 		cout << "expFactor: " << ssaoExpFactor << endl;
@@ -527,5 +534,6 @@
 	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false);
 	// the normals buffer
-	fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false);
+	//fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false);
+	fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false);
 
 	PrintGLerror("fbo");
@@ -1067,4 +1075,8 @@
 		if (ssaoExpFactor > 1.0f) ssaoExpFactor = 1.0f;
 		break;
+	case '9':
+		useLODs = !useLODs;
+		SceneEntity::SetUseLODs(useLODs);
+		break;
 	case 'o':
 	case 'O':
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp	(revision 2861)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp	(revision 2865)
@@ -24,13 +24,24 @@
 
 
+
 static CGprogram sCgDeferredProgram;
+static CGprogram sCgAntiAliasingProgram;
+
+
 static CGparameter sColorsTexParam;
 static CGparameter sPositionsTexParam;
 static CGparameter sNormalsTexParam;
 
+static CGparameter sColorsTexAntiAliasingParam;
+static CGparameter sNormalsTexAntiAliasingParam;
+
 
 DeferredShader::DeferredShader(int w, int h):
 mWidth(w), mHeight(h)
-{}
+{
+	mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
+	// the diffuse color buffer
+	mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false);
+}
 
 
@@ -65,4 +76,22 @@
 		cerr << "deferred program failed to load" << endl;
 
+	sCgAntiAliasingProgram = 
+		cgCreateProgramFromFile(context, 
+								CG_SOURCE,
+								"src/shaders/antialiasing.cg", 
+								RenderState::sCgFragmentProfile,
+								"main",
+								NULL);
+
+	if (sCgAntiAliasingProgram != NULL)
+	{
+		cgGLLoadProgram(sCgAntiAliasingProgram);
+
+		sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");  
+		sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals");
+	}
+	else
+		cerr << "antialiasing program failed to load" << endl;
+
 
 	PrintGLerror("init");
@@ -72,9 +101,17 @@
 void DeferredShader::Render(FrameBufferObject *fbo)
 {
-	FrameBufferObject::Release();
-
+	FirstPass(fbo);
+	AntiAliasing(fbo);
+}
+
+
+void DeferredShader::FirstPass(FrameBufferObject *fbo)
+{
 	GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture();
 	GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
+
+	// read the second buffer, write to the first buffer
+	mFbo->Bind();
 
 	glPushAttrib(GL_VIEWPORT_BIT);
@@ -141,7 +178,96 @@
 	glPopAttrib();
 
+	FrameBufferObject::Release();
+
 	PrintGLerror("deferred shading");
 }
 
 
+static void SetVertex(float x, float y, float x_offs, float y_offs)
+{
+	glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, y); // center
+	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, x - x_offs, y + y_offs); // left top
+	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, x + x_offs, y - y_offs); // right bottom
+	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, x + x_offs, y + y_offs); // right top
+	glMultiTexCoord2fARB(GL_TEXTURE4_ARB, x - x_offs, y - y_offs); // left bottom
+
+	glMultiTexCoord4fARB(GL_TEXTURE5_ARB, x - x_offs, y, x + x_offs, y); // left right
+	glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom
+
+	glVertex3f(x - 0.5f, y - 0.5f, -0.5f);
+}
+
+
+void DeferredShader::AntiAliasing(FrameBufferObject *fbo)
+{
+	GLuint colorsTex = mFbo->GetColorBuffer(0)->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
+
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, mWidth, mHeight);
+
+	glDisable(GL_ALPHA_TEST);
+	glDisable(GL_TEXTURE_2D);
+	glDisable(GL_LIGHTING);
+	
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	const float offs = 0.5f;
+	
+	glOrtho(-offs, offs, -offs, offs, 0, 1);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
+
+	cgGLBindProgram(sCgAntiAliasingProgram);
+
+	cgGLSetTextureParameter(sColorsTexAntiAliasingParam, colorsTex);
+	cgGLEnableTextureParameter(sColorsTexAntiAliasingParam);
+
+	cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex);
+	cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam);
+	
+	glColor3f(1.0f, 1.0f, 1.0f);
+
+	float offs2 = 0.5f;
+
+	glBegin(GL_QUADS);
+
+	// the neighbouring texels
+	float x_offs = 1.0f / mWidth;
+	float y_offs = 1.0f / mHeight;
+
+	SetVertex(0, 0, x_offs, y_offs);
+	SetVertex(1, 0, x_offs, y_offs);
+	SetVertex(1, 1, x_offs, y_offs);
+	SetVertex(0, 1, x_offs, y_offs);
+
+	glEnd();
+
+	cgGLDisableTextureParameter(sColorsTexAntiAliasingParam);
+	cgGLDisableTextureParameter(sNormalsTexAntiAliasingParam);
+
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
+	
+	glEnable(GL_LIGHTING);
+	glDisable(GL_TEXTURE_2D);
+	
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+
+	glMatrixMode(GL_MODELVIEW);
+	glPopMatrix();
+
+	glPopAttrib();
+
+	PrintGLerror("deferred shading");
+}
+
+
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2864)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2865)
@@ -10,6 +10,7 @@
 winHeight=768
 camPosition=483.398f 242.364f 186.078f
-camDirection=-1 -1 0
+camDirection=1 0 0
 useFullScreen=0
+useLODs=0
 #modelPath=data/city/model/
 
