Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h	(revision 2829)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h	(revision 2838)
@@ -78,4 +78,5 @@
 	float GetPitch() const { return mPitch; }
 	float GetYaw() const { return mYaw; }
+	void ResetPitchAndYaw() { mPitch = 0; mYaw = 0; }
 	/** Sets the camera direction.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2837)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2838)
@@ -315,4 +315,5 @@
 
 	Vector3 camPos(.0f, .0f, .0f);
+	Vector3 camDir(.0f, 1.0f, .0f);
 
 	cout << "=== reading environment file === " << endl;
@@ -336,8 +337,9 @@
 
 		env.GetBoolParam(string("useFullScreen"), useFullScreen);
+		env.GetFloatParam(string("expFactor"), expFactor);
+		env.GetVectorParam(string("camPosition"), camPos);
+		env.GetVectorParam(string("camDirection"), camDir);
+
 		//env.GetIntParam(string("numSssaoSamples"), numSsaoSamples);
-		env.GetFloatParam(string("expFactor"), expFactor);
-
-		env.GetVectorParam(string("camPosition"), camPos);
 
 		cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; 
@@ -359,5 +361,5 @@
 	camera->SetNear(nearDist);
 	
-	camera->Pitch(-M_PI * 0.5);
+	camera->SetDirection(camDir);
 	camera->SetPosition(camPos);
 
@@ -457,5 +459,5 @@
 	visualization = new Visualization(bvh, camera, NULL, &state);
 
-	sceneQuery = new SceneQuery(bvh->GetBox(), traverser);
+	//sceneQuery = new SceneQuery(bvh->GetBox(), traverser);
 
 
@@ -656,5 +658,5 @@
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer);
 	
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
 	int samples = 8;
 	//glEnable(GL_MULTISAMPLE_ARB);
@@ -665,5 +667,5 @@
 	glBindTexture(GL_TEXTURE_2D, colorsTex);
 
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
 	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0);
@@ -751,5 +753,5 @@
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer1);
 	
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer1);
 	
@@ -757,5 +759,5 @@
 	glBindTexture(GL_TEXTURE_2D, colorsTex1);
 
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
 	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex1, 0);
@@ -786,5 +788,5 @@
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer2);
 	
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer2);
 	
@@ -792,5 +794,5 @@
 	glBindTexture(GL_TEXTURE_2D, colorsTex2);
 
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL);
 	//glGenerateMipmapEXT(GL_TEXTURE_2D);
 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex2, 0);
@@ -798,4 +800,5 @@
 	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+
 	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -1678,15 +1681,16 @@
 	AxisAlignedBox3 box = bvh->GetBox();
 
-	// set far for viz
+	// hack: set far plane for viz
 	camera->SetFar(0.35f * Magnitude(box.Diagonal()));
 
 	const float offs = box.Size().x * 0.3f;
 	
-	Vector3 pos = camera->GetPosition();
-
-	Vector3 vizpos = Vector3(box.Min().x + 20, box.Min().y + 500, box.Min().z + box.Size().z * 50);
+	//Vector3 vizpos = Vector3(box.Min().x, box.Min().y + box.Size().y * 0.5f, box.Min().z + box.Size().z * 50);
+	Vector3 vizpos = Vector3(box.Min().x, box.Min().y  - box.Size().y * 0.35f, box.Min().z + box.Size().z * 50);
 	
 	visCamera->SetPosition(vizpos);
-	
+	visCamera->ResetPitchAndYaw();
+	//visCamera->Pitch(M_PI);
+
 	glPushAttrib(GL_VIEWPORT_BIT);
 	glViewport(winWidth - winWidth / 3, winHeight - winHeight / 3, winWidth / 3, winHeight / 3);
@@ -1704,7 +1708,10 @@
 	visCamera->SetupCameraView();
 
+	//Matrix4x4 rotX = RotationXMatrix(camera->GetYaw());
+	//glMultMatrixf((float *)rotX.x);
 	Matrix4x4 rotZ = RotationZMatrix(-camera->GetPitch());
 	glMultMatrixf((float *)rotZ.x);
 
+	Vector3 pos = camera->GetPosition();
 	glTranslatef(-pos.x, -pos.y, -pos.z);
 
@@ -1991,5 +1998,5 @@
 	Vector3 playerPos = camera->GetPosition();
 
-	bool validIntersect = sceneQuery->CalcIntersection(playerPos);
+	bool validIntersect = false;//sceneQuery->CalcIntersection(playerPos);
 
 	if (validIntersect &&
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2837)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2838)
@@ -253,5 +253,5 @@
 	if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 
 		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
-		(abs(depthDif)  < 9e-4f))
+		(abs(depthDif)  < 8e-5f))
 		OUT.color = attenuated_color * expFactor + col1 * float4(1.0f - expFactor);
 	else
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 2834)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 2838)
@@ -131,5 +131,5 @@
 
 	orthoCam->SetNear(0.0f);
-	orthoCam->Yaw(M_PI * 0.5f);
+	orthoCam->Yaw(-M_PI * 0.5f);
 
 	Vector3 pos = Vector3(mSceneBox.Center().x, mSceneBox.Center().y, mSceneBox.Max().z);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2834)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2838)
@@ -48,9 +48,13 @@
 	*/
 	Vector3 up = Vector3(0, 0, 1);
-	Vector3 right = -Normalize(-CrossProd(direction, up));
-	up = -Normalize(CrossProd(right, direction));
+	Vector3 right = Normalize(CrossProd(up, direction));
+	up = Normalize(CrossProd(direction, right));
 
 	mBaseOrientation = Matrix4x4(right, up, direction);
 	mViewOrientation = mBaseOrientation;
+
+	cout << "right: " << right << endl;
+	cout << "up:    " << up << endl;
+	cout << "dir:   " << direction << endl;
 }
 
@@ -181,6 +185,5 @@
 	const Vector3 fc = mPosition + view * z_far; 
 	
-	const Vector3 up = -GetUpVector();
-
+	const Vector3 up = GetUpVector();
 	const Vector3 right = GetRightVector();
 
@@ -229,10 +232,21 @@
 void Camera::SetDirection(const Vector3 &direction)
 {
-	Vector3 h1 = direction; h1.z = 0; h1.Normalize();
-	Vector3 h2 = direction; h1.x = 0; h2.Normalize();
-
-	mYaw = acos(DotProd(h1, Vector3(0, 1, 0)));
-	mPitch = acos(DotProd(h2, Vector3(0, 1, 0)));
-
+	Vector3 h1 = direction; h1.z = 0; 
+	
+	if (SqrMagnitude(h1) > 0)
+	{
+		h1.Normalize();
+		mPitch = acos(DotProd(h1, Vector3(0, 1, 0)));
+	}
+
+	Vector3 h2 = direction;// h2.x = 0; 
+	
+	if (SqrMagnitude(h2) > 0)
+	{
+		h2.Normalize();
+		mYaw = -acos(DotProd(h2, h1));//Vector3(0, 1, 0)));
+	}
+
+	cout<<"here2 " << DotProd(h1, Vector3(0, 1, 0)) << " " << mPitch << endl;
 	CalculateFromPitchAndYaw();
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2837)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2838)
@@ -10,4 +10,9 @@
 winHeight=768
 camPosition=483.398f 242.364f 186.078f
+camDirection=1 1 0
 useFullScreen=0
-numSsaoSamples=8
+
+############
+# shader stuff
+expFactor=0.1f
+#numSsaoSamples=8
