Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 2886)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 2887)
@@ -2,10 +2,10 @@
 #define __SHADERENV_H
 
-#define NUM_SAMPLES 8
-//#define NUM_SAMPLES 16
+//#define NUM_SAMPLES 8
+#define NUM_SAMPLES 16
 
 // rule of thumb: approx 1 / NUM_SAMPLES
-//#define SAMPLE_INTENSITY 0.15f
-#define SAMPLE_INTENSITY 0.25f
+#define SAMPLE_INTENSITY 0.14f
+//#define SAMPLE_INTENSITY 0.28f
 
 #define AREA_SIZE 5e-1f
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2884)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2887)
@@ -24,4 +24,5 @@
 {
 	float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f);
+	//float4 lightDir = float4(0.0f, 1.0f, 0.0f, 0.0f);
 	float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 2884)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 2887)
@@ -84,11 +84,7 @@
 	float4 s3 = tex2Dlod(colors, float4(offset + IN.lb.xy * w, 0, 0));
 
-	float4 sx = tex2D(colors, IN.c.xy);
-
-	//return (sx + sx) * 0.5f;
+	//float4 sx = tex2D(colors, IN.c.xy);
 
 	return (s0 + s1 + s2 + s3) * 0.25f;
-	//return (s0 + s1 + s2 + s3) * 0.25f;
-
 	//return float4(w);
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2886)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 2887)
@@ -88,10 +88,12 @@
 		// 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 view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal));
+		//const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal));
+		//total_ao += cos_angle * distance_intensity * view_correction;
 
-		total_ao += cos_angle * distance_intensity * view_correction;
+		total_ao += cos_angle * distance_intensity;
 	}
 
-	return max(0.0f, 1.0f - total_ao);
+	//return max(0.0f, 1.0f - total_ao);
+	return saturate(dot(currentViewDir, currentNormal));
 }
 
@@ -178,6 +180,7 @@
 	float4 ao = tex2D(ssaoTex, IN.texCoord.xy);
 
-	OUT.illum_col = col * ao.x;
-	//OUT.illum_col = ao;
+	//OUT.illum_col = col * ao.x;
+	OUT.illum_col = ao;
+
 	OUT.illum_col.w = ao.w;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2884)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg	(revision 2887)
@@ -96,9 +96,10 @@
 
 		// if normal perpenticular to view dir, only half of the samples count
-		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;
+		//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;
+
+		total_color.w -= cos_angle * distance_intensity;
+		total_color.xyz += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY;
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 2879)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 2887)
@@ -5,7 +5,9 @@
 #include "SceneQuery.h"
 #include "RenderTraverser.h"
+#include "FrameBufferObject.h"
+
 #include <IL/il.h>
 #include <assert.h>
