Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 2819)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 2822)
@@ -75,4 +75,7 @@
 	static CGparameter sDiffuseTexParam;
 
+	static CGparameter sAmbientParam;
+	static CGparameter sAmbientTexParam;
+
 protected:
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2819)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2822)
@@ -11,4 +11,7 @@
 CGparameter Material::sDiffuseParam;
 CGparameter Material::sDiffuseTexParam;
+CGparameter Material::sAmbientParam;
+CGparameter Material::sAmbientTexParam;
+
 
 RgbaColor RandomColor(float a, float b)
@@ -65,9 +68,23 @@
 	{
 		mTexture->Bind();
+
+		cgGLSetParameter4f(sAmbientTexParam, 
+						   mEmmisiveColor.r, 
+						   mEmmisiveColor.g, 
+						   mEmmisiveColor.b, 
+						   mEmmisiveColor.a);
+
 		cgGLSetParameter4f(sDiffuseTexParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a);
 	}
 	else
 	{
+		cgGLSetParameter4f(sAmbientParam, 
+						   mEmmisiveColor.r, 
+						   mEmmisiveColor.g, 
+						   mEmmisiveColor.b, 
+						   mEmmisiveColor.a);
+
 		cgGLSetParameter4f(sDiffuseParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a);
+		
 		glBindTexture(GL_TEXTURE_2D, 0);
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2821)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2822)
@@ -67,5 +67,5 @@
 int renderMode = RenderTraverser::CHCPLUSPLUS;
 // eye near plane distance
-float nearDist = 1.0f; 
+float nearDist = 0.2f; 
 /// the pixel threshold where a node is still considered invisible
 int threshold;
@@ -152,5 +152,5 @@
 
 
-#define NUM_SAMPLES 8
+#define NUM_SAMPLES 12
 
 static float samples[NUM_SAMPLES * 2];
@@ -429,4 +429,5 @@
 		sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth");
 		Material::sDiffuseTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "diffuse");
+		Material::sAmbientTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "ambient");
 
 		cgGLSetParameter1f(sMaxDepthParamTex, 10.0f / myfar);
@@ -449,4 +450,5 @@
 		sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth");
 		Material::sDiffuseParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "diffuse");
+		Material::sAmbientParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "ambient");
 
 		cgGLSetParameter1f(sMaxDepthParam, 10.0f / myfar);
@@ -555,37 +557,39 @@
 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
 
+	
+	////////////
+	//-- colors buffer
+
+	glGenRenderbuffersEXT(1, &colorsBuffer);
+	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer);
+	
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, texWidth, texHeight);
+	int samples = 8;
+	//glEnable(GL_MULTISAMPLE_ARB);
+	//glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA8, texWidth, texHeight);
+	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer);
+	
+	glGenTextures(1, &colorsTex);
+	glBindTexture(GL_TEXTURE_2D, colorsTex);
+
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+	glGenerateMipmapEXT(GL_TEXTURE_2D);
+	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0);
+
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+
 	//////////
 	//-- positions buffer
-
-	int samples = 8;
-
-	////////////
-	//-- colors buffer
-
-	glGenRenderbuffersEXT(1, &colorsBuffer);
-	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer);
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
-	
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer);
-	
-	glGenTextures(1, &colorsTex);
-	glBindTexture(GL_TEXTURE_2D, colorsTex);
-
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0);
-
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
 	PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
 	glGenRenderbuffersEXT(1, &positionsBuffer);
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, positionsBuffer);
-	//glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
-	glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA32F_ARB, texWidth, texHeight);
-	
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
+
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, positionsBuffer);
 
@@ -610,5 +614,5 @@
 	glGenRenderbuffersEXT(1, &normalsBuffer);
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, normalsBuffer);
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, texWidth, texHeight);
 	
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_RENDERBUFFER_EXT, normalsBuffer);
@@ -616,5 +620,5 @@
 	glGenTextures(1, &normalsTex);
 	glBindTexture(GL_TEXTURE_2D, normalsTex);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
 	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalsTex, 0);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2821)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2822)
@@ -1,6 +1,6 @@
-#define NUM_SAMPLES 8
-#define SAMPLE_INTENSITY 0.5f
-//#define SAMPLE_INTENSITY 0.2f
-#define AREA_SIZE 3e-1f
+#define NUM_SAMPLES 12
+//#define SAMPLE_INTENSITY 0.4f
+#define SAMPLE_INTENSITY 0.7f
+#define AREA_SIZE 5e-1f
 
 // kustls magic sample positions
