Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2942)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2943)
@@ -137,5 +137,6 @@
 	if (amb < 0.9f) // hack: prevent shadowing the sky	
 	{
-		const float x = 0.1f;
+		// base lighting
+		const float x = 0.4f;
 		OUT.color *= x + (1.0f - x) * (1.0f - d);
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2934)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2943)
@@ -22,5 +22,6 @@
 mTexturesEnabled(false), 
 mMode(RENDER),
-mRenderType(FIXED)
+mRenderType(FIXED),
+mUseAlphaToCoverage(true)
 {
 	Reset(); 
@@ -96,7 +97,8 @@
 		mAlphaTestEnabled = false;
 		
-		// not needed with GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
-		//glDisable(GL_ALPHA_TEST);
-		glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
+		if (mUseAlphaToCoverage)
+			glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
+		else
+			glDisable(GL_ALPHA_TEST);
 	}
 	else if (!mAlphaTestEnabled && alphaTest)
@@ -104,7 +106,8 @@
 		mAlphaTestEnabled = true;
 		
-		// not needed with GL_SAMPLE_ALPHA_TO_COVERAGE_ARB
-		//glEnable(GL_ALPHA_TEST);
-		glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
+		if (mUseAlphaToCoverage)
+			glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
+		else
+			glEnable(GL_ALPHA_TEST);
 	}
 
@@ -146,3 +149,9 @@
 
 
+void RenderState::SetUseAlphaToCoverage(bool useAlphaToCoverage)
+{
+	mUseAlphaToCoverage = useAlphaToCoverage;
 }
+
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp	(revision 2936)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp	(revision 2943)
@@ -268,11 +268,16 @@
 	planePoly = SplitPolygon(planePoly);
 
-	// something is wrong, probably some numerical error
-	if (!planePoly) 
-	{ 
-		cerr << "should not happen" << endl; 
+	if (planePoly) 
+	{
+		// we can now savely add the new polygon
+		clippedPolyhedron->Add(planePoly);
+	}
+	else if (0)
+	{
+		// something is wrong, probably some numerical error
+		cerr << "no polygon: should not happen" << endl; 
 		return new Polyhedron(*this); 
 	}
-
+	
 
 	/////////////
@@ -317,7 +322,4 @@
 	}
 
-	// we can now savely add the new polygon
-	clippedPolyhedron->Add(planePoly);
-
 	return clippedPolyhedron;
 }
@@ -357,5 +359,5 @@
 				break;
 			case Polygon3::FRONT_SIDE:
-				cerr << "SplitPolygon: should not come here" << endl;
+				//cerr << "SplitPolygon: should not come here" << endl;
 				DEL_PTR(polygon);
                 break;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2942)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2943)
@@ -87,5 +87,4 @@
 	Vector3 GetProjViewDir(const Matrix4x4 &lightSpace, const VertexArray &pts) const;
 
-	static void DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2);
 
 	/** Internal shador render method.
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2854)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2943)
@@ -57,4 +57,7 @@
 	*/
 	inline int GetCurrentVboId() const { return mCurrentVboId; }
+	/** If alpha to coverage is instead of alpha testing
+	*/
+	void SetUseAlphaToCoverage(bool useAlphaToCoverage);
 
 	void SetRenderType(RenderType type) { mRenderType = type; }
@@ -86,4 +89,6 @@
 
 	RenderType mRenderType;
+
+	bool mUseAlphaToCoverage;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2942)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2943)
@@ -23,6 +23,4 @@
 static Polyhedron *polyhedron = NULL;
 static Polyhedron *lightPoly = NULL;
-static Vector3 dummyPt;
-static Matrix4x4 dummyMat;
 
 
@@ -159,5 +157,5 @@
 
 
-void ShadowMap::DrawPoly(Polyhedron *poly, const Vector3 &color, const Vector3 &color2)
+static void DrawPoly(Polyhedron *poly, const Vector3 &color)
 {
 	if (!poly) return;
@@ -167,10 +165,4 @@
 		glColor3f(color.x, color.y, color.z);
 
-		if (i == poly->NumPolygons() - 1) // hack: different color for near
-		{
-			//glLineWidth(2);
-			glColor3f(color2.x, color2.y, color2.z);
-		
-		}
 		glBegin(GL_LINE_LOOP);
 
@@ -184,6 +176,4 @@
 
 		glEnd();
-		
-		//if (i == poly->NumPolygons() - 1) glLineWidth(1);
 	}
 }
