Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3015)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3016)
@@ -10,13 +10,13 @@
 
 // for quadratic falloff
-#define SAMPLE_INTENSITY 0.35f
+#define SAMPLE_INTENSITY 0.15f
 //#define SAMPLE_INTENSITY 0.32f
 
 #define AREA_SIZE 8e-1f
 
-#define DISTANCE_SCALE 1e-1f
-//#define DISTANCE_SCALE 1e-6f
+//#define DISTANCE_SCALE 1e-1f
+#define DISTANCE_SCALE 5e-2f
 
-#define ILLUM_INTENSITY 5e-1f;
+#define ILLUM_INTENSITY 5e-2f
 
 #define VIEW_CORRECTION_SCALE 0.1f
@@ -40,5 +40,5 @@
 #define MAX_LOD_LEVEL 10
 
-#define MIN_DEPTH_DIFF 1e-1f
+#define MIN_DEPTH_DIFF 1e-3f
 // burnout
 #define WHITE_LUMINANCE 3e4f
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3014)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3016)
@@ -140,5 +140,4 @@
 				  uniform sampler2D shadowMap,
 				  uniform float4x4 shadowMatrix,
-				  uniform float maxDepth,
 				  uniform float sampleWidth,
 				  uniform sampler2D noiseTexture,
@@ -183,5 +182,4 @@
 		)
 	{
-		position *= maxDepth;
 		position.w = 1.0f;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3009)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3016)
@@ -78,5 +78,4 @@
 pixel fragtex(fragin IN, 
 			  uniform sampler2D dirtTex,
-			  uniform float maxDepth,
 			  uniform sampler2D tex,
 			  uniform float3 eyePos,
@@ -110,5 +109,5 @@
 	const float2 screenCoord = projPos.xy * 0.5f + 0.5f;
 	const float magView = length(Interpol(screenCoord, bl, br, tl, tr));
-	pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView;
+	pix.col.w = length(eyePos - IN.worldPos.xyz) / magView;
 
 #if 0
@@ -122,5 +121,4 @@
 
 pixel frag(fragin IN, 
-		   uniform float maxDepth, 
 		   uniform float3 eyePos,
 		   uniform float3 bl,
@@ -147,5 +145,5 @@
 	float2 screenCoord = projPos.xy * 0.5f + 0.5f;
 	const float magView = length(Interpol(screenCoord, bl, br, tl, tr));
-	pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView;
+	pix.col.w = length(eyePos - IN.worldPos.xyz)  / magView;
 
 #if 0
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3014)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3016)
@@ -51,6 +51,6 @@
 				  uniform float2 downSampleOffs[NUM_DOWNSAMPLES]): COLOR
 {    
-	//return tex2Dlod(colors, float4(IN.texCoord, 0, 0));
-
+	return tex2Dlod(colors, float4(IN.texCoord, 0, 0));
+/*
     float4 average = .0f;
 
@@ -62,5 +62,5 @@
 	average *= 1.0f / (float)NUM_DOWNSAMPLES;
 
-    return average;
+    return average;*/
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3014)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3016)
@@ -150,5 +150,4 @@
 		   const uniform float4x4 oldModelViewProj,
 		   const uniform float4x4 modelViewProj,
-		   uniform float maxDepth,
 		   uniform float temporalCoherence,
 		   uniform float3 eyePos,
@@ -176,7 +175,8 @@
 
 	float3 centerPosition;
-	centerPosition.xyz = eyePos - viewDir * eyeDepth;
+	centerPosition.xyz = eyePos + eyeSpacePos;
 
 	const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr);
+
 #else
 
@@ -191,5 +191,5 @@
 	//-- compute temporally smoothing
 
-	float4 realPos = float4(centerPosition * maxDepth, 1.0f);
+	float4 realPos = float4(centerPosition, 1.0f);
 
 
@@ -264,6 +264,6 @@
 	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-	//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 3014)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3016)
@@ -10,5 +10,5 @@
 	 // normalized screen position
 	float4 pos: WPOS;
-	float4 texCoord: TEXCOORD0; 
+	float2 texCoord: TEXCOORD0; 
 	float3 view: TEXCOORD1;
 };
@@ -123,7 +123,9 @@
 		float cos_angle = max(dot(direction_to_sample, currentNormal), 0);
 
+		const float denom = (DISTANCE_SCALE + length_to_sample * length_to_sample);
 		// distance between current position and sample position controls AO intensity.
-		const float distance_intensity = 
-			(SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + length_to_sample * length_to_sample);
+		const float ssao_intensity = SAMPLE_INTENSITY / denom;
+
+		const float illum_intensity = ILLUM_INTENSITY / denom;
 
 		// if normal perpenticular to view dir, only half of the samples count
@@ -133,6 +135,6 @@
 		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;
+		total_ao += cos_angle * ssao_intensity;
+		total_color += cos_angle * illum_intensity * sample_color;
 	}
 
