Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3088)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3089)
@@ -6,6 +6,6 @@
 //-- ssao + gi parameters
 
-//#define NUM_SAMPLES 8
-#define NUM_SAMPLES 16
+#define NUM_SAMPLES 8
+//#define NUM_SAMPLES 16
 
 // for quadratic falloff
@@ -43,5 +43,5 @@
 
 #define MIN_DEPTH_DIFF 1e-2f
-#define PRECISION_SCALE 1e-1f
+#define PRECISION_SCALE 1e-2f
 
 // burnout
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3087)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3089)
@@ -33,5 +33,4 @@
 			 uniform float4 color,
 			 uniform float3 normal,
-			 uniform float emmisive,
 			 float3 lightDir)
 {
@@ -49,5 +48,4 @@
 	// hack: prevent shading the sky
 	if (color.w > 1e19f) outColor = color;
-	//if (emmisive > 1.5f) outColor = color;
 	else outColor = (ambient + diffuse) * color;
 
@@ -70,9 +68,6 @@
 	float4 color = tex2Dlod(colors, float4(IN.texCoord, 0, 0));
 	
-
-	// an ambient color term
-	float amb = color.w;
 	float3 normal = normalize(norm.xyz);
-	float4 col = shade(IN, color, normal, amb, lightDir);
+	float4 col = shade(IN, color, normal, lightDir);
 	
 	OUT.color = col;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3084)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3089)
@@ -42,5 +42,5 @@
 
 
-#pragma position_invariant vtx
+//#pragma position_invariant vtx
 
 vtxout vtx(vtxin IN)
@@ -61,5 +61,4 @@
 }
 
-#pragma position_invariant fragtex
 
 pixel fragtex(fragin IN, 
@@ -91,6 +90,4 @@
 
 
-#pragma position_invariant frag
-
 pixel frag(fragin IN, uniform float4x4 viewMatrix)
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3088)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3089)
@@ -54,5 +54,5 @@
 								   float3 bl, float3 br, float3 tl, float3 tr)
 {
-	const float eyeSpaceDepth = tex2D(tex, texcoord).w;
+	const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w;
 	float3 viewVec = Interpol(texcoord, bl, br, tl, tr);
 	float3 samplePos = -viewVec * eyeSpaceDepth;
@@ -80,6 +80,6 @@
 							   uniform float3 oldbr,
 							   uniform float3 oldtl,
-							   uniform float3 oldtr
-							  // float dummy3
+							   uniform float3 oldtr,
+							   float3 worldPos
 							   )
 {
@@ -87,5 +87,6 @@
 
 	const float2 offsetTransformed = myreflect(offset, mynoise);
-	const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor;
+	float2 texCoord = texcoord0 + offsetTransformed * scaleFactor;
+	//texCoord.x += 0.5f / 1024.0f; texCoord.y += 0.5f / 768.0f;
 	const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos;
 
@@ -95,14 +96,16 @@
 
 	// fit from unit cube into 0 .. 1
-	const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f;
-
+	float2 oldTexCoords = projPos.xy * 0.5f + 0.5f;
 	// retrieve the sample from the last frame
-	float4 oldCol = tex2D(oldTex, oldTexCoords);
-
-	float oldEyeSpaceDepth = oldCol.w;// dummy3;
+	float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0));
+
+	float oldEyeSpaceDepth = oldCol.w;
 	float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr);
 	float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth;
 
 	float dDiff = length(oldSamplePos - samplePos.xyz);
+
+	if (length(worldPos.xyz - samplePos.xyz) > 5.0f)
+		dDiff = .0f;
 
 	return dDiff;
@@ -150,14 +153,8 @@
 
 	// retrieve the sample from the last frame
-	//float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0));
-	float4 oldCol = tex2D(oldTex, oldTexCoords);
-
-	//eyeSpaceDepth = 1e6f;
-	
-	//const float dummy3 = 1e-4f;
-	//const float oldEyeSpaceDepth = 1e5f * dummy3;
-	//const float oldEyeSpaceDepth = oldCol.z / dummy3;
+	float4 oldCol = tex2Dlod(oldTex, float4(oldTexCoords, 0, 0));
+	//float4 oldCol = tex2D(oldTex, oldTexCoords);
+
 	const float oldEyeSpaceDepth = oldCol.w;
-
 	//oldTexCoords.x += 0.5f / 1024.0f; oldTexCoords.y += 0.5f / 768.0f;
 
@@ -166,20 +163,11 @@
 	float3 oldSamplePos = oldEyePos - viewVec * oldEyeSpaceDepth;
 
-	//const float oldDepth = oldCol.z;
 	const float depthDif = length(oldSamplePos - worldPos.xyz);