@@ -192,18 +182,6 @@
 void ShadowMap::DrawPolys()
 {
-	DrawPoly(lightPoly, Vector3(1, 0, 1), Vector3(1, 1, 1));
-	DrawPoly(polyhedron, Vector3(0, 1, 0), Vector3(0, 1, 1));
-
-	glPointSize(10.0f);
-
-	Vector3 pt = Vector3::ZERO();
-	//Vector3 pt = dummyPt;
-
-	Matrix4x4 myMat = Invert(dummyMat);
-	pt = myMat * pt;
-
-	glBegin(GL_POINTS);
-	glVertex3f(pt.x, pt.y, pt.z);
-	glEnd();
+	DrawPoly(lightPoly, Vector3(1, 0, 1));
+	DrawPoly(polyhedron, Vector3(0, 1, 0));
 }
 
@@ -235,9 +213,7 @@
 	//-- first find the free parameter values n, and P (the projection center), and the projection depth
 
-	//const float n = 1e2f;
-	//const float n = 1e6f;
 	const float n = ComputeN(bounds_ls);
 
-	cout << "n: " << n << endl;
+	//cout << "n: " << n << endl;
 
 	const Vector3 nearPt = GetNearCameraPointE(body);
@@ -248,17 +224,8 @@
 	// the start point has the x and y coordinate of e, the z coord of the near plane of the light volume
 	const Vector3 startPt = Vector3(lsNear.x, lsNear.y, bounds_ls.Max().z);
-	//const Vector3 schas = lightSpace * mCamera->GetPosition();
-	//const Vector3 startPt = Vector3(schas.x, schas.y, bounds_ls.Max().z);
-
-	cout << "mx: " <<  bounds_ls.Max() << endl;
-	cout << "mn: " << bounds_ls.Min() << endl;
-
+	
 	// the new projection center
 	const Vector3 projCenter = startPt + Vector3::UNIT_Z() * n;
 
-	cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl;
-
-	dummyPt = startPt;
-
 	//construct a translation that moves to the projection center
 	const Matrix4x4 projectionCenter = TranslationMatrix(-projCenter);
@@ -270,6 +237,4 @@
 	const float dx = fabs(bounds_ls.Max()[0] - bounds_ls.Min()[0]);
 
-	cout << "d: " << d << " dy: " << dy << " dx: " << dx << endl;
-
 	
 
@@ -281,10 +246,6 @@
 	matLispSM = GetFrustum(-1.0, 1.0, -1.0, 1.0, n, n + d);
 
-	//cout << "lispsm\n" << matLispSM << endl;
-
 	// translate to the projection center
 	matLispSM = projectionCenter * matLispSM;
-
-	//cout << "new\n" << matLispSM << endl;
 
 	// transform into OpenGL right handed system
@@ -314,5 +275,5 @@
 		Vector3 pt = *it;
 		Vector3 ptE = eyeView * pt;
-//cout<<"i"<< pt.z;
+		
 		if (ptE.z > 0) cerr <<"should not happen " << ptE.z << endl;
 		else
@@ -376,17 +337,8 @@
 	Vector3 projDir(b_lp - e_lp);
 
-	Matrix4x4 dummy = Invert(lightSpace);
-	Invert(dummy);
-	Vector3 dummyVec = dummy * e_lp;
-	Vector3 dummyVec2 = dummy * b_lp;
-
-	//projDir.z = -projDir.z;
-
-	cout << "dummy: " << Normalize(dummyVec2 - dummyVec) << endl;
 	//project the view direction into the shadow map plane
 	projDir.y = .0f;
 
 	return Normalize(projDir);
-	//return projDir;
 }
 
@@ -435,6 +387,4 @@
 	const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints);
 
