Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3312)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3313)
@@ -5,5 +5,5 @@
 ////////////
 //-- ssao + gi parameters
-#define NUM_PRECOMPUTED_SAMPLES 2048
+
 //#define NUM_SAMPLES 8
 //#define NUM_SAMPLES 16
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3311)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3313)
@@ -48,5 +48,5 @@
 	weight of the pixel in the new frame.
 */
-inline float3 temporalSmoothing(float4 worldPos,
+inline float2 temporalSmoothing(float4 worldPos,
 								float eyeSpaceDepth,
 								float2 texcoord0,
@@ -96,5 +96,4 @@
 	// the weight of the accumulated samples from the previous frames
 	float w;
-	float idx;
 
 	//////////////
@@ -109,13 +108,11 @@
 		// pixel valid => retrieve the convergence weight
 		w = oldPixel.y;
-		idx = oldPixel.z;
 	}
 	else
 	{	
-		w = .0f;
-		idx = .0f;
-	}
-
-	return float3(ssao, w, idx);
+		w = 0.0f;
+	}
+
+	return float2(ssao, w);
 }
 
@@ -145,6 +142,5 @@
 	float validSamples = .0f;
 
-
-	for (int i = 0; i < NUM_PRECOMPUTED_SAMPLES; ++ i) 
+	for (int i = 0; i < NUM_SAMPLES; ++ i) 
 	{
 		const float2 offset = samples[i];
@@ -224,5 +220,5 @@
 			sampler2D colors,
 			sampler2D noiseTex,
-			sampler2D samples,
+			float2 samples[NUM_SAMPLES],
 			float3 normal,
 			float3 centerPosition,
@@ -235,6 +231,5 @@
 			float convergence,
 			float sampleIntensity,
-			bool isMovingObject,
-			float idx
+			bool isMovingObject
 			)
 {
@@ -242,5 +237,5 @@
 	float validSamples = .0f;
 	float numSamples = .0f;
-	
+
 	for (int i = 0; i < NUM_SAMPLES; ++ i) 
 	{
@@ -251,18 +246,13 @@
 		//-- (affects performance for some reason!)
 
-		const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;
-
 		if (convergence < SSAO_CONVERGENCE_THRESHOLD)
 		{
-			float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord.x * 4.0f + idx * 0.01f, IN.texCoord.y * 4.0f, 0, 0)).xy;
+			float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy;
 			//offset = myreflect(samples[i], mynoise);
-			//offset = myrotate(samples[i], mynoise.x);
-
-			offset = myrotate(ssaoOffset, mynoise.x);
+			offset = myrotate(samples[i], mynoise.x);
 		}
 		else
 		{
-			offset = ssaoOffset;
-			//offset = samples[i];
+			offset = samples[i];
 		}
 		
@@ -304,5 +294,5 @@
 		// we check if the sample could have been near enough to the current pixel 
 		// to have any influence in the current or last frame
-		//const float tooFarAway = step(0.5f, lengthToSample - changeFactor);
+		const float tooFarAway = step(0.5f, lengthToSample - changeFactor);
 		//validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle));
 		validSamples = max(validSamples, pixelValid);
@@ -313,8 +303,9 @@
 		if (numSamples >= MIN_SAMPLES)
 		{
+			//break;
 			// if the pixel belongs to a static object and all the samples stay valid in the current frame
 			if (!isMovingObject && (validSamples < 1.0f)) break;
-			// if the pixel belongs to a dynamic object but the #accumulated samples
-			// for this pixel is sufficiently high (=> there was no discontinuity recently)
+			// if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high 
+			// (=> there was no discontinuity recently)
 			else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break;
 		}
@@ -344,5 +335,5 @@
 		   uniform sampler2D normals,
 		   uniform sampler2D noiseTex,
-		   uniform sampler2D samples,
+		   uniform float2 samples[NUM_SAMPLES],
 		   uniform sampler2D oldTex,
 		   uniform float4x4 modelViewProj,