@@ -72,7 +72,7 @@
 float ssao(fragment IN,
 	   uniform sampler2D positions,
-	   uniform sampler2D normals,
 	   uniform sampler2D noiseTexture,
-	   uniform float2 samples[NUM_SAMPLES]
+	   uniform float2 samples[NUM_SAMPLES],
+	   uniform float3 currentNormal
 	   )
 {
@@ -82,8 +82,4 @@
   float w = centerPosition.w;
 
-  // the normal on the current position
-  float3 centerNormal = tex2D(normals, IN.texCoord.xy).xyz;
-  //normalize(centerNormal);
-  
   // Check in a circular area around the current position.
   // Shoot vectors to the positions there, and check the angle to these positions.
@@ -120,12 +116,13 @@
     
     // Angle between current normal and direction to sample controls AO intensity.
-    float cos_angle = dot(direction_to_sample, centerNormal);
+    float cos_angle = dot(direction_to_sample, currentNormal);
     cos_angle = max(cos_angle, 0.0f);
     
     // distance between current position and sample position controls AO intensity.
+    //const float maxdist = 2e-1f;
     const float maxdist = 5e-1f;
-    //const float scale = 50.0f;
-
+    
     float distance_intensity = maxdist - length_to_sample;
+    //float distance_intensity = 0.5f / (1.0f + length_to_sample * length_to_sample);
     distance_intensity = max(distance_intensity, 0.0f);
     // quadratic influence
@@ -142,5 +139,6 @@
 	     uniform sampler2D colors,
 	     uniform sampler2D positions,
-	     uniform sampler2D normals)
+	     uniform float3 normal,
+	     uniform float amb)
 {
   float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f);
@@ -148,12 +146,8 @@
   
   float4 color = tex2D(colors, IN.texCoord.xy);
-  float3 normal = tex2D(normals, IN.texCoord.xy).xyz;
-
-  // expand normal
-  normal = normalize(normal * 2.0f - 1.0f);
-
+ 
   float4 position = tex2D(positions, IN.texCoord.xy);
 
-  float4 ambient = float4(0.3f);
+  float4 ambient = 0.3f;
 
   // float3 L = normalize(lightPosition - position);
@@ -166,5 +160,5 @@
   float diffuse = diffuseLight + diffuseLight2;
 
-  return (ambient + diffuse) * color;
+  return (ambient + diffuse) * color * (1.0f - amb) + amb * color;
 }
 
@@ -179,10 +173,16 @@
   pixel OUT;
 
-  float4 col = shade(IN, colors, positions, normals);
-  float ao = ssao(IN, positions, normals, noiseTexture, samples);
+  float4 normal = tex2D(normals, IN.texCoord.xy);
+  float amb = normal.w;
+
+  // expand normal
+  normal = normalize(normal * 2.0f - 1.0f);
+
+  float4 col = shade(IN, colors, positions, normal, amb);
+  float ao = ssao(IN, positions, noiseTexture, samples, normal);
   
   //OUT.color = tex2D(positions, IN.texCoord.xy);
   //OUT.color = ao;
-  //OUT.color =  col;
+  //OUT.color = col;
   OUT.color = ao * col;
 
@@ -197,6 +197,12 @@
 {
   pixel OUT;
-
-  float4 col = shade(IN, colors, positions, normals);
+  
+  float4 normal = tex2D(normals, IN.texCoord.xy);
+  float amb = normal.w;
+
+  // expand normal
+  normal = normalize(normal * 2.0f - 1.0f);
+  
+  float4 col = shade(IN, colors, positions, normal.xyz, amb);
   OUT.color = col;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2821)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2822)
@@ -37,5 +37,5 @@
   float4 col: COLOR0;
   float4 pos: COLOR1;
-  float3 norm: COLOR2;
+  float4 norm: COLOR2;
 };
 
@@ -62,11 +62,18 @@
 
 
-pixel fragtex(fragin IN, uniform sampler2D tex, uniform float maxDepth, uniform float4 diffuse)
+pixel fragtex(fragin IN, 
+	      uniform sampler2D tex, 
+	      uniform float maxDepth, 
+	      uniform float4 ambient, 
+	      uniform float4 diffuse)
 {
   pixel pix;
       
-  pix.col = diffuse * tex2D(tex, IN.texCoord.xy);
+  pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy);
   pix.pos = IN.worldPos * maxDepth;
-  pix.norm = IN.normal;
+  pix.norm.xyz = IN.normal * 0.5f + 0.5f;
+  // 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;
 
@@ -75,5 +82,8 @@
 
 
-pixel frag(fragin IN, uniform float maxDepth, uniform float4 diffuse)
+pixel frag(fragin IN, 
+	   uniform float maxDepth, 
+	   uniform float4 ambient, 
+	   uniform float4 diffuse)
 {
   pixel pix;
@@ -81,5 +91,7 @@
   pix.col = diffuse;
   pix.pos = IN.worldPos * maxDepth;
-  pix.norm = IN.normal;
+  pix.norm.xyz = IN.normal * 0.5f + 0.5f;
+  // hack: squeeze some information about ambient into the texture
+  pix.norm.w = ambient.x;
   pix.pos.w = IN.projPos.w;
 
