Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/IrradianceMapping.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/IrradianceMapping.vcproj	(revision 3017)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/IrradianceMapping.vcproj	(revision 3017)
@@ -0,0 +1,203 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8,00"
+	Name="IrradianceMapping"
+	ProjectGUID="{91680C49-A358-48AE-A02C-66CB884B7D7F}"
+	RootNamespace="IrradianceMapping"
+	Keyword="Win32Proj"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="2"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="3"
+				InlineFunctionExpansion="2"
+				FavorSizeOrSpeed="1"
+				OmitFramePointers="true"
+				EnableFiberSafeOptimizations="true"
+				AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;&quot;$(CG_INC_PATH)&quot;"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE; _CRT_SECURE_NO_WARNINGS"
+				RuntimeLibrary="2"
+				EnableEnhancedInstructionSet="2"
+				RuntimeTypeInfo="false"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="DemoEngine.lib glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib cg.lib cgGL.lib"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="&quot;lib/$(ConfigurationName)&quot;;libs;&quot;$(CG_LIB_PATH)&quot;;libs/GL;libs/Devil/lib;libs/Zlib/lib"
+				IgnoreAllDefaultLibraries="false"
+				IgnoreDefaultLibraryNames="LIBCMT"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\src\irradiance.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln	(revision 3012)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln	(revision 3017)
@@ -12,4 +12,7 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrradianceMapping", "IrradianceMapping.vcproj", "{91680C49-A358-48AE-A02C-66CB884B7D7F}"
+	ProjectSection(ProjectDependencies) = postProject
+		{03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023}
+	EndProjectSection
 EndProject
 Global
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 3007)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 3017)
@@ -93,15 +93,13 @@
 	{
 	case RGB_UBYTE: 
-		mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGB8;
-		components = GL_RGB;
-		break;
+		mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGB8; components = GL_RGB; break;
 	case RGBA_UBYTE:
 		mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; break;
+	case RGB_FLOAT_32: 
+		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGB16F_ARB; components = GL_RGB;	break;
 	case RGBA_FLOAT_16:
 		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA16F_ARB; break;
-	case RGB_FLOAT_32: 
-		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGB32F_ARB;
-		components = GL_RGB;
-		break;
+	case RGB_FLOAT_16: 
+		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGB32F_ARB; components = GL_RGB;	break;
 	case RGBA_FLOAT_32: 
 		mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA32F_ARB; break;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3016)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3017)
@@ -10,15 +10,15 @@
 
 // for quadratic falloff
-#define SAMPLE_INTENSITY 0.15f
-//#define SAMPLE_INTENSITY 0.32f
+#define SAMPLE_INTENSITY 0.1f
+//#define SAMPLE_INTENSITY 0.2f
 
-#define AREA_SIZE 8e-1f
+#define SAMPLE_RADIUS 8e-1f
 
 //#define DISTANCE_SCALE 1e-1f
 #define DISTANCE_SCALE 5e-2f
 
-#define ILLUM_INTENSITY 5e-2f
+#define ILLUM_INTENSITY 8e-2f
 
-#define VIEW_CORRECTION_SCALE 0.1f
+#define VIEW_CORRECTION_SCALE 1.0f
 
 
@@ -40,5 +40,5 @@
 #define MAX_LOD_LEVEL 10
 
-#define MIN_DEPTH_DIFF 1e-3f
+#define MIN_DEPTH_DIFF 1e-6f
 // burnout
 #define WHITE_LUMINANCE 3e4f
@@ -46,5 +46,5 @@
 ///////////////////
 
-#define NUM_DOWNSAMPLES 9
+#define NUM_DOWNSAMPLES 16
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg	(revision 3010)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg	(revision 3017)
@@ -64,6 +64,6 @@
 
 		float3 mynoise = (float3)tex2D(noiseTexture, IN.texCoord.xy);
-		const float3 offsetTransformed = myreflect(offset, mynoise) * AREA_SIZE;
-		//const float3 offsetTransformed = offset * AREA_SIZE;
+		const float3 offsetTransformed = myreflect(offset, mynoise) * SAMPLE_RADIUS;
+		//const float3 offsetTransformed = offset * SAMPLE_RADIUS;
 
 		// compute position
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3016)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3017)
@@ -168,8 +168,6 @@
 	// diffuse intensity
 	const float angle = saturate(dot(normal, lightDir)); 