@@ -391,5 +382,5 @@
 	//-- compute temporal reprojection
 
-	float3 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
+	float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
 	                                        oldTex, oldModelViewProj, 
 											colors, 
@@ -402,9 +393,5 @@
 	const float oldSsao = temporalVals.x;
 	float oldWeight = temporalVals.y;
-
-	float idx = (int)temporalVals.z;
-
-	if (idx >= NUM_PRECOMPUTED_SAMPLES) idx = 0;
-
+	
 	float3 ao;
 
@@ -412,7 +399,5 @@
 	if (eyeSpaceDepth < DEPTH_THRESHOLD)
 	{
-		ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, 
-			      scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, 
-				  sampleIntensity, isMovingObject, idx);
+		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), normals, sampleIntensity);
 	}
@@ -429,6 +414,4 @@
 	// the weight equals the number of sampled shot in this pass
 	const float newWeight = ao.z;
-
-	idx += newWeight;
 
 	// completely reset the ao in this pixel
@@ -437,32 +420,30 @@
 	const float partlyResetThres = 1.0f;
 	
-	// hack: just update static geometry
-	if (!isMovingObject)
+	if (1)//!isMovingObject)
 	{
 		if (ao.y > completelyResetThres) 
 		{
-			oldWeight = .0f;
-			idx = .0f;
+			oldWeight = .0f; 
 		}
 		else if (ao.y > partlyResetThres)
 		{
 			oldWeight = min(oldWeight, 4.0f * newWeight);
+			//oldWeight = .0f; 
 		}
 	}
-
 
 	//////////
 	//-- blend ao between old and new samples (and avoid division by zero)
 
-	OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight;
+	OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight);
+
 	OUT.illum_col.x /= (newWeight + oldWeight);
 
 	// the new weight for the next frame
 	const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence);
-	
+
 	OUT.illum_col.y = combinedWeight;
 	// can be used to check if this pixel belongs to a moving object
-	//OUT.illum_col.z = SqrLen(diffVec);
-	OUT.illum_col.z = idx;
+	OUT.illum_col.z = SqrLen(diffVec);
 	OUT.illum_col.w = eyeSpaceDepth;
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3311)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3313)
@@ -114,4 +114,38 @@
 }
 