-#include "FrameBufferObject.h"
+
 
 
@@ -33,5 +35,5 @@
 
 
-void startil()
+static void startil()
 {
 	ilInit();
@@ -40,5 +42,5 @@
 
 
-void stopil()
+static void stopil()
 {
 	ilShutDown();
@@ -51,6 +53,5 @@
 
 
-//void GrabDepthBuffer(float *data, RenderTexture *rt)
-void GrabDepthBuffer(float *data, GLuint depthTexture)
+static void GrabDepthBuffer(float *data, GLuint depthTexture)
 {
 	glEnable(GL_TEXTURE_2D);
@@ -64,5 +65,5 @@
 
 
-void ExportDepthBuffer(float *data)
+static void ExportDepthBuffer(float *data)
 {
 	startil();
@@ -92,5 +93,6 @@
 
 
-SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, RenderTraverser *renderer): 
+SceneQuery::SceneQuery(const AxisAlignedBox3 &sceneBox, 
+					   RenderTraverser *renderer): 
 mSceneBox(sceneBox), mDepth(NULL)
 {
@@ -135,6 +137,7 @@
 
 	orthoCam->SetNear(0.0f);
-	orthoCam->Yaw(M_PI * 0.5f);
-
+	orthoCam->SetDirection(Vector3(0, 0, 1));
+
+	cout << orthoCam->GetDirection() << endl;
 	Vector3 pos = Vector3(mSceneBox.Center().x, mSceneBox.Center().y, mSceneBox.Max().z);
 	orthoCam->SetPosition(pos);
@@ -147,7 +150,7 @@
 
 	glDrawBuffers(1, mrt);
-	
+
+	glPushAttrib(GL_VIEWPORT_BIT);
 	glViewport(0, 0, texWidth, texHeight);
-	glPushAttrib(GL_VIEWPORT_BIT);
 
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -186,5 +189,5 @@
 
 	GrabDepthBuffer(mDepth, fbo->GetDepthTex());
-	//ExportDepthBuffer(mDepth); PrintGLerror("grab");
+	ExportDepthBuffer(mDepth); PrintGLerror("grab");
 
 	DEL_PTR(fbo);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2886)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp	(revision 2887)
@@ -104,30 +104,43 @@
 /** Generate poisson disc distributed sample points on the unit disc
 */
-static void GenerateSamples()
-{
-#if 0
-	static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f);
-	poisson.Generate((Sample2 *)samples);
-#else
-	
-	const float radius = 1.0f;
-	const float sigma = ComputeSigmaFromRadius(1.0f);
-	
-	static HaltonSequence halton;
-
-	for (int i = 0; i < NUM_SAMPLES; ++ i)
-	{
-		Sample2 s;
-		Vector3 input;
-
-		halton.GetNext(3, (float *)&input.x);
-
-		PolarGaussianOnDisk(input,  // input (RND in interval [0-1)x[0-1))
-						    sigma,  // standard deviation of gaussian distribution
-							radius, // standard deviation of gaussian distribution
-							s);     // result
-		samples[i] = s;
-	}
-#endif
+static void GenerateSamples(int sampling)
+{
+	switch (sampling)
+	{
+	case SsaoShader::POISSON:
+		{
+			static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f);
+			poisson.Generate((Sample2 *)samples);
+		}
+		break;
+	case SsaoShader::GAUSS:
+		{
+			const float radius = 1.0f;
+			const float sigma = 0.25f;//ComputeSigmaFromRadius(1.0f);
+
+			static HaltonSequence halton;
+
+			for (int i = 0; i < NUM_SAMPLES; ++ i)
+			{
+				Sample2 s;
+				Vector3 input;
+
+				halton.GetNext(3, (float *)&input.x);
+
+				//GaussianOn2D(cinput, // input (RND in interval [0-1)x[0-1))
+				//	         sigma,            // standard deviation of gaussian distribution
+				//			 outputVec)   // resulting vector according to gaussian distr.
+
+				PolarGaussianOnDisk(input,  // input (RND in interval [0-1)x[0-1))
+					sigma,  // standard deviation of gaussian distribution
+					radius, // standard deviation of gaussian distribution
+					s);     // result
+				samples[i] = s;
+			}
+		}
+		break;
+	default:
+		break;
+	}
 }
 
@@ -179,5 +192,6 @@
 mScaleFactor(scaleFactor),
 mUseTemporalCoherence(true),
-mUseGlobIllum(false)
+mUseGlobIllum(false),
+mSampling(POISSON)
 {
 	// create noise texture for ssao
@@ -286,5 +300,5 @@
 
 		// generate samples for ssao kernel
-		GenerateSamples(); 
+		//GenerateSamples(mSampling); 
 
 		sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples");
@@ -292,5 +306,5 @@
 		//cgCompileProgram(sCgSsaoProgram);
 		
-		cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);
+		//cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);
 	}
 	else
@@ -326,6 +340,6 @@
 
 		// generate samples for ssao kernel
-		GenerateSamples(); 
-		cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples);
+		//GenerateSamples(); 
+		//cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples);
 
 		cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(3.0f, 17.0f));
@@ -515,5 +529,5 @@
 		// in the first case, the sample patterns look nicer, but the kernel
 		// needs longer to converge
