Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3134)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3136)
@@ -74,5 +74,5 @@
 	//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);
+	OUT.color.w = color.w;// / length(IN.view);
 	
 	return OUT;
@@ -187,6 +187,5 @@
 
 		float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex);
-		//float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTex);
-
+	
 		diffuse *= shadowTerm;
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3126)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3136)
@@ -69,4 +69,5 @@
 	// the normal has to be correctly transformed with the inverse transpose
 	OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
+	//OUT.normal = IN.normal;
 
 	return OUT;
@@ -94,4 +95,5 @@
 	// Transp(Inv(Inv(view))) = Transp(view)
 	pix.norm = mul(transpose(viewMatrix), IN.normal).xyz;
+	//pix.norm = IN.normal.xyz;
 	// compute eye linear depth
 	pix.col.w = length(IN.eyePos.xyz);
@@ -115,4 +117,5 @@
 	// multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view)
 	pix.norm = mul(transpose(viewMatrix), IN.normal).xyz;
+	//pix.norm = IN.normal.xyz;
 	// eye space depth
 	pix.col.w = length(IN.eyePos.xyz);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 3096)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 3136)
@@ -3,19 +3,15 @@
 struct fragment
 {
-	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
+	float2 texCoords:  TEXCOORD0; 
 };
 
 // the barrier for detecting a discontinuity (x = normal, y = depth)
-uniform float4 e_barrier = float4(5e-5, 5e-5, 0, 0); 
+//const uniform float4 barrier = float4(5e-5f, 5e-5f, 0, 0); 
+const uniform float4 barrier = float4(0.6f, 9e-2f, 0, 0); 
 // the weights for normal / depth discontinuity (x = normal, y = depth)
-uniform float4 e_weights = float4(0.5f, 0.5f, 1.0f, 1.0f); 
-//uniform float4 e_weights = float4(1.0f, 1.0f, 1.0f, 1.0f);
-uniform float4 e_kernel = float4(0.5f, 1.0f, 1.0f, 1.0f); 
+const uniform float4 weights = float4(0.5f, 0.5f, 1.0f, 1.0f); 
+//uniform float4 weights = float4(1.0f, 1.0f, 1.0f, 1.0f);
+// the maximal size of the filter kernel
+const uniform float kernel = 0.5f; 
 
 
@@ -23,74 +19,83 @@
 float4 main(fragment IN, 
 			uniform sampler2D colors,
-			uniform sampler2D normals
-			): COLOR
+			uniform sampler2D normals,
+			uniform float2 offsets[8]): COLOR
 {
-	//return tex2D(colors, IN.c.xy);
+	// center normal
+	const float3 centerNormal = normalize(tex2Dlod(normals, float4(IN.texCoords, 0, 0)).xyz);
+	// center color
+	const float4 centerColor = tex2Dlod(colors, float4(IN.texCoords, 0, 0));
+	// center depth
+	const float4 centerDepth = float4(centerColor.w);
+	
+	const float2 lt = IN.texCoords + offsets[0];
+	const float2 rb = IN.texCoords + offsets[1];
+	const float2 rt = IN.texCoords + offsets[2];
+	const float2 lb = IN.texCoords + offsets[3];
 
-	// normal discontinuity filter
-	float3 nc = (float3)tex2D(normals, IN.c.xy);
+	// compute normal discontinuities
+	float4 nd;
 
-	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.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 -= e_barrier.x;
-	nd = step((float4)0.0f, nd);
+	nd -= float4(barrier.x);
+	nd = step(float4(0.0f), nd);
 
-	float ne = saturate(dot(nd, e_weights.x));
+	// weight the influence of normal discontinuities
+	//const float ne = saturate(dot(nd, weights.x));
+	const float ne = nd.x * nd.y *nd.z * nd.w * weights.x;
 
-	// construct opposite coordinates
-	float4 lrr = IN.lr.wzyx;
-	float4 tbr = IN.tb.wzyx;
-
-	// depth filter: compute gradient difference:
+#if 1
+	////////////
+	// depth filter => compute gradient difference
 	// (c - sample) + (c - opposite sample)
 
-	float4 dc = float4(tex2D(colors, IN.c).w);
+	float depthVals[8];
 
-	float pos_lt = (float)tex2D(colors, IN.lt.xy).w;
-	float pos_rb = (float)tex2D(colors, IN.rb.xy).w;
+	for (int i = 0; i < 8; ++ i)
+	{	
+		depthVals[i] = (float)tex2Dlod(colors, float4(IN.texCoords + offsets[i], 0, 0)).w;
+	}
 
-	float pos_lb = (float)tex2D(colors, IN.lb.xy).w;
-	float pos_rt = (float)tex2D(colors, IN.rt.xy).w;
+	float4 dd; // the gradients
 
-	float pos_l = (float)tex2D(colors, IN.lr.xy).w;
-	float pos_r = (float)tex2D(colors, lrr.xy).w;
+	for (int i = 0; i < 4; ++ i)
+	{
+		dd = float4(depthVals[i * 2] + depthVals[i * 2 + 1]);
+	}
 
-	float pos_t = (float)tex2D(colors, IN.tb.xy).w;
-	float pos_b = (float)tex2D(colors, tbr.xy).w;
+	//dd = abs(2.0f * (1.0f - abs(1.0f - centerDepth / dd))) - barrier.y;
+	dd = abs(2.0f * centerDepth - dd) - barrier.y;
+	dd = step(dd, float4(0.0f));
 
-	float4 dd;
+	const float de = saturate(dot(dd, weights.y));
 
-	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, (float4)0.0f);
+	///////////////////////////
 
