Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 2954)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 2964)
@@ -29,4 +29,6 @@
 //#define ILLUM_INTENSITY 9e-1f;
 
+#define SSAO_MIPMAP_LEVEL 1
+#define GI_MIPMAP_LEVEL 2
 
 #endif // __SHADERENV_H
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.h	(revision 2850)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.h	(revision 2964)
@@ -62,5 +62,7 @@
 	*/
 	void Create();
-	
+	/** Returns id of this texture.
+	*/
+	int GetId() const { return mTexId; }
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 2963)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 2964)
@@ -118,7 +118,9 @@
 	}
 
-	cout << "... finished loading " << bvh->mNumNodes << " scene box: " << bvh->mBox << endl;
 
 	bvh->mBox = bvh->mRoot->GetBox();
+
+	cout << "... finished loading " << bvh->mNumNodes << " nodes" << endl;
+	cout << "scene box: " << bvh->mBox << endl;
 
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 2959)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 2964)
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg	(revision 2903)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg	(revision 2964)
@@ -76,5 +76,5 @@
 			++ j;
 			// sample downsampled texture in order to speed up texture accesses
-			float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz;
+			float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;
 			//float3 sample_position = tex2D(positions, texcoord).xyz;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2960)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2964)
@@ -66,12 +66,17 @@
 
 pixel fragtex(fragin IN, 
-			  uniform sampler2D tex, 
-			  uniform float maxDepth)
+			  uniform sampler2D dirtTex,
+			  uniform float maxDepth,
+			  uniform sampler2D tex)
 {
 	pixel pix;
 
+	//float4 dirtTexColor = tex2D(dirtTex, IN.texCoord.xy);
+	float4 texColor = tex2D(tex, IN.texCoord.xy);
+
 	// save color in first render target
 	// hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
-	pix.col = (glstate.material.emission + glstate.material.diffuse) * tex2D(tex, IN.texCoord.xy);
+	//pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor * dirtTexColor; 
+	pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor; 
 	
 	// save world position in second render target
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2911)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2964)
@@ -73,5 +73,5 @@
 
 		// sample downsampled texture in order to speed up texture accesses
-		float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz;
+		float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz;
 		//float3 sample_position = tex2D(positions, texcoord).xyz;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2904)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2964)
@@ -92,6 +92,6 @@
 
 		// use lower lod level to improve cache coherence
-		float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz;
-		float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, 2)).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;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2955)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2964)
@@ -13,4 +13,7 @@
 CGprogram RenderState::sCgMrtFragmentProgram = NULL;
 CGprogram RenderState::sCgMrtFragmentTexProgram = NULL;
+CGparameter RenderState::sTexParam;
+CGparameter RenderState::sDirtTexParamTex;
+
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2955)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2964)
@@ -81,4 +81,7 @@
 	static CGprogram sCgMrtFragmentTexProgram;
 
+	static CGparameter sTexParam;
+
+	static CGparameter sDirtTexParamTex;
 
 protected:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2960)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2964)
@@ -22,5 +22,4 @@
 
 	mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f);
-	//mAmbientColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
 	mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
 	mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f);
@@ -60,8 +59,24 @@
 	state->SetState(mTexture != NULL, mAlphaTestEnabled, mCullFaceEnabled);
 
-	if (mTexture)
-		mTexture->Bind();
+	if (state->GetRenderPassType() == RenderState::DEFERRED)
+	{
+		if (mTexture)
+		{
+			cgGLSetTextureParameter(RenderState::sTexParam, mTexture->GetId());
+			cgGLEnableTextureParameter(RenderState::sTexParam);
+			cgGLEnableTextureParameter(RenderState::sDirtTexParamTex);
+		}
+		else
+		{
+			cgGLDisableTextureParameter(RenderState::sTexParam);
+		}
+	}
 	else
-		glBindTexture(GL_TEXTURE_2D, 0);
+	{
+		if (mTexture)
+			mTexture->Bind();
+		else
+			glBindTexture(GL_TEXTURE_2D, 0);
+	}
 
 	glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2963)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2964)
@@ -39,4 +39,5 @@
 #include "ObjConverter.h"
 #include "SkyPreetham.h"
+#include "Texture.h"
 
 
@@ -167,4 +168,6 @@
 PerfTimer frameTimer, algTimer;
 
+Texture *dirtTexture = NULL;
+
 
 /// the used render type for this render pass
@@ -269,4 +272,5 @@
 static CGparameter sMaxDepthParam;
 static CGparameter sMaxDepthParamTex;
+
 static Matrix4x4 oldViewProjMatrix;
 
@@ -454,4 +458,8 @@
 	camera->SetFar(Magnitude(bvh->GetBox().Diagonal()));
 	
+	dirtTexture = new Texture(model_path + "waterstain.jpg");
+	//dirtTexture = new Texture(model_path + "dirt.jpg");
+	dirtTexture->Create();
+
 	InitCg();
 
@@ -470,18 +478,9 @@
 	
 	//const string aeroplaneStr = model_path + "toyplane.dem";
-	const string aeroplaneStr = model_path + "city_full.dem";
+	//const string aeroplaneStr = model_path + "city_full.dem";
 
 	SceneEntityContainer dummy;
 
-	if (loader->Load(aeroplaneStr, dummy))
-		cout << "successfully loaded " << dummy.size() << " scene entities" << endl;
-	else
-	{
-		cerr << "loading file " << aeroplaneStr << " failed" << endl;
-
-		CleanUp();
-		exit(0);
-	}
-
+	
 	string skyDomeStr(model_path + "sky.dem");
 
@@ -496,9 +495,21 @@
 	}
 
-	aeroplane = dummy[0];
-	skyDome = dummy[1];
+	skyDome = dummy[0];
+
+
+	/*if (loader->Load(aeroplaneStr, dummy))
+		cout << "successfully loaded " << dummy.size() << " scene entities" << endl;
+	else
+	{
+		cerr << "loading file " << aeroplaneStr << " failed" << endl;
+
+		CleanUp();
+		exit(0);
+	}
+
+	aeroplane = dummy[1];
 
 	aeroplane->GetTransform()->MultMatrix(transl);
-
+*/
 	const float turbitiy = 3.0f;
 	preetham = new SkyPreetham(turbitiy, skyDome);
@@ -569,4 +580,9 @@
 
 		sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth");
+		RenderState::sDirtTexParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "dirtTex");
+		RenderState::sTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tex");
+
+		cgGLEnableTextureParameter(RenderState::sDirtTexParamTex);
+		cgGLSetTextureParameter(RenderState::sDirtTexParamTex, dirtTexture->GetId());
 
 		cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist);
@@ -1086,16 +1102,18 @@
 	{
 		// actually render the scene geometry using the specified algorithm
-		//traverser->RenderScene();
+		traverser->RenderScene();
+	/*
 		state.Reset();
-	/*	SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end();
+		aeroplane->Render(&state);
+
+	SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end();
 
 		for (sit = sceneEntities.begin(); sit != sit_end; ++ sit)
 		{
 			renderQueue->Enqueue(*sit);
-		}*/
-
-		aeroplane->Render(&state);
+		}
 
 		renderQueue->Apply();
+		*/
 	}
 
