Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln	(revision 3017)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln	(revision 3019)
@@ -7,9 +7,4 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MainApp", "MainApp.vcproj", "{A564071F-D054-4556-883B-999D7F9CC58C}"
-	ProjectSection(ProjectDependencies) = postProject
-		{03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023}
-	EndProjectSection
-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}
@@ -34,8 +29,4 @@
 		{A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.ActiveCfg = Release|Win32
 		{A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.Build.0 = Release|Win32
-		{91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.ActiveCfg = Debug|Win32
-		{91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.Build.0 = Debug|Win32
-		{91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.ActiveCfg = Release|Win32
-		{91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj	(revision 3012)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj	(revision 3019)
@@ -41,5 +41,6 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;&quot;$(CG_INC_PATH)&quot;"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SET"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
@@ -61,5 +62,8 @@
 			<Tool
 				Name="VCLinkerTool"
+				AdditionalDependencies="DemoEngine.lib glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib cg.lib cgGL.lib"
+				OutputFile="$(OutDir)\FriendlyCulling.exe"
 				LinkIncremental="2"
+				AdditionalLibraryDirectories="&quot;lib/$(ConfigurationName)&quot;;libs;&quot;$(CG_LIB_PATH)&quot;;libs/GL;libs/Devil/lib;libs/Zlib/lib"
 				GenerateDebugInformation="true"
 				SubSystem="1"
@@ -122,5 +126,5 @@
 				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"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
 				RuntimeLibrary="2"
 				EnableEnhancedInstructionSet="2"
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3017)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3019)
@@ -48,5 +48,6 @@
 								   float3 bl, float3 br, float3 tl, float3 tr)
 {
-	const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w;
+	//const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w;
+	const float eyeSpaceDepth = tex2D(colors, texcoord).w;
 	float3 viewVec = Interpol(texcoord, bl, br, tl, tr);
 	float3 samplePos = -viewVec * eyeSpaceDepth;
@@ -94,7 +95,7 @@
 #endif
 		// weight with projected coordinate to reach similar kernel size for near and far
-		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;
+		const 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;
 
 		const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr);
@@ -105,14 +106,14 @@
 
 		float3 dirSample = samplePos - centerPosition;
-		const float lengthSample = length(dirSample);
-
-		float3 nDirSample = dirSample / lengthSample;
+		const float magSample = length(dirSample);
+		// normalize
+		dirSample /= magSample;
 
 		// angle between current normal and direction to sample controls AO intensity.
-		const float cosAngle = max(dot(nDirSample, currentNormal), 0.0f);
+		const float cosAngle = max(dot(dirSample, 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 + lengthSample * lengthSample);
+		const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + magSample * magSample);
 
 #if 1
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3017)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 3019)
@@ -85,5 +85,5 @@
 	for (int i = 0; i < NUM_SAMPLES; i ++) 
 	{
-		float2 offset = samples[i];
+		const float2 offset = samples[i];
 
 #if 1
@@ -104,37 +104,37 @@
 		//-- reconstruct world space position from sample
 
-		const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0));
+		//const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0));
+		const float4 sample = tex2D(colors, texcoord);
 
 		const float eyeSpaceDepth = sample.w;
-		//float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr));
 		float3 rotView = Interpol(texcoord, bl, br, tl, tr);
 		
-		const float3 sample_position = - rotView * eyeSpaceDepth;
-		const float3 sample_color = sample.xyz;
+		const float3 samplePos = - rotView * eyeSpaceDepth;
+		const float3 sampleCol = 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);
-
-		float3 direction_to_sample = vector_to_sample / length_to_sample;
+		float3 dirSample = samplePos - centerPosition.xyz;
+		const float magSample = length(dirSample);
+		// normalize
+		dirSample /= magSample;
 
 		// use angle between current normal and direction to sample controls AO intensity.
-		float cos_angle = max(dot(direction_to_sample, currentNormal), 0);
-
-		const float denom = (DISTANCE_SCALE + length_to_sample * length_to_sample);
-
-		const float ssao_intensity = SAMPLE_INTENSITY / denom;
-		const float illum_intensity = ILLUM_INTENSITY / denom;
+		float cosAngle = max(dot(dirSample, currentNormal), 0);
+
+		const float denom = (DISTANCE_SCALE + magSample * magSample);
+
+		float2 intensity = float2(SAMPLE_INTENSITY, ILLUM_INTENSITY);
+		intensity /= denom;
 
 		// 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;
+		const float viewCorrect = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal);
+	
+		total_ao += cosAngle * intensity.x * viewCorrect;
+		total_color += cosAngle * intensity.y * sampleCol * viewCorrect;
 #else
