Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 2958)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg	(revision 2959)
@@ -27,11 +27,24 @@
 
 
-struct PixelOutput
+
+struct pixel
 {
-	float4 color: SV_TARGET0;
+  float4 col: COLOR0;
+  float4 pos: COLOR1;
+  float4 norm: COLOR2;
 };
 
+// fragment input
+struct fragin
+{
+	float4 color: COLOR0;  
+	float4 position: POSITION; // eye space
+	float4 texCoord: TEXCOORD0;    
 
-
+	float4 projPos: WPOS;
+	float4 worldPos: TEXCOORD1; // world position
+	float3 normal: TEXCOORD2;
+	float4 mypos: TEXCOORD3;
+};
 //--------------------------------------------------------------------------------------
 // Vertex Shaders
@@ -91,16 +104,15 @@
 
 
-pixel frag_skydome(fragin IN, 
-				   uniform float maxDepth)
+pixel frag_skydome(fragin IN)
 {
 	pixel pix;
 
 	pix.col = IN.color;
-	pix.pos = IN.worldPos;// * maxDepth;
+	pix.pos = IN.worldPos * 1e20;// * maxDepth;
 
 	pix.norm.xyz = IN.normal;
 	
 	// hack: squeeze some information about the ambient term into the target
-	pix.norm.w = 0;
+	pix.norm.w = 1;
 	pix.pos.w = IN.mypos.w;
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2954)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2959)
@@ -33,5 +33,5 @@
 			 uniform float4 position,
 			 uniform float3 normal,
-			 uniform float amb,
+			 uniform float emmisive,
 			 float3 lightDir)
 {
@@ -50,5 +50,6 @@
 	const float4 ambient = glstate.light[0].ambient;
 	
-	return (ambient + diffuse) * color * (1.0f - amb) + amb * color;
+	//return (saturate(((ambient + diffuse))) * (1.0f - emmisive) + emmisive) * color;
+	return saturate((((ambient + diffuse)) * (1.0f - emmisive) + emmisive) * color);
 }
 
@@ -152,5 +153,5 @@
 	const float angle = saturate(dot(normal, lightDir)); 
 	//float4 lightDiffuse = float4(1.0f, 1.0f, 0.9f, 1.0f);
-	float4 lightDiffuse = glstate.light[0].diffuse;
+	const float4 lightDiffuse = glstate.light[0].diffuse;
 	//float4(1.0f, 1.0f, 0.9f, 1.0f);
 
@@ -178,5 +179,5 @@
 	
 	// base lighting
-	OUT.color = (ambient + diffuse) * color * (1.0f - emmisive) + emmisive * color;
+	OUT.color = (emmisive < 0.95) ? (ambient + diffuse) * color : color;
 
 	// also write out depth component
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2958)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2959)
@@ -13,4 +13,7 @@
 
 static CGprogram sCgSkyProgram = NULL;
+static CGprogram sCgMrtFragmentSkyDomeProgram = NULL;
+
+
 static CGparameter sLightDirParam;
 static CGparameter sThetaSunParam;
@@ -60,4 +63,26 @@
 	else
 		cerr << "sky program failed to load" << endl;
+
+	sCgMrtFragmentSkyDomeProgram = 
+		cgCreateProgramFromFile(context, 
+								CG_SOURCE,
+								"src/shaders/sky_preetham.cg", 
+								RenderState::sCgFragmentProfile,
+								"frag_skydome",
+								NULL);
+
+	if (sCgMrtFragmentSkyDomeProgram != NULL)
+	{
+		cgGLLoadProgram(sCgMrtFragmentSkyDomeProgram);
+
+		/*sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth");
+		Material::sDiffuseParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "diffuse");
+		Material::sAmbientParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "ambient");
+
+		cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist);
+		*/
+	}
+	else
+		cerr << "fragment skyprogram failed to load" << endl;
 }
 
@@ -127,7 +152,7 @@
 	Vector3 position = camera->GetPosition();
 
-	const float scaleFactor = 100.0f;
-
-	position.z -= 10 * scaleFactor;
+	const float scaleFactor = 80.0f;
+
+	position.z -= 3 * scaleFactor;
 	Matrix4x4 m = TranslationMatrix(position);
 
@@ -147,6 +172,11 @@
 	cgGLEnableProfile(RenderState::sCgVertexProfile);
 	cgGLBindProgram(sCgSkyProgram);
-	
-	
+
+	
+	if (state->GetRenderPassType() == RenderState::DEFERRED)
+	{
+		cgGLEnableProfile(RenderState::sCgFragmentProfile);
+		cgGLBindProgram(sCgMrtFragmentSkyDomeProgram);
+	}	
 
 	// Render sky dome.
@@ -155,4 +185,6 @@
 	// Render additively blended sun disc.
 	//RenderSunDisk(sunDir, camera);
+
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2955)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2959)
@@ -28,4 +28,5 @@
 
 	mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f);
+	//mAmbientColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
 	mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
 	mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.cpp	(revision 2958)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.cpp	(revision 2959)
@@ -114,5 +114,5 @@
 	mat->SetAmbient(RgbaColor(0, 0, 0, 0));
 	mat->SetDiffuse(RgbaColor(0, 0, 0, 0));
-
+	mat->SetCullFaceEnabled(false);
 	Geometry *geom = new Geometry(_vertices, _normals, _texcoords, numElements, false);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2958)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2959)
