Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3143)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3148)
@@ -1,3 +1,8 @@
 #include "../shaderenv.h"
+
+
+/******************************************/
+/* Filter for combining ssao with image   */
+/******************************************/
 
 
@@ -15,53 +20,7 @@
 
 
-
-
-
-inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)
-{
-	float3 x1 = lerp(bl, tl, w.y);
-	float3 x2 = lerp(br, tr, w.y); 
-	float3 v = lerp(x1, x2, w.x); 
-
-	return v;
-}
-
-
-// reconstruct world space position
-inline float3 ReconstructSamplePos(uniform sampler2D tex,
-								   float2 texcoord, 
-								   float3 bl, float3 br, float3 tl, float3 tr)
-{
-	const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w;
-	
-	float3 viewVec = Interpol(texcoord, bl, br, tl, tr);
-	float3 samplePos = -viewVec * eyeSpaceDepth;
-
-	return samplePos;
-}
-
-
-float Filter(float2 texCoord, 
-			 uniform sampler2D ssaoTex,
-			 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
-			 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
-			 float scale)
-{
-	float average = .0f;
-	float w = .0f;
-
-	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
-	{	
-		average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x;
-		w += filterWeights[i];
-	}
-
-	average *= 1.0f / (float)w;
-
-	return average;
-}
-
-//#define USE_POSITION
-
+/** Filter taking into account depth and normal differences, 
+   and convergence of a sample  
+*/
 float DiscontinuityFilter(float2 texCoord,
 						  float4 ao,
@@ -72,19 +31,10 @@
 						  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
 						  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
-						  float scale,
-						  float3 bl,
-						  float3 br,
-						  float3 tl,
-						  float3 tr)
+						  float scale)
 {
 	float average = .0f;
 	float total_w = .0f;
 
-#ifdef USE_POSITION
-	const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr);
-#else
 	const float eyeSpaceDepth = color.w;
-	//const float eyeSpaceDepth = ao.w;
-#endif
 
 	const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz);
@@ -109,40 +59,29 @@
 		//sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz;
 
-#ifdef USE_POSITION
-		samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr);
-		depthFactor = max(step(1.0f - 5e-1f, 1.0f - length(samplePos - centerPos)), 1e-3f);
-#else // use depth
+		// check depth discontinuity
 		sampleDepth = tex2Dlod(colorsTex, sampleTexCoord).w;
 		//sampleDepth = aoSample.w;
+		
 		//depthFactor = max(step(1e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth)), 1e-3f);
-		//depthFactor = max(1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth), 1e-6f);
-		//depthFactor = max(1.0f - abs(1.0f - eyeSpaceDepth / sampleDepth), 1e-6f);
-
 		depthFactor = 1.0f / max(abs(eyeSpaceDepth - sampleDepth), 1e-3f);
-#endif
 		//normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-6f);
 		normalFactor = max(dot(sampleNorm, centerNormal), 1e-6f);
-		convergenceFactor = min(200.0f, aoSample.y) * 0.01f;//max(step(18.5f, aoSample.y), 1e-3f);
+		convergenceFactor = min(200.0f, aoSample.y) * 0.01f;
 
-		//w = filterWeights[i] * normalFactor * depthFactor * convergenceFactor;
-		//w = 1000.0f * normalFactor * depthFactor;// * convergenceFactor;
-		//w = normalFactor;
+		// combine the weights
 		w = depthFactor * normalFactor * convergenceFactor;
-		//w = filterWeights[i] * normalFactor * converganceFactor;
-		//w = filterWeights[i] * normalFactor * depthFactor;
-		//w = convergenceFactor;
 
 		average += aoSample.x * w;
-		//average += aoSample.x;
 		total_w += w;
 	}
 
 	average /= max(total_w, 1e-1f);
-	//average /= NUM_SSAO_FILTERSAMPLES;
 
 	return saturate(average );
 }
 
-
+/** Function combining image and indirect illumination buffer using a 
+	depth and normal aware discontinuity filter.
+*/
 pixel combine(fragment IN, 
 			  uniform sampler2D colorsTex,
@@ -152,8 +91,5 @@
 			  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
 			  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
-			  uniform float3 bl,
-			  uniform float3 br,
-			  uniform  float3 tl,
-			  uniform float3 tr)
+			  )
 {
 	pixel OUT;
@@ -167,31 +103,12 @@
 		const float scaleFactor = 1.0f;
 		const float adaptFactor = 10.0f;
-		//const float adaptFactor = 500000.0f;
-
-		//ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);
-		//ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));
-		//ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y), 0);
-		//ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor  / (adaptFactor + ao.y), 0);
-
+		
 		const float scale =	adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y);
-		//const float scale = scaleFactor * ao.z;
-		
-		ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale, bl, br, tl, tr);
-		//if (ao.y < 50.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, ao.z, bl, br, tl, tr);
-		//ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0);
+			
+		ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, scale);
 	}
 
-	//float dummy = clamp(1.0f - ao.y * 1e-2f, 0, 1);
-	//float dummy2 = ao.y < 1.5f ? 1.0f : .0f;
 	OUT.illum_col.xyz = col.xyz * ao.x;
 
-	//	if (ao.y < 1.5f) OUT.illum_col.xyz = float3(10000, 10000, 0);
-	//	else if (ao.y < 3.5f) OUT.illum_col.xyz = float3(10000, 0, 10000);
-	//	else
-	//	if (ao.y < 10.5f) OUT.illum_col.xyz = float3(0, 10000, 0);
-	//OUT.illum_col = float4(dummy3, dummy3, dummy3, col.w);
-	//OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
-
-	//OUT.illum_col.xyz = float3(1.0f - ao.x, dummy2, 0);//dummy2);
 	//OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-2f, 0, 1), 1);
 	OUT.illum_col.w = col.w;