+/** In between step that only filters in one direction
+*/
+pixel FilterSsaoFullRes(fragment IN, 
+						uniform sampler2D colorsTex,
+						uniform sampler2D ssaoTex,
+						uniform float3 bl,
+						uniform float3 br,
+						uniform float3 tl,
+						uniform float3 tr,
+						uniform float2 res
+						)
+{
+	pixel OUT;
+
+	const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w;
+
+	OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
+	// just take unfiltered convergence in current pixel
+	const float convergence = OUT.illum_col.y;
+
+	// filter reaches size 1 pixel when sample size reaches threshold 
+	// afterwards we do not use the filter anymore
+
+	float2 xyStep = float2(1.0f / res.x, 0);
+
+	// filter up to a certain convergance value and leave out background (sky) by checking depth
+	if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD))
+	{
+		// the filtered ssao value
+		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
+	}
+
+	return OUT;
+}
 
 /** In between step that only filters in one direction
@@ -151,41 +185,4 @@
 }
 
-
-/** In between step that only filters in one direction
-*/
-pixel FilterSsaoFullRes(fragment IN, 
-						uniform sampler2D colorsTex,
-						uniform sampler2D ssaoTex,
-						uniform float3 bl,
-						uniform float3 br,
-						uniform float3 tl,
-						uniform float3 tr,
-						uniform float2 res
-						)
-{
-	pixel OUT;
-
-	const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w;
-
-	OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
-	// just take unfiltered convergence in current pixel
-	const float convergence = OUT.illum_col.y;
-
-	// filter reaches size 1 pixel when sample size reaches threshold 
-	// afterwards we do not use the filter anymore
-
-	const float2 xyStep = float2(1.0f / res.x, 0);
-
-	// filter up to a certain convergance value and leave out background (sky) by checking depth
-	if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD))
-	{
-		// the filtered ssao value
-		OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);
-	}
-
-	return OUT;
-}
-
-
 /** Function combining image and indirect illumination buffer using a 
     depth and convergence aware discontinuity filter.
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3311)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3313)
@@ -263,18 +263,20 @@
 
 	// check if the pixel belonged to a dyanmic object in the last frame
-	const bool newDynamic = false;//(squaredLen > DYNAMIC_OBJECTS_THRESHOLD);
-	const bool oldDynamic = false;//(oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);
+	const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD);
+	const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);
 
 	// actually 0 means pixel is valid
 	const float pixelIsValid = 0.0f;
 	// means that we only use slight temporal coherence over some frames
-	// so that there is no noticeable drag
+	// so that there si no noticeable drag
 	const float pixelCouldBeValid = 2.0f;
 	// this pixel information has to be discarded in order to not create artifacts
 	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)
+	const float xOffs = 0;// 0.5f / 1024.0f;
+	const float yOffs = 0;// 0.5f / 768.0f;
+
+	if ((oldTexCoords.x < xOffs) || (oldTexCoords.x > (1.0f - xOffs)) || 
+		(oldTexCoords.y < yOffs) || (oldTexCoords.y > (1.0f - yOffs))
 		)
 	{
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3311)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3313)
@@ -51,5 +51,5 @@
 	int tries = 0;
 
-	cout << "minDist before= " << minDist << endl;
+	//cout << "minDist before= " << minDist << endl;
 	Sample2 *s = (Sample2 *)samples;
 
@@ -109,5 +109,5 @@
 	}
 
-	cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl;
+	//cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl;
 }
 
@@ -172,6 +172,6 @@
 
 QuadraticDiscSampleGenerator2D::QuadraticDiscSampleGenerator2D(int numSamples, float radius):
-PoissonDiscSampleGenerator2D(numSamples, radius)
-//RandomSampleGenerator2D(numSamples, radius)
+//PoissonDiscSampleGenerator2D(numSamples, radius)
+RandomSampleGenerator2D(numSamples, radius)
 {}
 
@@ -194,6 +194,6 @@
 #else
 
-	PoissonDiscSampleGenerator2D::Generate(samples);
-	//RandomSampleGenerator2D::Generate(samples);
+	//PoissonDiscSampleGenerator2D::Generate(samples);
+	RandomSampleGenerator2D::Generate(samples);
 
 	Sample2 *s = (Sample2 *)samples;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h	(revision 3311)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h	(revision 3313)
@@ -78,6 +78,6 @@
 	with the distance
 */
-class QuadraticDiscSampleGenerator2D: public PoissonDiscSampleGenerator2D
-//class QuadraticDiscSampleGenerator2D: public RandomSampleGenerator2D
+//class QuadraticDiscSampleGenerator2D: public PoissonDiscSampleGenerator2D
+class QuadraticDiscSampleGenerator2D: public RandomSampleGenerator2D
 {
 public:
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3311)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3313)
@@ -1211,6 +1211,10 @@
 	if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView))
 	{
-		if (!shadowMap)	shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera);
-		if (!shadowTraverser) shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera());
+		if (!shadowMap)
+			shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera);
+
+		if (!shadowTraverser)
+			shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera());
+
 	}
 	
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3311)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3313)
@@ -71,11 +71,10 @@
 static GLuint noiseTex2D = 0;
 static GLuint noiseTex1D = 0;
-static GLuint sampleTex2D = 0;
-
-
-static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES];
+
+
 // ssao random spherical samples
-//static Sample2 samples2[NUM_SAMPLES];
-
+static Sample2 samples2[NUM_SAMPLES];
+//#define NUM_PRECOMPUTED_SAMPLES 240
+//static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES];
 // pcf samples
 static Sample2 pcfSamples[NUM_PCF_TABS];
