Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 2840)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 2952)
@@ -3,7 +3,8 @@
 
 #include "glInterface.h"
+#include "common.h"
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
-#include "common.h"
+
 
 namespace CHCDemoEngine 
@@ -37,5 +38,4 @@
 	static CGparameter sModelMatrixParam;
 
-
 protected:
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2945)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2952)
@@ -33,9 +33,8 @@
 			 uniform float4 position,
 			 uniform float3 normal,
-			 uniform float amb)
-{
-	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));
+			 uniform float amb,
+			 float3 lightDir)
+{
+	const float diffuseLight = saturate(dot(normal, lightDir));
 	
 	/*
@@ -60,5 +59,6 @@
 		   uniform sampler2D colors,
 		   uniform sampler2D positions,
-		   uniform sampler2D normals	
+		   uniform sampler2D normals,
+		   uniform float3 lightDir
 		   )
 {
@@ -74,5 +74,5 @@
 	float3 normal = normalize(norm.xyz);
 
-	float4 col = shade(IN, color, position, normal, amb);
+	float4 col = shade(IN, color, position, normal, amb, lightDir);
 	
 	//OUT.color = float4(1.0f);
@@ -88,5 +88,5 @@
 					 uniform float w,
 					 uniform float2 lightSpacePos,
-					 float depth,
+					 uniform float depth,
 					 uniform float2 samples[NUM_SAMPLES],
 					 uniform sampler2D noiseTexture
@@ -132,5 +132,6 @@
 				  uniform float4x4 shadowMatrix,
 				  uniform float maxDepth,
-				  uniform float sampleWidth
+				  uniform float sampleWidth,
+				  uniform float3 lightDir
 				  )
 {
@@ -219,5 +220,6 @@
 				  uniform float sampleWidth,
 				  uniform sampler2D noiseTexture,
-				  uniform float2 samples[NUM_SAMPLES]
+				  uniform float2 samples[NUM_SAMPLES],
+				  uniform float3 lightDir
 				  )
 {
@@ -229,6 +231,5 @@
 	
 	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;
@@ -240,5 +241,5 @@
 	// calc diffuse illumination + shadow term
 	if ((emmisive < 0.95f) // hack: prevent shadowing the sky	
-		&& (angle > 1e-3f)
+		&& (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity
 		)
 	{
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2951)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2952)
@@ -48,23 +48,23 @@
 vtxout vtx(vtxin IN, 
 		   const uniform float4x4 ModelViewProj,
-		   uniform float4x4 ModelMatrix)
+		   uniform float4x4 ModelView)
 {
-   vtxout OUT;
-  
-   // transform the vertex position into eye space
-   OUT.color = IN.color;
+	vtxout OUT;
 
-   OUT.texCoord = IN.texCoord;
-   OUT.worldPos = mul(ModelMatrix, IN.position);
+	// transform the vertex position into eye space
+	OUT.color = IN.color;
 
-   // transform the vertex position into eye space
-   //OUT.position = mul(ModelViewProj, OUT.worldPos);
-   OUT.position = mul(glstate.matrix.mvp, IN.position);
+	OUT.texCoord = IN.texCoord;
 
-   OUT.normal = IN.normal;
+	// transform the vertex position into eye space
+	OUT.position = mul(glstate.matrix.mvp, IN.position);
+	//OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position);
+	OUT.worldPos = mul(ModelView, IN.position);
 
-   OUT.mypos = OUT.position;
+	OUT.normal = IN.normal;
 
-   return OUT;
+	OUT.mypos = OUT.position;
+
+	return OUT;
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2947)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h	(revision 2952)
@@ -19,5 +19,5 @@
 class Vector3;
 class Camera;
-class Light;
+class DirectionalLight;
 
 /** This class implements a the computation of single shadow map
@@ -30,5 +30,5 @@
 		The shadow map has resolution size * size.
 	*/
-	ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam);
+	ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam);
 
 	~ShadowMap();
@@ -115,5 +115,5 @@
 	Matrix4x4 mTextureMatrix;
 	/// the used light
-	Light *mLight;
+	DirectionalLight *mLight;
 	/// the scene camera
 	Camera *mCamera;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2944)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 2952)
@@ -1,4 +1,4 @@
-#ifndef _DeferredRenderer_H__
-#define _DeferredRenderer_H__
+#ifndef _DEFERREDRENDERER_H__
+#define _DEFERREDRENDERER_H__
 
 #include "common.h"
@@ -17,4 +17,5 @@
 class Matrix4x4;
 class ShadowMap;
+class DirectionalLight;
 
 
@@ -29,5 +30,5 @@
 			
 		The parameter scaleFactor must be reciprocal value of the 
-		scale factor used for creating the positions texture. It is used recover the 
+		scale factor used for creating the world space position texture. It is used recover the 
 		exact scene size that was scaled in order to improve floating point precision.
 	*/