-	//eyeSpaceDepth *= dummy3;
-	
-	//const float depthDif = abs(oldEyeSpaceDepth - eyeSpaceDepth);// * 1e4f;
-	//const float depthDif = abs(oldEyeSpaceDepth - dummy2) * 1e3f;
-
-	//const float oldNumSamples = oldCol.y;
-	const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence);
-	float newWeight;
-
-	bool isValid = true;
+	
+	float notValid = 0.5f;
 
 	for (int i = 0; i < NUM_SAMPLES; ++ i) 
 	{
-		float sampleDif  = ComputeDifference(samples[i],
+		float sampleDif = ComputeDifference(samples[i],
 			                  oldTex,
 							  oldModelViewProj,
@@ -191,13 +179,17 @@
 							  eyePos,
 							  oldEyePos,
-							  oldbl, oldbr, oldtl, oldtr
-							  //,dummy3
-							  );
-
-		//if (sampleDif > 1e-1f) isValid = false;
-	}
-
+							  oldbl, oldbr, oldtl, oldtr,
+							  worldPos.xyz);
+
+		if (sampleDif >= 1e-1f) ++ notValid;
+	}
+
+	//if (notValid < 1.0f) temporalCoherence = 4.0f;
 	// the number of valid samples in this frame
 	//const float newNumSamples = ao.y;
+
+	//const float oldNumSamples = oldCol.y;
+	const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence);
+	float newWeight;
 
 	if ((temporalCoherence > 1e-6f)
@@ -207,5 +199,5 @@
 		// if visibility changed in the surrounding area we have to recompute
 		//&& (oldNumSamples > 0.8f * newNumSamples)
-		&& isValid
+		//&& (notValid < 1.0f)
 		)
 	{
@@ -213,5 +205,5 @@
 		newWeight = oldWeight + 1.0f;
 		illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight;
-		//if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0;
+		if (notValid > 1.0f) newWeight = 2;
 	}
 	else
@@ -221,12 +213,7 @@
 	}
 
-	//illum_col.x = depthDif;
-	
-	//isValid = 0.0f;
-	//illum_col.y = isValid / 16.0f;
 	illum_col.y = newWeight;
 	illum_col.w = eyeSpaceDepth;
-	//illum_col.z = dummy2;
-
+	
 	return illum_col;
 }
@@ -291,6 +278,6 @@
 		// the distance_scale offset is used to avoid singularity that occurs at global illumination when 
 		// the distance to a sample approaches zero
+		const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);
 		//const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f;
-		const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);
 
 #if 1
@@ -338,5 +325,5 @@
 	// reconstruct position from the eye space depth
 	const float3 viewDir = IN.view;
-	const float eyeSpaceDepth = tex2D(colors, IN.texCoord).w;
+	const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w;
 	const float3 eyeSpacePos = -viewDir * eyeSpaceDepth;
 	const float4 worldPos = float4(eyePos + eyeSpacePos, 1.0f);
@@ -399,9 +386,8 @@
 	float3 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-	//if (ao.y < 10.0f) 
-	//	ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
-
-	//OUT.illum_col = col * ao.x;
-	OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
+	if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
+
+	OUT.illum_col = col * ao.x;
+	//OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
 	//OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);
 	//OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 3062)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp	(revision 3089)
@@ -176,5 +176,5 @@
 	glLoadIdentity();
 
-	glOrtho(+xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z); 
+	glOrtho(xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z); 
 
 	glMatrixMode(GL_MODELVIEW);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3085)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3089)
@@ -37,5 +37,4 @@
 
 	const Vector3 pos = GetWorldCenter();
-
 	const float dist = SqrDistance(pos, viewPoint);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3074)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3089)
@@ -22,8 +22,9 @@
 void Transform3::Load(RenderState *state)
 {
-	if (mIsIdentity) return;
-
-	glPushMatrix();
-	glMultMatrixf((float *)mMatrix.x);
+	if (!mIsIdentity) 
+	{
+		glPushMatrix();
+		glMultMatrixf((float *)mMatrix.x);
+	}
 }
 
@@ -31,6 +32,8 @@
 void Transform3::Unload(RenderState *state)
 {
-	if (mIsIdentity) return;
-	glPopMatrix();
+	if (!mIsIdentity)
+	{
+		glPopMatrix();
+	}
 }
 
@@ -40,5 +43,4 @@
 	mIsIdentity = false;
 	mMatrix = mMatrix * trafo;
-	//mMatrix = trafo * mMatrix;
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3085)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3089)
@@ -459,7 +459,9 @@
 
 	LoadModel("hbuddha.dem", dynamicObjects);
+	//LoadModel("hbuddha2.dem", dynamicObjects);
 	buddha = dynamicObjects.back();
 	
 	const Vector3 sceneCenter(470.398f, 240.364f, 182.5f);
+	
 	Matrix4x4 transl = TranslationMatrix(sceneCenter);
 	buddha->GetTransform()->SetMatrix(transl);
@@ -938,7 +940,6 @@
 	
 		glEnable(GL_MULTISAMPLE_ARB);
-		
 		state.SetRenderTechnique(FORWARD);
-		glEnable(GL_LIGHTING);
+		//glEnable(GL_LIGHTING);
 
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -950,5 +951,4 @@
 		glDisable(GL_MULTISAMPLE_ARB);
 		state.SetUseAlphaToCoverage(false);
-
 		state.SetRenderTechnique(DEPTH_PASS);
 
