Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp	(revision 2800)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp	(revision 2817)
@@ -107,4 +107,5 @@
 Texture::~Texture()
 {
+	glDeleteTextures(1, &mTexId);
 	free(mImage);
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2816)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2817)
@@ -146,5 +146,5 @@
 
 static Vector3 samples[32];
-
+GLubyte *randomNormals;
 
 // function forward declarations
@@ -527,6 +527,6 @@
 	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);
+	glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA32F_ARB, texWidth, texHeight);
 	
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, positionsBuffer);
@@ -535,12 +535,12 @@
 	glBindTexture(GL_TEXTURE_2D, positionsTex);
 	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
+	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, positionsTex, 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);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+	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));
@@ -559,9 +559,9 @@
 	glBindTexture(GL_TEXTURE_2D, normalsTex);
 	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
+	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalsTex, 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_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -1452,4 +1452,15 @@
 	if (sCgContext)
 		cgDestroyContext(sCgContext);
+
+	glDeleteFramebuffersEXT(1, &fbo);
+	glDeleteRenderbuffersEXT(1, &depthBuffer);
+	glDeleteRenderbuffersEXT(1, &colorsBuffer);
+	glDeleteRenderbuffersEXT(1, &normalsBuffer);
+	glDeleteRenderbuffersEXT(1, &positionsBuffer);
+
+	glDeleteTextures(1, &colorsTex);
+	glDeleteTextures(1, &normalsTex);
+	glDeleteTextures(1, &positionsTex);
+	glDeleteTextures(1, &noiseTex);
 }
 
@@ -1629,5 +1640,8 @@
 	glLoadIdentity();
 
-	glOrtho(-0.5f, 0.5f, -0.5f, 0.5f, 0, 1);
+	const float offs = 0.5f;
+	//glPushAttrib(GL_VIEWPORT_BIT);
+	//glViewport(-offs, texHeight);
+	glOrtho(-offs, offs, -offs, offs, 0, 1);
 	
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -1655,8 +1669,12 @@
 	glBegin(GL_QUADS);
 #if 1
-	glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
-	glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f);
-	glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( 1,  1, -0.5f);
-	glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-1,  1, -0.5f);
+	// slightly larger than screen size in order to hide ambient occlusion errors
+	float offs2 = 0.55f;
+	//float offs2 = 0.5f;
+
+	glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f);
+	glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f);
+	glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f);
+	glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f);
 #else
 	glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
@@ -1727,49 +1745,12 @@
 	tl = tl * 0.5f + 0.5f;
 	tr = tr * 0.5f + 0.5f;
