Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2999)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3000)
@@ -39,5 +39,5 @@
   float4 col: COLOR0;
   //float4 pos: COLOR1;
-  float2 pos: COLOR1;
+  float4 pos: COLOR1;
   float4 norm: COLOR2;
 };
@@ -85,5 +85,6 @@
 			  uniform float3 br,
 			  uniform float3 tl,
-			  uniform float3 tr)
+			  uniform float3 tr
+			  )
 {
 	float4 texColor = tex2D(tex, IN.texCoord.xy);
@@ -97,18 +98,12 @@
 	// hack: use combination of emmisive + diffuse (emmisive used as constant ambient term)
 	pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 
-
-	// save world position in second render target
-	//pix.pos = IN.worldPos * maxDepth;
 	// save world space normal in third rt
 	pix.norm.xyz = IN.normal;
-
 	// store projection coordinates with positions (used for ssao)
 	pix.norm.w = IN.projPos.w;
 
 	const float4 projPos = IN.mypos / IN.mypos.w;
-	// store the projected depth
-	pix.pos.y = projPos.z;
-
-	float2 screenCoord = projPos.xy * 0.5f + 0.5f;
+	
+	const float2 screenCoord = projPos.xy * 0.5f + 0.5f;
 	const float magView = length(Interpol(screenCoord, bl, br, tl, tr));
 
@@ -117,6 +112,11 @@
 
 	// eye linear depth
-	pix.col.w = (length(eyePos - IN.worldPos.xyz) * maxDepth) / magView;
-	pix.pos.x = pix.col.x;
+	pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView;
+
+	// save world position in second render target
+	pix.pos = IN.worldPos * maxDepth;
+	//pix.pos.x = pix.col.w;
+	// store the projected depth
+	pix.pos.w = projPos.z;
 
 	return pix;
@@ -136,5 +136,4 @@
 	// hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
 	pix.col = glstate.material.diffuse + glstate.material.emission;
-	//pix.pos = IN.worldPos * maxDepth;
 
 	pix.norm.xyz = IN.normal;
@@ -144,7 +143,5 @@
 
 	const float4 projPos = IN.mypos / IN.mypos.w;
-	// store the projected depth
-	pix.pos.y = projPos.z;
-
+	
 	float2 screenCoord = projPos.xy * 0.5f + 0.5f;
 	const float magView = length(Interpol(screenCoord, bl, br, tl, tr));
@@ -152,6 +149,10 @@
 	// hack: squeeze some information about the ambient term into the target
 	//pix.col.w = glstate.material.emission.x;
-	pix.col.w = (length(eyePos - IN.worldPos.xyz) * maxDepth) / magView;
-	pix.pos.x = pix.col.x;
+	pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView;
+
+	pix.pos = IN.worldPos * maxDepth;
+	//pix.pos.x = pix.col.w;
+	// store the projected depth
+	pix.pos.w = projPos.z;
 
 	return pix;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2999)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3000)
@@ -173,8 +173,5 @@
 	const float4 centerPosition = tex2D(positions, IN.texCoord.xy);
 
-#if 0	
-	const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
-
-#else
+#if 0
 	/// reconstruct position from the eye space depth
 /*	float3 viewDir = normalize(IN.view);
@@ -185,4 +182,7 @@
 */
 	const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
+#else
+
+	const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
 
 #endif
@@ -217,5 +217,5 @@
 
 	const float oldDepth = oldCol.w;
-	const float oldNumSamples = oldCol.y;
+	//const float oldNumSamples = oldCol.y;
 	const float oldWeight = clamp(oldCol.z, 0, temporalCoherence);
 
@@ -256,6 +256,5 @@
 pixel combine(fragment IN, 
 			  uniform sampler2D colors,
-			  uniform sampler2D ssaoTex,
-			  uniform sampler2D positions)
+			  uniform sampler2D ssaoTex)
 {
 	pixel OUT;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2999)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3000)