-		total_ao += cos_angle * ssao_intensity;
-		total_color += cos_angle * illum_intensity * sample_color;
+		total_ao += cos_angle * intensity.x;
+		total_color += cos_angle * intensity.y * sampleCol;
 #endif
 	}
@@ -143,5 +143,4 @@
 	gi.ao = float2(max(0.0f, 1.0f - total_ao), numSamples);
 
-	//return saturate(total_color);
 	return gi;
 }
@@ -211,6 +210,6 @@
 
 	// retrieve the sample from the last frame
-	float4 oldSsao = tex2D(oldSsaoTex, tex);
-	float4 oldIllum = tex2D(oldIllumTex, tex);
+	float3 oldSsao = tex2D(oldSsaoTex, tex);
+	float3 oldIllum = tex2D(oldIllumTex, tex);
 
 	const float oldDepth = oldSsao.z;
@@ -218,6 +217,6 @@
 	const float depthDif = projDepth - oldDepth;
 
-	float oldWeight = clamp(oldSsao.y, 0, temporalCoherence);
-
+	// the weights that indicate the state of convergence
+	const float oldWeight = clamp(oldSsao.y, .0f, temporalCoherence);
 	float newWeight;
 
@@ -234,6 +233,11 @@
 		newWeight = oldWeight + 1;
 
-		OUT.ssao_col.x = (gi.ao + oldSsao.x * oldWeight) / newWeight;
-		OUT.illum_col.xyz  = (gi.illum + oldIllum.xyz * oldWeight) / newWeight;
+		float4 tmp = float4(gi.ao.x, gi.illum);
+		float4 oldTmp = float4(oldSsao.x, oldIllum);
+
+		float4 interpol = (tmp + oldTmp * oldWeight) / newWeight;
+
+		OUT.ssao_col.x = interpol.x;
+		OUT.illum_col.xyz = interpol.yzw;
 	}
 	else
@@ -261,8 +265,11 @@
 
 	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;
+	float ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)).x;
+
+	float3 illum = tex2Dlod(illumTex, float4(IN.texCoord, 0, 0)).xyz;
+
+	OUT.illum_col.xyz = (col.xyz + illum) * ao;
+	//OUT.illum_col.xyz = col.xyz * ao;
+
 	OUT.illum_col.w = col.w;
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2982)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3019)
@@ -29,4 +29,5 @@
 	CLEAR_CONTAINER(mTrafos);
 	CLEAR_CONTAINER(mShapes);
+	CLEAR_CONTAINER(mLODs);
 }
 
@@ -73,5 +74,4 @@
 		str.read(reinterpret_cast<char *>(&numShapes), sizeof(int));
 
-		
 		LODLevel *lodLevel = new LODLevel(dist);
 
@@ -93,4 +93,5 @@
 		}
 
+		mLODs.push_back(lodLevel);
 		sceneGeom->AddLODLevel(lodLevel);
 	}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3016)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3019)
@@ -19,4 +19,19 @@
 class DirectionalLight;
 