-	//float4 lightDiffuse = float4(1.0f, 1.0f, 0.9f, 1.0f);
 	const float4 lightDiffuse = glstate.light[0].diffuse;
-	//float4(1.0f, 1.0f, 0.9f, 1.0f);
-
+	
 	float4 diffuse = lightDiffuse * angle;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3016)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3017)
@@ -17,5 +17,5 @@
   float4 worldPos: TEXCOORD1; // world position
   float3 normal: TEXCOORD2;
-  float4 mypos: TEXCOORD3;
+  float4 projPos: TEXCOORD3;
 };
 
@@ -28,8 +28,8 @@
 	float4 texCoord: TEXCOORD0;    
 
-	float4 projPos: WPOS;
+	float4 winPos: WPOS;
 	float4 worldPos: TEXCOORD1; // world position
 	float3 normal: TEXCOORD2;
-	float4 mypos: TEXCOORD3;
+	float4 projPos: TEXCOORD3;
 };
 
@@ -38,5 +38,5 @@
 {
 	float4 col: COLOR0;
-	float4 norm: COLOR1;
+	float3 norm: COLOR1;
 	float3 pos: COLOR2;
 };
@@ -59,5 +59,5 @@
 
 	OUT.normal = IN.normal;
-	OUT.mypos = OUT.position;
+	OUT.projPos = OUT.position;
 
 	return OUT;
@@ -75,4 +75,5 @@
 }
 
+//#pragma position_invariant fragtex
 
 pixel fragtex(fragin IN, 
@@ -96,23 +97,19 @@
 	// hack: use combination of emmisive + diffuse (emmisive used as constant ambient term)
 	pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 
-	// 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;
+	// save world space normal in rt
+	pix.norm = IN.normal;
 
-	const float4 projPos = IN.mypos / IN.mypos.w;
-	
 	// hack: squeeze some information about ambient into the texture
 	//pix.col.w = glstate.material.emission.x;
 
 	// compute eye linear depth
-	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) / magView;
-
-#if 0
-	// save world position in second render target
-	pix.pos = IN.worldPos.xyz * maxDepth;
-#endif
+	const float4 projPos = IN.projPos / IN.projPos.w;
+	
+	float2 screenCoord = projPos.xy * 0.5f + 0.5f;
+	
+	const float3 viewVec = Interpol(screenCoord, bl, br, tl, tr);
+	const float invMagView = 1.0f / length(viewVec);
+	// note: has to done in this order, otherwise strange precision problems!
+	pix.col.w = invMagView * length(eyePos - IN.worldPos.xyz);
 
 	return pix;
@@ -132,10 +129,5 @@
 	pix.col = glstate.material.diffuse + glstate.material.emission;
 
-	pix.norm.xyz = IN.normal;
-	
-	// store projection coordinates with positions (used for ssao)
-	pix.norm.w = IN.mypos.w;
-
-	const float4 projPos = IN.mypos / IN.mypos.w;
+	pix.norm = IN.normal;
 
 	// hack: squeeze some information about the ambient term into the target
@@ -143,11 +135,9 @@
 	
 	// compute eye linear depth and scale with lenght to avoid sqr root in pixel shader
+	const float4 projPos = IN.projPos / IN.projPos.w;
+	
 	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)  / magView;
-
-#if 0
-	pix.pos = IN.worldPos.xyz * maxDepth;
-#endif
+	pix.col.w = length(eyePos - IN.worldPos.xyz) / magView;
 
 	return pix;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3016)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3017)
@@ -46,5 +46,7 @@
     return average;
 }*/
