Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 2960)
@@ -3,6 +3,4 @@
 
 #include "glInterface.h"
-#include <Cg/cg.h>
-#include <Cg/cgGL.h>
 #include "common.h"
 
@@ -80,10 +78,4 @@
 	void InitMaterial();
 
-	static CGparameter sDiffuseParam;
-	static CGparameter sDiffuseTexParam;
-
-	static CGparameter sAmbientParam;
-	static CGparameter sAmbientTexParam;
-
 protected:
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2958)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2960)
@@ -67,12 +67,11 @@
 pixel fragtex(fragin IN, 
 			  uniform sampler2D tex, 
-			  uniform float maxDepth, 
-			  uniform float4 ambient, 
-			  uniform float4 diffuse)
+			  uniform float maxDepth)
 {
 	pixel pix;
 
 	// save color in first render target
-	pix.col = (ambient + diffuse) * tex2D(tex, IN.texCoord.xy);
+	// hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
+	pix.col = (glstate.material.emission + glstate.material.diffuse) * tex2D(tex, IN.texCoord.xy);
 	
 	// save world position in second render target
@@ -82,5 +81,5 @@
 
 	// hack: squeeze some information about ambient into the texture
-	pix.norm.w = ambient.x;
+	pix.norm.w = glstate.material.emission.x;
 	// store projection coordinates with positions (used for ssao)
 	pix.pos.w = IN.projPos.w;
@@ -98,12 +97,10 @@
 
 pixel frag(fragin IN, 
-		   uniform float maxDepth, 
-		   uniform float4 ambient, 
-		   uniform float4 diffuse
-		   )
+		   uniform float maxDepth)
 {
 	pixel pix;
 
-	pix.col = diffuse;
+	// hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
+	pix.col = glstate.material.diffuse + glstate.material.emission;
 	pix.pos = IN.worldPos * maxDepth;
 
@@ -111,5 +108,5 @@
 	
 	// hack: squeeze some information about the ambient term into the target
-	pix.norm.w = ambient.x;
+	pix.norm.w = glstate.material.emission.x;
 	pix.pos.w = IN.mypos.w;
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2959)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2960)
@@ -103,49 +103,10 @@
 
 
-void SkyPreetham::Compute(const Vector3 &sunDir, Camera *camera, RenderState *state)
-{
-	float sun_theta[2];
-
-	sun_theta[0] = acos(sunDir.z);
-
-	const float cos_theta = cos(sun_theta[0]);
-	sun_theta[1] = cos_theta * cos_theta;
-
+void SkyPreetham::RenderSkyDome(const Vector3 &sunDir, Camera *camera, RenderState *state)
+{
+	pair<float, float> sun_theta;
 	Vector3 zenithColor;
-
-	zenithColor.x = ( 0.00165f * CBQ(sun_theta[0]) - 0.00374f * SQR(sun_theta[0]) + 0.00208f * sun_theta[0] + 0.0f)     * SQR(mTurbidity) +	
-				    (-0.02902f * CBQ(sun_theta[0]) + 0.06377f * SQR(sun_theta[0]) - 0.03202f * sun_theta[0] + 0.00394f) * mTurbidity +
-					( 0.11693f * CBQ(sun_theta[0]) - 0.21196f * SQR(sun_theta[0]) + 0.06052f * sun_theta[0] + 0.25885f);
-
-	zenithColor.y = (0.00275f  * CBQ(sun_theta[0]) - 0.00610f * SQR(sun_theta[0]) + 0.00316f * sun_theta[0] + 0.0f)     * SQR(mTurbidity) +
-	                (-0.04214f * CBQ(sun_theta[0]) + 0.08970f * SQR(sun_theta[0]) - 0.04153f * sun_theta[0] + 0.00515f) * mTurbidity +
-		            ( 0.15346f * CBQ(sun_theta[0]) - 0.26756f * SQR(sun_theta[0]) + 0.06669f * sun_theta[0] + 0.26688f);
-	
-	zenithColor.z  = (float)((4.0453f * mTurbidity - 4.9710f) *	tan((4.0f / 9.0f - mTurbidity / 120.0f) * 
-							 (M_PI - 2.0f * sun_theta[0])) - 0.2155f * mTurbidity + 2.4192f);
-
-	// convert kcd/m² to cd/m²
-	zenithColor.z *= 1000.0f;
-
-	double ABCDE_x[5], ABCDE_y[5], ABCDE_Y[5];
-
-	ABCDE_x[0] = -0.01925 * mTurbidity - 0.25922;
-	ABCDE_x[1] = -0.06651 * mTurbidity + 0.00081;
-	ABCDE_x[2] = -0.00041 * mTurbidity + 0.21247;
-	ABCDE_x[3] = -0.06409 * mTurbidity - 0.89887;
-	ABCDE_x[4] = -0.00325 * mTurbidity + 0.04517;
-
-	ABCDE_y[0] = -0.01669 * mTurbidity - 0.26078;
-	ABCDE_y[1] = -0.09495 * mTurbidity + 0.00921;
-	ABCDE_y[2] = -0.00792 * mTurbidity + 0.21023;
-	ABCDE_y[3] = -0.04405 * mTurbidity - 1.65369;
-	ABCDE_y[4] = -0.01092 * mTurbidity + 0.05291;
-
-	ABCDE_Y[0] =  0.17872 * mTurbidity - 1.46303;
-	ABCDE_Y[1] = -0.35540 * mTurbidity + 0.42749;
-	ABCDE_Y[2] = -0.02266 * mTurbidity + 5.32505;
-	ABCDE_Y[3] =  0.12064 * mTurbidity - 2.57705;
-	ABCDE_Y[4] = -0.06696 * mTurbidity + 0.37027;
-
+	vector<Vector3> ABCDE;
+	ComputeFactors(sunDir, zenithColor, ABCDE, sun_theta);
 
 	// Move skybox with camera.
@@ -161,12 +122,12 @@
 	
 	cgGLSetParameter3f(sLightDirParam, sunDir.x, sunDir.y, sunDir.z);
-	cgGLSetParameter2f(sThetaSunParam, sun_theta[0], sun_theta[1]);
+	cgGLSetParameter2f(sThetaSunParam, sun_theta.first, sun_theta.second);
 	cgGLSetParameter3f(sZenithColorParam, zenithColor.x, zenithColor.y, zenithColor.z);
 
-	cgGLSetParameter3f(sAColorParam, ABCDE_x[0], ABCDE_y[0], ABCDE_Y[0]);
-	cgGLSetParameter3f(sBColorParam, ABCDE_x[1], ABCDE_y[1], ABCDE_Y[1]);
-	cgGLSetParameter3f(sCColorParam, ABCDE_x[2], ABCDE_y[2], ABCDE_Y[2]);
-	cgGLSetParameter3f(sDColorParam, ABCDE_x[3], ABCDE_y[3], ABCDE_Y[3]);
-	cgGLSetParameter3f(sEColorParam, ABCDE_x[4], ABCDE_y[4], ABCDE_Y[4]);
+	cgGLSetParameter3f(sAColorParam, ABCDE[0].x, ABCDE[0].y, ABCDE[0].z);
+	cgGLSetParameter3f(sBColorParam, ABCDE[1].x, ABCDE[1].y, ABCDE[1].z);
+	cgGLSetParameter3f(sCColorParam, ABCDE[2].x, ABCDE[2].y, ABCDE[2].z);
+	cgGLSetParameter3f(sDColorParam, ABCDE[3].x, ABCDE[3].y, ABCDE[3].z);
+	cgGLSetParameter3f(sEColorParam, ABCDE[4].x, ABCDE[4].y, ABCDE[4].z);
 
 	cgGLEnableProfile(RenderState::sCgVertexProfile);
@@ -265,2 +226,96 @@
 	*/
 }
+
+
+void SkyPreetham::ComputeFactors(const Vector3 &sunDir, 
+								 Vector3 &zenithColor, 
+								 vector<Vector3> &ABCDE,  
+								 std::pair<float, float> &sunThetha) const
+{
+	sunThetha.first = acos(sunDir.z);
+
+	const float cos_theta = cos(sunThetha.first);
+	sunThetha.second = cos_theta * cos_theta;
+
+	zenithColor.x = ( 0.00165f * CBQ(sunThetha.first) - 0.00374f * SQR(sunThetha.first) + 0.00208f * sunThetha.first + 0.0f)     * SQR(mTurbidity) +	
+				    (-0.02902f * CBQ(sunThetha.first) + 0.06377f * SQR(sunThetha.first) - 0.03202f * sunThetha.first + 0.00394f) * mTurbidity +
+					( 0.11693f * CBQ(sunThetha.first) - 0.21196f * SQR(sunThetha.first) + 0.06052f * sunThetha.first + 0.25885f);
+
+	zenithColor.y = ( 0.00275f * CBQ(sunThetha.first) - 0.00610f * SQR(sunThetha.first) + 0.00316f * sunThetha.first + 0.0f)     * SQR(mTurbidity) +
+	                (-0.04214f * CBQ(sunThetha.first) + 0.08970f * SQR(sunThetha.first) - 0.04153f * sunThetha.first + 0.00515f) * mTurbidity +
+		            ( 0.15346f * CBQ(sunThetha.first) - 0.26756f * SQR(sunThetha.first) + 0.06669f * sunThetha.first + 0.26688f);
+	
+	zenithColor.z  = (float)((4.0453f * mTurbidity - 4.9710f) *	tan((4.0f / 9.0f - mTurbidity / 120.0f) * 
+							 (M_PI - 2.0f * sunThetha.first)) - 0.2155f * mTurbidity + 2.4192f);
+
+	// convert kcd/m² to cd/m²
+	zenithColor.z *= 1000.0f;
+
+	ABCDE.push_back(Vector3(-0.01925 * mTurbidity - 0.25922, -0.01669 * mTurbidity - 0.26078,  0.17872 * mTurbidity - 1.46303));
+	ABCDE.push_back(Vector3(-0.06651 * mTurbidity + 0.00081, -0.09495 * mTurbidity + 0.00921, -0.35540 * mTurbidity + 0.42749));
+	ABCDE.push_back(Vector3(-0.00041 * mTurbidity + 0.21247, -0.00792 * mTurbidity + 0.21023, -0.02266 * mTurbidity + 5.32505));
+	ABCDE.push_back(Vector3(-0.06409 * mTurbidity - 0.89887, -0.04405 * mTurbidity - 1.65369,  0.12064 * mTurbidity - 2.57705));
+	ABCDE.push_back(Vector3(-0.00325 * mTurbidity + 0.04517, -0.01092 * mTurbidity + 0.05291, -0.06696 * mTurbidity + 0.37027));
+}
+
+
+void SkyPreetham::ComputeSunColor(const Vector3 &sunDir, Vector3 &ambient, Vector3 &diffuse) const
+{
+	// sunDir is sun direction
+	// ambient color: shadow color
+	// diffuse color: sun color
+	pair<float, float> sun_theta;
+	Vector3 zenithColor;
+	vector<Vector3> ABCDE;
+
+	ComputeFactors(sunDir, zenithColor, ABCDE, sun_theta);
+
+	ambient = zenithColor;
+
+	Vector3 zenith_XYZ;                                                                                             
+
+	zenith_XYZ.x = (ambient.x / ambient.y) * ambient.z;                                                                        
+	zenith_XYZ.y = ambient.z;                                                                                          
+	zenith_XYZ.z = ((1.0f - ambient.x - ambient.y) / ambient.y) * ambient.z;                                                                
+
+	ambient.x =  3.240479f * zenith_XYZ.x - 1.537150f * zenith_XYZ.y - 0.498535f * zenith_XYZ.z;
+	ambient.y = -0.969256f * zenith_XYZ.x + 1.875992f * zenith_XYZ.y + 0.041556f * zenith_XYZ.z;	
+	ambient.z =  0.055648f * zenith_XYZ.x - 0.204043f * zenith_XYZ.y + 1.057311f * zenith_XYZ.z;
+
+	// downscale ambient color
+	ambient *= 5e-5f;
+
+	// simulate the sun intensity by modulating the ambient term.
+	ambient *= (1.0f - 0.9f * DotProd(sunDir, Vector3::UNIT_Z()));
+	ambient += Vector3(0.2f);
+
+	Vector3 num;
+	  
+	num.x = (1.0f + ABCDE[0].x * exp(ABCDE[1].x / sunDir.z)) * (1.0f + ABCDE[2].x)+ ABCDE[4].x;    
+	num.y = (1.0f + ABCDE[0].y * exp(ABCDE[1].y / sunDir.z)) * (1.0f + ABCDE[2].y)+ ABCDE[4].y;   
+	num.z = (1.0f + ABCDE[0].z * exp(ABCDE[1].z / sunDir.z)) * (1.0f + ABCDE[2].z)+ ABCDE[4].z;   
+
+	Vector3 den;
+
+	den.x = (1.0f + ABCDE[0].x * exp(ABCDE[1].x)) * (1.0f + ABCDE[2].x * exp(ABCDE[3].x * sun_theta.first) + ABCDE[4].x * sun_theta.second);  
+	den.y = (1.0f + ABCDE[0].y * exp(ABCDE[1].y)) * (1.0f + ABCDE[2].y * exp(ABCDE[3].y * sun_theta.first) + ABCDE[4].y * sun_theta.second);   
+	den.z = (1.0f + ABCDE[0].z * exp(ABCDE[1].z)) * (1.0f + ABCDE[2].z * exp(ABCDE[3].z * sun_theta.first) + ABCDE[4].z * sun_theta.second);   
+
+
+	Vector3 xyY = (num / den) * zenithColor;    
+
+	Vector3 XYZ;                                                                                             
+
+	XYZ.x = (xyY.x / xyY.y) * xyY.z;                                                                        
+	XYZ.y = xyY.z;                                                                                          
+	XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z;                                                                
+
+
+	Vector3 color;	
+	color.x =  3.240479f * XYZ.x - 1.537150f * XYZ.y - 0.498535f * XYZ.z;
+	color.y = -0.969256f * XYZ.x + 1.875992f * XYZ.y + 0.041556f *XYZ.z;	
+	color.z =  0.055648f * XYZ.x - 0.204043f * XYZ.y + 1.057311f * XYZ.z;
+
+	// Calculate final sun diffuse color.
+	diffuse = color * 0.00017f;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2959)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2960)
@@ -8,10 +8,4 @@
 namespace CHCDemoEngine
 {
-
-CGparameter Material::sDiffuseParam;
-CGparameter Material::sDiffuseTexParam;
-CGparameter Material::sAmbientParam;
-CGparameter Material::sAmbientTexParam;
-
 
 RgbaColor RandomColor(float a, float b)
@@ -67,32 +61,12 @@
 
 	if (mTexture)
-	{
 		mTexture->Bind();
-	}
 	else
-	{
 		glBindTexture(GL_TEXTURE_2D, 0);
-	}
 
-	if (state->GetRenderPassType() == RenderState::DEFERRED)
-	{
-		if (mTexture)
-		{
-			cgGLSetParameter4f(sAmbientTexParam, mEmmisiveColor.r, mEmmisiveColor.g, mEmmisiveColor.b, mEmmisiveColor.a);
-			cgGLSetParameter4f(sDiffuseTexParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a);
-		}
-		else
-		{
-			cgGLSetParameter4f(sAmbientParam, mEmmisiveColor.r, mEmmisiveColor.g, mEmmisiveColor.b, mEmmisiveColor.a);
-			cgGLSetParameter4f(sDiffuseParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a);
-		}
-	}
-	else if (state->GetRenderPassType() == RenderState::FIXED)
-	{
-		glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
-		glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r);
-		glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r);
-		glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
-	}
+	glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
+	glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r);
+	glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r);
+	glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 2960)
@@ -25,4 +25,10 @@
 	if (mIsIdentity) return;
 	