+
+class ShaderProgram
+{
+public:
+
+	ShaderProgram(CGprogram program): mProgram(program) {}
+
+	~ShaderProgram() { cgDestroyProgram(mProgram); }
+
+	CGprogram mProgram;
+};
+
+
+typedef  std::vector<ShaderProgram *> ShaderContainer;
+typedef  std::vector<FrameBufferObject *> FBOContainer;
 
 /** This class implements a deferred shading algorithm that takes
@@ -108,5 +123,4 @@
 
 	int mSamplingMethod;
-	int mFboIndex;
 
 	int mShadingMethod;
@@ -114,8 +128,13 @@
 	bool mRegenerateSamples;
 
-	// the main fbo we are working with
-	FrameBufferObject *mFbo;
+	int mIllumFboIndex;
+	// the fbo for indirect illumination (ssao + color bleeding)
+	FrameBufferObject *mIllumFbo;
 
 	FrameBufferObject *mDownSampleFbo;
+
+	FBOContainer mFBOs;
+
+	static ShaderContainer sShaders;
 };
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 2981)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 3019)
@@ -9,4 +9,6 @@
 #include "common.h"
 
+
+#define _CRTDBG_MAP_ALLOC
 
 class igzstream;
@@ -60,4 +62,5 @@
 	ShapeContainer mShapes;
 
+	LODContainer mLODs;
 
 	////////
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.cpp	(revision 2784)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.cpp	(revision 3019)
@@ -276,14 +276,4 @@
 }
 
-char *
-strdup(char *a)
-{
-	if (a) {
-		char *s = new char[strlen(a)+1];
-		strcpy(s, a);
-		return s;
-	} else
-		return NULL;
-}
 
 bool
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 3011)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 3019)
@@ -160,4 +160,7 @@
 	DEL_PTR(mFbo);
 	DEL_PTR(mShadowCam);
+
+	DEL_PTR(lightPoly);
+	DEL_PTR(polyhedron);
 }
 
@@ -649,8 +652,6 @@
 	glDisable(GL_DEPTH_TEST);
 
-	//glLineWidth(2);
 	Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox);
 	DrawPoly(hpoly, Vector3(1, 1, 1));
-
 	DEL_PTR(hpoly);
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3018)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3019)
@@ -1,8 +1,28 @@
 // chcdemo.cpp : Defines the entry point for the console application.
 //
-#include "glInterface.h"
+
+#ifdef _CRT_SET
+	#define _CRTDBG_MAP_ALLOC
+	#include <stdlib.h>
+	#include <crtdbg.h>
+#endif
+
+#include "common.h"
+
+#ifdef _CRT_SET
+	// redefine new operator
+	#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
+	#define new DEBUG_NEW
+#endif
+
+
 #include <math.h>
 #include <time.h>
-#include "common.h"
+#include "glInterface.h"
+
+#include <Cg/cg.h>
+#include <Cg/cgGL.h>
+
+
 #include "RenderTraverser.h"
 #include "SceneEntity.h"
@@ -40,8 +60,4 @@
 #include "EntityMerger.h"
 
-#include <Cg/cg.h>
-#include <Cg/cgGL.h>
-
-
 using namespace std;
 using namespace CHCDemoEngine;
@@ -59,5 +75,4 @@
 /// the renderable scene geometry
 SceneEntityContainer sceneEntities;
-SceneEntityContainer sceneEntities2;
 
 // traverses and renders the hierarchy
@@ -255,5 +270,5 @@
 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; }
 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; }
-
+// initialise the frame buffer objects
 void InitFBO();
 
@@ -309,4 +324,19 @@
 int main(int argc, char* argv[])
 {
+#ifdef _CRT_SET
+
+	//Now just call this function at the start of your program and if you're
+	//compiling in debug mode (F5), any leaks will be displayed in the Output
+	//window when the program shuts down. If you're not in debug mode this will
+	//be ignored. Use it as you will!
+	//note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
+
+	_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
+	_CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
+	_CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 
+#endif
+
+	cout << "=== reading environment file ===" << endl << endl;
+
 	int returnCode = 0;
 
@@ -317,5 +347,5 @@
 	cout << "=== reading environment file ===" << endl << endl;
 
-	string envFileName = "default.env";
+	const string envFileName = "default.env";
 	if (!env.Read(envFileName))
 	{
@@ -347,5 +377,4 @@
 		//env.GetStringParam(string("modelPath"), model_path);
 		//env.GetIntParam(string("numSssaoSamples"), numSsaoSamples);
-
 
 		cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; 
@@ -395,5 +424,4 @@
 	SceneEntity::SetUseLODs(useLODs);
 
-
 	if (!useFullScreen)
 	{
@@ -420,5 +448,4 @@
 	InitGLstate();
 
-
 	glEnable(GL_MULTISAMPLE_ARB);
 	glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
@@ -432,4 +459,5 @@
 
 	const string filename = string(model_path + "city.dem");
+	
 
 	if (loader->Load(filename, sceneEntities))
@@ -441,4 +469,5 @@
 		exit(0);
 	}
+	
 
 	const string bvh_filename = string(model_path + "city.bvh");
@@ -452,5 +481,4 @@
 		exit(0);
 	}
-	
 
 	// set far plane based on scene extent
@@ -468,5 +496,4 @@
 	
 	Matrix4x4 transl = TranslationMatrix(cubeCenter);
-	
 
 	SceneEntityContainer dummy;
@@ -474,6 +501,6 @@
 	string skyDomeStr(model_path + "sky.dem");
 
-	if (loader->Load(skyDomeStr, dummy))
-		cout << "successfully loaded " << dummy.size() << " scene entities" << endl;
+	if (loader->Load(skyDomeStr, sceneEntities))
+		cout << "successfully loaded " << sceneEntities.size() << " scene entities" << endl;
 	else
 	{
@@ -484,5 +511,5 @@
 	}
 
-	skyDome = dummy[0];
+	skyDome = sceneEntities.back();
 
 
@@ -506,5 +533,5 @@
 	// clean up
 	CleanUp();
-
+	
 	return 0;
 }
@@ -572,5 +599,5 @@
 		cgGLLoadProgram(RenderState::sCgMrtFragmentProgram);
 
-		sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "eyePos");
+		sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "eyePos");
 	}
 	else
@@ -613,4 +640,5 @@
 	glGenTextures(1, &fontTex);
 	glBindTexture(GL_TEXTURE_2D, fontTex);
+
 	if (!myfont.Create("data/fonts/verdana.glf", fontTex))
 		return false;
@@ -1747,4 +1775,9 @@
 	DEL_PTR(ssaoShader);
 
+	DEL_PTR(light);
+	DEL_PTR(visCamera);
+
+	DEL_PTR(preetham);
+
 	if (sCgMrtVertexProgram)
 		cgDestroyProgram(sCgMrtVertexProgram);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3018)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3019)
@@ -61,4 +61,5 @@
 
 
+ShaderContainer DeferredRenderer::sShaders;
 
 ///////////////////////////////////////
@@ -296,4 +297,19 @@
 
 
+static void InitBuffer(FrameBufferObject *fbo, int index)
+{
+	// read the second buffer, write to the first buffer
+	fbo->Bind();
+	glDrawBuffers(1, mrt + index);
+
+	//glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	glEnd();
+
+	FrameBufferObject::Release();
+}
+
+
 DeferredRenderer::DeferredRenderer(int w, int h, Camera *cam, float scaleFactor):
 mWidth(w), mHeight(h), 
@@ -303,5 +319,5 @@
 mSamplingMethod(SAMPLING_POISSON),
 mShadingMethod(DEFAULT),
-mFboIndex(0)
+mIllumFboIndex(0)
 {
 	// create noise texture for ssao
@@ -312,29 +328,25 @@
 	//-- the flip-flop fbos
 
-	mFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE);
-	//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);
+	mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE);
+	mFBOs.push_back(mIllumFbo);
+
+	for (int i = 0; i < 4; ++ i)
+	{
+		mIllumFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
+		InitBuffer(mIllumFbo, i);
+	}
 
 	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::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
-}
-
+
+	mFBOs.push_back(mDownSampleFbo);
+}
 
 
 DeferredRenderer::~DeferredRenderer() 
 {
-	if (sCgSsaoProgram)	cgDestroyProgram(sCgSsaoProgram);
-	if (sCgDeferredProgram)	cgDestroyProgram(sCgDeferredProgram);
-	if (sCgSsaoProgram)	cgDestroyProgram(sCgSsaoProgram);
-	if (sCgGiProgram) cgDestroyProgram(sCgGiProgram);
-	if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram);
-
-	DEL_PTR(mFbo);
+	CLEAR_CONTAINER(sShaders);
+	CLEAR_CONTAINER(mFBOs);
 
 	glDeleteTextures(1, &noiseTex);
@@ -350,4 +362,7 @@
 void DeferredRenderer::Init(CGcontext context)
 {	
+	ShaderProgram *pr;
+
+
 	sCgDeferredProgram = 
 		cgCreateProgramFromFile(context, 
@@ -368,4 +383,7 @@
 		
 		sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir");
+
+		pr = new ShaderProgram(sCgDeferredProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -407,4 +425,7 @@
 		sBRParam = cgGetNamedParameter(sCgSsaoProgram, "br"); 
 		sBLParam = cgGetNamedParameter(sCgSsaoProgram, "bl"); 
+
+		pr = new ShaderProgram(sCgSsaoProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -443,4 +464,7 @@
 
 		sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos");
+
+		pr = new ShaderProgram(sCgGiProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -462,4 +486,7 @@
 		sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex");
 		sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex");
+
+		pr = new ShaderProgram(sCgCombinedIllumProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -484,4 +511,7 @@
 		sFilterOffsetsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterOffs");
 		sFilterWeightsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterWeights");
+
+		pr = new ShaderProgram(sCgCombinedSsaoProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -503,4 +533,7 @@
 		sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");  
 		sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals");
+
+		pr = new ShaderProgram(sCgAntiAliasingProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -538,4 +571,7 @@
 
 		cgGLSetParameterArray2f(sSamplesShadowParam, 0, NUM_PCF_TABS, (const float *)pcfSamples);
+
+		pr = new ShaderProgram(sCgDeferredShadowProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -553,5 +589,8 @@
 	{
 		cgGLLoadProgram(sCgLogLumProgram);
-		sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors");  
+		sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors"); 
+
+		pr = new ShaderProgram(sCgLogLumProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -576,4 +615,7 @@
 
 		sColorsTexToneParam = cgGetNamedParameter(sCgToneProgram, "colors");  
+
+		pr = new ShaderProgram(sCgToneProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -596,4 +638,7 @@
 		sColorsTexDownSampleParam = cgGetNamedParameter(sCgDownSampleProgram, "colors"); 
 		sDownSampleOffsetParam = cgGetNamedParameter(sCgDownSampleProgram, "downSampleOffs");
+
+		pr = new ShaderProgram(sCgDownSampleProgram);
+		sShaders.push_back(pr);
 	}
 	else
@@ -618,5 +663,5 @@
 	// the other one will be written
 
-	mFboIndex = 2 - mFboIndex;
+	mIllumFboIndex = 2 - mIllumFboIndex;
 	
 
@@ -726,12 +771,12 @@
 #endif
 
-	GLuint oldTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture();
+	GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
 
 	glPushAttrib(GL_VIEWPORT_BIT);
-	glViewport(0, 0, mFbo->GetWidth(), mFbo->GetHeight());
+	glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight());
 
 	// read the second buffer, write to the first buffer
-	mFbo->Bind();
-	glDrawBuffers(1, mrt + mFboIndex);
+	mIllumFbo->Bind();
+	glDrawBuffers(1, mrt + mIllumFboIndex);
 
 	
@@ -850,5 +895,5 @@
 	cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam);
 
-
+	// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 	glColor3f(1.0f, 1.0f, 1.0f);
 
@@ -939,13 +984,13 @@
 
 	glPushAttrib(GL_VIEWPORT_BIT);
-	glViewport(0, 0, mFbo->GetWidth(), mFbo->GetHeight());
+	glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight());
 
 	// read the second buffer, write to the first buffer
-	mFbo->Bind();
-
-	glDrawBuffers(2, mrt + mFboIndex);
-
-	GLuint oldSsaoTex = mFbo->GetColorBuffer(2 - mFboIndex)->GetTexture();
-	GLuint oldIllumTex = mFbo->GetColorBuffer(2 - mFboIndex + 1)->GetTexture();
+	mIllumFbo->Bind();
+
+	glDrawBuffers(2, mrt + mIllumFboIndex);
+
+	GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
+	GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture();
 	
 	cgGLBindProgram(sCgGiProgram);
@@ -1024,6 +1069,6 @@
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 
-	GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture();
-	GLuint illumTex = mFbo->GetColorBuffer(mFboIndex + 1)->GetTexture();
+	GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
+	GLuint illumTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture();
 
 
@@ -1084,5 +1129,5 @@
 	GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture();
 	
-	GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture();
+	GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
 
 	// overwrite old color texture
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h	(revision 2980)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h	(revision 3019)
@@ -32,5 +32,5 @@
 class Vector3;
 class Geometry;
-
+struct LODLevel;
 
 
@@ -445,9 +445,6 @@
 
 
-char *
-GetAbsPath(char *path);
-
-char *
-strdup(char *a);
+char *GetAbsPath(char *path);
+
 
 std::string
@@ -495,4 +492,5 @@
 typedef std::vector<LODLevel *> LODLevelContainer;
 typedef std::vector<Polygon3 *> PolygonContainer;
+typedef std::vector<LODLevel *> LODContainer;
 
 typedef std::vector<Vector3> VertexArray;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3016)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3019)
@@ -18,7 +18,7 @@
 		<Configuration
 			Name="Debug|Win32"
-			OutputDirectory="$(SolutionDir)/bin/$(ConfigurationName)"
+			OutputDirectory="$(SolutionDir)/lib/$(ConfigurationName)"
 			IntermediateDirectory="obj/$(ConfigurationName)"
-			ConfigurationType="1"
+			ConfigurationType="4"
 			CharacterSet="1"
 			>
@@ -62,12 +62,5 @@
 			/>
 			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib cg.lib cgGL.lib"
-				LinkIncremental="2"
-				AdditionalLibraryDirectories="libs/GL;libs/Devil/lib;libs/Zlib/lib;&quot;$(CG_LIB_PATH)&quot;"
-				IgnoreDefaultLibraryNames="LIBCMT"
-				GenerateDebugInformation="true"
-				SubSystem="1"
-				TargetMachine="1"
+				Name="VCLibrarianTool"
 			/>
 			<Tool
@@ -75,7 +68,4 @@
 			/>
 			<Tool
-				Name="VCManifestTool"
-			/>
-			<Tool
 				Name="VCXDCMakeTool"
 			/>
@@ -85,10 +75,4 @@
 			<Tool
 				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
-			<Tool
-				Name="VCWebDeploymentTool"
 			/>
 			<Tool
@@ -128,5 +112,5 @@
 				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"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
 				StringPooling="true"
 				RuntimeLibrary="2"
