Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Plane3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Plane3.cpp	(revision 2944)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Plane3.cpp	(revision 2945)
@@ -121,15 +121,16 @@
 	mD = -w / mag;
 
+	/*
 	// find point on plane
-	/*const Vector3 pt = mNormal * -mD;
+	const Vector3 pt = mNormal * -mD;
 
 	// transform point
 	const Vector3 newPt = m * pt;
+
 	// transform normal
-	const Vector3 newNormal = TransformNormal(m, newPt);
+	nNormal = Normalize(TransformNormal(m, newPt));
 
-	const float mag = Magnitude(newNormal);
-
-	return Plane3(newNormal / mag,  newPt / mag);*/
+	mD = -DotProd(mNormal, newPt);
+	*/
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2944)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2945)
@@ -35,19 +35,18 @@
 			 uniform float amb)
 {
-	float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f);
-	//float4 lightDir = float4(0.0f, 1.0f, 0.0f, 0.0f);
+	const float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f);
+	const float3 light = normalize(lightDir.xyz);
+	const float diffuseLight = saturate(dot(normal, light));
+	
+	/*
 	float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f);
+	float3 light2 = normalize(lightDir2.xyz);
+	float diffuseLight2 = saturate(dot(normal, light2));
+*/
+	float diffuse = diffuseLight;// + diffuseLight2;
 
 	// global ambient
 	const float4 ambient = 0.25f;
-
-	// float3 L = normalize(lightPosition - position);
-	float3 light = normalize(lightDir.xyz);
-	float3 light2 = normalize(lightDir2.xyz);
-
-	float diffuseLight = saturate(dot(normal, light));
-	float diffuseLight2 = saturate(dot(normal, light2));
-
-	float diffuse = diffuseLight + diffuseLight2;
+	//const float4 ambient = 0.0f;
 
 	return (ambient + diffuse) * color * (1.0f - amb) + amb * color;
@@ -73,6 +72,5 @@
 	float amb = norm.w;
 
-	// expand normal
-	float3 normal = normalize(norm.xyz);// * 2.0f - float4(1.0f));
+	float3 normal = normalize(norm.xyz);
 
 	float4 col = shade(IN, color, position, normal, amb);
@@ -95,8 +93,5 @@
 					 )
 {
-	float s;
-
 	float total_d = 0.0;
-	//float total_d = tex2D(shadowMap, lightSpacePos).x;
 
 	for (int i = 0; i < NUM_SAMPLES; ++ i) 
@@ -118,6 +113,5 @@
 		float shadowDepth = tex2D(shadowMap, texcoord).x;
 
-		total_d += step(shadowDepth, depth);
-		//total_d += length(offsetTransformed);
+		total_d += step(depth, shadowDepth);
 	}
 
