Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 3117)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp	(revision 3193)
@@ -217,10 +217,4 @@
 	
 	glBindTexture(GL_TEXTURE_2D, mTexId);
-	
-	/*GLint width, height;
-	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
-	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
-	cout << "w: " << width << "h: " << height << endl;
-	*/
 
 	unsigned char *data = new unsigned char[bytes * 4 * mWidth * mHeight];
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3192)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3193)
@@ -6,10 +6,10 @@
 //-- ssao + gi parameters
 
-//#define NUM_SAMPLES 8
+#define NUM_SAMPLES 8
 //#define NUM_SAMPLES 16
-#define NUM_SAMPLES 48
+//#define NUM_SAMPLES 24
 
 // for quadratic falloff
-#define SAMPLE_INTENSITY 0.2f
+#define SAMPLE_INTENSITY 0.5f
 //#define SAMPLE_INTENSITY 0.1f
 
@@ -17,6 +17,6 @@
 //#define SAMPLE_INTENSITY 0.2f
 
-#define SAMPLE_RADIUS 8e-1f
-//#define SAMPLE_RADIUS 4e-1f
+//#define SAMPLE_RADIUS 8e-1f
+#define SAMPLE_RADIUS 4e-1f
 
 //#define DISTANCE_SCALE 1e-1f
@@ -30,5 +30,5 @@
 //#define NUM_SSAO_FILTERSAMPLES 80
 #define NUM_SSAO_FILTER_SAMPLES 16
-#define NUM_SSAO_FILTER_WIDTH 15.0f
+#define NUM_SSAO_FILTER_WIDTH 12.0f
 #define SSAO_CONVERGENCE_WEIGHT 200.0f
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 3110)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 3193)
@@ -83,6 +83,4 @@
 			      0.055648f, -0.204043f,  1.057311f);
 
-	//float3 hcol = mul(conv_Mat, XYZ);
-	//OUT.color = float4(hcol, 1.0f);
 	OUT.color = float4(mul(conv_Mat, XYZ), 1.0f);
 
@@ -102,4 +100,6 @@
 
 	pix.col = IN.hdrColor;
+	//pix.col.xyz = float3(0.3f, 0.6f, 1.0f);
+	// set depth to large value
 	pix.col.w = 1e20f;
 	pix.norm = IN.normal;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3192)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3193)
@@ -1,4 +1,4 @@
 #include "../shaderenv.h"
-
+#include "common.h"
 
 struct fragment
@@ -17,15 +17,4 @@
 	float3 diffVal: COLOR2;
 };
-
-
-float2 myreflect(float2 pt, float2 n)
-{
-	// distance to plane
-	float d = dot(n, pt);
-	// reflect around plane
-	float2 rpt = pt - d * 2.0f * n;
-
-	return rpt;
-}
 
 
@@ -123,14 +112,4 @@
 
 	return total_d;
-}
-
-
-inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)
-{
-	float3 x1 = lerp(bl, tl, w.y);
-	float3 x2 = lerp(br, tr, w.y); 
-	float3 v  = lerp(x1, x2, w.x); 
-
-	return v;
 }
 
@@ -157,5 +136,4 @@
 
 	const float3 normal = tex2D(normals, IN.texCoord.xy);
-
 	float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0));
 
@@ -166,5 +144,4 @@
 
 	const float eyeDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w;
-
 	const float4 worldPos = float4(eyePos - viewDir * eyeDepth, 1);
 	
@@ -197,4 +174,5 @@
 	// store scaled view vector from now on so wie don't have to normalize later (e.g., for ssao)
 	//OUT.color.w = color.w / lenView;
+	OUT.color.w = color.w;
 
 	return OUT;
@@ -217,12 +195,4 @@
 	return color;
 }
-
-
-
-inline float SqrLen(float3 v)
-{
-	return v.x * v.x + v.y * v.y + v.z * v.z;
-}
-
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3192)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3193)
@@ -104,5 +104,6 @@
 	float total_w = .0f;
 