@@ -967,5 +967,4 @@
 
 		glEnable(GL_MULTISAMPLE_ARB);
-		
 		state.SetRenderTechnique(DEPTH_PASS);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3088)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3089)
@@ -143,4 +143,5 @@
 	p->Bind();
 
+	// interpolate the view vector
 	Vector3 bl = mCornersView[0];
 	Vector3 br = mCornersView[1];
@@ -153,8 +154,18 @@
 	glBegin(GL_QUADS);
 
-	glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f);
+	/*glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex3f(-offs, -offs, -0.5f);
 	glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex3f( offs, -offs, -0.5f);
 	glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex3f( offs,  offs, -0.5f);
 	glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex3f(-offs,  offs, -0.5f);
+
+	glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex2f(-offs, -offs);
+	glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex2f(offs, -offs);
+	glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex2f(offs, offs);
+	glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex2f(-offs, offs);
+*/	
+	glTexCoord2f(0, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, bl.x, bl.y, bl.z); glVertex2f(0, 0);
+	glTexCoord2f(1, 0); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, br.x, br.y, br.z); glVertex2f(1, 0);
+	glTexCoord2f(1, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tr.x, tr.y, tr.z); glVertex2f(1, 1);
+	glTexCoord2f(0, 1); glMultiTexCoord3fARB(GL_TEXTURE1_ARB, tl.x, tl.y, tl.z); glVertex2f(0, 1);
 
 	glEnd();
@@ -427,5 +438,5 @@
 	mIllumFboIndex = 2 - mIllumFboIndex;
 	
-
+	// enable fragment shading
 	ShaderManager::GetSingleton()->EnableFragmentProfile();
 
@@ -436,6 +447,5 @@
 	glDisable(GL_DEPTH_TEST);
 
-	glPushAttrib(GL_VIEWPORT_BIT);
-	glViewport(0, 0, mWidth, mHeight);
+	glPolygonMode(GL_FRONT, GL_FILL);
 
 	glMatrixMode(GL_PROJECTION);
@@ -444,9 +454,16 @@
 
 	const float offs = 0.5f;
-	glOrtho(-offs, offs, -offs, offs, 0, 1);
+	//glOrtho(-offs, offs, -offs, offs, 0, 1);
+	//glOrtho(0, 1, 0, 1, 0, 1);
+	gluOrtho2D(0, 1, 0, 1);
+
 
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix();
 	glLoadIdentity();
+
+	
+	glPushAttrib(GL_VIEWPORT_BIT);
+	glViewport(0, 0, mWidth, mHeight);
 
 	if (shadowMap)
@@ -497,4 +514,5 @@
 	glPopMatrix();
 
+	// viewport
 	glPopAttrib();
 
@@ -591,5 +609,6 @@
 	glMultiTexCoord4fARB(GL_TEXTURE6_ARB, x, y + y_offs, x, y - y_offs); // top bottom
 
-	glVertex3f(x - 0.5f, y - 0.5f, -0.5f);
+	//glVertex3f(x - 0.5f, y - 0.5f, -0.5f);
+	glVertex2f(x, y);
 }
 
@@ -608,6 +627,4 @@
 
 	sCgAntiAliasingProgram->Bind();
-
-	glColor3f(1.0f, 1.0f, 1.0f);
 
 	glBegin(GL_QUADS);
@@ -762,5 +779,6 @@
 	poisson.Generate((float *)filterOffsets);
 
-	const float filterWidth = 10.0f;
+	//const float filterWidth = 10.0f;
+	const float filterWidth = 7.0f;
 	const float xoffs = filterWidth / fbo->GetWidth();
 	const float yoffs = filterWidth / fbo->GetHeight();
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3076)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 3089)
@@ -169,4 +169,8 @@
 
 #endif
+		geom->mVertices[i].x += 470.398f;
+		geom->mVertices[i].y += 240.364f;
+		geom->mVertices[i].z += 182.5f;
+
 		if (i < geom->mTexcoordCount)
 		{
@@ -238,6 +242,6 @@
 	while (fgets(str, len, file) != NULL)
 	{
-		if (1)//(line % 100) == 0)
-			cout << "read line " << line << " " << str;
+//		if (1)//(line % 100) == 0)
+//			cout << "read line " << line << " " << str;
 		switch (str[0]) 
 		{
@@ -342,6 +346,6 @@
 	//-- texture
 
-	int texId = -1;
-	//int texId = 0;
+	//int texId = -1;
+	int texId = 0;
 	str.write(reinterpret_cast<char *>(&texId), sizeof(int));
 
@@ -386,6 +390,6 @@
 	//-- write textures
 
-	//int textureCount = 1;
-	int textureCount = 0;
+	int textureCount = 1;
+	//int textureCount = 0;
 
 	ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int));
@@ -401,6 +405,5 @@
 		ofile.write(texName.c_str(), sizeof(char) * texnameSize);
 
-		int boundS = 1;
-		int boundT = 1;
+		int boundS = 1, boundT = 1;
 
 		ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int));