+	// note: would not need to pass the model matrix, 
+	// as all required information is avaiabl in the glstate
+	// however, we require it compute the word positions,
+	// as computing the world position by use the inverse of the viewprojection
+	// matrix turned out to be too inaccurate for temporal reprojection
+
 	if (state->GetRenderPassType() == RenderState::DEFERRED)
 	{
@@ -39,4 +45,5 @@
 	if (mIsIdentity) return;
 
+	// reset model matrix
 	if (state->GetRenderPassType() == RenderState::DEFERRED)
 	{
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h	(revision 2958)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h	(revision 2960)
@@ -3,5 +3,5 @@
 
 #include "glInterface.h"
-
+#include "common.h"
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
@@ -22,7 +22,15 @@
 	virtual ~SkyPreetham();
 
-	void Compute(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Camera *camera, CHCDemoEngine::RenderState *state);
+	void RenderSkyDome(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Camera *camera, CHCDemoEngine::RenderState *state);
 
 	static void Init(CGcontext context);
+
+	void ComputeFactors(const CHCDemoEngine::Vector3 &sunDir, 
+		                CHCDemoEngine::Vector3 &zenithColor, 
+						std::vector<CHCDemoEngine::Vector3> &ABCDE, 
+						std::pair<float, float> &sunThetha) const;
+
+	void ComputeSunColor(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Vector3 &ambient, CHCDemoEngine::Vector3 &diffuse) const;
+
 
 protected:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2959)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2960)