-  
+ 
+
+// let bilinear filtering do its work
 float4 DownSample(frag IN,
 				  uniform sampler2D colors,
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3016)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3017)
@@ -11,6 +11,4 @@
 struct fragment
 {
-	 // normalized screen position
-	float4 pos: WPOS;
 	float2 texCoord: TEXCOORD0; 
 	float3 view: TEXCOORD1;
@@ -46,18 +44,12 @@
 
 // reconstruct world space position
-inline float3 ReconstructSamplePosition(
-										uniform sampler2D colors,
-										float2 texcoord, 
-										float3 bl, float3 br, float3 tl, float3 tr)
-{
-#if USE_EYE_SPACE_DEPTH
-	float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w;
-	//float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr));
-	float3 rotView = Interpol(texcoord, bl, br, tl, tr);
-	
-	float3 samplePos = -rotView * eyeSpaceDepth;
-#else
-	float3 samplePos = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;
-#endif
+inline float3 ReconstructSamplePos(uniform sampler2D colors,
+								   float2 texcoord, 
+								   float3 bl, float3 br, float3 tl, float3 tr)
+{
+	const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w;
+	float3 viewVec = Interpol(texcoord, bl, br, tl, tr);
+	float3 samplePos = -viewVec * eyeSpaceDepth;
+
 	return samplePos;
 }
@@ -76,6 +68,6 @@
 		   uniform float3 br,
 		   uniform float3 tl,
-		   uniform float3 tr
-		   //, uniform float3 viewDir
+		   uniform float3 tr, 
+		   uniform float3 viewDir
 		   )
 {
@@ -96,5 +88,5 @@
 		// add random noise: reflect around random normal vector (warning: slow!)
 
-		float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy).xy;
+		float2 mynoise = tex2D(noiseTexture, IN.texCoord).xy;
 		const float2 offsetTransformed = myreflect(offset, mynoise);
 #else
@@ -102,15 +94,15 @@
 #endif
 		// weight with projected coordinate to reach similar kernel size for near and far
-		float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * scaleFactor;
+		float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor;
 
 		//if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f))++ numSamples;
 
-		float3 samplePos = ReconstructSamplePosition(colors, texcoord, bl, br, tl, tr);
-
-
-		///////
-		//-- compute contribution of current sample taking into account direction and angle
-
-		float3 dirSample = samplePos - centerPosition.xyz;
+		const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr);
+
+
+		////////////////
+		//-- compute contribution of sample using the direction and angle
+
+		float3 dirSample = samplePos - centerPosition;
 		const float lengthSample = length(dirSample);
 
@@ -118,19 +110,18 @@
 
 		// angle between current normal and direction to sample controls AO intensity.
-		const float cos_angle = max(dot(nDirSample, currentNormal), 0.0f);
+		const float cosAngle = max(dot(nDirSample, currentNormal), 0.0f);
 
 		// the distance_scale offset is used to avoid singularity that occurs at global illumination when 
 		// the distance to a sample approaches zero
-		const float intensity = 
-			//(SAMPLE_INTENSITY * DISTANCE_SCALE) / (DISTANCE_SCALE + lengthSample * lengthSample);
-			SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthSample * lengthSample);
-
-#if 0
+		const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthSample * lengthSample);
+
+#if 1
 		// if surface normal perpenticular to view dir, approx. half of the samples will not count
 		// => compensate for this (on the other hand, projected sampling area could be larger!)
-		const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal));
-		total_ao += cos_angle * intensity * viewCorrection;
+		const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal);
+		total_ao += cosAngle * intensity * viewCorrection;
+#else
+		total_ao += cosAngle * intensity;
 #endif
-		total_ao += cos_angle * intensity;
 	}
 
@@ -138,4 +129,5 @@
 }
 