-	const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr);
+	//const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr);
+	const float3 centerPos = ReconstructSamplePos(colorsTex, texCoord, bl, br, tl, tr);
 	const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz;
 
@@ -127,5 +128,9 @@
 
 		// check spatial discontinuity
-		samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr);
+		// using the depth from the color texture is not 100% correct as depth was
+		// not scaled with the interpolated view vector depth yet ...
+		samplePos = ReconstructSamplePos(colorsTex, sampleTexCoord.xy, bl, br, tl, tr);
+		//samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr);
+
 		len = min(SqrLen(centerPos - samplePos), 1e3f);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3192)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3193)
@@ -153,5 +153,5 @@
 	sample normal as weight.
 */
-float2 ssao2(fragment IN,
+float3 ssao2(fragment IN,
 			 sampler2D colors,
 			 sampler2D noiseTex,
@@ -230,8 +230,10 @@
 		// check if the samples have been valid in the last frame
 		//numSamples += (1.0f - step(1.0f, lengthToSample)) * sampleColor.x;
-		numSamples += 1.0f - sampleColor.x;
-	}
-
-	return float2(max(0.0f, 1.0f - total_ao), numSamples);
+		++ numSamples;
+	}
+
+	total_ao /= numSamples;
+
+	return float3(max(0.0f, 1.0f - total_ao), .0f, numSamples);
 }
 
@@ -316,5 +318,5 @@
 
 		++ numSamples;
-		if ((validSamples < 1.0f) && (newWeight > 20) && (numSamples >= 8)) break;
+		//if ((validSamples < 1.0f) && (newWeight > 20) && (numSamples >= 8)) break;
 	}
 
@@ -391,6 +393,6 @@
 	if (eyeSpaceDepth < 1e10f)
 	{
-		ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight);
-		//ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);
+		//ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight);
+		ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals);
 	}
 	else
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3189)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3193)
@@ -111,5 +111,5 @@
 	//const float scaleFactor = 5.0f;
 
-	position.z -= 3 * scaleFactor;
+	position.z -= 3.0f * scaleFactor;
 	Matrix4x4 m = TranslationMatrix(position);
 
@@ -143,5 +143,5 @@
 	else
 	{
-		// no tone mapping => scale to range 
+		// no tone mapping => linearily scale to displayable dynamic range 
 		vtxParams->SetValue1f(8, 8e-5f);
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3189)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3193)
@@ -145,4 +145,5 @@
 double accumulatedTime = 1000.0;
 float fps = 1e3f;
+float turbitity = 5.0f;
 
 int shadowSize = 2048;
@@ -369,6 +370,5 @@
 		env.GetFloatParam(string("keyRotation"), keyRotation);
 		env.GetFloatParam(string("tempCohFactor"), ssaoTempCohFactor);
-
-		
+		env.GetFloatParam(string("turbitity"), turbitity);
 		
 		env.GetVectorParam(string("camPosition"), camPos);
@@ -403,4 +403,5 @@
 		cout << "use antialiasing: " << useAntiAliasing << endl;
 		cout << "use advanced shading: " << useAdvancedShading << endl;
+		cout << "turbitity: " << turbitity << endl;
 
 		//cout << "model path: " << model_path << endl;
@@ -478,9 +479,9 @@
 	//-- load some dynamic stuff
 
-	//resourceManager->mUseNormalMapping = true;
-	resourceManager->mUseNormalMapping = false;
-
-	//LoadModel("fisch.dem", dynamicObjects);
-	LoadModel("hbuddha.dem", dynamicObjects);
+	resourceManager->mUseNormalMapping = true;
+	//resourceManager->mUseNormalMapping = false;
+
+	LoadModel("fisch.dem", dynamicObjects);
+	//LoadModel("hbuddha.dem", dynamicObjects);
 	//LoadModel("venusm.dem", dynamicObjects);
 	//LoadModel("camel.dem", dynamicObjects);
