Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3230)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3232)
@@ -6,8 +6,8 @@
 //-- ssao + gi parameters
 
-//#define NUM_SAMPLES 8
+#define NUM_SAMPLES 8
 //#define NUM_SAMPLES 16
 //#define NUM_SAMPLES 24
-#define NUM_SAMPLES 48
+//#define NUM_SAMPLES 48
 
 #define MIN_SAMPLES 8
@@ -60,5 +60,8 @@
 #define NUM_DOWNSAMPLES 9
 
+#define NUM_DOF_TABS 16
 
 
+//#define USE_GTX
+
 #endif // __SHADERENV_H
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/depthOfField.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/depthOfField.cg	(revision 3232)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/depthOfField.cg	(revision 3232)
@@ -0,0 +1,66 @@
+#include "../shaderenv.h"
+
+struct fragment
+{
+	float2 texCoords:  TEXCOORD0; 
+};
+
+
+float2 ComputeBlurFactors(float4 color, float sceneRange)
+{
+	float2 result;
+
+	// Compute blur factor based on the CoC size scaled and normalized to 0..1 range
+	//float pixCoC = abs(Dlens * focalLen * (Zfocus - v.fDepth) / (Zfocus * (v.fDepth - focalLen)));
+	
+	//float blur = saturate(pixCoC * scale / maxCoC);
+	
+	// Depth/blurriness value scaled to 0..1 range
+	//result = float2(v.fDepth / sceneRange, blur);
+
+	return result;
+}
+
+
+float4 Blur(float4 color, 
+			float2 texCoords,
+			float2 blurFactors,
+			sampler2D colorsTex,
+			float2 filterOffs[NUM_DOF_TABS]
+			)
+{
+	float average = .0f;
+	float total_w = .0f;
+
+	for (int i = 0; i < NUM_DOF_TABS; ++ i)
+	{
+		float2 sampleTexCoord = texCoords + filterOffs[i];
+		float4 sampleCol = tex2Dlod(colorsTex, float4(sampleTexCoord, 0, 0));
+		
+		// combine the weights
+		float w = 1;
+		
+		average += sampleCol * w;
+		total_w += w;
+	}
+
+	average /= max(total_w, 1e-6f);
+
+	return saturate(average);
+}
+
+
+float4 DepthOfField(fragment IN, 
+					uniform sampler2D colorsTex,
+					uniform float2 filterOffs[NUM_DOF_TABS],
+					uniform float sceneRange
+					 ): COLOR
+{
+	// center color
+	const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0));
+	
+	float2 blurFactors = ComputeBlurFactors(color, sceneRange);
+	float4 outCol = Blur(color, IN.texCoords, blurFactors, colorsTex, filterOffs);
+	
+	return outCol;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3226)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3232)
@@ -115,4 +115,6 @@
 	float4 ao =  tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));
 
+#if 0 // use half size
+
 	// the following has to be done for half resolution ssao:
 	// get the minimum convergence by exactly sampling the 4 surrounding
@@ -124,5 +126,5 @@
 
 	// get position exactly between old texel centers
-	/*float2 center;
+	float2 center;
 	center.x = (floor(IN.texCoord.x * w - .5f) + 1.0f) / w;
 	center.y = (floor(IN.texCoord.y * h - .5f) + 1.0f) / h;
@@ -137,8 +139,13 @@
 
 	const float minConvergence = min(m1, m2);
-	const float convergence = minConvergence;*/
-	//const float convergence = 0;
+	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 
 	// afterwards we do not use the filter anymore
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/common.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/common.h	(revision 3230)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/common.h	(revision 3232)
@@ -47,6 +47,4 @@
 
 
-
-
 inline float2 myrotate(float2 pt, float angle)
 {
@@ -60,4 +58,2 @@
 }
 
-
-#define USE_GTX
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/temporal.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/temporal.cg	(revision 2868)
+++ 	(revision )
@@ -1,60 +1,0 @@
-
-/** Computes the temporally smoothed indirect illumination buffer and combines it
-	with the color buffer
-*/
-pixel main(fragment IN, 
-		   uniform sampler2D colors,
-		   uniform sampler2D ssao,
-		   uniform sampler2D oldssao,
-		   uniform sampler2D positions
-		   const uniform float4x4 oldModelViewProj,
-		   uniform float maxDepth,
-		   uniform float expFactor
-		   )
-{
-	pixel OUT;
-
-	float4 centerPosition = tex2D(positions, IN.texCoord.xy);
-	
-	float4 col = tex2D(colors, IN.texCoord.xy);
-
-	float ao = tex2D(ssao, IN.texCoord.xy);
-	float4 attenuated_color = ao * col;
-	//float4 attenuated_color = ao;
-
-	//float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
-	//float4 attenuated_color = ao * col + new_col;
-	
-	const float x = expFactor;
-
-	float4 dummy = centerPosition * maxDepth;
-	dummy.w = 1.0f;
-
-	float4 oldPos = mul(oldModelViewProj, dummy);
-
-	float newDepth = oldPos.z / oldPos.w;
- 
-	float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f;
-	float4 col1 = tex2D(oldTex, tex);
-
-	float oldDepth = col1.w;
-	float depthDif = 1.0f - newDepth / oldDepth;
-
-	if ((tex.x >= 0.0f) && (tex.x < 1.0f) && 
-		(tex.y >= 0.0f) && (tex.y < 1.0f) && 
-		(abs(depthDif)  < 1e-4f))
-	{
-		OUT.color = attenuated_color * expFactor + col1 * float4(1.0f - expFactor);
-	}
-	else
-	{
-		OUT.color = attenuated_color;
-	}
-
-	//OUT.color.xyz = viewDir;
-	//OUT.color = attenuated_color;
-	
-	//OUT.color.w = tex2D(colors, IN.texCoord.xy).w;
-
-	return OUT;
-}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3230)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3232)
@@ -189,7 +189,4 @@
 #else
 