@@ -273,5 +273,4 @@
 static CGparameter sMaxDepthParamTex;
 static Matrix4x4 oldViewProjMatrix;
-static CGprogram sCgMrtFragmentSkyDomeProgram = NULL;
 
 
@@ -547,25 +546,25 @@
 		cerr << "fragment tex program failed to load" << endl;
 
-	sCgMrtFragmentSkyDomeProgram = 
+	RenderState::sCgMrtFragmentProgram = 
 		cgCreateProgramFromFile(sCgContext, 
 								CG_SOURCE,
-								"src/shaders/sky_preetham.cg", 
+								"src/shaders/mrt.cg", 
 								RenderState::sCgFragmentProfile,
-								"frag_skydome",
+								"frag",
 								NULL);
 
-	if (sCgMrtFragmentSkyDomeProgram != NULL)
-	{
-		cgGLLoadProgram(sCgMrtFragmentSkyDomeProgram);
-
-		/*sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth");
+	if (RenderState::sCgMrtFragmentProgram != NULL)
+	{
+		cgGLLoadProgram(RenderState::sCgMrtFragmentProgram);
+
+		sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth");
 		Material::sDiffuseParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "diffuse");
 		Material::sAmbientParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "ambient");
 
 		cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist);
-		*/
 	}
 	else
-		cerr << "fragment skyprogram failed to load" << endl;
+		cerr << "fragment program failed to load" << endl;
+	
 
 	PrintGLerror("init");
@@ -618,5 +617,5 @@
 void InitGLstate() 
 {
-	glClearColor(0.3f, 0.3f, 0.4f, 1.0f);
+	glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
 	
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -643,5 +642,5 @@
 	glDisable(GL_TEXTURE_2D);
 
-	GLfloat ambientColor[] = {0.5, 0.5, 0.5, 1.0};
+	GLfloat ambientColor[] = {0.2, 0.2, 0.2, 1.0};
 	GLfloat diffuseColor[] = {1.0, 0.0, 0.0, 1.0};
 	GLfloat specularColor[] = {0.0, 0.0, 0.0, 1.0};
@@ -671,14 +670,16 @@
 	if (!skyDome) cerr << "loadig plane failed" << endl;
 
-	preetham = new SkyPreetham(3.0f, skyDome);
+	const float turbitiy = 3.0f;
+	preetham = new SkyPreetham(turbitiy, skyDome);
 
 
 	//////////////////////////////
 
-	//GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
-	GLfloat lmodel_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
+	//GLfloat lmodel_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
+	GLfloat lmodel_ambient[] = {0.7f, 0.7f, 0.8f, 1.0f};
 
 	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
-	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
+	//glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
+	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
 	glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT);
 }
@@ -795,6 +796,6 @@
 void SetupLighting()
 {
-	//glEnable(GL_LIGHTING);
 	glEnable(GL_LIGHT0);
+	glDisable(GL_LIGHT1);
 	
 	Vector3 lightDir = -light->GetDirection();
@@ -807,4 +808,5 @@
 	GLfloat diffuse[] = {1.0f, 0.95f, 0.85f, 1.0f};
 	GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
+	//GLfloat specular[] = {0.0f, 0.0f, 0.0f, 1.0f};
 
 	Vector3 sunAmbient;
@@ -832,5 +834,5 @@
 	diffuse[1] = sunDiffuse.y;
 	diffuse[2] = sunDiffuse.z;
-
+	
 	//cout<< "sunambient: " << sunAmbient << endl;
 	//cout<< "sundiffuse: " << sunDiffuse << endl;
@@ -1101,5 +1103,4 @@
 	RenderSky();
 	
-
 
 	if ((renderMethod == RENDER_DEFERRED) ||
@@ -1960,12 +1961,9 @@
 void RenderSky()
 {
-	glEnable(GL_LIGHTING);
+	//glEnable(GL_LIGHTING);
 	cgGLEnableProfile(RenderState::sCgVertexProfile);
 
-	if (state.GetRenderPassType() == RenderState::DEFERRED)
-	{
-		cgGLEnableProfile(RenderState::sCgFragmentProfile);
-		cgGLBindProgram(sCgMrtFragmentSkyDomeProgram);
-	}
+	if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED))
+		state.SetRenderPassType(RenderState::DEFERRED);
 
 	SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end();
@@ -1976,8 +1974,8 @@
 	//cube->Render(&state);
 	//aeroplane->Render(&state);
-	glDisable(GL_CULL_FACE);
+	//glEnable(GL_LIGHTING);
+
 	preetham->Compute(-light->GetDirection(), camera, &state);
-	glEnable(GL_CULL_FACE);
-
+	
 	cgGLDisableProfile(RenderState::sCgVertexProfile);
 	cgGLDisableProfile(RenderState::sCgFragmentProfile);
@@ -2034,4 +2032,5 @@
 
 	glDepthFunc(GL_LESS);
+	state.Reset();
 
 	PrintGLerror("visibleobjects");
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 2959)
@@ -11,7 +11,6 @@
 camPosition=483.398f 242.364f 186.078f
 camDirection=1 0 0
-#lightDirection=-0.8f 1.0f -0.7f
-#lightDirection=0.2f -1.0f -.5f
-lightDirection=0.0f 0.0f -1.0f
+lightDirection=-0.8f 1.0f -0.7f
+#lightDirection=0.0f 0.0f -1.0f
 useFullScreen=0
 useLODs=1