@@ -42,4 +43,5 @@
 				const Matrix4x4 &projViewMatrix, 
 				float tempCohFactor, 
+				DirectionalLight *light,
 				ShadowMap *shadowMap = NULL);
 
@@ -69,7 +71,7 @@
 	void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix);
 
-	void FirstPass(FrameBufferObject *fbo);
+	void FirstPass(FrameBufferObject *fbo, DirectionalLight *light);
 
-	void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap);
+	void FirstPassShadow(FrameBufferObject *fbo, DirectionalLight *light, ShadowMap *shadowMap);
 
 	void CombineSsao(FrameBufferObject *fbo);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 2951)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 2952)
@@ -8,4 +8,5 @@
 
 CGparameter Transform3::sModelMatrixParam;
+
 
 Transform3::Transform3(Matrix4x4 *trafo): mMatrix(trafo)
@@ -23,14 +24,12 @@
 {
 	if (!mMatrix) return;
-
+	
 	if (state->GetRenderType() == RenderState::DEFERRED)
 	{
 		cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix->x);
 	}
-//	else
-//	{
-		glPushMatrix();
-		glMultMatrixf((float *)mMatrix->x);
-//	}
+
+	glPushMatrix();
+	glMultMatrixf((float *)mMatrix->x);
 }
 
@@ -45,8 +44,6 @@
 		cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x);
 	}
-//	else
-//	{
-		glPopMatrix();
-//	}
+
+	glPopMatrix();
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2951)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 2952)
@@ -137,5 +137,5 @@
 
 
-ShadowMap::ShadowMap(Light *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam):
+ShadowMap::ShadowMap(DirectionalLight *light, int size, const AxisAlignedBox3 &sceneBox, Camera *cam):
 mSceneBox(sceneBox), mSize(size), mCamera(cam), mLight(light)
 {
@@ -456,5 +456,5 @@
 	const Vector3 projViewDir = GetProjViewDir(lightView * lightProj, frustumPoints);
 
-	//do Light Space Perspective shadow mapping
+	//do DirectionalLight Space Perspective shadow mapping
 	//rotate the lightspace so that the projected light view always points upwards
 	//calculate a frame matrix that uses the projViewDir[lightspace] as up vector
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2951)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2952)
@@ -184,6 +184,7 @@
 
 ShadowMap *shadowMap = NULL;
-Light *light = NULL;
+DirectionalLight *light = NULL;
 DeferredRenderer *ssaoShader = NULL;
+
 
 
@@ -242,8 +243,6 @@
 static CGprogram sCgMrtVertexProgram = NULL;
 
-static CGparameter sModelViewProjMatrixParam;
 static CGparameter sMaxDepthParam;
 static CGparameter sMaxDepthParamTex;
-
 static Matrix4x4 oldViewProjMatrix;
 
@@ -284,4 +283,5 @@
 	Vector3 camPos(.0f, .0f, .0f);
 	Vector3 camDir(.0f, 1.0f, .0f);
+	Vector3 lightDir(-0.8f, 1.0f, -0.7f);
 
 	cout << "=== reading environment file ===" << endl << endl;
@@ -308,4 +308,5 @@
 		env.GetVectorParam(string("camPosition"), camPos);
 		env.GetVectorParam(string("camDirection"), camDir);
+		env.GetVectorParam(string("lightDirection"), lightDir);
 
 		env.GetBoolParam(string("useLODs"), useLODs);
@@ -345,7 +346,10 @@
 
 	visCamera = new Camera(winWidth, winHeight, fov);
-
 	visCamera->SetNear(0.0f);
 	visCamera->Yaw(.5 * M_PI);
+
+	// create a new light
+	light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1));
+
 
 	renderQueue = new RenderQueue(&state, camera);
@@ -449,10 +453,4 @@
 	sceneQuery = new SceneQuery(bvh->GetBox(), traverser);
 
-	//Vector3 lightDir = Normalize(Vector3(0.2, -0.8, -1));
-	Vector3 lightDir = Normalize(-Vector3(0.8f, -1.0f, 0.7f));
-	
-	light = new Light(lightDir, RgbaColor(1, 1, 1, 1));
-
-
 	// frame time is restarted every frame
 	frameTimer.Start();
@@ -495,6 +493,6 @@
 		cgGLLoadProgram(sCgMrtVertexProgram);
 
-		Transform3::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelMatrix");
-		sModelViewProjMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj");
+		//sInvViewProjParam = cgGetNamedParameter(sCgMrtVertexProgram, "InvViewProj");
+		Transform3::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelView");
 	}
 
@@ -757,5 +755,6 @@
 	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
 
-	GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f};
+	Vector3 lightDir = -light->GetDirection();
+	GLfloat position[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f};
 	glLightfv(GL_LIGHT0, GL_POSITION, position);
 
@@ -802,5 +801,4 @@
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
-
 	gluPerspective(fov, winAspectRatio, nearDist, farDist);
 