@@ -199,66 +116,2 @@
 	return OUT;
 }
-
-
-float DiscontinuityFilter2(float2 texCoord,
-						  float4 ao,
-						  uniform sampler2D ssaoTex,
-						  uniform sampler2D normalsTex,
-						  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
-						  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],
-						  float scale
-						  )
-{
-	float average = .0f;
-	float total_w = .0f;
-
-	const float eyeSpaceDepth = ao.w;
-	const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz);
-
-	float4 aoSample;
-	float3 sampleNorm;
-	float w;
-	float4 offs;
-	float depthFactor;
-	float normalFactor;
-
-	for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)
-	{
-		offs = float4(texCoord + filterOffs[i] * scale, 0, 0);
-		aoSample = tex2Dlod(ssaoTex, offs);
-		
-		sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz);
-
-		//depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f);
-		//depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f);
-		//normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f);
-		w = filterWeights[i];
-		//w = filterWeights[i] * normalFactor * depthFactor;
-		//w = normalFactor * depthFactor;
-		//w = depthFactor;
-
-		average += aoSample.y * w;
-		total_w += w;
-	}
-
-	average *= 1.0f / max(total_w, 1e-3f);
-
-	return average;
-}
-
-pixel smoothSsao(fragment IN, 
-				 uniform sampler2D ssaoTex,
-				 uniform sampler2D normalsTex,
-				 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],
-				 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]
-			  )
-{
-	pixel OUT;
-
-	float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
-	//ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 0.1f);
-	
-	OUT.illum_col = ao;
-
-	return OUT;
-}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3137)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg	(revision 3148)
@@ -35,5 +35,5 @@
 	// the rgb weights
 	const float3 w = float3(0.299f, 0.587f, 0.114f);
-	//float3 w = float3(0.2125f, 0.7154f, 0.0721f);
+	//const float3 w = float3(0.2125f, 0.7154f, 0.0721f);
 
 	float4 color;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3137)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3148)
@@ -82,5 +82,4 @@
 	void CombineSsao(FrameBufferObject *fbo);
 	void CombineIllum(FrameBufferObject *fbo);
-	void SmoothSsao(FrameBufferObject *fbo);
 
 	void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3144)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3148)
@@ -57,5 +57,4 @@
 static ShaderProgram *sCgToneProgram = NULL;
 static ShaderProgram *sCgDownSampleProgram = NULL;
-static ShaderProgram *sCgSmoothSsaoProgram = NULL;
 static ShaderProgram *sCgScaleDepthProgram = NULL;
 
@@ -374,5 +373,4 @@
 	sCgScaleDepthProgram = sm->CreateFragmentProgram("deferred", "ScaleDepth", "ScaleDepth");
 	sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum");
-	sCgSmoothSsaoProgram = sm->CreateFragmentProgram("combineSsao", "smoothSsao", "smoothSsao");
 
 
@@ -441,9 +439,4 @@
 	////////////////
 
-	string smoothSsaoParams[] = {"normalsTex", "ssaoTex", "filterOffs", "filterWeights"};
-	sCgSmoothSsaoProgram->AddParameters(smoothSsaoParams, 0, 4);
-	
-	
-	///////////
 
 	const float filterWidth = 100.0f;
@@ -526,5 +519,4 @@
 	case SSAO:
 		ComputeSsao(fbo, tempCohFactor);
-		//SmoothSsao(fbo);
 		CombineSsao(fbo);
 		break;
@@ -810,5 +802,4 @@
 	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
 	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-	//GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture();
 	GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
 	
@@ -816,4 +807,5 @@
 
 	int i = 0;
+
 	sCgCombineSsaoProgram->SetTexture(i ++, colorsTex);
 	sCgCombineSsaoProgram->SetTexture(i ++, normalsTex);
@@ -827,9 +819,4 @@
 	Vector3 tl = mCornersView[2];
 	Vector3 tr = mCornersView[3];
-
-	sCgCombineSsaoProgram->SetValue3f(i ++, bl.x, bl.y, bl.z);
-	sCgCombineSsaoProgram->SetValue3f(i ++, br.x, br.y, br.z);
-	sCgCombineSsaoProgram->SetValue3f(i ++, tl.x, tl.y, tl.z);
-	sCgCombineSsaoProgram->SetValue3f(i ++, tr.x, tr.y, tr.z);
 
 
@@ -1117,31 +1104,3 @@
 
 
-void DeferredRenderer::SmoothSsao(FrameBufferObject *fbo)
-{
-	mIllumFbo->Bind();
-
-	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
-	GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
-
-	// overwrite old ssao texture
-	glDrawBuffers(1, mrt + 2 - mIllumFboIndex);
-
-	glPushAttrib(GL_VIEWPORT_BIT);
-	glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight());
-
-	int i = 0;
-	sCgSmoothSsaoProgram->SetTexture(i ++, normalsTex);
-	sCgSmoothSsaoProgram->SetTexture(i ++, ssaoTex);
-
-	sCgSmoothSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES);
-	sCgSmoothSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES);
-	
-	DrawQuad(sCgSmoothSsaoProgram);
-
-	glPopAttrib();
-
-	PrintGLerror("combine ssao");
-}
-
-
 } // namespace
