Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.h	(revision 2839)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Halton.h	(revision 3129)
@@ -156,30 +156,28 @@
 
 	// special construtor for pregenerating static halton sequences
-	HaltonSequence(const int dim, const int number);
-
-	HaltonSequence(): index(1) {}
-
-	void Reset() 
-	{
-		index = 1;
-	}
-
-	void
-		GetNext(const int dimensions, float *p);
-
-	void GenerateNext() 
-	{
-		++ index;
-	}
+	HaltonSequence(int dim, int number);
+
+	HaltonSequence(): index(1) 
+	{ 
+		float dummy[2]; 
+		for (int i = 0; i < 20; ++ i) GetNext(2, dummy);
+	}
+
+	void Reset() { index = 1; }
+
+	void GetNext(int dimensions, float *p);
+
+	void GenerateNext() { ++ index; }
 
 	double GetNumber(const int dimension)  
 	{
 		int base = FindPrime(dimension);
-		if(base == 1) {
-			base++;  //The first dimension uses base 2.
+		if (base == 1) 
+		{
+			base++;  // The first dimension uses base 2.
 		} 
 
 		int _p1 = base;
-		float _ip1 = 1.0f/base;
+		float _ip1 = 1.0f / base;
 		float p, u=0.0f;
 		int kk, a;
@@ -198,5 +196,5 @@
 		@param dimension the dimension
 	*/
-	double GetNumberOld(const int dimension)  
+	double GetNumberOld(int dimension)  
 	{
 		int base = FindPrime(dimension);
@@ -214,5 +212,5 @@
 		if ((base >= 2) && (index >= 1)) 
 		{
-			while(copyOfIndex > 0) 
+			while (copyOfIndex > 0) 
 			{
 				N1 = (copyOfIndex / base);
@@ -226,5 +224,5 @@
 		else 
 		{
-			std::cerr<<"Error generating Halton sequence."<<std::endl;
+			std::cerr << "Error generating Halton sequence." << std::endl;
 			exit(1);
 		}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3128)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3129)
@@ -167,9 +167,9 @@
 
 		//depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f);
-		depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f);
-		normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f);
-
-		w = filterWeights[i] * normalFactor * depthFactor;
-		//w = filterWeights[i] * depthFactor;
+		depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f);
+		normalFactor = max(step(0.3f, dot(sampleNorm, norm)), 1e-3f);
+
+		//w = filterWeights[i] * normalFactor * depthFactor;
+		w = normalFactor * depthFactor;
 
 		average += aoSample.y * w;
@@ -177,5 +177,5 @@
 	}
 
-	average *= 1.0f / max(total_w, 1e-6f);
+	average *= 1.0f / max(total_w, 1e-3f);
 
 	return average;
@@ -193,7 +193,6 @@
 	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-	//const static float scaleFactor = 10.0f;
+	//const static float scaleFactor = 20.0f;
 	const static float scaleFactor = 10.0f;
-
 	ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor * ao.z, 1);
 	
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3128)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3129)
@@ -209,6 +209,6 @@
 #endif
 
-	const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence);
-	//const float oldWeight = oldPixel.y;
+	//const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence);
+	const float oldWeight = oldPixel.y;
 
 	float newWeight;
@@ -220,10 +220,10 @@
 		// if visibility changed in the surrounding area we have to recompute
 		//&& (oldNumSamples > 0.8f * newNumSamples)
-		&& (notValid < 1.0f)
+		//&& (notValid < 1.0f)
 		)
 	{
 		// increase the weight for convergence
 		newWeight = oldWeight + 1.0f;
-		//if (notValid > 1.0f) newWeight = 10.0f;
+		if (notValid > 1.0f) newWeight = 10.0f;
 		//if (notValid > 1.0f) newWeight = max(15.0f - notValid * 2.0f, 1.0f);
 	}
@@ -236,5 +236,5 @@
 	//	newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50));
 	//if (newWeight >= 2000) newWeight = 1000;
-	//newWeight -= step(2000.0f, newWeight) * 1000.0f;
+	newWeight -= step(512.0f, newWeight) * 256.0f;
 
 	return float3(oldPixel.x, newWeight, eyeSpaceDepth);
@@ -257,4 +257,5 @@
 			float3 viewDir
 			, float2 noiseOffs
+			, sampler2D noiseTex1D
 			)
 {
@@ -266,4 +267,7 @@
 	float numSamples = .0f;
 
+
+	//float2 jitter = tex2Dlod(noiseTex1D, float4(IN.texCoord.x * 4.0f + noiseOffs.x, 0.5f, 0, 0)).xy;
+	//float2 jitter = tex2Dlod(noiseTex1D, float4(noiseOffs.x, 0.5f, 0, 0)).xy;
 
 	for (int i = 0; i < NUM_SAMPLES; ++ i) 
@@ -282,8 +286,8 @@
 #endif
 		// weight with projected coordinate to reach similar kernel size for near and far
+		//const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor + jitter;
 		const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor;
 
 		//if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples;
-
 		const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr);
 
@@ -340,5 +344,6 @@
 		   uniform float3 oldtl,
 		   uniform float3 oldtr,
-		   uniform sampler2D attribsTex
+		   uniform sampler2D attribsTex,
+		   uniform sampler2D noiseTex1D
 		   )
 {
@@ -378,11 +383,11 @@
 											scaleFactor, 
 											oldbl, oldbr, oldtl, oldtr,
-											diffVec);
+											diffVec
+											);
 
 	const float oldSsao = temporalVals.x;