@@ -823,12 +821,6 @@
 	if ((renderType == RenderState::DEFERRED) || (renderType == RenderState::DEPTH_PASS_DEFERRED))
 	{
-		// set modelview matrix for shaders
-		cgGLSetStateMatrixParameter(sModelViewProjMatrixParam, 
-									CG_GL_MODELVIEW_PROJECTION_MATRIX, 
-									CG_GL_MATRIX_IDENTITY);
-
-		static Matrix4x4 identity = IdentityMatrix();
-		cgGLSetMatrixParameterfc(Transform3::sModelMatrixParam, (const float *)identity.x);
-	}		
+		cgGLSetMatrixParameterfc(Transform3::sModelMatrixParam, (const float *)IdentityMatrix().x);
+	}
 }
 
@@ -1012,11 +1004,12 @@
 
 	// set up lights
-	GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f};
-	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
+	Vector3 lightDir = -light->GetDirection();
+	GLfloat lightPos[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f};
+	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
+
+	// second light
+	//GLfloat lightPos1[] = {-0.5f, 0.5f, 0.4f, 0.0f};
+	//glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);
+
 
 	if (renderLightView)
@@ -1090,5 +1083,5 @@
 
 		ShadowMap *sm = showShadowMap ? shadowMap : NULL;
-		ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, sm);
+		ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, light, sm);
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2946)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 2952)
@@ -8,4 +8,5 @@
 #include "Halton.h"
 #include "ShadowMapping.h"
+#include "Light.h"
 
 
@@ -91,4 +92,7 @@
 static CGparameter sNoiseTexShadowParam;
 static CGparameter sSamplesShadowParam; 
+
+static CGparameter sLightDirParam;
+static CGparameter sLightDirShadowParam;
 
 
@@ -245,6 +249,4 @@
 	if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram);
 
-	//DEL_PTR(mNewFbo);
-	//DEL_PTR(mOldFbo);
 	DEL_PTR(mFbo);
 
@@ -277,4 +279,5 @@
 		sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors");  
 		sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals");
+		sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir");
 	}
 	else
@@ -427,4 +430,5 @@
 		sNoiseTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "noiseTexture");
 		sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples");
+		sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir");
 
 		PoissonDiscSampleGenerator2 poisson(16, 1.0f);
@@ -444,4 +448,5 @@
 							  const Matrix4x4 &projViewMatrix,
 							  float tempCohFactor,
+							  DirectionalLight *light,
 							  ShadowMap *shadowMap)
 {
@@ -477,7 +482,7 @@
 
 	if (shadowMap)
-		FirstPassShadow(fbo, shadowMap);
+		FirstPassShadow(fbo, light, shadowMap);
 	else
-		FirstPass(fbo);
+		FirstPass(fbo, light);
 
 	switch (mShadingMethod)
@@ -691,5 +696,5 @@
 
 
-void DeferredRenderer::FirstPass(FrameBufferObject *fbo)
+void DeferredRenderer::FirstPass(FrameBufferObject *fbo, DirectionalLight *light)
 {
 	GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture();
@@ -717,4 +722,7 @@
 	cgGLEnableTextureParameter(sNormalsTexDeferredParam);
 	
+	Vector3 lightDir = -light->GetDirection();
+	cgGLSetParameter3f(sLightDirParam, lightDir.x, lightDir.y, lightDir.z);
+
 	glColor3f(1.0f, 1.0f, 1.0f);
 
@@ -952,5 +960,7 @@
 
 
-void DeferredRenderer::FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap)
+void DeferredRenderer::FirstPassShadow(FrameBufferObject *fbo, 
+									   DirectionalLight *light, 
+									   ShadowMap *shadowMap)
 {
 	GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture();
@@ -995,4 +1005,7 @@
 	cgGLEnableTextureParameter(sNoiseTexShadowParam);
 
+	Vector3 lightDir = -light->GetDirection();
+	cgGLSetParameter3f(sLightDirShadowParam, lightDir.x, lightDir.y, lightDir.z);
+
 
 	glColor3f(1.0f, 1.0f, 1.0f);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Light.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Light.h	(revision 2891)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Light.h	(revision 2952)
@@ -12,9 +12,9 @@
 /** Class representing a directional light source
 */
-class Light
+class DirectionalLight
 {
 public:
 	
-	Light(const Vector3 &dir, const RgbaColor &col): mDirection(dir), mColor(col) {}
+	DirectionalLight(const Vector3 &dir, const RgbaColor &col): mColor(col) { mDirection = Normalize(dir); }
 
 	Vector3 GetDirection() const { return mDirection; }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2945)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2952)
@@ -11,4 +11,5 @@
 camPosition=483.398f 242.364f 186.078f
 camDirection=1 0 0
+lightDir=-0.8f 1.0f -0.7f
 useFullScreen=0
 useLODs=1