-	//static PoissonDiscSampleGenerator2D poisson(mNumSamples, 1.0f);
-	//poisson.Generate(samples);
-
 	PoissonDiscSampleGenerator2D::Generate(samples);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3220)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3232)
@@ -155,4 +155,6 @@
 	void SaveFrame(FrameBufferObject *fbo);
 
+	void DepthOfField(FrameBufferObject *fbo);
+
 
 	////////////
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3231)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3232)
@@ -65,4 +65,6 @@
 static ShaderProgram *sCgLenseFlareProgram = NULL;
 
+static ShaderProgram *sCgDOFProgram = NULL;
+
 
 static GLuint noiseTex2D = 0;
@@ -74,6 +76,8 @@
 #define NUM_PRECOMPUTED_SAMPLES 240
 static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES];
-// number of pcf tabs
+// pcf samples
 static Sample2 pcfSamples[NUM_PCF_TABS];
+// dof samples
+static Sample2 dofSamples[NUM_DOF_TABS];
 
 
@@ -392,4 +396,5 @@
 	sCgPrepareSsaoProgram = sm->CreateFragmentProgram("deferred", "PrepareSsao", "PrepareSsao");
 	sCgLenseFlareProgram = sm->CreateFragmentProgram("lenseFlare", "LenseFlare", "LenseFlare");
+	sCgDOFProgram = sm->CreateFragmentProgram("depthOfField", "DepthOfField", "DepthOfField");
 
 
@@ -408,4 +413,5 @@
 		 "temporalCoherence", "samples", "bl", "br", "tl", 
 		 "tr", "oldModelViewProj", "modelViewProj"};
+
 	sCgGiProgram->AddParameters(giParams, 0, 13);
 
@@ -433,4 +439,5 @@
 		"ssaoFilterRadius", "modelViewProj", "bl", "br", "tl", 
 		"tr", "w", "h"};
+
 	sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13);
 
@@ -471,5 +478,4 @@
 
 	////////////////
-
 	
 	string lenseFlareParams[] = 
@@ -479,7 +485,14 @@
 	sCgLenseFlareProgram->AddParameters(lenseFlareParams, 0, 9);
 
-
+	
 	////////////////
-	//-- prepare filters for ssao
+	
+	string dofParams[] = {"colorsTex", "filterOffs", "sceneRange"};
+
+	sCgDOFProgram->AddParameters(dofParams, 0, 3);
+
+
+	////////////////
+	//-- prepare filter for ssao
 
 	PrepareSsaoFilter();
@@ -500,4 +513,15 @@
 	sCgDeferredShadowProgram->SetArray2f(8, (float *)pcfSamples, NUM_PCF_TABS);
 	sCgDeferredShadowProgram->SetArray1f(9, (float *)filterWeights, NUM_PCF_TABS);
+
+
+	/////////
+	//-- pcf tabs for depth of field
+
+	// todo matt: it is stupid to put num samples and width of kernel into constructor => change this!!!
+	PoissonDiscSampleGenerator2D poisson3(NUM_DOF_TABS, 1.0f);
+	poisson2.Generate((float *)dofSamples);
+
+	//float dofWeights[NUM_PCF_TABS];
+	//sCgDOFProgram->SetArray1f(2, (float *)dofWeights, NUM_DOF_TABS);
 
 	PrintGLerror("init");
@@ -551,4 +575,8 @@
 	}
 
+
+	/// do depth of field
+	DepthOfField(fbo);
+
 	/// compute lense flare
 	LenseFlare(fbo, light);
@@ -1277,4 +1305,25 @@
 
 
+void DeferredRenderer::DepthOfField(FrameBufferObject *fbo)
+{
+	ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx);
+	GLuint colorsTex = colorBuffer->GetTexture();
+	
+	FlipFbos(fbo);
+
+	float sceneRange = 1.0f;
+
+	int i = 0;
+
+	sCgDOFProgram->SetTexture(i ++, colorsTex);
+	sCgDOFProgram->SetArray2f(i ++, (float *)dofSamples, NUM_DOF_TABS);
+	sCgDOFProgram->SetValue1f(i ++, sceneRange);
+
+	DrawQuad(sCgDOFProgram);
+
+	PrintGLerror("LenseFlare");
+}
+
+
 void DeferredRenderer::SaveFrame(FrameBufferObject *fbo)
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3230)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3232)
@@ -776,4 +776,8 @@
 			</File>
 			<File
+				RelativePath=".\src\shaders\depthOfField.cg"
+				>
+			</File>
+			<File
 				RelativePath=".\src\shaders\globillum.cg"
 				>