+#pragma position_invariant main
 
 /** The mrt shader for screen space ambient occlusion
@@ -143,5 +135,4 @@
 pixel main(fragment IN, 
 		   uniform sampler2D colors,
-		   uniform sampler2D positions,
 		   uniform sampler2D normals,
 		   uniform sampler2D noiseTexture,
@@ -161,45 +152,33 @@
 
 	float4 norm = tex2Dlod(normals, float4(IN.texCoord, 0 ,0));
-	float3 normal = normalize(norm.xyz);
-
-	// the w coordinate from the persp. projection
-	float w = norm.w;
-
-
-#if USE_EYE_SPACE_DEPTH
+	const float3 normal = normalize(norm.xyz);
+
 	/// reconstruct position from the eye space depth
 	float3 viewDir = IN.view;
 	const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w;
-
 	const float3 eyeSpacePos = -viewDir * eyeDepth;
-
-	float3 centerPosition;
-	centerPosition.xyz = eyePos + eyeSpacePos;
-
-	const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr);
-
-#else
-
-	// the current world position
-	const float3 centerPosition = tex2Dlod(positions, float4(IN.texCoord, 0, 0)).xyz;
-
-	const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, bl, br, tl, tr);
-
-#endif
+	const float3 centerPosition = eyePos + eyeSpacePos;
+
+	float4 realPos = float4(centerPosition, 1.0f);
+
+
+	////////////////
+	//-- calculcate the current projected depth for next frame
+	
+	float4 currentPos = mul(modelViewProj, realPos);
+	
+	const float w = SAMPLE_RADIUS / currentPos.w;
+	currentPos /= currentPos.w;
+	
+	const float currentDepth = currentPos.z * 1e-3f;
+
+	const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir));
+
 
 	/////////////////
 	//-- compute temporally smoothing
 
-	float4 realPos = float4(centerPosition, 1.0f);
-
-
-	// calculcate the current projected depth for next frame
-	float4 currentPos = mul(modelViewProj, realPos);
-	currentPos /= currentPos.w;
-	const float currentDepth = currentPos.z;
-	
-
-	///////////
-	//-- reprojection new frame into old one 
+
+	// reproject new frame into old one 
 	
 	// calculate projected depth
@@ -208,18 +187,19 @@
 
 	// the current depth projected into the old frame
-	const float projDepth = projPos.z;
+	const float projDepth = projPos.z * 1e-3f;
 
 	// fit from unit cube into 0 .. 1
-	float2 tex = (projPos.xy) * 0.5f + 0.5f;
+	const float2 tex = projPos.xy * 0.5f + 0.5f;
 
 	// retrieve the sample from the last frame
 	float4 oldCol = tex2D(oldTex, tex);
 
-	const float oldDepth = oldCol.w;
-	const float depthDif = 1.0f - projDepth / oldDepth;
+	const float oldDepth = oldCol.z;
+	//const float depthDif = 1.0f - projDepth / oldDepth;
+	const float depthDif = projDepth - oldDepth;
 
 
 	//const float oldNumSamples = oldCol.y;
-	const float oldWeight = clamp(oldCol.z, 0, temporalCoherence);
+	const float oldWeight = clamp(oldCol.y, 0, temporalCoherence);
 
 	float newWeight;
@@ -227,5 +207,4 @@
 	// the number of valid samples in this frame
 	//const float newNumSamples = ao.y;
-
 
 	if (//(temporalCoherence > 0) &&
@@ -239,17 +218,39 @@
 		// increase the weight for convergence
 		newWeight = oldWeight + 1.0f;
-		OUT.illum_col.xy = (ao.xy + oldCol.xy * oldWeight) / newWeight;
+		OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight;
 		//if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0;
 	}
 	else
 	{	
-		OUT.illum_col.xy = ao.xy;
+		OUT.illum_col.x = ao.x;
 		newWeight = 0;
 	}
 
-	OUT.illum_col.z = newWeight;
-	OUT.illum_col.w = currentDepth;
+	//OUT.illum_col.y=depthDif;
+	OUT.illum_col.y = newWeight;
+	OUT.illum_col.z = currentDepth;
 
 	return OUT;
+}
+
+
+float Filter(float2 texCoord, 
+			 uniform sampler2D ssaoTex,
+			 uniform float2 filterOffs[NUM_DOWNSAMPLES],
+			 uniform float filterWeights[NUM_DOWNSAMPLES]
+)
+{
+	float average = .0f;
+	float w = .0f;
+
+	for (int i = 0; i < NUM_DOWNSAMPLES; ++ i)
+	{
+		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x;
+		w += filterWeights[i];
+	}
+
+	average *= 1.0f / (float)w;
+
+	return average;
 }
 
@@ -257,13 +258,19 @@
 pixel combine(fragment IN, 
 			  uniform sampler2D colors,
-			  uniform sampler2D ssaoTex)
+			  uniform sampler2D ssaoTex,
+			  uniform float2 filterOffs[NUM_DOWNSAMPLES],
+			  uniform float filterWeights[NUM_DOWNSAMPLES]
+			  )
 {
 	pixel OUT;
 
 	float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0));
-	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
+	float3 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
+
+	if (ao.y < 2000.0f)
+		ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
 
 	OUT.illum_col = col * ao.x;
-	//OUT.illum_col = float4(ao.x,ao.x,ao.x, ao.w);
+	//OUT.illum_col.xyz = float3(ao.x,1-ao.y*1e-2f, 0);
 	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 3016)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3017)
@@ -8,6 +8,4 @@
 struct fragment
 {
-	 // normalized screen position
-	float4 pos: WPOS;
 	float2 texCoord: TEXCOORD0; 
 	float3 view: TEXCOORD1;
@@ -68,5 +66,5 @@
 				   uniform float3 tl,
 				   uniform float3 tr
-				   //, uniform float3 viewDir
+				   , uniform float3 viewDir
 				   )
 {
@@ -98,5 +96,5 @@
 #endif
 		// weight with projected coordinate to reach similar kernel size for near and far
-		float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w;
+		float2 texcoord = IN.texCoord.xy + offsetTransformed * w;
 
 		//if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples;
@@ -115,4 +113,6 @@
 		const float3 sample_color = sample.xyz;
 
+		// distance between current position and sample position controls AO intensity.
+
 		float3 vector_to_sample = sample_position - centerPosition.xyz;
 		const float length_to_sample = length(vector_to_sample);
@@ -124,17 +124,18 @@
 
 		const float denom = (DISTANCE_SCALE + length_to_sample * length_to_sample);
-		// distance between current position and sample position controls AO intensity.
+
 		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
-#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
+		// if normal perpenticular to view dir, only the samples approx count half
+#if 1
+		const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal);
+	
+		total_ao += cos_angle * ssao_intensity * view_correction;
+		total_color += cos_angle * illum_intensity * sample_color * view_correction;
+#else
 		total_ao += cos_angle * ssao_intensity;
 		total_color += cos_angle * illum_intensity * sample_color;
+#endif
 	}
 
@@ -170,8 +171,5 @@
 	float3 normal = normalize(norm.xyz);	
 
-	// the w coordinate from the persp. projection
-	float w = norm.w;
-
-
+	
 	/////////////
 	//-- reconstruct position from the eye space depth
@@ -182,12 +180,17 @@
 	const float3 eyeSpacePos = -viewDir * eyeDepth;
 
-	float3 centerPosition = eyePos + eyeSpacePos;
-	//const float3 centerPosition = tex2D(positions, IN.texCoord.xy).xyz;
-
+	const float3 centerPosition = eyePos + eyeSpacePos;
+	const float4 realPos = float4(centerPosition, 1.0f);
+
+	// calculcate the current projected depth for next frame
+	float4 currentPos = mul(modelViewProj, realPos);
+	const float w = SAMPLE_RADIUS / currentPos.w;
+	currentPos /= currentPos.w;
+	const float currentDepth = currentPos.z * 1e-3f;
 
 	///////////
 	//-- compute color bleeding + ao
 
-	GiStruct gi = globIllum(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr);
+	GiStruct gi = globIllum(IN, colors, noiseTexture, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view));
 	
 
@@ -195,16 +198,6 @@
 	//-- compute temporally smoothing
 
-	float4 realPos = float4(centerPosition, 1.0f);
-
-
-	// calculcate the current projected depth for next frame
-	float4 currentPos = mul(modelViewProj, realPos);
-	currentPos /= currentPos.w;
-	const float currentDepth = currentPos.z;
-	
-
-	///////////
-	//-- reprojection new frame into old one 
-	
+	
+	// reprojection new frame into old one 
 	// calculate projected depth
 	float4 projPos = mul(oldModelViewProj, realPos);
@@ -212,8 +205,8 @@
 
 	// the current depth projected into the old frame
-	const float projDepth = projPos.z;
+	const float projDepth = projPos.z * 1e-3f;
 
 	// fit from unit cube into 0 .. 1
-	float2 tex = (projPos.xy) * 0.5f + 0.5f;
+	float2 tex = projPos.xy * 0.5f + 0.5f;
 
 	// retrieve the sample from the last frame
@@ -221,14 +214,14 @@
 	float4 oldIllum = tex2D(oldIllumTex, tex);
 
-	const float oldDepth = oldSsao.w;
-	const float depthDif = 1.0f - projDepth / oldDepth;
-
-	float oldWeight = clamp(oldSsao.z, 0, temporalCoherence);
+	const float oldDepth = oldSsao.z;
+	//const float depthDif = 1.0f - projDepth / oldDepth;
+	const float depthDif = projDepth - oldDepth;
+
+	float oldWeight = clamp(oldSsao.y, 0, temporalCoherence);
 
 	float newWeight;
 
 	//const float oldNumSamples = oldSsao.y;
-	//const float oldAvgDepth = oldSsao.z;
-
+	
 	if (//(temporalCoherence > 0.0f) &&
 		(tex.x >= 0.0f) && (tex.x < 1.0f) && 
@@ -241,5 +234,5 @@
 		newWeight = oldWeight + 1;
 
-		OUT.ssao_col.xy = (gi.ao + oldSsao.xy * oldWeight) / newWeight;
+		OUT.ssao_col.x = (gi.ao + oldSsao.x * oldWeight) / newWeight;
 		OUT.illum_col.xyz  = (gi.illum + oldIllum.xyz * oldWeight) / newWeight;
 	}
@@ -248,10 +241,10 @@
 		newWeight = 0;
 
-		OUT.ssao_col.xy = gi.ao.xy;
+		OUT.ssao_col.x = gi.ao.x;
 		OUT.illum_col.xyz = gi.illum;
 	}
 
-	OUT.ssao_col.z = newWeight;
-	OUT.ssao_col.w = currentDepth;
+	OUT.ssao_col.y = newWeight;
+	OUT.ssao_col.z = currentDepth;
 
 	return OUT;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2983)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3017)
@@ -343,4 +343,10 @@
 		diffuse = color * 3e-1f;
 
+	// diffuse component should be more saturated (and less blueish) for high sun positions
+	diffuse.x *= 1.2f;
+	diffuse.z *= 0.8f;
+
+	// scale diffuse component in order to make sky look less bright in relation to
+	// the geometry in the evening
 	diffuse *= (2.0f - 1.0f * DotProd(sunDir, Vector3::UNIT_Z()));
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3016)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3017)
@@ -616,5 +616,5 @@
 	fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST);
 	// the normals buffer
-	fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
+	fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
 	// the positions buffer
 	//fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
@@ -947,8 +947,10 @@
 	cgGLSetParameter3f(sTRParam, tr.x, tr.y, tr.z);
 
+	//cout<<bl << " " << br << endl;
 	cgGLSetParameter3f(sBLParamTex, bl.x, bl.y, bl.z);
 	cgGLSetParameter3f(sBRParamTex, br.x, br.y, br.z);
 	cgGLSetParameter3f(sTLParamTex, tl.x, tl.y, tl.z);
 	cgGLSetParameter3f(sTRParamTex, tr.x, tr.y, tr.z);
+
 
 	// draw to 3 color buffers
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3016)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3017)
@@ -53,5 +53,6 @@
 
 static CGparameter sDownSampleOffsetParam;
-
+static CGparameter sFilterOffsetsParam;
+static CGparameter sFilterWeightsParam;
 
 static CGprogram sCgDownSampleProgram;
@@ -65,5 +66,4 @@
 
 static CGparameter sColorsTexParam;
-static CGparameter sPositionsTexParam;
 static CGparameter sNormalsTexParam;
 
@@ -175,5 +175,34 @@
 }
 
-
+static void ComputeSampleOffsets(float *sampleOffsets, int w, int h)
+{
+	/*
+	const float xoffs = 0.5f / w;
+	const float yoffs = 0.5f / h;
+
+	sampleOffsets[0] =  xoffs; sampleOffsets[1] =  yoffs;
+	sampleOffsets[2] =  xoffs; sampleOffsets[3] = -yoffs;
+	sampleOffsets[4] = -xoffs; sampleOffsets[5] = -yoffs;
+	sampleOffsets[6] = -xoffs; sampleOffsets[7] =  yoffs;
+	*/
+	//const float xoffs = .5f / w;
+	//const float yoffs = .5f / h;
+	
+	const float xoffs = 1.0f / w;
+	const float yoffs = 1.0f / h;
+
+	int idx  = 0;
+
+	for (int x = -1; x <= 1; ++ x)
+	{
+		for (int y = -1; y <= 1; ++ y)
+		{
+			sampleOffsets[idx + 0] = x * xoffs;
+			sampleOffsets[idx + 1] = y * yoffs;
+
+			idx += 2;
+		}
+	}
+}
 
 /** Generate poisson disc distributed sample points on the unit disc
@@ -284,14 +313,15 @@
 
 	mFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE);
-
-	mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-	mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-	mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-	mFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	//mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE);
+
+	mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
 
 	mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE);
+
 	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+	mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
 }
 
@@ -361,5 +391,4 @@
 		cgGLLoadProgram(sCgSsaoProgram);
 
-		sPositionsTexParam = cgGetNamedParameter(sCgSsaoProgram, "positions");  
 		sColorsTexParam = cgGetNamedParameter(sCgSsaoProgram, "colors");  
 		sEyePosParam = cgGetNamedParameter(sCgSsaoProgram, "eyePos");
@@ -452,4 +481,7 @@
 		sColorsTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "colors");  
 		sSsaoTexCombinedSsaoParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "ssaoTex");
+
+		sFilterOffsetsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterOffs");
+		sFilterWeightsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterWeights");
 	}
 	else
@@ -622,5 +654,4 @@
 		DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0);
 		DownSample(fbo, 1, mDownSampleFbo, 1);
-		DownSample(fbo, 2, mDownSampleFbo, 2);
 
 		ComputeSsao(fbo, tempCohFactor, oldProjViewMatrix, projViewMatrix);
@@ -690,9 +721,7 @@
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-	GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();
 #else
 	GLuint colorsTex = mDownSampleFbo->GetColorBuffer(0)->GetTexture();
 	GLuint normalsTex = mDownSampleFbo->GetColorBuffer(1)->GetTexture();
-	GLuint positionsTex = mDownSampleFbo->GetColorBuffer(2)->GetTexture();
 #endif
 
@@ -708,7 +737,4 @@
 	
 	cgGLBindProgram(sCgSsaoProgram);
-
-	cgGLSetTextureParameter(sPositionsTexParam, positionsTex);
-	cgGLEnableTextureParameter(sPositionsTexParam);
 
 	cgGLSetTextureParameter(sColorsTexParam, colorsTex);
@@ -764,8 +790,9 @@
 	glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs,  offs, -0.5f);
 
+	//cout<<bl << " " << br << endl;
+
 	glEnd();
 
 	cgGLDisableTextureParameter(sColorsTexParam);
-	cgGLDisableTextureParameter(sPositionsTexParam);
 	cgGLDisableTextureParameter(sNormalsTexParam);
 	cgGLDisableTextureParameter(sNoiseTexParam);
@@ -1040,4 +1067,13 @@
 
 
+static float GaussianDistribution(float x, float y, float rho)
+{
+    float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho);
+    g *= expf( -(x*x + y*y) / (2.0f * rho * rho));
+
+    return g;
+}
+
+
 void DeferredRenderer::CombineSsao(FrameBufferObject *fbo)
 {
@@ -1054,4 +1090,28 @@
 
 	cgGLBindProgram(sCgCombinedSsaoProgram);
+
+	float filterOffsets[NUM_DOWNSAMPLES * 2];
+	float filterWeights[NUM_DOWNSAMPLES];
+
+	PoissonDiscSampleGenerator2 poisson(NUM_DOWNSAMPLES, 1.0f);
+	poisson.Generate((float *)filterOffsets);
+
+	const float xoffs = 2.0f / fbo->GetWidth();
+	const float yoffs = 2.0f / fbo->GetHeight();
+
+	for (int i = 0; i < NUM_DOWNSAMPLES; ++ i)
+	{
+		float x = filterOffsets[2 * i + 0];
+		float y = filterOffsets[2 * i + 1];
+
+		filterOffsets[2 * i + 0] *= xoffs;
+		filterOffsets[2 * i + 1] *= yoffs;
+
+		filterWeights[i] = GaussianDistribution(x, y, 1.0f);
+	}
+
+	//ComputeSampleOffsets(filterOffsets, fbo->GetWidth(), fbo->GetHeight());
+	cgGLSetParameterArray2f(sFilterOffsetsParam, 0, NUM_DOWNSAMPLES, (const float *)filterOffsets);
+	cgGLSetParameterArray1f(sFilterWeightsParam, 0, NUM_DOWNSAMPLES, (const float *)filterWeights);
 
 	cgGLSetTextureParameter(sColorsTexCombinedSsaoParam, colorsTex);
@@ -1187,11 +1247,9 @@
 
 	const float minKey = 0.09f;
-	const float maxKey = 0.5f;
+	const float maxKey = 0.45f;
 
 	const float lightIntensity = DotProd(-light->GetDirection(), Vector3::UNIT_Z());
 	middleGrey = lightIntensity * maxKey + (1.0f - lightIntensity) * minKey;
 
-
-#if 1
 
 	//////////
@@ -1226,5 +1284,4 @@
 	PrintGLerror("ToneMapParams");
 
-#endif
 
 	///////////////////
@@ -1265,45 +1322,8 @@
 
 
-static void ComputeDownsSampleOffsets(float *downSampleOffsets, int w, int h)
-{
-	/*
-	float downSampleOffsets[8];
-
-	const float xoffs = 0.5f / w;
-	const float yoffs = 0.5f / h;
-
-	downSampleOffsets[0] =  xoffs; downSampleOffsets[1] =  yoffs;
-	downSampleOffsets[2] =  xoffs; downSampleOffsets[3] = -yoffs;
-	downSampleOffsets[4] = -xoffs; downSampleOffsets[5] = -yoffs;
-	downSampleOffsets[6] = -xoffs; downSampleOffsets[7] =  yoffs;
-	*/
-	//const float xoffs = .5f / w;
-	//const float yoffs = .5f / h;
-	
-	const float xoffs = 1.0f / w;
-	const float yoffs = 1.0f / h;
-
-	int idx  = 0;
-
-	for (int x = -1; x <= 1; ++ x)
-	{
-		for (int y = -1; y <= 1; ++ y)
-		{
-			downSampleOffsets[idx + 0] = x * xoffs;
-			downSampleOffsets[idx + 1] = y * yoffs;
-
-			idx += 2;
-		}
-	}
-}
-
-
 void DeferredRenderer::DownSample(FrameBufferObject *fbo, int bufferIdx,
 								  FrameBufferObject *downSampleFbo, 
 								  int downSampleBufferIdx)
 {
-	float downSampleOffsets[NUM_DOWNSAMPLES * 2];
-	ComputeDownsSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight());
-
 	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(bufferIdx);
 	GLuint colorsTex = colorBuffer->GetTexture();
@@ -1316,4 +1336,7 @@
 	cgGLSetTextureParameter(sColorsTexDownSampleParam, colorsTex);
 	cgGLEnableTextureParameter(sColorsTexDownSampleParam);
+
+	float downSampleOffsets[NUM_DOWNSAMPLES * 2];
+	ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight());
 
 	cgGLSetParameterArray2f(sDownSampleOffsetParam, 0, NUM_DOWNSAMPLES, (const float *)downSampleOffsets);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h	(revision 3007)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h	(revision 3017)
@@ -15,5 +15,6 @@
 public:
 
-	enum FORMAT { RGB_UBYTE, RGBA_UBYTE, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32};
+	enum FORMAT { RGB_UBYTE, RGBA_UBYTE, RGB_FLOAT_16, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32 };
+
 	enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE };
 	enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR };
