Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h	(revision 2934)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h	(revision 2942)
@@ -161,5 +161,4 @@
 Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
 Matrix4x4 MyLookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
-Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2941)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2942)
@@ -104,5 +104,7 @@
 	lightSpacePos /= lightSpacePos.w;
 
-	/*float shadowDepth[9];
+	OUT.color = col;
+
+	float shadowDepth[9];
 
 	float w = sampleWidth;
@@ -132,7 +134,12 @@
 
 	d /= 9.0f;
-	*/
-
-	OUT.color = col;
+	
+	if (amb < 0.9f) // hack: prevent shadowing the sky	
+	{
+		const float x = 0.1f;
+		OUT.color *= x + (1.0f - x) * (1.0f - d);
+	}
+	
+	/*
 
 	float shadowDepth = tex2D(shadowMap, lightSpacePos.xy).x;
@@ -142,14 +149,6 @@
 	{
 		OUT.color *= 0.1f;
-	}
-	/*
-	if (amb < 0.9f) // hack: prevent shadowing the sky	
-	{
-		const float x = 0.1f;
-		OUT.color *= x + (1.0f - x) * (1.0f - d);
-	}
-	*/
-	//OUT.color = lightSpacePos;//float4(lightSpacePos.z / lightSpacePos.w);
-	//OUT.color = float4(shadowDepth);
+	}*/
+
 	OUT.color.w = color.w;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2936)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2942)
@@ -89,5 +89,7 @@
 	static void DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2);
 
-
+	/** Internal shador render method.
+	*/
+	void _Render(RenderTraverser *renderer);
 
 	//////////////
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2941)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2942)
@@ -570,26 +570,4 @@
 void ShadowMap::ComputeShadowMap(RenderTraverser *renderer, const Matrix4x4 &projView)
 {
-	const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f);
-	const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f);
-	
-	const Vector3 dir = mLight->GetDirection();
-	//const Vector3 dir(0, 0, -1);
-
-	// set position so that we can see the whole scene
-	//Vector3 pos = mSceneBox.Center();
-	//pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f);
-	//mShadowCam->SetPosition(pos);
-	mShadowCam->SetPosition(mCamera->GetPosition());
-
-	Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir);
-	Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, upVec);
-	//Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, mCamera->GetDirection());
-
-	Matrix4x4 refl = ScaleMatrix(-1, 1, 1); 
-	lightView = lightView * refl;
-
-	mShadowCam->mViewOrientation = lightView;
-
-
 	mFbo->Bind();
 	
@@ -598,6 +576,4 @@
 	glPushAttrib(GL_VIEWPORT_BIT);
 	glViewport(0, 0, mSize, mSize);
-
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 	glDisable(GL_LIGHTING);
@@ -605,35 +581,11 @@
 	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
 
-//glDisable(GL_CULL_FACE);
-
-	glPolygonOffset(1.0f, 2000.0f);
-	glEnable(GL_POLYGON_OFFSET_FILL);
-	//glDisable(GL_POLYGON_OFFSET_FILL);
-
 	glShadeModel(GL_FLAT);
-	glEnable(GL_DEPTH_TEST);
-
-	Matrix4x4 lightProj;
-
-	CalcLightProjection(lightProj);
-
-	glMatrixMode(GL_PROJECTION);
-	glPushMatrix();
-	glLoadMatrixf((float *)lightProj.x);
-
-	mLightProjView = lightView * lightProj;
-
-	cout << "here3" << endl;
-	DEL_PTR(lightPoly);
-	lightPoly = CreatePolyhedron(mLightProjView, mSceneBox);
-	cout << "here4\n" << lightView << endl;
-
-	glMatrixMode(GL_MODELVIEW);
-	glPushMatrix();
-	glLoadIdentity();
-
-	mShadowCam->SetupCameraView();
-
-	dummyMat = mLightProjView;
+
+
+	/////////////
+	//-- render scene into shadow map
+
+	_Render(renderer);
 
 
@@ -648,22 +600,5 @@
 	mTextureMatrix = mLightProjView * biasMatrix; 
 
-
-
-
-	/////////////
-	//-- render scene into shadow map
-
-	renderer->RenderScene();
-
-	
-	glDisable(GL_POLYGON_OFFSET_FILL);
-	glMatrixMode(GL_MODELVIEW);
-	glPopMatrix();
-
-	glMatrixMode(GL_PROJECTION);
-	glPopMatrix();
-
 	glPopAttrib();
-
 	
 	glEnable(GL_LIGHTING);
@@ -680,4 +615,5 @@
 	PrintGLerror("shadow map");
 #endif
+	
 	FrameBufferObject::Release();
 }
@@ -685,4 +621,16 @@
 
 void ShadowMap::RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView)
+{
+	glEnable(GL_LIGHTING);
+	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+	_Render(renderer);
+	
+	glDisable(GL_POLYGON_OFFSET_FILL);
+	glDisable(GL_LIGHTING);
+}
+
+
+void ShadowMap::_Render(RenderTraverser *renderer)
 {
 	const Vector3 dir = mLight->GetDirection();
@@ -700,21 +648,12 @@
 	Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir);
 	Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), dir, upVec);
-	//Matrix4x4 lightView = MyLookAt(mShadowCam->GetPosition(), -dir, mCamera->GetDirection());
-
-	//Matrix4x4 refl = ScaleMatrix(-1, 1, 1); 
-	//lightView = lightView * refl;
 
 	mShadowCam->mViewOrientation = lightView;
 
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-	glEnable(GL_LIGHTING);
-	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 
 	glPolygonOffset(1.0f, 2000.0f);
 	glEnable(GL_POLYGON_OFFSET_FILL);
 	
-	glEnable(GL_DEPTH_TEST);
-
 	Matrix4x4 lightProj;
 	CalcLightProjection(lightProj);
@@ -730,8 +669,4 @@
 	lightPoly = CreatePolyhedron(mLightProjView, mSceneBox);
 
-	Frustum frustum(mLightProjView);
-	cout << "near: " << Normalize(frustum.mClipPlanes[4].mNormal) << endl;
-	cout << "far: " << Normalize(frustum.mClipPlanes[5].mNormal) << endl;
-
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix();
@@ -739,8 +674,7 @@
 
 	//glDisable(GL_CULL_FACE);
-
 	mShadowCam->SetupCameraView();
-	
-
+
+	
 	/////////////
 	//-- render scene into shadow map
@@ -748,20 +682,4 @@
 	renderer->RenderScene();
 
-	
-	glDisable(GL_POLYGON_OFFSET_FILL);
-
-	glDisable(GL_LIGHTING);
-	glDisable(GL_DEPTH_TEST);
-
-	glLineWidth(2);
-	Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox);
-	DrawPoly(hpoly, Vector3(1, 1, 1), Vector3(0, 1, 1));
-
-	DEL_PTR(hpoly);
-
-
-	glEnable(GL_LIGHTING);
-	glEnable(GL_DEPTH_TEST);
-
 	glMatrixMode(GL_MODELVIEW);
 	glPopMatrix();
@@ -770,20 +688,6 @@
 	glPopMatrix();
 
-
-#if 0
-	float *data = new float[mSize * mSize];
-
-	GrabDepthBuffer(data, mFbo->GetDepthTex());
-	ExportDepthBuffer(data, mSize);
-
-	delete [] data;
-	
-	PrintGLerror("shadow map");
-#endif
-	FrameBufferObject::Release();
-}
-
-
-
-
+	
+	glDisable(GL_POLYGON_OFFSET_FILL);
+}
 } // namespace
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2939)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2942)
@@ -1035,5 +1035,5 @@
 	// this would conveniently solves some issues (e.g, skys without shadows)
 
-	//RenderSky();
+	RenderSky();
 	
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp	(revision 2940)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp	(revision 2942)
@@ -777,10 +777,8 @@
 				0,        0,        0,        1);
 
-	Vector3 position = m * -pos;
-	
 	// note: left handed system => we go into positive z
 	m.x[3][0] = -DotProd(nRight, pos);
 	m.x[3][1] = -DotProd(nUp, pos);
-	m.x[3][2] =  DotProd(nDir, pos);
+	m.x[3][2] = DotProd(nDir, pos);
 
 	return m;
@@ -788,24 +786,3 @@
 
 
-Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up) 
-{
-	const Vector3 nDir = Normalize(dir);
-	Vector3 nUp = Normalize(up);
-
-	Vector3 nRight = Normalize(CrossProd(nDir, nUp));
-	nUp = Normalize(CrossProd(nRight, nDir));
-
-	Matrix4x4 m(nRight, nUp, nDir);
-
-	Vector3 position = m * -pos;
-	
-	// note: left handed system => we go into positive z
-	m.x[3][0] = position.x;
-	m.x[3][1] = position.y;
-	m.x[3][2] = position.z;
-
-	return m;
-}
-
-
-}
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2941)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 2942)
@@ -41,5 +41,5 @@
 	mIsOrtho = false;
 
-	SetPosition(Vector3(0, 0, 0));
+	SetPosition(Vector3::ZERO());
 
 	mPitch = mYaw = 0;