@@ -148,5 +150,4 @@
 pixel2 main(fragment IN, 
 		   uniform sampler2D colors,
-		   uniform sampler2D positions,
 		   uniform sampler2D normals,
 		   uniform sampler2D noiseTexture,
@@ -156,5 +157,4 @@
 		   const uniform float4x4 oldModelViewProj,
 		   const uniform float4x4 modelViewProj,
-		   uniform float maxDepth,
 		   uniform float temporalCoherence,
 		   uniform float3 eyePos,
@@ -167,5 +167,5 @@
 	pixel2 OUT;
 
-	float4 norm = tex2D(normals, IN.texCoord.xy);
+	float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0));
 	float3 normal = normalize(norm.xyz);	
 
@@ -178,11 +178,9 @@
 
 	float3 viewDir = IN.view;
-	const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)).w;
+	const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w;
 	
 	const float3 eyeSpacePos = -viewDir * eyeDepth;
 
-	float3 centerPosition;
-	centerPosition.xyz = eyePos - viewDir * eyeDepth;
-	
+	float3 centerPosition = eyePos + eyeSpacePos;
 	//const float3 centerPosition = tex2D(positions, IN.texCoord.xy).xyz;
 
@@ -197,5 +195,5 @@
 	//-- compute temporally smoothing
 
-	float4 realPos = float4(centerPosition * maxDepth, 1.0f);
+	float4 realPos = float4(centerPosition, 1.0f);
 
 
@@ -269,8 +267,8 @@
 	pixel OUT;
 
-	float4 col = tex2D(colors, IN.texCoord.xy);
-	float ao = tex2D(ssaoTex, IN.texCoord.xy).x;
-	float4 illum = tex2D(illumTex, IN.texCoord.xy);
-	
+	float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0));
+	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)).x;
+	float4 illum = tex2Dlod(illumTex, float4(IN.texCoord, 0, 0));
+
 	OUT.illum_col = (col + illum) * ao;
 	OUT.illum_col.w = col.w;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3007)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3016)
@@ -103,7 +103,4 @@
 	int mHeight;
 
-	/// a scale factor of scene positions in order to get better float precision in the shader
-	float mScaleFactor;
-
 	Camera *mCamera;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3015)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3016)
@@ -24,6 +24,4 @@
 #include "RenderQueue.h"
 #include "Material.h"
-#include <Cg/cg.h>
-#include <Cg/cgGL.h>
 #include "glfont2.h"
 #include "PerformanceGraph.h"
@@ -42,4 +40,6 @@
 #include "EntityMerger.h"
 
+#include <Cg/cg.h>
+#include <Cg/cgGL.h>
 
 
@@ -98,4 +98,5 @@
 SkyPreetham *preetham = NULL;
 
+
 /// the used render type for this render pass
 enum RenderMethod
@@ -269,6 +270,4 @@
 static CGprogram sCgMrtVertexProgram = NULL;
 
-static CGparameter sMaxDepthParam;
-static CGparameter sMaxDepthParamTex;
 static CGparameter sEyePosParamTex;
 static CGparameter sEyePosParam;
@@ -565,13 +564,7 @@
 		cgGLLoadProgram(RenderState::sCgMrtFragmentTexProgram);
 
-		sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth");
 		sEyePosParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "eyePos");
 		RenderState::sTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tex");
 	
-		//const float maxDepth = MAX_DEPTH_CONST / farDist;
-		const float maxDepth = 1.0f;
-
-		cgGLSetParameter1f(sMaxDepthParamTex, maxDepth);
-
 		sTLParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tl"); 
 		sTRParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tr"); 
@@ -594,12 +587,6 @@
 		cgGLLoadProgram(RenderState::sCgMrtFragmentProgram);
 
-		sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth");
 		sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "eyePos");
 		
-		//const float maxDepth = MAX_DEPTH_CONST / farDist;
-		const float maxDepth = 1.0f;
-
-		cgGLSetParameter1f(sMaxDepthParam, maxDepth);
-
 		sTLParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "tl"); 
 		sTRParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "tr"); 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3015)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3016)
@@ -70,5 +70,4 @@
 static CGparameter sOldModelViewProjMatrixParam;
 static CGparameter sModelViewProjMatrixParam;
-static CGparameter sMaxDepthParam;
 static CGparameter sEyePosParam;
 static CGparameter sEyePosShadowParam;
@@ -83,5 +82,4 @@
 
 static CGparameter sColorsTexGiParam;
-static CGparameter sPositionsTexGiParam;
 static CGparameter sNormalsTexGiParam;
 
@@ -89,5 +87,4 @@
 static CGparameter sOldModelViewProjMatrixGiParam;
 static CGparameter sModelViewProjMatrixGiParam;
-static CGparameter sMaxDepthGiParam;
 static CGparameter sSamplesGiParam; 
 static CGparameter sOldSsaoTexGiParam;
@@ -131,5 +128,4 @@
 
 static CGparameter sShadowMatrixParam;
-static CGparameter sMaxDepthShadowParam;
 static CGparameter sSampleWidthParam;
 
@@ -274,5 +270,4 @@
 mWidth(w), mHeight(h), 
 mCamera(cam),
-mScaleFactor(scaleFactor),
 mUseTemporalCoherence(true),
 mRegenerateSamples(true),