@@ -37,5 +37,4 @@
 #include "Light.h"
 #include "SceneEntityConverter.h"
-#include "SunColor.h"
 #include "ObjConverter.h"
 #include "SkyPreetham.h"
@@ -415,4 +414,21 @@
 	InitGLstate();
 
+
+	Vector3 cubeCenter(470.398f, 240.364f, 182.5f);
+	AxisAlignedBox3 box(cubeCenter - Vector3(2.0f), cubeCenter + Vector3(2.0f));
+
+	Material *mat = new Material(RgbaColor(1, 0.4, 0.4, 0));
+	Transform3 *tf = new Transform3();
+	cube = SceneEntityConverter().ConvertBox(box, mat, tf);
+
+	//aeroplane = ObjConverter().Load(model_path + "toyplane.obj");
+	//if (!aeroplane)	cerr << "loadig plane failed" << endl;
+
+	skyDome = ObjConverter().Load(model_path + "sky.obj");
+	if (!skyDome) cerr << "loadig plane failed" << endl;
+
+	const float turbitiy = 3.0f;
+	preetham = new SkyPreetham(turbitiy, skyDome);
+
 	glEnable(GL_MULTISAMPLE_ARB);
 	glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
@@ -538,6 +554,4 @@
 
 		sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth");
-		Material::sDiffuseTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "diffuse");
-		Material::sAmbientTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "ambient");
 
 		cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist);
