Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 3114)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 3326)
@@ -153,13 +153,15 @@
 	*/
 	void Render(RenderState *state, SceneEntity *parent);
-
+	/** Adds a new technique to the material
+	*/
 	void AddTechnique(Technique *t);
-
+	/** Returns the default technique (usually the first)
+	*/
 	Technique *GetDefaultTechnique() const;
 
 	Technique *GetTechnique(int i) const;
-
+	/** Returns the number of techniques associated with this material
+	*/
 	int GetNumTechniques() const;
-
 
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3325)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3326)
@@ -61,5 +61,5 @@
 #define NUM_DOF_TABS 16
 
-#define USE_GTX
+//#define USE_GTX
 
 #define SSAO_FILTER_RADIUS 5
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3325)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3326)
@@ -273,5 +273,5 @@
 		// to the current pixel or if the angle is small enough
 		// to have any influence in the current or last frame
-#if 1
+#if 0
 		const float tooFarAway = step(0.5f, lengthToSample - changeFactor);
 
@@ -281,6 +281,4 @@
 		else
 			validSamples = max(validSamples, pixelValid);
-#else
-		validSamples = max(validSamples, pixelValid);
 #endif
 
@@ -408,5 +406,5 @@
 		// or if the angle is small enough
 		// to have any influence in the current or last frame
-#if 1
+#if 0
 		const float partlyResetThres = 1.0f;
 
@@ -416,6 +414,4 @@
 		else
 			validSamples = max(validSamples, pixelValid);
-#else
-		validSamples = max(validSamples, pixelValid);
 #endif
 
@@ -523,6 +519,10 @@
 	if (eyeSpaceDepth < DEPTH_THRESHOLD)
 	{
-		//ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject);
-		ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals, oldIdx);
+		if (0)
+			ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject);
+		else
+			ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, 
+			           bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, 
+					   isMovingObject, normals, oldIdx);
 	}
 	else
@@ -545,5 +545,5 @@
 	
 	// don't check for moving objects, otherwise almost no coherence
-	if (!isMovingObject)
+	/*if (!isMovingObject)
 	{
 		if (ao.y > completelyResetThres) 
@@ -558,5 +558,6 @@
 			oldIdx = .0f;
 		}
-	}
+	}*/
+
 
 	//////////
@@ -573,8 +574,9 @@
 	OUT.illum_col.w = eyeSpaceDepth;
 
-	// can be used to check if this pixel belongs to a moving object
+	// this value can be used to check if this pixel belongs to a moving object
 	OUT.col.x = SqrLen(diffVec);
 	//OUT.illum_col.z = SqrLen(diffVec);
-	
+
+	OUT.illum_col.xyz = normal.xyz;
 	return OUT;
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3323)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3326)
@@ -192,5 +192,5 @@
 	{
 		// the filtered ssao value
-		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);
+		//OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);
 	}
 
@@ -223,5 +223,5 @@
 	const float convergence = ao.y;
 
-	const float2 xyStep = float2(0, 1.0f / res.y);
+	const float2 xyStep = float2(.0f, 1.0f / res.y);
 	
 	// filter reaches size 1 pixel when sample size reaches threshold 
@@ -232,5 +232,5 @@
 	{
 		// the filtered ssao value
-		ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);
+		//ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);
 	}
 
@@ -249,4 +249,7 @@
 	}
 
+	//OUT.illum_col.xyz = float3(col.w * 5e-3f, 0, 0);
+	OUT.illum_col.xyz = ao.xyz;
+
 	OUT.illum_col.w = col.w;
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3325)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3326)
@@ -15,5 +15,5 @@
 	float4 color: COLOR0;
 	float3 normal: COLOR1;
-	float3 diffVal: COLOR2;
+	//float3 diffVal: COLOR2;
 };
 
@@ -37,5 +37,5 @@
 	float4 outColor;
 
-	// hack: prevent shading the sky
+	// hack: prevent to shade the sky
 	if (color.w > DEPTH_THRESHOLD)
 	{
@@ -171,5 +171,6 @@
 		lightSpacePos /= lightSpacePos.w;
 
-		float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex);
+		float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, 
+			                              lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex);
 		diffuse *= shadowTerm;
 	}
@@ -209,5 +210,4 @@
 	*/
 inline float2 PixelValid(sampler2D oldTex,
-						 sampler2D oldTex2,
 						 float4 color,
 						 float3 difVec,
@@ -220,5 +220,6 @@
 						 float3 oldbr,
 						 float3 oldtl,
-						 float3 oldtr
+						 float3 oldtr,
+						 sampler2D myTex
 						 )
 {
@@ -249,9 +250,9 @@
 	
 	// fit from unit cube into 0 .. 1
-	const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f;
-	//const float2 oldTexCoords = texCoord;
+	const float2 oldTexCoords = backProjPos.xy * .5f + .5f;
+	
 	// retrieve the sample from the last frame
-	const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f));
-	const float4 oldPixel2 = tex2Dlod(oldTex2, float4(oldTexCoords, .0f, .0f));
+	const float4 oldPixel = tex2Dlod(myTex, float4(oldTexCoords, .0f, .0f));
+	const float oldDiff = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)).x;
 
 	// calculate eye space position of sample in old frame