@@ -59,5 +59,4 @@
 GiStruct globIllum(fragment IN,
 				   uniform sampler2D colors,
-				   uniform sampler2D positions,
 				   uniform sampler2D noiseTexture,
 				   uniform float2 samples[NUM_SAMPLES],
@@ -109,11 +108,8 @@
 		//float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr));
 		float3 rotView = Interpol(texcoord, bl, br, tl, tr);
+		//float3 rotView = Interpol(texcoord, bl, br, tl, tr);
 		
 		const float3 sample_position = eyePos - rotView * eyeSpaceDepth;
 		const float3 sample_color = sample.xyz;
-
-		// use lower lod level to improve cache coherence
-		//float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;
-		//float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, GI_MIPMAP_LEVEL)).xyz;
 
 		float3 vector_to_sample = sample_position - centerPosition.xyz;
@@ -147,6 +143,5 @@
 
 
-/** The mrt shader for screen space ambient occlusion + indirect illumination
-*/
+
 pixel2 main(fragment IN, 
 		   uniform sampler2D colors,
@@ -181,4 +176,14 @@
 	// the current world position
 	const float4 centerPosition = tex2D(positions, IN.texCoord.xy);
+
+	/// reconstruct position from the eye space depth
+	/*float3 viewDir = normalize(IN.view);
+	const float eyeDepth = tex2D(colors, IN.texCoord.xy).w;
+	
+	float4 centerPosition;
+	centerPosition.xyz = eyePos - viewDir * eyeDepth;
+
+	centerPosition.w = centerPosition2.w;
+*/
 	// the current color
 	const float4 currentCol = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
@@ -186,5 +191,5 @@
 	const float currentDepth = centerPosition.w;
 
-	GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
+	GiStruct gi = globIllum(IN, colors, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
 	
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2998)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3000)
@@ -84,5 +84,4 @@
 static CGparameter sColorsTexCombinedSsaoParam;
 static CGparameter sSsaoTexCombinedSsaoParam;
-static CGparameter sPositionsTexCombinedSsaoParam;
 
 static CGparameter sTLParam;
@@ -436,5 +435,4 @@
 		sColorsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "colors");  
 		sSsaoTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "ssaoTex");
-		sPositionsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "positions");
 	}
 	else
@@ -1058,6 +1056,4 @@
 	cgGLEnableTextureParameter(sSsaoTexCombinedSsaoParam);
 
-	cgGLSetTextureParameter(sPositionsTexCombinedSsaoParam, positionsTex);
-	cgGLEnableTextureParameter(sPositionsTexCombinedSsaoParam);
 	
 	glColor3f(1.0f, 1.0f, 1.0f);
@@ -1076,5 +1072,4 @@
 	cgGLDisableTextureParameter(sColorsTexCombinedSsaoParam);
 	cgGLDisableTextureParameter(sSsaoTexCombinedSsaoParam);
-	cgGLDisableTextureParameter(sPositionsTexCombinedSsaoParam);
 	
 	cgGLDisableProfile(RenderState::sCgFragmentProfile);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 2999)