-
-/*
-	cout << "tl: " << tl << endl;
-	cout << "tr: " << tr << endl;
-	cout << "bl: " << bl << endl;
-	cout << "br: " << bl << endl << endl;
-	*/
-}
-
-
-void CreateNoiseTex3D()
-{
-	Vector3 *data = new Vector3[texWidth * texHeight];
-
-	for (int i = 0; i < texWidth * texHeight; ++ i)
-	{
-		// create random samples over sphere
-		const float rx = RandomValue(0, 1);
-		const float ry = RandomValue(0, 1);
-
-		const float theta = 2.0f * acos(sqrt(1.0f - rx));
-		const float phi = 2.0f * M_PI * ry;
-
-		data[i] = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
-		// bring in 0 .. 1 so we can use unsigned byte
-		data[i] = data[i] * 0.5f + 0.5f;
-	}
-
-	glGenTextures(1, &noiseTex);
-	glBindTexture(GL_TEXTURE_2D, noiseTex);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,  texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
-	glBindTexture(GL_TEXTURE_2D, 0);
-
-	PrintGLerror("noisetexture");
-}
-
-#if 0
+}
+
+
 void CreateNoiseTex2D()
 {
-	Vector3 *data = new Vector3[texWidth * texHeight];
-
-	for (int i = 0; i < texWidth * texHeight; ++ i)
+	randomNormals = new GLubyte[texWidth * texHeight * 4];
+
+	for (int i = 0; i < texWidth * texHeight * 4; i += 4)
 	{
 		// create random samples over sphere
@@ -1777,44 +1758,8 @@
 		const float theta = 2.0f * acos(sqrt(1.0f - rx));
 
-		data[i] = Vector3(sin(theta), cos(theta), 0);
-
-		//if (i % 10000) cout << "vec: " << data[i] << endl;
-	
-		// bring in 0 .. 1 so we could use unsigned byte
-		data[i] = 1;//data[i] * 0.5f + 0.5f;
-	}
-
-	glGenTextures(1, &noiseTex);
-	glBindTexture(GL_TEXTURE_2D, noiseTex);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, texWidth, texHeight, 0, GL_RGB, GL_FLOAT, (float *)data);
-	
-	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_REPEAT);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
-	glBindTexture(GL_TEXTURE_2D, 0);
-
-	PrintGLerror("noisetexture");
-}
-
-#else
-void CreateNoiseTex2D()
-{
-	GLubyte *data = new GLubyte[texWidth * texHeight * 4];
-
-	for (int i = 0; i < texWidth * texHeight * 4; i += 4)
-	{
-		// create random samples over sphere
-		const float rx = RandomValue(0, 1);
-		const float theta = 2.0f * acos(sqrt(1.0f - rx));
-
-		data[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f);
-		data[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f);
-		data[i + 2] = 0;
-		data[i + 3] = 255;
-
-		//if (i % 100000) cout << "vec: " << " " << (int)data[i] << " " << (int)data[i + 1] << endl;
+		randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f);
+		randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f);
+		randomNormals[i + 2] = 0;
+		randomNormals[i + 3] = 255;
 	}
 
@@ -1822,16 +1767,13 @@
 	glGenTextures(1, &noiseTex);
 	glBindTexture(GL_TEXTURE_2D, noiseTex);
-	//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
 
-	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, data);
-	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, randomNormals);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
 	glBindTexture(GL_TEXTURE_2D, 0);
-
 	glDisable(GL_TEXTURE_2D);
 
@@ -1839,3 +1781,2 @@
 	PrintGLerror("noisetexture");
 }
-#endif
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2816)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2817)
@@ -79,6 +79,6 @@
 
   //const float areaSize = 5e-1f;
-  const float areaSize = 2e-1f;
-  const float sampleIntensity = 0.1f;
+  const float areaSize = 3e-1f;
+  const float sampleIntensity = 0.2f;
   
   for (int i = 0; i < SAMPLES; i ++) {
@@ -130,5 +130,5 @@
   pixel OUT;
 
-  float4 lightDir = float4(0.8f, 1.0f, 1.5f, 0.0f);
+  float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f);
   float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f);
   
@@ -145,5 +145,5 @@
   // float3 L = normalize(lightPosition - position);
   float3 light = normalize(lightDir.xyz);
-  float3 light2 = normalize(lightDir.xyz);
+  float3 light2 = normalize(lightDir2.xyz);
 
   float diffuseLight = max(dot(normal, light), 0.0f);
@@ -155,10 +155,10 @@
   //OUT.color = ao; 
   OUT.color = ao * (ambient + diffuse) * color;
+//OUT.color = (ambient + diffuse) * color;
 
   //float4 currentPos = tex2D(normals, IN.texCoord.xy) * 0.5f + 0.5f;
-  //float4 currentPos = tex2D(positions, IN.texCoord.xy);
-  //OUT.color = currentPos.w;
-  
-    
+  //float4 currentPos = tex2D(normals, IN.texCoord.xy);
+  //OUT.color = currentPos;
+      
   return OUT;
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2811)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2817)
@@ -175,13 +175,4 @@
 	}
 
-	for (int i = 0; i < vertexCount; i += 3)
-	{
-		Triangle3 tri(vertices[i], vertices[i + 1], vertices[i + 2]);
-		Vector3 n = tri.GetNormal();
-		normals[i + 0] = n;
-		normals[i + 1] = n;
-		normals[i + 2] = n;
-	}
-
 	return new Geometry(vertices, normals, texcoords, vertexCount, true);
 }