@@ -266,13 +267,15 @@
 	const float squaredLen = SqrLen(difVec);
 	
+
 	// test if this pixel was valid in the old frame
 	float isPixelValid;
 
 	// check if the pixel belonged to a dynamic object in the last frame
-	const bool newDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD);
-	const bool oldDynamic = (oldPixel2.x > DYNAMIC_OBJECTS_THRESHOLD);
+	const bool newDynamic = (squaredLen > 100000);//DYNAMIC_OBJECTS_THRESHOLD);
+	const bool oldDynamic = (oldDiff > 1000000);//DYNAMIC_OBJECTS_THRESHOLD);
+
 
 	// actually 0 means pixel is valid
-	const float pixelIsValid = 0.0f;
+	const float pixelIsValid = .0f;
 	// means that we only use slight temporal coherence over some frames
 	// so that there is no noticeable drag
@@ -281,21 +284,20 @@
 	const float pixelIsNotValid = 100.0f;
 
+
 	// check if the pixel was outside of the frame buffer
-	if ((oldTexCoords.x <= 0) || (oldTexCoords.x >= 1.0f) || 
-		(oldTexCoords.y <= 0) || (oldTexCoords.y >= 1.0f)
+	if ((oldTexCoords.x <= .0f) || (oldTexCoords.x >= 1.0f) || 
+		(oldTexCoords.y <= .0f) || (oldTexCoords.y >= 1.0f)
 		)
 	{
 		isPixelValid = pixelIsNotValid;
 	}
-	else if (// check if changed from dynamic to not dynamic object
-		((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) ||
-		(
-		(oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) &&
-		// check if we have a dynamic object 
-		(oldDynamic || newDynamic) && 
-		// and there is a depth discontinuity
-		(depthDif > MIN_DEPTH_DIFF))))
+	else if ( // check if changed from dynamic to not dynamic object
+   	         ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) ||
+			 (
+			  (oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) &&
+			  (oldDynamic || newDynamic) &&  // check if we have a dynamic object 
+			  (depthDif > MIN_DEPTH_DIFF)))) // and there is a depth discontinuity
 	{	
-		isPixelValid = pixelCouldBeValid; 
+		isPixelValid = pixelCouldBeValid;
 	}
 	else 
@@ -303,5 +305,6 @@
 		isPixelValid = pixelIsValid;
 	}
-
+	
+	//isPixelValid = 2e20f;
 	return float2(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth));
 }
@@ -312,21 +315,21 @@
 */
 pixel PrepareSsao(fragment IN,
-				   uniform sampler2D colorsTex,
-				   uniform sampler2D normalsTex,
-				   uniform sampler2D diffVals,
-				   uniform sampler2D oldTex,
-				   uniform sampler2D oldTex2,
-				   uniform float4x4 modelViewProj,
-				   uniform float4x4 oldModelViewProj,
-				   uniform float3 oldbl,
-				   uniform float3 oldbr,
-				   uniform float3 oldtl,
-				   uniform float3 oldtr,
-				   uniform float3 oldEyePos
-				   )
+				  uniform sampler2D colorsTex,
+				  uniform sampler2D normalsTex,
+				  uniform sampler2D diffVals,
+				  uniform sampler2D oldTex,
+				  uniform float4x4 modelViewProj,
+				  uniform float4x4 oldModelViewProj,
+				  uniform float3 oldbl,
+				  uniform float3 oldbr,
+				  uniform float3 oldtl,
+				  uniform float3 oldtr,
+				  uniform float3 oldEyePos,
+				  uniform sampler2D myTex
+				  )
 {   
 	pixel pix;
 
-	float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
+	float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, .0f, .0f));
 	// store scaled view vector so wie don't have to normalize for e.g., ssao
 	color.w /= length(IN.view);
@@ -337,15 +340,15 @@
 
 	// do reprojection and filter out the pixels that are not save
-	float2 pValid = PixelValid(oldTex,
-		                       oldTex2,
-		                       color, 
-							   difVec.xyz,
-							   IN.texCoord,
-							   IN.view,
-							   oldEyePos,
-							   modelViewProj,
-							   oldModelViewProj,
-							   oldbl, oldbr, oldtl, oldtr
-							   );
+	const float2 pValid = PixelValid(oldTex,
+		                             color, 
+									 difVec.xyz,
+									 IN.texCoord,
+									 IN.view,
+									 oldEyePos,
+									 modelViewProj,							  
+									 oldModelViewProj,
+									 oldbl, oldbr, oldtl, oldtr,
+									 myTex
+									 );
 
 	pix.color = color;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3325)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3326)