+++ 	(revision )
@@ -1,343 +1,0 @@
-#include <iostream>
-#include "FrameBufferObject.h"
-#include "glInterface.h"
-
-using namespace std;
-
-
-namespace CHCDemoEngine
-{
-
-
-void PrintFBOStatus(GLenum status)
-{
-	switch(status)
-	{
-	case GL_FRAMEBUFFER_COMPLETE_EXT:
-		//cout << "frame buffer object complete" << endl;
-		break;
-	case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
-		cerr << "incomplete attachment" << endl;
-		break;
-	case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
-		cerr << "missing attachment" << endl;
-		break;
-	case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
-		cerr << "incomplete dimensions" << endl;
-		break;
-	case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
-		cerr << "incomplete formats" << endl;
-		break;
-	case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
-		cerr << "incomplete draw buffer" << endl;
-		break;
-	case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
-		cerr << "incomplete read buffer" << endl;
-		break;
-	case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
-		cerr << "framebuffer unsupported" << endl;
-		break;
-	default:
-		cerr << "unknown status code " << status << endl;
-	}
-}
-
-
-ColorBufferObject::ColorBufferObject(int w, int h, 
-									 int attachment_idx,
-									 FORMAT format, 
-									 WRAP_TYPE wrapType, 
-									 FILTER_TYPE filterType, 
-									 FILTER_TYPE filterTypeMipMap 
-									 )
-{
-	Init(w, h, attachment_idx, format, wrapType, filterType, true, filterTypeMipMap);
-}
-
-
-ColorBufferObject::ColorBufferObject(int w, int h, 
-									 int attachment_idx,
-									 FORMAT format, 
-									 WRAP_TYPE wrapType, 
-									 FILTER_TYPE filterType
-									 )
-{
-	Init(w, h, attachment_idx, format, wrapType, filterType, false, FILTER_NEAREST);
-}
-
-
-ColorBufferObject::~ColorBufferObject()
-{
-	glDeleteRenderbuffersEXT(1, &mId);
-	glDeleteTextures(1, &mTexId);
-}
-
-
-void ColorBufferObject::Init(int w, int h, 
-							 int attachment_idx,
-							 FORMAT format, 
-							 WRAP_TYPE wrapType, 
-							 FILTER_TYPE filterType, 
-							 bool useMipMap, 
-							 FILTER_TYPE filterTypeMipMap
-							 )
-{
-	mWidth = w;
-	mHeight = h;
-
-	int myformat = GL_RGBA;
-
-	switch (format)
-	{
-	case BUFFER_UBYTE:
-		mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; break;
-	case BUFFER_FLOAT_16:
-		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA16F_ARB; break;
-	case BUFFER_FLOAT_32: 
-		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA32F_ARB; break;
-	case BUFFER_LUMINANCE_ALPHA: 
-		mGlFormat = GL_FLOAT; mInternalFormat = GL_LUMINANCE_ALPHA ;
-		myformat = GL_LUMINANCE_ALPHA;
-		break;
-	default:
-		mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8;
-		cerr << "should not come here" << endl;
-	}
-
-
-	glGenRenderbuffersEXT(1, &mId);
-	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mId);
-	
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, mInternalFormat, w, h);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_RENDERBUFFER_EXT, mId);
-
-
-	glGenTextures(1, &mTexId);
-	glBindTexture(GL_TEXTURE_2D, mTexId);
-	glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, myformat, mGlFormat, NULL);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_TEXTURE_2D, mTexId, 0);
-
-	GLuint minfilterParam;
-	GLuint magfilterParam;
-
-	if (filterType == FILTER_NEAREST)
-		magfilterParam = GL_NEAREST;
-	else // FILTER_LINEAR
-		magfilterParam = GL_LINEAR; 
-
-	if (!useMipMap)
-	{
-		if (filterType == FILTER_NEAREST)
-			minfilterParam = GL_NEAREST;
-		else // FILTER_LINEAR
-			minfilterParam = GL_LINEAR;
-	}
-	else
-	{
-		if (filterType == FILTER_NEAREST)
-		{
-			if (filterTypeMipMap == FILTER_NEAREST)
-				minfilterParam = GL_NEAREST_MIPMAP_NEAREST;
-			else // FILTER_LINEAR
-				minfilterParam = GL_NEAREST_MIPMAP_LINEAR;
-		}
-		else // FILTER_LINEAR
-		{
-			if (filterTypeMipMap == FILTER_NEAREST)
-				minfilterParam = GL_LINEAR_MIPMAP_NEAREST;
-			else // FILTER_LINEAR
-				minfilterParam = GL_LINEAR_MIPMAP_LINEAR;
-		}
-	}
-
-	GLuint wrapParam;
-
-	switch (wrapType)
-	{
-	case WRAP_REPEAT:
-		wrapParam = GL_REPEAT; break;
-	case WRAP_CLAMP_TO_EDGE:
-		wrapParam = GL_CLAMP_TO_EDGE; break;
-	}
-
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilterParam);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilterParam);
-
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapParam);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapParam);
-
-	if (useMipMap) 
-	{
-		glGenerateMipmapEXT(GL_TEXTURE_2D);
-	}
-
-	// print status
-	PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
-}
-
-
-
-void *ColorBufferObject::ReadTexture() const
-{
-	int bytes = 0;
-
-	switch (mInternalFormat)
-	{
-	case GL_RGBA8:
-		bytes = 8; break;
-	case GL_RGBA16F_ARB:
-		bytes = 16; break;
-	case GL_RGBA32F_ARB: 
-		bytes = 32; break;
-	default:
-		cerr << "should not come here" << endl;
-	}
-
-	
-	glBindTexture(GL_TEXTURE_2D, mTexId);
-	
-	GLint width, height;
-	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
-	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
-
-	//cout << "w: " << width << "h: " << height << endl;
-
-	unsigned char *data = new unsigned char[bytes * 4 * width * height];
-
-	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, data);
-
-	glBindTexture(GL_TEXTURE_2D, 0);
-	glDisable(GL_TEXTURE_2D);
-
-	float *d = (float *)data;
-
-	return data;
-}
-
-
-/*****************************************************************/
-/*                 FrameBufferObject implementation              */
-/*****************************************************************/
-
-
-FrameBufferObject::FrameBufferObject(int w, int h, DEPTH_FORMAT d, bool useDepthTex)
-: mWidth(w), mHeight(h), mDepthTexId(0)
-{
-	glGenFramebuffersEXT(1, &mId);
-	
-	Bind();
-	///////////
-	//-- create depth buffer
-
-	if (d != DEPTH_NONE)
-	{
-		glGenRenderbuffersEXT(1, &mDepthId);	
-		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mDepthId);
-
-		GLuint depthFormat;
-
-		switch (d)
-		{
-		case DEPTH_16:
-			depthFormat = GL_DEPTH_COMPONENT16; break;
-		case DEPTH_24:
-			depthFormat = GL_DEPTH_COMPONENT24; break;
-		case DEPTH_32: 
-			depthFormat = GL_DEPTH_COMPONENT32; break;
-		default:	
-			cerr << "should not come here" << endl;
-		}
-
-		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, depthFormat, w, h);
-		
-
-		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mDepthId);
-
-		if (useDepthTex)
-		{
-			glGenTextures(1, &mDepthTexId);
-			glBindTexture(GL_TEXTURE_2D, mDepthTexId);
-
-			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_MIN_FILTER, GL_LINEAR);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
-			glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, mWidth, mHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
-
-			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, mDepthTexId, 0);
-		}
-	}
-
-	Release();
-}
-
-
-FrameBufferObject::~FrameBufferObject()
-{
-	glDeleteFramebuffersEXT(1, &mId);
-	glDeleteRenderbuffersEXT(1, &mDepthId);
-
-	if (mDepthTexId) glDeleteTextures(1, &mDepthTexId);
-
-	CLEAR_CONTAINER(mColorBuffers);
-}
-
-
-int FrameBufferObject::AddColorBuffer(ColorBufferObject::FORMAT col, 
-									  ColorBufferObject::WRAP_TYPE wrapType, 
-									  ColorBufferObject::FILTER_TYPE filterType, 
-									  ColorBufferObject::FILTER_TYPE filterTypeMipMap)
-{
-	Bind();
-
-	const int idx = (int)mColorBuffers.size();
-
-	ColorBufferObject *colorBuf = 
-		new ColorBufferObject(mWidth, mHeight, idx, col, wrapType, filterType, filterTypeMipMap);
-
-	mColorBuffers.push_back(colorBuf);
-
-	Release();
-
-	return idx;
-}
-
-
-
-int FrameBufferObject::AddColorBuffer(ColorBufferObject::FORMAT col, 
-									  ColorBufferObject::WRAP_TYPE wrapType, 
-									  ColorBufferObject::FILTER_TYPE filterType)
-{
-	Bind();
-
-	const int idx = (int)mColorBuffers.size();
-
-	ColorBufferObject *colorBuf = 
-		new ColorBufferObject(mWidth, mHeight, idx, col, wrapType, filterType);
-
-	mColorBuffers.push_back(colorBuf);
-
-	Release();
-
-	return idx;
-}
-
-
-void FrameBufferObject::Bind() const
-{
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mId);
-}
-
-
-void FrameBufferObject::Release()
-{
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-}
-
-
-} // namespace
