Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2988)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2990)
@@ -82,6 +82,4 @@
 	
 	OUT.color = col;
-
-	OUT.color.xyz = color.w;
 	
 #if 1
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2989)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2990)
@@ -21,5 +21,5 @@
 
 
-float2 myreflect(float2 pt, float2 n)
+inline float2 myreflect(float2 pt, float2 n)
 {
 	// distance to plane
@@ -32,29 +32,5 @@
 
 
-float3 RotateY(float3 v, float a)
-{
-	float3 r;
-
-	r.z = v.z * cos(a) - v.x * sin(a);
-	r.x = v.z * sin(a) + v.x * cos(a);
-	r.y = v.y;
-
-	return r;
-}
-
-
-float3 RotateX(float3 v, float a)
-{
-	float3 r;
-
-	r.y = v.y * cos(a) - v.z * sin(a);
-	r.z = v.y * sin(a) + v.z * cos(a);
-	r.x = v.x;
-
-	return r;
-}
-
-
-float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)
+inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)
 {
 	//float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f);
@@ -68,13 +44,15 @@
 
 
-float2 Interpol2(float2 w, float2 bl, float2 br, float2 tl, float2 tr)
-{
-	//float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f);
-	float2 x1 = lerp(bl, tl, w.y); //bl * (1.0f - w.x) + br * w.x;
-	float2 x2 = lerp(br, tr, w.y); //tl * (1.0f - w.x) + tr * w.x;
-
-	float2 v = lerp(x1, x2, w.x); //x1 * (1.0f - w.y) + x2 * w.y;
-
-	return v;
+inline float3 ReconstructSamplePosition(uniform sampler2D colors, float2 texcoord, float3 bl, float3 br, float3 tl, float3 tr)
+{
+	/*float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w;
+		
+	// reconstruct world space position
+	float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr));
+	float3 sample_position = eyePos - rotView * eyeSpaceDepth;
+	*/
+	float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;
+
+	return sample_position;
 }
 
@@ -89,5 +67,5 @@
 		   uniform float4 centerPosition,
 		   uniform float scaleFactor,
-		   uniform float3 viewDir,
+		   //uniform float3 viewDir,
 		   uniform float3 eyePos,
 		   uniform float3 bl,
@@ -124,12 +102,5 @@
 			++ numSamples;
 
-		// sample downsampled texture in order to speed up texture accesses
-		float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w;
-		
-		// reconstruct world space position
-		float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr));
-		float3 sample_position = eyePos - rotView * eyeSpaceDepth;
-
-		//float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;
+		float3 sample_position = ReconstructSamplePosition(colors, texcoord, bl, br, tl, tr);
 
 		float3 vector_to_sample = sample_position - centerPosition.xyz;
@@ -190,8 +161,9 @@
 	// the current world position
 	const float4 centerPosition = tex2D(positions, IN.texCoord.xy);
+	
+	/*
 	/// the current view direction
 	float3 viewDir = normalize(IN.view);
-
-	/*const float eyeDepth = tex2D(colors, IN.texCoord.xy).w;
+	const float eyeDepth = tex2D(colors, IN.texCoord.xy).w;
 	float4 centerPosition2;
 	centerPosition2.xyz = eyePos - view2 * eyeDepth;
@@ -202,5 +174,5 @@
 
 	//const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, viewDir, eyePos);
-	const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition, w, viewDir, eyePos, bl, br, tl, tr);
+	const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, /*viewDir, */eyePos, bl, br, tl, tr);
 		
 
@@ -271,6 +243,6 @@
 	float4 ao = tex2D(ssaoTex, IN.texCoord.xy);
 
-	//OUT.illum_col = col * ao.x;
-	OUT.illum_col = float4(ao.x,ao.x,ao.x, ao.w);
+	OUT.illum_col = col * ao.x;
+	//OUT.illum_col = float4(ao.x,ao.x,ao.x, ao.w);
 	OUT.illum_col.w = col.w;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2976)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2990)