@@ -492,5 +493,6 @@
 	buddha = dynamicObjects.back();
 	
-	const Vector3 sceneCenter(470.398f, 240.364f, 182.5f);
+	//const Vector3 sceneCenter(470.398f, 240.364f, 182.5f);
+	const Vector3 sceneCenter(470.398f, 240.364f, 180.3);
 	
 	Matrix4x4 transl = TranslationMatrix(sceneCenter);
@@ -547,6 +549,5 @@
 
 	/// the turbitity of the sky (from clear to hazy, use <3 for clear sky)
-	const float turbitiy = 5.0f;
-	preetham = new SkyPreetham(turbitiy, skyDome);
+	preetham = new SkyPreetham(turbitity, skyDome);
 
 	CreateAnimation();
@@ -809,4 +810,5 @@
 	Vector3 sunDiffuse;
 
+#if 1
 	preetham->ComputeSunColor(lightDir, sunAmbient, sunDiffuse, !useHDRValues);
 
@@ -819,5 +821,15 @@
 	diffuse[2] = sunDiffuse.z;
 
-	//cout << sunDiffuse << " " << sunAmbient << endl;
+#else
+	
+	ambient[0] = .2f;
+	ambient[1] = .2f;
+	ambient[2] = .2f;
+
+	diffuse[0] = 1.0f;
+	diffuse[1] = 1.0f;
+	diffuse[2] = 1.0f;
+
+#endif
 
 	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3192)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3193)
@@ -517,5 +517,5 @@
 	// multisampling is difficult / costly with deferred shading
 	// at least do some edge blurring 
-	if (useAntiAliasing) AntiAliasing(fbo, light);
+	//if (useAntiAliasing) AntiAliasing(fbo, light);
 
 	switch (mShadingMethod)
@@ -544,5 +544,5 @@
 	// multisampling is difficult / costly with deferred shading
 	// at least do some edge blurring 
-	//if (useAntiAliasing) AntiAliasing(fbo, light); else 
+	if (useAntiAliasing) AntiAliasing(fbo, light);// else 
 	Output(fbo); // just output the latest buffer
 
@@ -1020,5 +1020,4 @@
 	normalsTex = fbo->GetColorBuffer(1)->GetTexture();
 	diffVals = fbo->GetColorBuffer(2)->GetTexture();
-	//diffVals = mDownSampleFbo->GetColorBuffer(2)->GetTexture();
 
 	// flip flop between illumination buffers
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3161)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3193)
@@ -174,5 +174,6 @@
 
 		ambient.x = ambient.y = ambient.z = 0.2f;
-		diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f;
+		//diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f;
+		diffuse.x = 0.8f; diffuse.y = 0.8f; diffuse.z = 0.4f;
 		//diffuse.x = diffuse.y = diffuse.z = 1.0f;
 		spec.x = spec.y = spec.z = .0f;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3192)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3193)
@@ -38,6 +38,15 @@
 
 # bad view point (culling bug!)
-camPosition=469.381 267.293 184.778
-camDirection=0.142006 0.645885 -0.750111
+#camPosition=469.381 267.293 184.778
+#camDirection=0.142006 0.645885 -0.750111
+
+#camPosition=458.412 255.767 182.632
+#camDirection=0.891691 0.42723 0.149535
+
+#camPosition=740.137 487.855 188.506
+#camDirection=0.669256 0.727829 0.149535
+
+camPosition=492.678 249.827 187.232
+camDirection=-0.651041 -0.693292 -0.309017
 
 #lightDirection=-0.8f 1.0f -0.7f
@@ -64,8 +73,14 @@
 # ssao temporal coherence factor
 tempCohFactor=1000.0f
+
 # tone mapping
 useHDR=0
+
 # use antialiasing
 useAA=1
+
 # use ssao / color bleeding
 useAdvancedShading=1
+
+# skylight turbitity
+turbitity=3.0f