@@ -559,7 +573,4 @@
 
 		sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth");
-		Material::sDiffuseParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "diffuse");
-		Material::sAmbientParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "ambient");
-
 		cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist);
 	}
@@ -625,6 +636,4 @@
 	glEnable(GL_DEPTH_TEST);
 
-	SetupLighting();
-
 	glColor3f(1.0f, 1.0f, 1.0f);
 	glShadeModel(GL_SMOOTH);
@@ -656,20 +665,4 @@
 	else
 		cout << "successfully created font" << endl;
-
-	Vector3 cubeCenter(470.398f, 240.364f, 182.5f);
-	AxisAlignedBox3 box(cubeCenter - Vector3(2.0f), cubeCenter + Vector3(2.0f));
-
-	Material *mat = new Material(RgbaColor(1, 0.4, 0.4, 0));
-	Transform3 *tf = new Transform3();
-	cube = SceneEntityConverter().ConvertBox(box, mat, tf);
-
-	//aeroplane = ObjConverter().Load(model_path + "toyplane.obj");
-	//if (!aeroplane)	cerr << "loadig plane failed" << endl;
-
-	skyDome = ObjConverter().Load(model_path + "sky.obj");
-	if (!skyDome) cerr << "loadig plane failed" << endl;
-
-	const float turbitiy = 3.0f;
-	preetham = new SkyPreetham(turbitiy, skyDome);
 
 
@@ -820,5 +813,5 @@
 
 
-	SunColor().Compute(lightDir, sunAmbient, sunDiffuse);
+	preetham->ComputeSunColor(lightDir, sunAmbient, sunDiffuse);
 
 	const float maxComponent = sunDiffuse.MaxComponent();