@@ -44,16 +44,33 @@
 
 
+float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)
+{
+	//float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f);
+	float3 x1 = lerp(bl, tl, w.y); //bl * (1.0f - w.x) + br * w.x;
+	float3 x2 = lerp(br, tr, w.y); //tl * (1.0f - w.x) + tr * w.x;
+
+	float3 v = lerp(x1, x2, w.x); //x1 * (1.0f - w.y) + x2 * w.y;
+
+	return v;
+}
+
+
 /** Computes  diffuse reflections + ambient occlusion
 */
 GiStruct globIllum(fragment IN,
-				 uniform sampler2D colors,
-				 uniform sampler2D positions,
-				 uniform sampler2D noiseTexture,
-				 uniform float2 samples[NUM_SAMPLES],
-				 uniform float3 currentNormal,
-				 uniform float4 centerPosition,
-				 float w
-				 //, uniform float3 currentViewDir
-				 )
+				   uniform sampler2D colors,
+				   uniform sampler2D positions,
+				   uniform sampler2D noiseTexture,
+				   uniform float2 samples[NUM_SAMPLES],
+				   uniform float3 currentNormal,
+				   uniform float4 centerPosition,
+				   float w,
+				   // uniform float3 viewDir,
+				   uniform float3 eyePos,
+				   uniform float3 bl,
+				   uniform float3 br,
+				   uniform float3 tl,
+				   uniform float3 tr
+				   )
 {
 	GiStruct gi;
@@ -89,7 +106,15 @@
 			++ numSamples;
 
+		// reconstruct world space position from sample
+		float4 sample = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL));
+		const float eyeSpaceDepth = sample.w;
+		float3 rotView = normalize(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 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;
@@ -106,9 +131,9 @@
 
 		// if normal perpenticular to view dir, only half of the samples count
-		/*
+#if 0
 		const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal));
 		total_color.w -= cos_angle * distance_intensity * view_correction;
 		total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY;
-		*/
+#endif
 		total_ao += cos_angle * distance_intensity;
 		total_color += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY;
@@ -135,5 +160,10 @@
 		   const uniform float4x4 oldModelViewProj,
 		   uniform float maxDepth,
-		   uniform float temporalCoherence
+		   uniform float temporalCoherence,
+		   uniform float3 eyePos,
+		   uniform float3 bl,
+		   uniform float3 br,
+		   uniform float3 tl,
+		   uniform float3 tr
 		   )
 {
@@ -144,4 +174,5 @@
 	// something like a constant ambient term
 	const float amb = norm.w;
+	
 	/// the current view direction
 	//float3 viewDir = normalize(IN.view);
@@ -156,5 +187,5 @@
 	const float currentDepth = centerPosition.w;
 
-	GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w); //, viewDir);
+	GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr);
 	
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2989)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2990)
@@ -525,5 +525,5 @@
 
 
-	const float turbitiy = 9.0f;
+	const float turbitiy = 5.0f;
 	preetham = new SkyPreetham(turbitiy, skyDome);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2988)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2990)
@@ -89,4 +89,14 @@
 static CGparameter sBRParam;
 static CGparameter sBLParam;
+
+
+static CGparameter sTLGiParam;
+static CGparameter sTRGiParam;
+static CGparameter sBRGiParam;
+static CGparameter sBLGiParam;
+
+static CGparameter sEyePosGiParam;
+
+
 
 ////////////
@@ -390,5 +400,12 @@
 		
 		sOldSsaoTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldSsaoTex");  
-		sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex");  
+		sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex"); 
+
+		sTLGiParam = cgGetNamedParameter(sCgGiProgram, "tl"); 
+		sTRGiParam = cgGetNamedParameter(sCgGiProgram, "tr"); 
+		sBRGiParam = cgGetNamedParameter(sCgGiProgram, "br"); 
+		sBLGiParam = cgGetNamedParameter(sCgGiProgram, "bl"); 
+
+		sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos");
 	}
 	else
@@ -477,7 +494,5 @@
 		sNoiseTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "noiseTexture");
 		sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples");
-
 		sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir");
-
 		sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors");
 
@@ -576,4 +591,7 @@
 	else
 		FirstPass(fbo, light);
+
+	glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture());
+	glGenerateMipmapEXT(GL_TEXTURE_2D);
 
 	switch (mShadingMethod)
@@ -921,4 +939,5 @@
 	cgGLSetParameter1f(sMaxDepthGiParam, mScaleFactor);
 
+
 	cgGLSetParameter1f(sTemporalCoherenceGiParam, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0);
 
@@ -943,4 +962,13 @@
 	Vector3 tl, tr, bl, br;
 	ComputeViewVectors(tl, tr, bl, br);
+	
+	const Vector3 pos = mCamera->GetPosition() / mScaleFactor;
+	cgGLSetParameter3f(sEyePosGiParam, pos.x, pos.y, pos.z);
+
+	cgGLSetParameter3f(sBLGiParam, bl.x, bl.y, bl.z);
+	cgGLSetParameter3f(sBRGiParam, br.x, br.y, br.z);
+	cgGLSetParameter3f(sTLGiParam, tl.x, tl.y, tl.z);
+	cgGLSetParameter3f(sTRGiParam, tr.x, tr.y, tr.z);
+
 
 	glBegin(GL_QUADS);