-		GenerateSamples(); 
+		GenerateSamples(mSampling); 
 		cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples);
 	}
@@ -755,5 +769,5 @@
 		// in the first case, the sample patterns look nicer, but the kernel
 		// needs longer to converge
-		GenerateSamples(); 
+		GenerateSamples(mSampling); 
 		cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples);
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 2885)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 2887)
@@ -368,5 +368,5 @@
 
 	// store near plane
-	sNearPlane = Plane3(mCamera->GetDirection(), mCamera->GetPosition());
+	sNearPlane = Plane3(-mCamera->GetDirection(), mCamera->GetPosition());
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2886)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h	(revision 2887)
@@ -47,4 +47,8 @@
 	void SetUseTemporalCoherence(bool temporal);
 
+	enum SAMPLING_METHOD {POISSON, GAUSS};
+
+	void SetSamplingMethod(int s) { mSampling = s;}
+
 
 protected:
@@ -80,4 +84,6 @@
 	bool mUseGlobIllum;
 	bool mUseTemporalCoherence;
+
+	int mSampling;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2884)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2887)
@@ -35,4 +35,6 @@
 #include "SsaoShader.h"
 #include "DeferredShader.h"
+#include "ShadowMapping.h"
+#include "Light.h"
 
 
@@ -170,8 +172,10 @@
 bool useLODs = true;
 
+int samplingMethod = SsaoShader::POISSON;
 
 static Matrix4x4 matProjectionView = IdentityMatrix();
 
-
+ShadowMapping *shadowMapping = NULL;
+Light *light = NULL;
 
 // function forward declarations
@@ -213,4 +217,5 @@
 
 
+
 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; }
 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; }
@@ -326,5 +331,8 @@
 	camera->SetNear(nearDist);
 	
+	cout << "here2 " << Normalize(camDir) << endl;
+
 	camera->SetDirection(camDir);
+	cout << "here3 " << camera->GetDirection() << endl;
 	camera->SetPosition(camPos);
 
@@ -425,8 +433,10 @@
 	DeferredShader::Init(sCgContext);
 	SsaoShader::Init(sCgContext);
+	ShadowMapping::Init(sCgContext);
 
 	//deferredShader = new DeferredShader(texWidth, texHeight);
 	//ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f);
 
+
 	// initialize the render traverser
 	ResetTraverser();
@@ -435,4 +445,9 @@
 
 	sceneQuery = new SceneQuery(bvh->GetBox(), traverser);
+
+	light = new Light(Vector3(0, 0, -1), RgbaColor(1, 1, 1, 1));
+
+	shadowMapping = new ShadowMapping(bvh->GetBox(), 512);
+	shadowMapping->ComputeShadowMap(light, traverser);
 
 	// frame time is restarted every frame
@@ -845,7 +860,7 @@
 		camera->Pitch(-KeyRotationAngle());
 	if (upKeyPressed)
+		KeyHorizontalMotion(-KeyShift());
+	if (downKeyPressed)
 		KeyHorizontalMotion(KeyShift());
-	if (downKeyPressed)
-		KeyHorizontalMotion(-KeyShift());
 	if (ascendKeyPressed)
 		KeyVerticalMotion(KeyShift());
@@ -862,4 +877,9 @@
 	}
 	
+	
+	//shadowMapping->ComputeShadowMap(light, traverser);
+
+
+
 	// render without shading
 	switch (renderType)
@@ -1098,4 +1118,14 @@
 		SceneEntity::SetUseLODs(useLODs);
 		break;
+	case 'P':
+	case 'p':
+		if (samplingMethod == SsaoShader::GAUSS)
+			samplingMethod = SsaoShader::POISSON;
+		else
+			samplingMethod = SsaoShader::GAUSS;
+
+		ssaoShader->SetSamplingMethod(samplingMethod);
+
+		break;
 	case 'g':
 	case 'G':
@@ -1345,5 +1375,5 @@
 	camera->Pitch(eyeXAngle);
 