@@ -199,5 +193,5 @@
 	
 	/*
-
+	// hard shadows
 	float shadowDepth = tex2D(shadowMap, lightSpacePos.xy).x;
 
@@ -212,5 +206,7 @@
 	return OUT;
 }
+
 #else
+
 
 pixel main_shadow(fragment IN, 
@@ -231,29 +227,37 @@
 	float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0));
 	float4 position = tex2D(positions, IN.texCoord.xy);
-
-
-	// an ambient color term
-	float amb = norm.w;
-
-	float3 normal = normalize(norm.xyz);
-	float4 col = shade(IN, color, position, normal, amb);
-	
-	position *= maxDepth;
-	position.w = 1.0f;
-	
-	float4 lightSpacePos = mul(shadowMatrix, position);
-	lightSpacePos /= lightSpacePos.w;
-
-	OUT.color = col;
-
-	float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTexture);
-
-	if (amb < 0.9f) // hack: prevent shadowing the sky	
-	{
-		// base lighting
-		const float baseLighting = 0.3f;
-		OUT.color *= baseLighting + (1.0f - baseLighting) * (1.0f - shadowTerm);
-	}
-	
+	
+	const float3 normal = normalize(norm.xyz);
+	const float3 lightDir = normalize(float3(0.8f, -1.0f, 0.7f));
+
+	// hack: an emmisive color term
+	float emmisive = norm.w;
+
+	// diffuse intensity
+	const float angle = saturate(dot(normal, lightDir)); 
+	float diffuse = angle;
+
+	// calc diffuse illumination + shadow term
+	if ((emmisive < 0.95f) // hack: prevent shadowing the sky	
+		&& (angle > 1e-3f)
+		)
+	{
+		position *= maxDepth;
+		position.w = 1.0f;
+
+		float4 lightSpacePos = mul(shadowMatrix, position);
+		lightSpacePos /= lightSpacePos.w;
+
+		float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTexture);
+
+		diffuse *= shadowTerm;
+	}
+
+	// global ambient
+	const float4 ambient = 0.25f;
+	
+	// base lighting
+	OUT.color = (ambient + diffuse) * color * (1.0f - emmisive) + emmisive * color;
+
 	// also write out depth component
 	OUT.color.w = color.w;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2944)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2945)
@@ -282,8 +282,6 @@
 	//-- first find the free parameter values n, and P (the projection center), and the projection depth
 
-	//const float n = ComputeN(bounds_ls);
-	const float n = ComputeNOpt(lightSpace, extremalPoints, body);
-
-	cout << "n: " << n << endl;
+	const float n = ComputeN(bounds_ls);
+	//const float n = ComputeNOpt(lightSpace, extremalPoints, body); cout << "n: " << n << endl;
 
 	if (n >= 1e6f) // light direction nearly parallel to view => switch to uniform
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2944)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2945)
@@ -100,6 +100,5 @@
 static int winHeight = 768;
 
-//const float shadowSize = 4096;
-const float shadowSize = 2048;
+int shadowSize = 2048;
 
 static float winAspectRatio = 1.0f;
@@ -313,4 +312,5 @@
 
 		env.GetBoolParam(string("useLODs"), useLODs);
+		env.GetIntParam(string("shadowSize"), shadowSize);
 
 		//env.GetStringParam(string("modelPath"), model_path);
@@ -330,4 +330,5 @@
 		cout << "camPosition: " << camPos << endl;
 		cout << "temporal coherence: " << ssaoTempCohFactor << endl;
+		cout << "shadow size: " << shadowSize << endl;
 
 		//cout << "model path: " << model_path << endl;
@@ -747,11 +748,12 @@
 	glEnable(GL_LIGHTING);
 	glEnable(GL_LIGHT0);
-	glEnable(GL_LIGHT1);
-	
-	GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
+	
+	///////////
+	//-- first light: sunlight
+
+	//GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
+	GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0};
 	GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0};
 	GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
-	    
-	GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
 
 	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
@@ -759,11 +761,19 @@
 	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
 
+	GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f};
+	glLightfv(GL_LIGHT0, GL_POSITION, position);
+
+#if 0
 
 	////////////
 	//-- second light
+	
+	// physically incorrect to have second directional light, 
+	// but gives nicer shading for fixed function
+
+	glEnable(GL_LIGHT1);
 
 	GLfloat ambient1[] = {0.2, 0.2, 0.2, 1.0};
 	GLfloat diffuse1[] = {1.0, 1.0, 1.0, 1.0};
-	//GLfloat diffuse1[] = {0.5, 0.5, 0.5, 1.0};
 	GLfloat specular1[] = {0.0, 0.0, 0.0, 1.0};
 
@@ -772,12 +782,14 @@
 	glLightfv(GL_LIGHT1, GL_SPECULAR, specular1);
 
-	
-	//////////////////////////////
-
-	GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f};
-	glLightfv(GL_LIGHT0, GL_POSITION, position);
-
 	GLfloat position1[] = {-0.5f, 0.5f, 0.4f, 0.0f};
 	glLightfv(GL_LIGHT1, GL_POSITION, position1);
+
+	//GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
+
+#endif
+
+	//////////////////////////////
+
+	GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
 
 	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
@@ -1006,7 +1018,8 @@
 	glLightfv(GL_LIGHT0, GL_POSITION, position);
 
+#if 0
 	GLfloat position1[] = {-0.5f, 0.5f, 0.4f, 0.0f};
 	glLightfv(GL_LIGHT1, GL_POSITION, position1);
-
+#endif
 
 	if (renderLightView)
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2901)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2945)
@@ -10,7 +10,8 @@
 winHeight=768
 camPosition=483.398f 242.364f 186.078f
-camDirection=0 1 0
+camDirection=1 0 0
 useFullScreen=0
 useLODs=1
+shadowSize=2048
 #modelPath=data/city/model/
 