@@ -1976,5 +1969,5 @@
 	//glEnable(GL_LIGHTING);
 
-	preetham->Compute(-light->GetDirection(), camera, &state);
+	preetham->RenderSkyDome(-light->GetDirection(), camera, &state);
 	
 	cgGLDisableProfile(RenderState::sCgVertexProfile);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SunColor.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SunColor.cpp	(revision 2957)
+++ 	(revision )
@@ -1,122 +1,0 @@
-#include "SunColor.h"
-#include "Vector3.h"
-#include "common.h"
-
-
-using namespace CHCDemoEngine;
-using namespace std;
-
-
-inline float CBQ(float x)
-{
-	return x * x * x;
-}
-
-
-inline float SQR(float x)
-{
-	return x * x ;
-}
-
-
-void SunColor::Compute(const Vector3 &sunDir, Vector3 &ambient, Vector3 &diffuse) const
-{
-	const float turbidity = 3.0f;
-
-	// sunDir is sun direction
-	// ambient color: shadow color
-	// diffuse color: sun color
-
-	float sun_theta[2];
-	
-	sun_theta[0] = acos(sunDir.z);
-
-	const float cos_theta = cos(sun_theta[0]);
-	sun_theta[1] = cos_theta * cos_theta;
-
-	Vector3 zenithColor;
-
-	zenithColor.x = ( 0.00165f * CBQ(sun_theta[0]) - 0.00374f * SQR(sun_theta[0]) + 0.00208f * sun_theta[0] + 0.0f)     * SQR(turbidity) +	
-				    (-0.02902f * CBQ(sun_theta[0]) + 0.06377f * SQR(sun_theta[0]) - 0.03202f * sun_theta[0] + 0.00394f) * turbidity +
-					( 0.11693f * CBQ(sun_theta[0]) - 0.21196f * SQR(sun_theta[0]) + 0.06052f * sun_theta[0] + 0.25885f);
-
-	zenithColor.y = (0.00275f  * CBQ(sun_theta[0]) - 0.00610f * SQR(sun_theta[0]) + 0.00316f * sun_theta[0] + 0.0f)     * SQR(turbidity) +
-	                (-0.04214f * CBQ(sun_theta[0]) + 0.08970f * SQR(sun_theta[0]) - 0.04153f * sun_theta[0] + 0.00515f) * turbidity +
-		            ( 0.15346f * CBQ(sun_theta[0]) - 0.26756f * SQR(sun_theta[0]) + 0.06669f * sun_theta[0] + 0.26688f);
-	
-	zenithColor.z  = (float)((4.0453f * turbidity - 4.9710f) *	tan((4.0f / 9.0f - turbidity / 120.0f) * 
-							 (M_PI - 2.0f * sun_theta[0])) - 0.2155f * turbidity + 2.4192f);
-
-	// convert kcd/m² to cd/m²
-	zenithColor.z *= 1000.0f;
-
-	ambient = zenithColor;
-
-	Vector3 zenith_XYZ;                                                                                             
-
-	zenith_XYZ.x = (ambient.x / ambient.y) * ambient.z;                                                                        
-	zenith_XYZ.y = ambient.z;                                                                                          
-	zenith_XYZ.z = ((1.0f - ambient.x - ambient.y) / ambient.y) * ambient.z;                                                                
-
-	ambient.x =  3.240479f * zenith_XYZ.x - 1.537150f * zenith_XYZ.y - 0.498535f * zenith_XYZ.z;
-	ambient.y = -0.969256f * zenith_XYZ.x + 1.875992f * zenith_XYZ.y + 0.041556f * zenith_XYZ.z;	
-	ambient.z =  0.055648f * zenith_XYZ.x - 0.204043f * zenith_XYZ.y + 1.057311f * zenith_XYZ.z;
-
-	// downscale ambient color
-	ambient *= 5e-5f;
-
-	// simulate the sun intensity by modulating the ambient term.
-	ambient *= (1.0f - 0.9f * DotProd(sunDir, Vector3::UNIT_Z()));
-	ambient += Vector3(0.2f);
-
-	float ABCDE_x[5], ABCDE_y[5], ABCDE_Y[5];
-
-	ABCDE_x[0] = -0.01925f * turbidity - 0.25922f;
-	ABCDE_x[1] = -0.06651f * turbidity + 0.00081f;
-	ABCDE_x[2] = -0.00041f * turbidity + 0.21247f;
-	ABCDE_x[3] = -0.06409f * turbidity - 0.89887f;
-	ABCDE_x[4] = -0.00325f * turbidity + 0.04517f;
-
-	ABCDE_y[0] = -0.01669f * turbidity - 0.26078f;
-	ABCDE_y[1] = -0.09495f * turbidity + 0.00921f;
-	ABCDE_y[2] = -0.00792f * turbidity + 0.21023f;
-	ABCDE_y[3] = -0.04405f * turbidity - 1.65369f;
-	ABCDE_y[4] = -0.01092f * turbidity + 0.05291f;
-
-	ABCDE_Y[0] =  0.17872f * turbidity - 1.46303f;
-	ABCDE_Y[1] = -0.35540f * turbidity + 0.42749f;
-	ABCDE_Y[2] = -0.02266f * turbidity + 5.32505f;
-	ABCDE_Y[3] =  0.12064f * turbidity - 2.57705f;
-	ABCDE_Y[4] = -0.06696f * turbidity + 0.37027f;
-
-	Vector3 num;
-	  
-	num.x = (1.0f + ABCDE_x[0] * exp( ABCDE_x[1] / sunDir.z )) * (1.0f + ABCDE_x[2])+ ABCDE_x[4];    
-	num.y = (1.0f + ABCDE_y[0] * exp( ABCDE_y[1] / sunDir.z )) * (1.0f + ABCDE_y[2])+ ABCDE_y[4];   
-	num.z = (1.0f + ABCDE_Y[0] * exp( ABCDE_Y[1] / sunDir.z )) * (1.0f + ABCDE_Y[2])+ ABCDE_Y[4];   
-
-
-	Vector3 den;
-
-	den.x = (1.0f + ABCDE_x[0] * exp( ABCDE_x[1] )) * (1.0f + ABCDE_x[2] * exp( ABCDE_x[3] * sun_theta[0] ) + ABCDE_x[4] * sun_theta[1]);  
-	den.y = (1.0f + ABCDE_y[0] * exp( ABCDE_y[1] )) * (1.0f + ABCDE_y[2] * exp( ABCDE_y[3] * sun_theta[0]) + ABCDE_y[4] * sun_theta[1]);   
-	den.z = (1.0f + ABCDE_Y[0] * exp( ABCDE_Y[1] )) * (1.0f + ABCDE_Y[2] * exp( ABCDE_Y[3] * sun_theta[0] ) + ABCDE_Y[4] * sun_theta[1]);   
-
-
-	Vector3 xyY = (num / den) * zenithColor;    
-
-	Vector3 XYZ;                                                                                             
-
-	XYZ.x = (xyY.x / xyY.y) * xyY.z;                                                                        
-	XYZ.y = xyY.z;                                                                                          
-	XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z;                                                                
-
-
-	Vector3 color;	
-	color.x = 3.240479f*XYZ.x -1.537150f*XYZ.y-0.498535f*XYZ.z;
-	color.y = -0.969256f*XYZ.x +1.875992f*XYZ.y +0.041556f*XYZ.z;	
-	color.z = 0.055648f*XYZ.x -0.204043f*XYZ.y +1.057311f*XYZ.z;
-
-	// Calculate final sun diffuse color.
-	diffuse = color * 0.00017f;
-}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SunColor.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SunColor.h	(revision 2955)
+++ 	(revision )
@@ -1,17 +1,0 @@
-#ifndef __SUNCOLOR_H__
-#define __SUNCOLOR_H__
-
-namespace CHCDemoEngine{
-class Vector3;
-}
-
-/** Class describing a plane in 3D space.
-*/
-class SunColor 
-{
-public:
-
-	void Compute(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Vector3 &ambient, CHCDemoEngine::Vector3 &diffuse) const;
-};
-
-#endif
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2960)
@@ -291,12 +291,4 @@
 				>
 			</File>
-			<File
-				RelativePath=".\src\SunColor.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\src\SunColor.h"
-				>
-			</File>
 			<Filter
 				Name="timer"
