Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3024)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3025)
@@ -91,8 +91,9 @@
 float CalcShadowTerm(fragment IN,
 					 uniform sampler2D shadowMap,
-					 uniform float w,
+					 uniform float scale,
 					 uniform float2 lightSpacePos,
 					 uniform float depth,
 					 uniform float2 samples[NUM_PCF_TABS],
+					 uniform float weights[NUM_PCF_TABS],
 					 uniform sampler2D noiseTexture
 					 )
@@ -101,9 +102,11 @@
 	//return step(depth, shadowDepth);
 
-	float total_d = 0.0;
-	
+	float total_d = .0f;
+	float total_w = .0f;
+
 	for (int i = 0; i < NUM_PCF_TABS; ++ i) 
 	{
 		const float2 offset = samples[i];
+		const float w = weights[i];
 
 #if 1
@@ -117,15 +120,17 @@
 #endif
 		// weight with projected coordinate to reach similar kernel size for near and far
-		float2 texcoord = lightSpacePos + offsetTransformed * w;
+		float2 texcoord = lightSpacePos + offsetTransformed * scale;
 
 		float shadowDepth = tex2D(shadowMap, texcoord).x;
 
-		total_d += step(depth, shadowDepth);
+		total_d += w * step(depth, shadowDepth);
+		total_w += w;
 	}
 
-	total_d /= (float)NUM_PCF_TABS;
+	total_d /= (float)total_w;
 
 	return total_d;
 }
+
 
 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)
@@ -195,4 +200,5 @@
 
 		float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTexture);
+		//float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTexture);
 
 		diffuse *= shadowTerm;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3021)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3025)
@@ -7,4 +7,6 @@
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
+#include <string>
+#include <map>
 
 
@@ -19,4 +21,7 @@
 class DirectionalLight;
 
+typedef std::map<std::string, CGparameter> CGParameterMap;
+typedef std::vector<CGparameter> CGParameterArray;
+
 
 class ShaderProgram
@@ -26,8 +31,42 @@
 	ShaderProgram(CGprogram program): mProgram(program) {}
 
-	~ShaderProgram() { cgDestroyProgram(mProgram); }
+	ShaderProgram(CGcontext context, 
+		          const std::string &filename, 
+				  CGprofile profile,
+				  const std::string &functionName);
+
+	~ShaderProgram() { if (mProgram != NULL) cgDestroyProgram(mProgram); }
+
+	void SetValue1f(const std::string &name, float value);
+	void SetValue2f(const std::string &name, float val1, float val2);
+	void SetValue3f(const std::string &name, float val1, float val, float val3);
+
+	void SetArray1f(const std::string &name, float *vals, int numElements);
+	void SetArray2f(const std::string &name, float *vals, int numElements);
+	void SetArray3f(const std::string &name, float *vals, int numElements);
+
+	void SetMatrix(const std::string &name, const Matrix4x4 &mat);
+
+	void SetTexture(const std::string &name,  unsigned int tex);
+
+	void Release();
+
+	void Bind();
+
+	inline bool IsValid() { return mProgram != NULL; }
+
+
+protected:
+
+	CGparameter GetOrCreateParameter(const std::string &name);
+
+	CGParameterMap mParamHash;
+	//CGParameterArray mParameters;
+
+	CGParameterArray mTextureParams;
 
 	CGprogram mProgram;
 };
+
 
 typedef  std::vector<ShaderProgram *> ShaderContainer;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3021)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3025)
@@ -66,4 +66,5 @@
 static CGparameter sFilterOffsetsParam;
 static CGparameter sFilterWeightsParam;
+static CGparameter sPCFFilterWeightsParam;
 
 static CGprogram sCgDownSampleProgram;
@@ -174,4 +175,14 @@
 
 int DeferredRenderer::colorBufferIdx = 0;
+
+
+
+static float GaussianDistribution(float x, float y, float rho)
+{
+    float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho);
+    g *= expf( -(x*x + y*y) / (2.0f * rho * rho));
+
+    return g;
+}
 
 
@@ -380,5 +391,4 @@
 	ShaderProgram *pr;
 
-
 	sCgDeferredProgram = 
 		cgCreateProgramFromFile(context, 
@@ -583,8 +593,19 @@
 		sEyePosShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "eyePos");
 
+		float filterWeights[NUM_PCF_TABS];
+
+		sPCFFilterWeightsParam = cgGetNamedParameter(sCgDeferredShadowProgram, "weights");
+
 		PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f);
 		poisson.Generate((float *)pcfSamples);
 
+		
+		for (int i = 0; i < NUM_PCF_TABS; ++ i)
+		{
+			filterWeights[i] = GaussianDistribution(pcfSamples[i].x, pcfSamples[i].y, 1.0f);
+		}
+
 		cgGLSetParameterArray2f(sSamplesShadowParam, 0, NUM_PCF_TABS, (const float *)pcfSamples);
+		cgGLSetParameterArray1f(sPCFFilterWeightsParam, 0, NUM_PCF_TABS, (const float *)filterWeights);
 
 		pr = new ShaderProgram(sCgDeferredShadowProgram);
@@ -777,5 +798,4 @@
 #endif
 
-
 	cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x);
 #if 0
@@ -1129,13 +1149,4 @@
 
 
-static float GaussianDistribution(float x, float y, float rho)
-{
-    float g = 1.0f / sqrtf(2.0f * M_PI * rho * rho);
-    g *= expf( -(x*x + y*y) / (2.0f * rho * rho));
-
-    return g;
-}
-
-
 void DeferredRenderer::CombineSsao(FrameBufferObject *fbo)
 {
@@ -1238,5 +1249,5 @@
 
 	cgGLSetParameter1f(sSampleWidthParam, 2.0f / shadowMap->GetSize());
-	
+
 	 
 	cgGLSetMatrixParameterfc(sShadowMatrixParam, (const float *)shadowMatrix.x);
@@ -1441,5 +1452,5 @@
 
 	fbo->Bind();
-#if 1
+	
 	colorBufferIdx = 3 - colorBufferIdx;
 	glDrawBuffers(1, mrt + colorBufferIdx);
@@ -1468,5 +1479,4 @@
 
 	glEnd();
-#endif
 
 	cgGLDisableTextureParameter(sColorsTexToneParam);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3021)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3025)
@@ -244,4 +244,8 @@
 			</File>
 			<File
+				RelativePath=".\src\ShaderProgram.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\src\ShaderProgram.h"
 				>
