Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3323)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3324)
@@ -5,12 +5,12 @@
 ////////////
 //-- ssao + gi parameters
-
+#define NUM_PRECOMPUTED_SAMPLES 4096
 //#define NUM_SAMPLES 8
 //#define NUM_SAMPLES 16
 //#define NUM_SAMPLES 24
-#define NUM_SAMPLES 24
+#define NUM_SAMPLES 48
 
 //#define MIN_SAMPLES 48
-#define MIN_SAMPLES 24
+#define MIN_SAMPLES 8
 
 #define DISTANCE_SCALE 1e-2f
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3322)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3324)
@@ -77,19 +77,19 @@
 	weight of the pixel in the new frame.
 */
-inline float2 Reproject(float4 worldPos,
-								float eyeSpaceDepth,
-								float2 texcoord0,
-								float3 oldEyePos,
-								sampler2D oldTex,
-								float4x4 oldModelViewProj,
-								sampler2D colors,
-								float3 projPos,
-								float invW,
-								float3 oldbl,
-								float3 oldbr,
-								float3 oldtl,
-								float3 oldtr,
-								float3 diffVec
-								)
+inline float3 Reproject(float4 worldPos,
+						float eyeSpaceDepth,
+						float2 texcoord0,
+						float3 oldEyePos,
+						sampler2D oldTex,
+						float4x4 oldModelViewProj,
+						sampler2D colors,
+						float3 projPos,
+						float invW,
+						float3 oldbl,
+						float3 oldbr,
+						float3 oldtl,
+						float3 oldtr,
+						float3 diffVec
+						)
 {
 	// compute position from old frame for dynamic objects + translational portion
@@ -125,4 +125,6 @@
 	// the weight of the accumulated samples from the previous frames
 	float w;
+
+	float idx = oldPixel.z;
 
 	//////////////
@@ -151,5 +153,5 @@
 	}
 
-	return float2(ssao, w);
+	return float3(ssao, w, idx);
 }
 
@@ -167,5 +169,5 @@
 			 sampler2D colors,
 			 sampler2D noiseTex,
-			 float2 samples[NUM_SAMPLES],
+			 sampler2D samples,
 			 float3 normal,
 			 float3 centerPosition,
@@ -179,5 +181,6 @@
 			 float sampleIntensity,
 			 bool isMovingObject,
-			 sampler2D normalTex
+			 sampler2D normalTex,
+			 int idx
 			 )
 {
@@ -190,17 +193,21 @@
 		float2 offset;
 
+		const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;
+
+
 		////////////////////
 		//-- add random noise: reflect around random normal vector 
 		//-- (affects performance for some reason!)
 
-		if (1)//convergence < SSAO_CONVERGENCE_THRESHOLD)
+		if (convergence < SSAO_CONVERGENCE_THRESHOLD)
 		{
 			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(samples[i], mynoise.x);
+			offset = myrotate(ssaoOffset, mynoise.x);
 		}
 		else
 		{
-			offset = samples[i];
+			offset = ssaoOffset;
 		}
 		
@@ -441,5 +448,5 @@
 		   uniform sampler2D normals,
 		   uniform sampler2D noiseTex,
-		   uniform float2 samples[NUM_SAMPLES],
+		   uniform sampler2D samples,
 		   uniform sampler2D oldTex,
 		   uniform float4x4 modelViewProj,
@@ -488,5 +495,5 @@
 	//-- compute temporal reprojection
 
-	float2 temporalVals = Reproject(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
+	float3 temporalVals = Reproject(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,
 	                                oldTex, oldModelViewProj, 
 									colors, 
@@ -499,5 +506,6 @@
 	const float oldSsao = temporalVals.x;
 	float oldWeight = temporalVals.y;
-	
+	float oldIdx = temporalVals.z;
+
 	float3 ao;
 
@@ -506,5 +514,5 @@
 	{
 		//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);
+		ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals, oldIdx);
 		//ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity);
 	}
@@ -552,5 +560,6 @@
 	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 = SqrLen(diffVec);
+	OUT.illum_col.z = oldIdx + newWeight;
 	OUT.illum_col.w = eyeSpaceDepth;
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3313)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3324)
@@ -263,20 +263,18 @@
 
 	// check if the pixel belonged to a dyanmic object in the last frame
-	const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD);
-	const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);
+	const bool oldDynamic =  false;(squaredLen > DYNAMIC_OBJECTS_THRESHOLD);
+	const bool newDynamic = false; (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 si no noticeable drag
+	// so that there is 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;
 
-	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))
+	// 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)
 		)
 	{
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3322)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3324)
@@ -71,10 +71,11 @@
 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];
-//#define NUM_PRECOMPUTED_SAMPLES 240
-//static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES];
+//static Sample2 samples2[NUM_SAMPLES];
+
 // pcf samples
 static Sample2 pcfSamples[NUM_PCF_TABS];
@@ -212,7 +213,6 @@
 	case DeferredRenderer::SAMPLING_QUADRATIC:
 		{
-			//static QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
+			QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);
 			//static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f);
-			static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f);
 			g.Generate((float *)samples2);
 		}
@@ -263,4 +263,41 @@
 
 	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");
@@ -439,4 +476,5 @@
 		 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 
 		 "oldtl", "oldtr", "attribsTex", "kernelRadius", "sampleIntensity"};
+	
 	sCgSsaoProgram->AddParameters(ssaoParams, 0, 20);
 	
@@ -751,7 +789,5 @@
 	sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0);
 	
-	static int currentPos = 0;
-
-	if (mUseTemporalCoherence || mRegenerateSamples)
+	if (/*mUseTemporalCoherence || */mRegenerateSamples)
 	{
 		mRegenerateSamples = false;
@@ -760,13 +796,10 @@
 		// in the first case, the sample patterns look nicer, but the kernel
 		// needs longer to converge
-		//if (currentPos + NUM_SAMPLES >= NUM_PRECOMPUTED_SAMPLES)	{
-			currentPos = 0;
-			GenerateSamples(mSamplingMethod);
-		//}
-
+		GenerateSamples(mSamplingMethod);
+		CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES);
 		//if (mSortSamples) { SortSamples(); }
-		sCgSsaoProgram->SetArray2f(i, (float *)samples2 + currentPos, NUM_SAMPLES);
-
-		currentPos += NUM_SAMPLES;
+		//sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES);
+		//sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES);
+		sCgSsaoProgram->SetTexture(i, sampleTex2D);
 	}
 	
@@ -774,5 +807,7 @@
 
 	for (int j = 0; j < 4; ++ j, ++ i)
+	{
 		sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z);
+	}
 
 	sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix);