-	const float newWeight = clamp(temporalVals.y, .0f, temporalCoherence);
-
-	//float2 noiseOffs = float2(temporalVals.y / 139.0f, temporalVals.y / 141.0f);
-	float2 noiseOffs = float2(.0f);
+	const float newWeight = clamp(temporalVals.y, 1.0f, temporalCoherence);
+	float2 noiseOffs = float2((temporalVals.y - 1)/ 139.0f, .0f);
+	//float2 noiseOffs = float2(.0f);
 
 	float2 ao;
@@ -392,5 +397,5 @@
 	{
 		ao = ssao(IN, colors, noiseTex, samples, normal, 
-		          eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), noiseOffs);
+		          eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), noiseOffs, noiseTex1D);
 	}
 	else
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3128)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3129)
@@ -60,5 +60,6 @@
 
 
-static GLuint noiseTex = 0;
+static GLuint noiseTex2D = 0;
+static GLuint noiseTex1D = 0;
 
 
@@ -214,6 +215,6 @@
 
 	glEnable(GL_TEXTURE_2D);
-	glGenTextures(1, &noiseTex);
-	glBindTexture(GL_TEXTURE_2D, noiseTex);
+	glGenTextures(1, &noiseTex2D);
+	glBindTexture(GL_TEXTURE_2D, noiseTex2D);
 		
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -233,4 +234,43 @@
 	PrintGLerror("noisetexture");
 }
+
+
+static void CreateNoiseTex1D(int w)
+{
+	float *randomValues = new float[w * 3];
+
+	static HaltonSequence halton;
+	
+	randomValues[0] = randomValues[1] = randomValues[2] = 0;
+
+	for (int i = 3; i < w * 3; i += 3)
+	{
+		// create random samples on a circle
+		randomValues[i + 0] = 20.0f * RandomValue(0, 1) / 512.0f;
+		randomValues[i + 1] = 20.0f * RandomValue(0, 1) / 384.0f;
+		randomValues[i + 2] = 0;
+	}
+
+	glEnable(GL_TEXTURE_2D);
+	glGenTextures(1, &noiseTex1D);
+	glBindTexture(GL_TEXTURE_2D, noiseTex1D);
+		
+	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);
+
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, 1, 0, GL_RGB, GL_FLOAT, randomValues);
+
+	glBindTexture(GL_TEXTURE_2D, 0);
+	glDisable(GL_TEXTURE_2D);
+
+	delete [] randomValues;
+
+	cout << "created noise texture 1D" << endl;
+
+	PrintGLerror("noisetexture 1D");
+}
+
 
 
@@ -284,4 +324,5 @@
 	//CreateNoiseTex2D(mIllumFbo->GetWidth(), mIllumFbo->GetHeight());
 	CreateNoiseTex2D(mWidth / 8, mHeight / 8);
+	CreateNoiseTex1D(mWidth / 8);
 
 	mProjViewMatrix = IdentityMatrix();
@@ -302,5 +343,6 @@
 {
 	CLEAR_CONTAINER(mFBOs);
-	glDeleteTextures(1, &noiseTex);
+	glDeleteTextures(1, &noiseTex2D);
+	glDeleteTextures(1, &noiseTex1D);
 }
 
@@ -337,6 +379,6 @@
 		 "samples", "bl", "br", "tl", "tr", 
 		 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 
-		 "oldtl", "oldtr", "attribsTex"};
-	sCgSsaoProgram->AddParameters(ssaoParams, 0, 18);
+		 "oldtl", "oldtr", "attribsTex", "noiseTex1D"};
+	sCgSsaoProgram->AddParameters(ssaoParams, 0, 19);
 	
 	string giParams[] = 
@@ -538,10 +580,10 @@
 	sCgSsaoProgram->SetTexture(i ++, normalsTex);
 	sCgSsaoProgram->SetTexture(i ++, oldTex);
-	sCgSsaoProgram->SetTexture(i ++, noiseTex);
+	sCgSsaoProgram->SetTexture(i ++, noiseTex2D);
 
 	sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0);
 	
-	//if (mUseTemporalCoherence || mRegenerateSamples)
-	if (mRegenerateSamples)
+	if (mUseTemporalCoherence || mRegenerateSamples)
+	//if (mRegenerateSamples)
 	{
 		mRegenerateSamples = false;
@@ -550,5 +592,5 @@
 		// in the first case, the sample patterns look nicer, but the kernel
 		// needs longer to converge
-		GenerateSamples(mSamplingMethod); 
+		GenerateSamples(mSamplingMethod);
 		sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES);
 	}
@@ -573,4 +615,6 @@
 
 	sCgSsaoProgram->SetTexture(i ++, attribsTex);
+
+	sCgSsaoProgram->SetTexture(i ++, noiseTex1D);
 
 	DrawQuad(sCgSsaoProgram);
@@ -675,5 +719,5 @@
 	sCgGiProgram->SetTexture(0, colorsTex);
 	sCgGiProgram->SetTexture(1, normalsTex);
-	sCgGiProgram->SetTexture(2, noiseTex);
+	sCgGiProgram->SetTexture(2, noiseTex2D);
 	sCgGiProgram->SetTexture(3, oldSsaoTex);
 	sCgGiProgram->SetTexture(4, oldIllumTex);
@@ -748,4 +792,5 @@
 	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
 	GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
+	//GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
 
 	// overwrite old color texture
@@ -787,5 +832,5 @@
 	sCgDeferredShadowProgram->SetTexture(1, normalsTex);
 	sCgDeferredShadowProgram->SetTexture(2, shadowTex);
-	sCgDeferredShadowProgram->SetTexture(3, noiseTex);
+	sCgDeferredShadowProgram->SetTexture(3, noiseTex2D);
 	sCgDeferredShadowProgram->SetMatrix(4, shadowMatrix);
 	sCgDeferredShadowProgram->SetValue1f(5, 2.0f / shadowMap->GetSize());