-	cout << "projViewDir: " << projViewDir << " orig " << mCamera->GetDirection() << endl;
-								
 	//do Light Space Perspective shadow mapping
 	//rotate the lightspace so that the projected light view always points upwards
@@ -444,5 +394,4 @@
 	const Matrix4x4 frame = MyLookAt(Vector3::ZERO(), projViewDir, Vector3::UNIT_Y());
 
-	cout << "frame\n " << frame << endl;
 	lightProj *= frame;
 
@@ -464,10 +413,7 @@
 	AxisAlignedBox3 lightPts = GetExtremalPoints(lightView * lightProj, frustumPoints);
 
-	cout << "max: " << lightPts.Max() << " min: " << lightPts.Min() << endl;
 	// focus projection matrix on the extremal points => scale to unit cube
 	Matrix4x4 scaleTranslate = GetFittingProjectionMatrix(lightPts);
 
-	cout << "scaleTranslate:\n" << scaleTranslate << endl;
-
 	lightProj = lightProj * scaleTranslate;
 
@@ -475,7 +421,4 @@
 
 	AxisAlignedBox3 lightPtsNew = GetExtremalPoints(mymat, frustumPoints);
-
-	cout << "newmax: " << lightPtsNew.Max() << endl;
-	cout << "newmin: " << lightPtsNew.Min() << endl;
 
 	// we have to flip the signs in order to tranform to opengl right handed system
@@ -578,5 +521,5 @@
 
 	glDisable(GL_LIGHTING);
-	glDisable(GL_TEXTURE_2D);
+	//glDisable(GL_TEXTURE_2D);
 	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
 
@@ -602,4 +545,5 @@
 	glPopAttrib();
 	
+	glShadeModel(GL_SMOOTH);
 	glEnable(GL_LIGHTING);
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
@@ -623,10 +567,20 @@
 {
 	glEnable(GL_LIGHTING);
-	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
+	
 	_Render(renderer);
 	
+	/*glDisable(GL_LIGHTING);
+	glDisable(GL_DEPTH_TEST);
+
+	//glLineWidth(2);
+	Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox);
+	DrawPoly(hpoly, Vector3(1, 1, 1));
+
+	DEL_PTR(hpoly);
+
+	glEnable(GL_LIGHTING);
+	glEnable(GL_DEPTH_TEST);*/
+
 	glDisable(GL_POLYGON_OFFSET_FILL);
-	glDisable(GL_LIGHTING);
 }
 
@@ -637,5 +591,4 @@
 	//const Vector3 dir(0, 0, -1);
 
-	cout << "dir: " << dir << endl;
 	mShadowCam->SetDirection(dir);
 
@@ -664,5 +617,4 @@
 
 	mLightProjView = lightView * lightProj;
-	dummyMat = mLightProjView;
 
 	DEL_PTR(lightPoly);
@@ -682,4 +634,5 @@
 	renderer->RenderScene();
 
+
 	glMatrixMode(GL_MODELVIEW);
 	glPopMatrix();
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2942)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2943)
@@ -100,5 +100,6 @@
 static int winHeight = 768;
 
-const float shadowSize = 4096;
+//const float shadowSize = 4096;
+const float shadowSize = 2048;
 
 static float winAspectRatio = 1.0f;
@@ -922,4 +923,6 @@
 
 		// the scene is rendered withouth any shading	
+		glShadeModel(GL_FLAT);
+	
 		glDisable(GL_LIGHTING);
 	
@@ -934,4 +937,6 @@
 		{
 			shadowChanged = false;
+
+			//glEnable(GL_MULTISAMPLE_ARB);
 
 			cgGLDisableProfile(RenderState::sCgFragmentProfile);
@@ -944,6 +949,10 @@
 			BvhNode::SetCurrentState(1);
 
+			state.SetUseAlphaToCoverage(false);
+
 			// the scene is rendered withouth any shading	
 			shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView);
+
+			state.SetUseAlphaToCoverage(true);
 
 			// change back state
@@ -1025,4 +1034,6 @@
 	{
 		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+		glShadeModel(GL_SMOOTH);
+
 		RenderVisibleObjects();
 	}