@@ -374,5 +369,4 @@
 		sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj");
 		sModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "modelViewProj");
-		sMaxDepthParam = cgGetNamedParameter(sCgSsaoProgram, "maxDepth");
 		sTemporalCoherenceParam = cgGetNamedParameter(sCgSsaoProgram, "temporalCoherence");
 
@@ -401,5 +395,4 @@
 
 		// we need size of texture for scaling
-		sPositionsTexGiParam = cgGetNamedParameter(sCgGiProgram, "positions");  
 		sColorsTexGiParam = cgGetNamedParameter(sCgGiProgram, "colors");  
 		sNormalsTexGiParam = cgGetNamedParameter(sCgGiProgram, "normals");  
@@ -407,5 +400,4 @@
 		sOldModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "oldModelViewProj");
 		sModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "modelViewProj");
-		sMaxDepthGiParam = cgGetNamedParameter(sCgGiProgram, "maxDepth");
 		sTemporalCoherenceGiParam = cgGetNamedParameter(sCgGiProgram, "temporalCoherence");
 
@@ -501,5 +493,4 @@
 
 		sShadowMapParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMap");  
-		sMaxDepthShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "maxDepth");
 		sSampleWidthParam = cgGetNamedParameter(sCgDeferredShadowProgram, "sampleWidth");
 		sShadowMatrixParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMatrix");
@@ -696,5 +687,5 @@
 
 	cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x);
-#if 1
+#if 0
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
@@ -733,7 +724,5 @@
 	cgGLEnableTextureParameter(sOldTexParam);
 	
-	cgGLSetParameter1f(sMaxDepthParam, mScaleFactor);
-
-	Vector3 pos = mCamera->GetPosition() / mScaleFactor;
+	Vector3 pos = mCamera->GetPosition();
 	cgGLSetParameter3f(sEyePosParam, pos.x, pos.y, pos.z);
 	
@@ -913,8 +902,11 @@
 	cgGLSetMatrixParameterfc(sModelViewProjMatrixGiParam, (const float *)projViewMatrix.x);
 
-	//GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+#if 0
+	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
+#else
 	GLuint colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture();
 	GLuint normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture();
-	GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();
+#endif
 
 	glPushAttrib(GL_VIEWPORT_BIT);
@@ -931,6 +923,4 @@
 	cgGLBindProgram(sCgGiProgram);
 
-	cgGLSetTextureParameter(sPositionsTexGiParam, positionsTex);
-	cgGLEnableTextureParameter(sPositionsTexGiParam);
 
 	cgGLSetTextureParameter(sColorsTexGiParam, colorsTex);
@@ -948,6 +938,4 @@
 	cgGLSetTextureParameter(sOldIllumTexGiParam, oldIllumTex);
 	cgGLEnableTextureParameter(sOldIllumTexGiParam);
-
-	cgGLSetParameter1f(sMaxDepthGiParam, mScaleFactor);
 
 
@@ -964,9 +952,5 @@
 		GenerateSamples(mSamplingMethod); 
 
-#ifdef USE_3D_SSAO
-		cgGLSetParameterArray3f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples3);
-#else
 		cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples2);
-#endif
 	}
 
@@ -975,5 +959,5 @@
 	ComputeViewVectors(tl, tr, bl, br);
 	
-	const Vector3 pos = mCamera->GetPosition() / mScaleFactor;
+	const Vector3 pos = mCamera->GetPosition();
 	cgGLSetParameter3f(sEyePosGiParam, pos.x, pos.y, pos.z);
 
@@ -997,5 +981,4 @@
 
 	cgGLDisableTextureParameter(sColorsTexGiParam);
-	cgGLDisableTextureParameter(sPositionsTexGiParam);
 	cgGLDisableTextureParameter(sNormalsTexGiParam);
 	cgGLDisableTextureParameter(sNoiseTexGiParam);
@@ -1132,6 +1115,4 @@
 	cgGLEnableTextureParameter(sShadowMapParam);
 
-	cgGLSetParameter1f(sMaxDepthShadowParam, mScaleFactor);
-
 	cgGLSetParameter1f(sSampleWidthParam, 2.0f / shadowMap->GetSize());
 	
@@ -1148,5 +1129,5 @@
 	ComputeViewVectors(tl, tr, bl, br);
 	
-	const Vector3 pos = mCamera->GetPosition() / mScaleFactor;
+	const Vector3 pos = mCamera->GetPosition();
 	cgGLSetParameter3f(sEyePosShadowParam, pos.x, pos.y, pos.z);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3010)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3016)
@@ -515,8 +515,4 @@
 				</File>
 				<File
-					RelativePath=".\src\shaderenv.h"
-					>
-				</File>
-				<File
 					RelativePath=".\src\ShadowMapping.h"
 					>
@@ -769,4 +765,8 @@
 			<File
 				RelativePath=".\src\shaders\mrt.cg"
+				>
+			</File>
+			<File
+				RelativePath=".\src\shaderenv.h"
 				>
 			</File>
