Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3285)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3296)
@@ -115,6 +115,4 @@
 	float4 ao =  tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
-#if 0 // for half resolution
-
 	// the following has to be done for half resolution ssao:
 	// get the minimum convergence by exactly sampling the 4 surrounding
@@ -141,10 +139,4 @@
 	const float convergence = minConvergence;
 
-#else
-	
-	// just take unfiltered convergence in current pixel
-	const float convergence = ao.y;
-
-#endif
 	
 	// filter reaches size 1 pixel when sample size reaches threshold 
@@ -188,2 +180,60 @@
 	return OUT;
 }
+
+
+/** Function combining image and indirect illumination buffer using a 
+	depth and normal aware discontinuity filter. We assume that 
+	we are using half resolution ssao for this version of the combineSsao
+*/
+pixel CombineSsaoFullRes(fragment IN, 
+						 uniform sampler2D colorsTex,
+						 uniform sampler2D ssaoTex,
+						 uniform sampler2D normalsTex,
+						 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES],
+						 uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES],
+						 uniform float ssaoFilterRadius,
+						 uniform float4x4 modelViewProj,
+						 uniform float3 bl,
+						 uniform float3 br,
+						 uniform float3 tl,
+						 uniform float3 tr,
+						 uniform float w,
+						 uniform float h
+						 )
+{
+	pixel OUT;
+
+	float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));
+	float4 ao =  tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
+
+	// just take unfiltered convergence in current pixel
+	const float convergence = ao.y;
+	
+	// filter reaches size 1 pixel when sample size reaches threshold 
+	// afterwards we do not use the filter anymore
+
+	// filter up to a certain convergance value and leave out background (sky) by checking depth
+	if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (col.w < 1e10f))
+	{
+		const float distanceScale = 1.0f;
+
+		// descend to zero filter size after reaching thres pixels
+		const float convergenceWeight = SSAO_CONVERGENCE_THRESHOLD / (ssaoFilterRadius - 1.0f);
+		const float convergenceScale = convergenceWeight / (convergence + convergenceWeight);
+		const float scale = ssaoFilterRadius * convergenceScale * distanceScale;
+
+		// the filtered ssao value
+		ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr);
+	}
+
+	// just apply ssao if we are not in the sky
+	if (col.w < 1e10f)
+		OUT.illum_col.xyz = col.xyz * max(2e-2f, 1.0f - ao.x);
+		//OUT.illum_col.xyz = col.xyz * ao.x;
+	else
+		OUT.illum_col.xyz = col.xyz;
+
+	OUT.illum_col.w = col.w;
+
+	return OUT;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3242)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3296)
@@ -168,4 +168,5 @@
 	void DepthOfField(FrameBufferObject *fbo);
 
+	void CombineSsao2(FrameBufferObject *fbo);
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3287)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3296)
@@ -395,5 +395,6 @@
 	sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "GiFrag");
 	sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "CombineGi");
-	sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoHalfRes", "CombineSsao");
+	//sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoHalfRes", "CombineSsao");
+	sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "CombineSsaoFullRes", "CombineSsao");
 	sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "AntiAliasing");
 	sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "ToneMap");
@@ -624,4 +625,5 @@
 }
 
+#if 0
 
 void DeferredRenderer::PrepareSsaoFilter()
@@ -647,4 +649,42 @@
 	}
 }
+
+#else
+
+void DeferredRenderer::PrepareSsaoFilter()
+{
+	const float filterWidth = 1.0f;
+
+	PoissonDiscSampleGenerator2D poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f);
+	poisson.Generate((float *)ssaoFilterOffsets);
+
+	const float xoffs = (float)filterWidth / mWidth;
+	const float yoffs = (float)filterWidth / mHeight;
+
+	for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES / 2; ++ i)
+	{
+		float x = xoffs * (i - NUM_SSAO_FILTER_SAMPLES / 4);
+		float y = 0;
+
+		ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f);
+		
+		ssaoFilterOffsets[2 * i + 0] = xoffs;
+		ssaoFilterOffsets[2 * i + 1] = yoffs;
+	}
+
+	for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES / 2; ++ i)
+	{
+		float x = 0;
+		float y = yoffs * (i - NUM_SSAO_FILTER_SAMPLES / 4);
+
+		ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f);
+		//ssaoFilterWeights[i] = 1.0f;
+
+		ssaoFilterOffsets[2 * (NUM_SSAO_FILTER_SAMPLES / 2 + i) + 0] *= xoffs;
+		ssaoFilterOffsets[2 * (NUM_SSAO_FILTER_SAMPLES / 2 + i) + 1] *= yoffs;
+	}
+}
+
+#endif
 
 
@@ -983,5 +1023,41 @@
 
 	for (int j = 0; j < 4; ++ j, ++ i)
+	{
 		sCgCombineSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z);
+	}
+
+	sCgCombineSsaoProgram->SetValue1f(i ++, mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetWidth());
+	sCgCombineSsaoProgram->SetValue1f(i ++, mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetHeight());
+
+	DrawQuad(sCgCombineSsaoProgram);
+	
+	PrintGLerror("combine ssao");
+}
+
+
+void DeferredRenderer::CombineSsao2(FrameBufferObject *fbo)
+{
+	GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture();
+	GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture();
+	GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture();
+	
+	FlipFbos(fbo);
+
+	int i = 0;
+
+	sCgCombineSsaoProgram->SetTexture(i ++, colorsTex);
+	sCgCombineSsaoProgram->SetTexture(i ++, normalsTex);
+	sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex);
+
+	sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES);
+	sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES);
+	sCgCombineSsaoProgram->SetValue1f(i ++, mSsaoFilterRadius);
+
+	sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix);
+
+	for (int j = 0; j < 4; ++ j, ++ i)
+	{
+		sCgCombineSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z);
+	}
 
 	sCgCombineSsaoProgram->SetValue1f(i ++, mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetWidth());
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt	(revision 3295)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt	(revision 3296)
@@ -203,2 +203,9 @@
 
 sibenik: textures dissappear!!
+
+optimize!!
+full resolution, sky test (stencil??), shadows
+smaller textures??
+test normal ssao with simpler shader!
+
+fix normals!!
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3284)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3296)
@@ -824,4 +824,8 @@
 			</File>
 			<File
+				RelativePath=".\src\shaders\combineSsaoSep.cg"
+				>
+			</File>
+			<File
 				RelativePath=".\src\shaders\common.h"
 				>
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3295)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env	(revision 3296)
@@ -62,9 +62,9 @@
 ## window options
 
-winWidth=800
-winHeight=600
+#winWidth=800
+#winHeight=600
 
-#winWidth=1024
-#winHeight=768
+winWidth=1024
+winHeight=768
 
 useFullScreen=0
@@ -113,4 +113,2 @@
 defaultAmbient=0.4 0.4 0.4
 defaultDiffuse=1.4 1.4 1.4
-
-fix normals: read bavoil!!