-	pos += horView * (yMotionBegin - y) * 0.2f;
+	pos -= horView * (yMotionBegin - y) * 0.2f;
 	
 	camera->SetPosition(pos);
@@ -1387,5 +1417,5 @@
 	rVec = rot * rVec;
 	
-	pos -= rVec * (x - horizontalMotionBegin) * 0.1f;
+	pos += rVec * (x - horizontalMotionBegin) * 0.1f;
 	pos[2] += (verticalMotionBegin - y) * 0.1f;
 
@@ -1496,4 +1526,5 @@
 	glMultMatrixf((float *)rotZ.x);
 
+	// inverse translation in order to fix current position
 	Vector3 pos = camera->GetPosition();
 	glTranslatef(-pos.x, -pos.y, -pos.z);
@@ -1508,10 +1539,20 @@
 	glClear(GL_DEPTH_BUFFER_BIT);
 
-
 	////////////
 	//-- visualization of the occlusion culling
 
 	visualization->Render();
-	
+
+	glColor3f(0.0f, 1.0f, 0.0f);
+	glBegin(GL_LINES);
+	glVertex3d(pos.x, pos.y, pos.z);
+	glVertex3d(pos.x + 100, pos.y, pos.z);
+	glEnd();
+
+	glColor3f(0.0f, 0.0f, 1.0f);
+	glBegin(GL_LINES);
+	glVertex3d(pos.x, pos.y, pos.z);
+	glVertex3d(pos.x, pos.y + 100, pos.z);
+	glEnd();
 	
 	// reset previous settings
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2864)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2887)
@@ -8,4 +8,9 @@
 
 using namespace std;
+
+// this is the start vector. 
+// warning: our coordinate system has the negative z axis pointing up
+// which is different from the system used in opengl!!
+static Vector3 startVector = Vector3(0, 1, 0);
 
 
@@ -20,5 +25,7 @@
 
 	mPitch = mYaw = 0;
-	Precompute(Vector3(0, 1, 0));
+	Precompute(startVector);
+
+	CalculateFromPitchAndYaw();
 }
 
@@ -36,5 +43,7 @@
 
 	mPitch = mYaw = 0;
-	Precompute(Vector3(0, 1, 0));
+	Precompute(startVector);
+
+	CalculateFromPitchAndYaw();
 }
 
@@ -49,5 +58,4 @@
 	mViewOrientation = mBaseOrientation;
 }
-
 
 
@@ -173,5 +181,5 @@
 	const float h_far = w_far / GetAspect();
 
-	const Vector3 view = GetDirection();
+	const Vector3 view = -GetDirection();
 	const Vector3 fc = mPosition + view * z_far; 
 	
@@ -225,6 +233,9 @@
 	Normalize(dir);
 
-	mPitch = atan2(dir.x, dir.z);
-	mYaw = atan2(dir.y, sqrt((dir.x * dir.x) + (dir.z * dir.z)));
+	//mPitch = atan2(dir.x, dir.z);
+	//mYaw = atan2(dir.y, sqrt((dir.x * dir.x) + (dir.z * dir.z)));
+
+	mPitch = -atan2(dir.x, dir.y);
+	mYaw = atan2(dir.z, sqrt((dir.x * dir.x) + (dir.y * dir.y)));
 
 	CalculateFromPitchAndYaw();
@@ -246,5 +257,5 @@
 Vector3 Camera::GetDirection() const
 { 
-	return -Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]);
+	return Vector3(mViewOrientation.x[0][2], mViewOrientation.x[1][2], mViewOrientation.x[2][2]);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2868)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2887)
@@ -10,5 +10,5 @@
 winHeight=768
 camPosition=483.398f 242.364f 186.078f
-camDirection=1 0 0
+camDirection=-1 0 0
 useFullScreen=0
 useLODs=1
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2886)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2887)
@@ -551,4 +551,8 @@
 				</File>
 				<File
+					RelativePath=".\src\Light.h"
+					>
+				</File>
+				<File
 					RelativePath=".\src\LODInfo.h"
 					>
