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;
-}