@@ -268,4 +268,34 @@
 
 
+static void UpdateSampleTex(Sample2 *samples, int numSamples)
+{
+	glEnable(GL_TEXTURE_2D);
+	glBindTexture(GL_TEXTURE_2D, sampleTex2D);
+		
+	const int w = numSamples; const int h = 1;
+
+	float *tempBuffer = new float[numSamples * 3];
+
+	for (int i = 0; i < numSamples; ++ i)
+	{
+		tempBuffer[i * 3 + 0] = samples[i].x;
+		tempBuffer[i * 3 + 1] = samples[i].y;
+		tempBuffer[i * 3 + 2] = 0;
+		
+	}
+
+	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGB, GL_FLOAT, (float *)tempBuffer);
+
+	glBindTexture(GL_TEXTURE_2D, 0);
+	glDisable(GL_TEXTURE_2D);
+
+	cout << "updated sample texture" << endl;
+
+	delete [] tempBuffer;
+
+	PrintGLerror("noisetexture");
+}
+
+
 static void CreateSampleTex(Sample2 *samples, int numSamples)
 {
@@ -279,6 +309,5 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
-	int w = numSamples;
-	int h = 1;
+	const int w = numSamples; const int h = 1;
 
 	float *tempBuffer = new float[numSamples * 3];
@@ -506,8 +535,6 @@
 
 	string combineSsaoParams[] = 
-		//{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence"};
 		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence", "spatialWeight"};
 
-	//sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13);
 	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9);
 
@@ -517,5 +544,4 @@
 	string filterSsaoParams[] = 
 		{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence", "spatialWeight"};
-
 	sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 9);
 
@@ -549,8 +575,7 @@
 	
 	string prepareSsaoParams[] = 
-		{"colorsTex", "normalsTex", "diffVals", "oldTex", "oldTex2", 
+		{"colorsTex", "normalsTex", "diffVals", "oldTex", 
 		 "oldEyePos", "modelViewProj", "oldModelViewProj",
-		 "oldbl", "oldbr", "oldtl", "oldtr"};
-
+		 "oldbl", "oldbr", "oldtl", "oldtr", "myTex"};
 	sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 12);
 
@@ -673,5 +698,7 @@
 	// if it hasn't been done yet => just output the latest buffer
 	if (!mUseAntiAliasing || !displayAfterAA)
+	{
 		Output(fbo); 
+	}
 
 	glEnable(GL_LIGHTING);
@@ -801,5 +828,14 @@
 		// needs longer to converge
 		GenerateSamples(mSamplingMethod);
-		CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES);
+
+		if (!sampleTex2D)
+		{
+			CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES);
+		}
+		else
+		{
+			UpdateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES);
+		}
+
 		//if (mSortSamples) { SortSamples(); }
 		//sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES);
@@ -936,7 +972,7 @@
 	// read the second buffer, write to the first buffer
 	mIllumFbo->Bind();
-
 	glDrawBuffers(2, mrt + mIllumFboIndex);
 
+	// bind the old buffers for temporal coherence
 	GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
 	GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture();
@@ -1012,6 +1048,4 @@
 	GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
 	
-	//mIllumFbo->Bind();
-	//glDrawBuffers(1, mrt + mIllumFboIndex + 1);
 	mTempFbo->Bind();
 	glDrawBuffers(1, mrt);
@@ -1040,5 +1074,4 @@
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-	//GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture();
 	GLuint ssaoTex = mTempFbo->GetColorBuffer(0)->GetTexture();
 	
@@ -1173,5 +1206,5 @@
 	// flip flop between illumination buffers
 	GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
-	GLuint oldTex2 = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture();
+	GLuint myTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture();
 
 	int i = 0;
@@ -1181,5 +1214,4 @@
 	sCgPrepareSsaoProgram->SetTexture(i ++, diffVals);
 	sCgPrepareSsaoProgram->SetTexture(i ++, oldTex);
-	sCgPrepareSsaoProgram->SetTexture(i ++, oldTex2);
 
 	Vector3 de;
@@ -1193,8 +1225,11 @@
 	sCgPrepareSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix);
 
+
 	for (int j = 0; j < 4; ++ j, ++ i)
 	{
 		sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z);
 	}
+
+	sCgPrepareSsaoProgram->SetTexture(i ++, myTex);
 
 	glPushAttrib(GL_VIEWPORT_BIT);
@@ -1244,5 +1279,5 @@
 	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
 	GLuint colorsTex = colorBuffer->GetTexture();
-	//FrameBufferObject::Release();
+	
 
 	FlipFbos(fbo);
@@ -1272,5 +1307,5 @@
 	DrawQuad(sCgDownSampleProgram);
 
-	PrintGLerror("output");
+	PrintGLerror("Output");
 }
 
@@ -1279,5 +1314,7 @@
 {
 	for (int i = 0; i < 4; ++ i)
+	{
 		mOldCornersView[i] = mCornersView[i];
+	}
 
 	mOldProjViewMatrix = mProjViewMatrix;