-	float de = saturate(dot(dd, e_weights.y));
+	// weight: 0 = no antialiasing, 1 = full antialiasing
+	const float w = (1.0f - de * ne) * kernel.x;
 
-	// weight: 0 = no aa, 1 = full antialiasing
-	float w = (1.0f - de * ne) * e_kernel.x;
+	// smoothed color: the offset is big where discontinuities are
+	// (a - c) * w + c = a * w + c * (1 - w)
+	const float2 width = IN.texCoords * (1.0f - w);
 
-	// smoothed color
-	// (a - c) * w + c = a * w + c * (1 - w)
-	float2 offset = IN.c.xy * (1.0f - w);
+	float4 s0 = tex2Dlod(colors, float4(width + lt * w, 0, 0));
+	float4 s1 = tex2Dlod(colors, float4(width + rb * w, 0, 0));
+	float4 s2 = tex2Dlod(colors, float4(width + rt * w, 0, 0));
+	float4 s3 = tex2Dlod(colors, float4(width + lb * w, 0, 0));
+#endif
 
-	float4 s0 = tex2Dlod(colors, float4(offset + IN.lt.xy * w, 0, 0));
-	float4 s1 = tex2Dlod(colors, float4(offset + IN.rb.xy * w, 0, 0));
-	float4 s2 = tex2Dlod(colors, float4(offset + IN.rt.xy * w, 0, 0));
-	float4 s3 = tex2Dlod(colors, float4(offset + IN.lb.xy * w, 0, 0));
-
-	float4 centerColor = tex2Dlod(colors, float4(IN.c.xy, 0, 0));
-
-	float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f;
-	//return (s0 + s1 + s2 + s3) * 0.25f;
-
-	col.w = centerColor.w;
+	//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 = float4(de.x, de.x, de.x, 0);
+	//float4 col = float4(w, w, w, 0);
+	//float4 col = centerColor;
+	// push through the current depth
+	col.w = centerDepth.x;
 
 	return col;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3135)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3136)
@@ -420,6 +420,6 @@
 	///////////////////
 
-	string aaParams[] = {"colors", "normals"};
-	sCgAntiAliasingProgram->AddParameters(aaParams, 0, 2);
+	string aaParams[] = {"colors", "normals", "offsets"};
+	sCgAntiAliasingProgram->AddParameters(aaParams, 0, 3);
 
 	/////////////////////
@@ -658,5 +658,5 @@
 	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
 	GLuint colorsTex = colorBuffer->GetTexture();
-	GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
 
 	//FrameBufferObject::Release();
@@ -664,23 +664,27 @@
 	// read the second buffer, write to the first buffer
 	FlipFbos(fbo);
-	
+
+	// the neighbouring texels
+	float xOffs = 1.0f / fbo->GetWidth();
+	float yOffs = 1.0f / fbo->GetHeight();
 
 	sCgAntiAliasingProgram->SetTexture(0, colorsTex);
 	sCgAntiAliasingProgram->SetTexture(1, normalsTex);
 
-	sCgAntiAliasingProgram->Bind();
-
-	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();
+	float offsets[16];
+	int i = 0;
+
+	offsets[i] = -xOffs; offsets[i + 1] =  yOffs; i += 2; // left top
+	offsets[i] =  xOffs; offsets[i + 1] = -yOffs; i += 2; // right bottom
+	offsets[i] =  xOffs; offsets[i + 1] =  yOffs; i += 2; // right top
+	offsets[i] = -xOffs; offsets[i + 1] = -yOffs; i += 2; // left bottom
+	offsets[i] = -xOffs; offsets[i + 1] =    .0f; i += 2; // left
+	offsets[i] =  xOffs; offsets[i + 1] =    .0f; i += 2; // right
+	offsets[i] =    .0f; offsets[i + 1] =  yOffs; i += 2; // top
+	offsets[i] =    .0f; offsets[i + 1] = -yOffs; i += 2; // bottom
+
+	sCgAntiAliasingProgram->SetArray2f(2, offsets, 8);
+
+	DrawQuad(sCgAntiAliasingProgram);
 
 	PrintGLerror("antialiasing");