@@ -92,9 +91,5 @@
 /** Helper method that computes the view vectors in the corners of the current view frustum.
 */
-static void ComputeViewVectors(PerspectiveCamera *cam, 
-							   Vector3 &bl,
-							   Vector3 &br, 
-							   Vector3 &tl,
-							   Vector3 &tr)
+static void ComputeViewVectors(PerspectiveCamera *cam, Vector3 &bl, Vector3 &br, Vector3 &tl, Vector3 &tr)
 {
 	Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;
@@ -212,6 +207,6 @@
 	case DeferredRenderer::SAMPLING_QUADRATIC:
 		{
-			QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
-			//static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f);
+			//static QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
+			static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f);
 			g.Generate((float *)samples2);
 		}
@@ -262,41 +257,4 @@
 
 	cout << "created noise texture" << endl;
-
-	PrintGLerror("noisetexture");
-}
-
-
-static void CreateSampleTex(Sample2 *samples, int numSamples)
-{
-	glEnable(GL_TEXTURE_2D);
-	glGenTextures(1, &sampleTex2D);
-	glBindTexture(GL_TEXTURE_2D, sampleTex2D);
-		
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
-	int w = numSamples;
-	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;
-		
-	}
-
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, w, h, 0, GL_RGB, GL_FLOAT, (float *)tempBuffer);
-
-	glBindTexture(GL_TEXTURE_2D, 0);
-	glDisable(GL_TEXTURE_2D);
-
-	cout << "created sample texture" << endl;
-
-	delete [] tempBuffer;
 
 	PrintGLerror("noisetexture");
@@ -469,9 +427,8 @@
 
 	string ssaoParams[] = 
-	    {"colors", "normals", "oldTex", "noiseTex", "temporalCoherence", 
+		{"colors", "normals", "oldTex", "noiseTex", "temporalCoherence", 
 		 "samples", "bl", "br", "tl", "tr", 
 		 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 
 		 "oldtl", "oldtr", "attribsTex", "kernelRadius", "sampleIntensity"};
-	
 	sCgSsaoProgram->AddParameters(ssaoParams, 0, 20);
 	
@@ -783,7 +740,9 @@
 	sCgSsaoProgram->SetTexture(i ++, noiseTex2D);
 
-	sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : .0f);
-	
-	if (/*mUseTemporalCoherence || */mRegenerateSamples)
+	sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0);
+	
+	static int currentPos = 0;
+
+	if (mUseTemporalCoherence || mRegenerateSamples)
 	{
 		mRegenerateSamples = false;
@@ -792,19 +751,19 @@
 		// in the first case, the sample patterns look nicer, but the kernel
 		// needs longer to converge
-		GenerateSamples(mSamplingMethod);
-		CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES);
+		//if (currentPos + NUM_SAMPLES >= NUM_PRECOMPUTED_SAMPLES)	{
+			currentPos = 0;
+			GenerateSamples(mSamplingMethod);
+		//}
+
 		//if (mSortSamples) { SortSamples(); }
-		//sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES);
-		//sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES);
-		sCgSsaoProgram->SetTexture(i, sampleTex2D);
-	}
-	
-
+		sCgSsaoProgram->SetArray2f(i, (float *)samples2 + currentPos, NUM_SAMPLES);
+
+		currentPos += NUM_SAMPLES;
+	}
+	
 	++ i;
 
 	for (int j = 0; j < 4; ++ j, ++ i)
-	{
 		sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z);
-	}
 
 	sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix);
@@ -815,5 +774,4 @@
 	de.y = mOldEyePos.y - mEyePos.y; 
 	de.z = mOldEyePos.z - mEyePos.z;
-
 
 	sCgSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3312)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3313)
@@ -106,5 +106,5 @@
 ssaoSampleIntensity=0.8f
 # ssao temporal coherence factor
-tempCohFactor=2048.0f
+tempCohFactor=2000.0f
 # ssao filter radius
 ssaoFilterRadius=12.0f
