Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2802)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 2818)
@@ -2,11 +2,15 @@
 #define __SCENEENTITY_H
 
+#include "glInterface.h"
 #include "common.h"
 #include "AxisAlignedBox3.h"
 #include "Triangle3.h"
-
+#include <Cg/cg.h>
+#include <Cg/cgGL.h>
 
 namespace CHCDemoEngine 
 {
+
+
 
 class Material;
@@ -23,4 +27,5 @@
 
 public:
+	static CGparameter sModelMatrixParam;
 	/** Creates a scene entity.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2801)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2818)
@@ -4,4 +4,7 @@
 
 #include "common.h"
+#include "glInterface.h"
+#include <Cg/cg.h>
+#include <Cg/cgGL.h>
 
 
@@ -51,4 +54,8 @@
 	bool IsDepthPass() { return mIsDepthPass; }
 
+	static CGprofile sCgFragmentProfile;
+	static CGprofile sCgVertexProfile; 
+
+
 protected:
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2802)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2818)
@@ -4,4 +4,6 @@
 #include "Material.h"
 #include "RenderState.h"
+#include <Cg/cg.h>
+#include <Cg/cgGL.h>
 
 
@@ -9,4 +11,5 @@
 {
 
+CGparameter SceneEntity::sModelMatrixParam;
 
 SceneEntity::SceneEntity(Geometry *geometry, 
@@ -29,12 +32,16 @@
 	if (mTransform)
 	{
-		glPushMatrix();
-		glMultMatrixf((float *)mTransform->x);
+		cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mTransform->x);
+		//glPushMatrix();
+		//glMultMatrixf((float *)mTransform->x);
 		mGeometry->Render(state);
 
-		glPopMatrix();
+		//glPopMatrix();
 	}
 	else
 	{
+		static Matrix4x4 identity = IdentityMatrix();
+
+		cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x);
 		mGeometry->Render(state);
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp	(revision 2795)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp	(revision 2818)
@@ -119,5 +119,4 @@
 					}
 
-					
 					// always traverse a node if it was visible
 					if (wasVisible)
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2795)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 2818)
@@ -22,6 +22,5 @@
 	mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f);
 	mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
-	//mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f);
-	mSpecularColor = RgbaColor(0.5f, 0.5f, 0.5f, 1.0f);
+	mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f);
 	mEmmisiveColor = RgbaColor(.0f, .0f, .0f, 1.0f);
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2817)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2818)
@@ -1,8 +1,8 @@
 // occquery.cpp : Defines the entry point for the console application.
 //
+#include "glInterface.h"
 #include <math.h>
 #include <time.h>
 #include "common.h"
-#include "glInterface.h"
 #include "RenderTraverser.h"
 #include "SceneEntity.h"
@@ -209,7 +209,4 @@
 static CGprogram sCgMrtFragmentProgram = NULL;
 
-static CGprofile sCgFragmentProfile;
-static CGprofile sCgVertexProfile; 
-
 static CGparameter sColorsTexParam;
 static CGparameter sPositionsTexParam;
@@ -217,11 +214,6 @@
 static CGparameter sNoiseTexParam;
 
-/*static CGparameter sTexSizeParam; 
-static CGparameter sSamplesParam; 
-static CGparameter sEyeVecParam; 
-static CGparameter sRadiusParam; 
-*/
-static CGparameter sProjectionMatrixParam;
-static CGparameter sModelViewMatrixParam;	
+static CGparameter sModelViewProjMatrixParam;
+//static CGparameter sModelMatrixParam;
 static CGparameter sMaxDepthParam;
 
@@ -276,4 +268,7 @@
 
 	glutCreateWindow("FriendlyCulling");
+
+	//glutGameModeString( "1024x768:32@75" ); //the settings for fullscreen mode
+	//glutEnterGameMode(); //set glut to fullscreen using the settings in the line above
 
 	glutDisplayFunc(Display);
@@ -333,5 +328,5 @@
 	//bvh = bvhLoader.Load("data/city/model/city.bvh", sceneEntities);
 
-	myfar = 1.0f * Magnitude(bvh->GetBox().Diagonal());
+	myfar = 10.0f * Magnitude(bvh->GetBox().Diagonal());
 
 	if (!bvh)
@@ -353,5 +348,5 @@
 	visualization = new Visualization(bvh, camera, NULL, &state);
 
-	sceneQuery = new SceneQuery(bvh->GetBox(), traverser);
+	//sceneQuery = new SceneQuery(bvh->GetBox(), traverser);
 
 
@@ -376,10 +371,10 @@
 
 	// get the best profile for this hardware
-	sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
+	RenderState::sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
 	//assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN);
-	cgGLSetOptimalOptions(sCgFragmentProfile);
-
-	sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
-	cgGLSetOptimalOptions(sCgVertexProfile);
+	cgGLSetOptimalOptions(RenderState::sCgFragmentProfile);
+
+	RenderState::sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
+	cgGLSetOptimalOptions(RenderState::sCgVertexProfile);
 
 	sCgMrtVertexProgram = 
@@ -387,5 +382,5 @@
 								CG_SOURCE,
 								"src/shaders/mrt.cg", 
-								sCgVertexProfile,
+								RenderState::sCgVertexProfile,
 								"vtx",
 								NULL);
@@ -394,6 +389,7 @@
 	{
 		cgGLLoadProgram(sCgMrtVertexProgram);
-	
-		sModelViewMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj");
+
+		SceneEntity::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelMatrix");
+		sModelViewProjMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj");
 	}
 
@@ -402,5 +398,5 @@
 								CG_SOURCE,
 								"src/shaders/mrt.cg", 
-								sCgFragmentProfile,
+								RenderState::sCgFragmentProfile,
 								"frag",
 								NULL);
@@ -411,5 +407,6 @@
 
 		sMaxDepthParam = cgGetNamedParameter(sCgMrtFragmentProgram, "maxDepth");
-		cgGLSetParameter1f(sMaxDepthParam, 1.0f / myfar);
+
+		cgGLSetParameter1f(sMaxDepthParam, 10.0f / myfar);
 	}
 	else
@@ -426,5 +423,5 @@
 								"src/shaders/deferred.cg", 
 								//"src/test.cg", 
-								sCgFragmentProfile,
+								RenderState::sCgFragmentProfile,
 								NULL,
 								NULL);
@@ -438,16 +435,5 @@
 		sColorsTexParam = cgGetNamedParameter(sCgSSAOProgram, "colors");  
 		sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals");  
-		sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture");  
-
-		sProjectionMatrixParam = cgGetNamedParameter(sCgSSAOProgram, "ProjTrafo");
-
-		/*sTexSizeParam = cgGetNamedParameter(sCgSSAOProgram, "invTexSize");
-		sRadiusParam = cgGetNamedParameter(sCgSSAOProgram, "radius");
-		sEyeVecParam = cgGetNamedParameter(sCgSSAOProgram, "eyevec");
-		sSamplesParam = cgGetNamedParameter(sCgSSAOProgram, "samples");
-
-		cgGLSetParameter1f(sTexSizeParam, 1.0f / (float)texWidth);
-		cgGLSetParameter1f(sRadiusParam, radius);
-		cgGLSetParameterArray3f(sSamplesParam, 0, 32, (const float *)samples);*/
+		sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture");
 	}
 	else
@@ -455,4 +441,6 @@
 
 	PrintGLerror("init");
+
+	cout << "cg initialised" << endl;
 }
 
@@ -584,27 +572,4 @@
 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
 
-
-	////////////////
-	//-- second fbo
-
-	/*glGenFramebuffersEXT(1, &fbo2);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2);
-
-	// create color buffer
-	glGenRenderbuffersEXT(1, &occlusionbuffer);
-	//glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
-	glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_FLOAT_RGBA_NV, texWidth2, texHeight2);
-	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, occlusionbuffer);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, occlusionbuffer);
-
-	glGenTextures(1, &occlusionTex);
-	glBindTexture(GL_TEXTURE_2D, occlusionTex);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth2, texHeight2, 0, GL_RGBA, GL_FLOAT, NULL);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorTex, 0);
-
-	PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);*/
 	PrintGLerror("fbo");
 }
@@ -882,8 +847,8 @@
 	glViewport(0, 0, texWidth, texHeight);
 
-	cgGLEnableProfile(sCgFragmentProfile);
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgMrtFragmentProgram);
 
-	cgGLEnableProfile(sCgVertexProfile);
+	cgGLEnableProfile(RenderState::sCgVertexProfile);
 	cgGLBindProgram(sCgMrtVertexProgram);
 
@@ -896,4 +861,7 @@
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
+	// set modelview matrix for shaders
+	cgGLSetStateMatrixParameter(sModelViewProjMatrixParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
+
 	// render without shading
 	if (depthPass) 
@@ -907,15 +875,11 @@
 		glEnable(GL_LIGHTING);
 	}
-
+	
+	static Matrix4x4 identity = IdentityMatrix();
+
+	cgGLSetMatrixParameterfc(SceneEntity::sModelMatrixParam, (const float *)identity.x);
 	// bring eye modelview matrix up-to-date
 	SetupEyeView();
 
-	Vector3 dir = camera->GetDirection();
-	//cgGLSetParameter3f(sEyeVecParam, dir.x, dir.y, dir.z);
-
-	// set modelview matrix for shaders
-	cgGLSetStateMatrixParameter(sModelViewMatrixParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
-	cgGLEnableProfile(sCgVertexProfile);
-
 	// actually render the scene geometry using one of the specified algorithms
 	traverser->RenderScene();
@@ -947,11 +911,9 @@
 	
 	
-	cgGLDisableProfile(sCgVertexProfile);
-	cgGLDisableProfile(sCgFragmentProfile);
+	cgGLDisableProfile(RenderState::sCgVertexProfile);
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
 
 	glPopAttrib();
 
-	cgGLSetStateMatrixParameter(sProjectionMatrixParam, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
-	
 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
 
@@ -1497,6 +1459,6 @@
 	static char msg[7][300];
 
-	static double renderTime = algTime;
-	const float expFactor = 0.5f;
+	static double renderTime = elapsedTime;//algTime;
+	const float expFactor = 0.1f;
 
 	// if some strange render time spike happened in this frame => don't count
@@ -1629,7 +1591,7 @@
 {
 	glDisable(GL_TEXTURE_2D);
-	//glEnable(GL_TEXTURE_2D);
+	
 	glDisable(GL_LIGHTING);
-	//glBindTexture(GL_TEXTURE_2D, noiseTex);
+	
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
@@ -1641,11 +1603,10 @@
 
 	const float offs = 0.5f;
-	//glPushAttrib(GL_VIEWPORT_BIT);
-	//glViewport(-offs, texHeight);
+	
 	glOrtho(-offs, offs, -offs, offs, 0, 1);
 	
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	cgGLEnableProfile(sCgFragmentProfile);
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgSSAOProgram);
 
@@ -1668,8 +1629,8 @@
 
 	glBegin(GL_QUADS);
-#if 1
+
 	// slightly larger than screen size in order to hide ambient occlusion errors
-	float offs2 = 0.55f;
-	//float offs2 = 0.5f;
+	//float offs2 = 0.55f;
+	float offs2 = 0.5f;
 
 	glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f);
@@ -1677,10 +1638,5 @@
 	glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f);
 	glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f);
-#else
-	glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
-	glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f);
-	glTexCoord2f(1, 1); glVertex3f( 1,  1, -0.5f);
-	glTexCoord2f(0, 1); glVertex3f(-1,  1, -0.5f);
-#endif
+
 	glEnd();
 
@@ -1690,5 +1646,5 @@
 	cgGLDisableTextureParameter(sNoiseTexParam);
 
-	cgGLDisableProfile(sCgFragmentProfile);
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
 	
 	glEnable(GL_LIGHTING);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2817)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2818)
@@ -60,11 +60,11 @@
 	   uniform sampler2D positions,
 	   uniform sampler2D normals,
-	   const uniform float4x4 ProjTrafo,
 	   uniform sampler2D noiseTexture				
 	   )
 {
   // the current world position
-  float4 centerPositionW = tex2D(positions, IN.texCoord.xy);
-  float3 centerPosition = centerPositionW.xyz;
+  float4 centerPosition = tex2D(positions, IN.texCoord.xy);
+  // the w coordinate from the persp. projection
+  float w = centerPosition.w;
 
   // the normal on the current position
@@ -87,6 +87,7 @@
     //sample noisetex; r stores costheta, g stores sintheta
     float3 noise = tex2D(noiseTexture, IN.texCoord.xy).xyz * 2.0f - 1.0f;
-
-    //float2 offsetTransformed = offset;//reflect(offset, noise.xy);
+	
+    // rotation
+    //float2 offsetTransformed = offset;
     float2 offsetTransformed;
     offsetTransformed.x = noise.r * offset.x - noise.g * offset.y;
@@ -94,9 +95,9 @@
 		
     // weight with projected coordinate to reach similar kernel size for near and far
-    float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * centerPositionW.w;
+    float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * w;
     
     float3 sample_position = tex2D(positions, texcoord).xyz;
     
-    float3 vector_to_sample = sample_position - centerPosition;
+    float3 vector_to_sample = sample_position - centerPosition.xyz;
     float length_to_sample = length(vector_to_sample);
     float3 direction_to_sample = vector_to_sample / (length_to_sample + 1e-9f);
@@ -125,5 +126,4 @@
            uniform sampler2D positions,
            uniform sampler2D normals,
-	   const uniform float4x4 ProjTrafo,
 	   uniform sampler2D noiseTexture)
 {
@@ -137,5 +137,5 @@
 
   // expand normal
-  normal = normal * 2.0f - 1.0f;
+  normal = normalize(normal * 2.0f - 1.0f);
 
   float4 position = tex2D(positions, IN.texCoord.xy);
@@ -146,5 +146,5 @@
   float3 light = normalize(lightDir.xyz);
   float3 light2 = normalize(lightDir2.xyz);
-
+ 
   float diffuseLight = max(dot(normal, light), 0.0f);
   float diffuseLight2 = max(dot(normal, light2), 0.0f);
@@ -152,12 +152,8 @@
   float diffuse = diffuseLight + diffuseLight2;
 
-  float ao = ssao(IN, positions, normals, ProjTrafo, noiseTexture);
+  float ao = ssao(IN, positions, normals, noiseTexture);
   //OUT.color = ao; 
   OUT.color = ao * (ambient + diffuse) * color;
-//OUT.color = (ambient + diffuse) * color;
-
-  //float4 currentPos = tex2D(normals, IN.texCoord.xy) * 0.5f + 0.5f;
-  //float4 currentPos = tex2D(normals, IN.texCoord.xy);
-  //OUT.color = currentPos;
+  //OUT.color = (ambient + diffuse) * color;
       
   return OUT;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2813)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 2818)
@@ -41,17 +41,21 @@
 
 
-vtxout vtx(vtxin IN, uniform float4x4 ModelViewProj)
+vtxout vtx(vtxin IN, 
+	   const uniform float4x4 ModelViewProj,
+	   uniform float4x4 ModelMatrix)
 {
    vtxout OUT;
   
    // transform the vertex position into eye space
-   OUT.position = mul(ModelViewProj, IN.position);
-
    OUT.color = IN.color;
 
    OUT.texCoord = IN.texCoord;
+   OUT.worldPos = mul(ModelMatrix, IN.position);
+
+   // transform the vertex position into eye space
+   OUT.position = mul(ModelViewProj, OUT.worldPos);
+
    OUT.worldPos = IN.position;
-   // eye pos with linear depth
-   //OUT.worldPos = OUT.position;
+
    OUT.normal = IN.normal;
 
@@ -66,6 +70,6 @@
   pix.col = tex2D(tex, IN.texCoord.xy);
   pix.pos = IN.worldPos * maxDepth;
+  pix.norm = IN.normal;
   pix.pos.w = IN.projPos.w;
-  pix.norm = IN.normal;
 
   return pix;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/FragmentSsao.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/FragmentSsao.cg	(revision 2810)
+++ 	(revision )
@@ -1,105 +1,0 @@
-struct INPUTDATA
-{
-	float2 diffuseTexCoords : TEXCOORD0;
-	
-};
-
-struct OUTPUTDATA
-{
-	float4 color			: COLOR0;
-
-};
-
-#define SAMPLES				24
-
-//kustls magic sample positions
-static const float2 samples[SAMPLES] =
-	{
-		{-0.326212f, -0.405805f},
-		{-0.840144f, -0.07358f},
-		{-0.695914f, 0.457137f},
-		{-0.203345f, 0.620716},
-		{0.96234f, -0.194983f},
-		{0.473434f, -0.480026f},
-		{0.519456, 0.767022f},
-		{0.185461f, -0.893124f},
-		{0.507431f, 0.064425f},
-		{0.89642f, 0.412458f},
-		{-0.32194f, -0.932615f},
-		{-0.791559f, -0.597705f},
-		{0.326212f, 0.405805f},
-		{0.840144f, 0.07358f},
-		{0.695914f, -0.457137f},
-		{0.203345f, -0.620716},
-		{-0.96234f, 0.194983f},
-		{-0.473434f, 0.480026f},
-		{-0.519456, -0.767022f},
-		{-0.185461f, 0.893124f},
-		{-0.507431f, -0.064425f},
-		{-0.89642f, -0.412458f},
-		{0.32194f, 0.932615f},
-		{0.791559f, 0.597705f}
-	};
-	
-//based on kustls shader	
-OUTPUTDATA main(INPUTDATA input,
-				uniform sampler2D positions,
-				uniform sampler2D colors,
-				uniform sampler2D normals,
-				const uniform float4x4 projectionTransformation,
-				uniform sampler2D noiseTexture				
-				)
-{
-			
-	OUTPUTDATA o;
-
-	float4 centerPositionW = tex2D(positions, input.diffuseTexCoords);
-	float3 centerPosition = centerPositionW.xyz;
-	float3 centerNormal = tex2D(normals, input.diffuseTexCoords).xyz;
-	float3 centerColor = tex2D(colors, input.diffuseTexCoords).xyz;
-
-	// Check in a circular area around the current position.
-	// Shoot vectors to the positions there, and check the angle to these positions.
-	// Summing up these angles gives an estimation of the occlusion at the current position.
-
-	float total_ao = 0.0;
-	const float areaSize = 4.0f;
-	const float sampleIntensity = 0.1;
-
-	for (int sample = 0; sample < SAMPLES; sample++)
-	{
-		float2 offset = samples[sample];
-		
-		//sample noisetex; r stores costheta, g stores sintheta
-		float3 randomRotation = tex2D(noiseTexture, input.diffuseTexCoords*10.0f).xyz;
-				
-		float2 offsetTransformed;
-		offsetTransformed.x = randomRotation.r*offset.x - randomRotation.g*offset.y;
-		offsetTransformed.y = randomRotation.g*offset.x + randomRotation.r*offset.y;
-		
-		
-		float2 texcoord = input.diffuseTexCoords + offsetTransformed * areaSize*(1.0f-centerPositionW.w);
-		
-		float3 sample_position = tex2D(positions, texcoord).xyz;
-		
-		float3 vector_to_sample = sample_position - centerPosition;
-		float length_to_sample = length(vector_to_sample);
-		float3 direction_to_sample = vector_to_sample / length_to_sample;
-		
-		// Angle between current normal and direction to sample controls AO intensity.
-		float angle = dot(direction_to_sample, centerNormal);
-		angle = max(angle, 0.0);
-		
-		// Distance between current position and sample position controls AO intensity.
-		float distance_intensity = 2.0 - 2.0f*length_to_sample;
-		distance_intensity = max(distance_intensity, 0.0);
-		
-		total_ao += angle * sampleIntensity * distance_intensity;
-	}
-	
-	
-	o.color.rgb = (1.0f-total_ao)*saturate(centerColor);
-	
-
-	return o;
-}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/test.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/test.cg	(revision 2809)
+++ 	(revision )
@@ -1,27 +1,0 @@
-struct fragment
-{
-      float4 position  : POSITION; // screen position
-      float4 color0    : COLOR0;
-      float4 texCoord: TEXCOORD0;
-};
-
-
-struct pixel
-{
-      float4 color : COLOR;	
-};
-
-
-pixel main(fragment IN, 
-           const uniform sampler2D tex, 
-           const uniform sampler2D depthTex)
-{
-      pixel OUT;
-      //OUT.color = IN.color0;
-	
-      float4 col = tex2D(tex, IN.texCoord.xy) * 0.01;
-      col += tex2D(depthTex, IN.texCoord.xy).x * 0.5;
-      OUT.color = col;
-	
-      return OUT;
-}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ambient_occlusion.fx
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ambient_occlusion.fx	(revision 2810)
+++ 	(revision )
@@ -1,193 +1,0 @@
-//=======================================================================================
-string description = "Screenspace Ambient Occlusion";
-//=======================================================================================
-
-
-//=======================================================================================
-
-
-#define SAMPLES				24
-
-static const float2 samples[SAMPLES] =
-	{
-		{-0.326212f, -0.405805f},
-		{-0.840144f, -0.07358f},
-		{-0.695914f, 0.457137f},
-		{-0.203345f, 0.620716},
-		{0.96234f, -0.194983f},
-		{0.473434f, -0.480026f},
-		{0.519456, 0.767022f},
-		{0.185461f, -0.893124f},
-		{0.507431f, 0.064425f},
-		{0.89642f, 0.412458f},
-		{-0.32194f, -0.932615f},
-		{-0.791559f, -0.597705f},
-		{0.326212f, 0.405805f},
-		{0.840144f, 0.07358f},
-		{0.695914f, -0.457137f},
-		{0.203345f, -0.620716},
-		{-0.96234f, 0.194983f},
-		{-0.473434f, 0.480026f},
-		{-0.519456, -0.767022f},
-		{-0.185461f, 0.893124f},
-		{-0.507431f, -0.064425f},
-		{-0.89642f, -0.412458f},
-		{0.32194f, 0.932615f},
-		{0.791559f, 0.597705f}
-	};
-	
-	
-//=======================================================================================
-
-
-float4x4 WorldViewProj			: WorldViewProjection;
-float4x4 WorldView				: WorldView;
-
-float4x4 CameraViewProjection;
-
-shared float3 WorldCenterPosition;		// Center positions around this point (usually eye point).
-shared float WorldScale;				// Scale positions to maintain precision.
-
-float AreaSize = 1.0;
-float SampleIntensity = 0.1;
-
-
-//=======================================================================================
-
-
-shared texture positions;
-shared texture diffuse;
-shared texture normals;
-
-sampler PositionsSampler = sampler_state 
-{
-    texture = <positions>;
-    AddressU  = CLAMP;        
-    AddressV  = CLAMP;
-    AddressW  = CLAMP;
-    MINFILTER = POINT;
-    MAGFILTER = POINT;
-    MIPFILTER = NONE;
-};
-
-sampler DiffuseSampler = sampler_state 
-{
-    texture = <diffuse>;
-    AddressU  = CLAMP;        
-    AddressV  = CLAMP;
-    AddressW  = CLAMP;
-    MINFILTER = POINT;
-    MAGFILTER = POINT;
-    MIPFILTER = NONE;
-};
-
-sampler NormalsSampler = sampler_state 
-{
-    texture = <normals>;
-    AddressU  = CLAMP;        
-    AddressV  = CLAMP;
-    AddressW  = CLAMP;
-    MINFILTER = POINT;
-    MAGFILTER = POINT;
-    MIPFILTER = NONE;
-};
-
-
-//=======================================================================================
-
-
-struct VertexInput {
-	float4 position			: POSITION;
-	float2 texcoord			: TEXCOORD0;
-};
-
-struct VertexOutput {
-	float4 position			: POSITION;
-	float2 texcoord			: TEXCOORD0;
-};
-
-struct PixelOutput {
-	float4 color			: COLOR0;
-};
-
-
-//=======================================================================================
-
-
-VertexOutput vs_render(VertexInput IN)
-{
-	VertexOutput OUT;
-
-	OUT.position = float4(IN.position.xyz, 1.0);
-	OUT.texcoord = IN.texcoord;
-	
-	return OUT;
-}
-
-
-//=======================================================================================
-
-
-PixelOutput ps_render(VertexOutput IN)
-{
-	PixelOutput OUT;
-
-	float4 positions = tex2D(PositionsSampler, IN.texcoord);
-	float4 normals = tex2D(NormalsSampler, IN.texcoord);
-	
-	float3 current_position = positions.xyz;
-	float3 current_normal = normals.xyz * 2.0 - 1.0;
-	
-	// Get postprojection Z value to adjust AO area size.
-	float3 worldposition = (positions.xyz / WorldScale) + WorldCenterPosition;
-	float4 projected_position = mul(float4(worldposition.xyz, 1.0), CameraViewProjection);
-	projected_position.xyz /= projected_position.w;
-	
-
-	// Check in a circular area around the current position.
-	// Shoot vectors to the positions there, and check the angle to these positions.
-	// Summing up these angles gives an estimation of the occlusion at the current position.
-
-	float total_ao = 0.0;
-
-	for (float sample = 0.0; sample < SAMPLES; sample++)
-	{
-		float2 offset = samples[sample];
-		float2 texcoord = IN.texcoord + offset * AreaSize * (1.0 - projected_position.z);
-		
-		float3 sample_position = tex2D(PositionsSampler, texcoord).xyz;
-		
-		float3 vector_to_sample = sample_position - current_position;
-		float length_to_sample = length(vector_to_sample);
-		float3 direction_to_sample = vector_to_sample / length_to_sample;
-		length_to_sample /= WorldScale;
-		
-		// Angle between current normal and direction to sample controls AO intensity.
-		float angle = dot(direction_to_sample, current_normal);
-		angle = max(angle, 0.0);
-		
-		// Distance between current position and sample position controls AO intensity.
-		float distance_intensity = 1.0 - length_to_sample * 2.0;
-		distance_intensity = max(distance_intensity, 0.0);
-		
-		total_ao += angle * SampleIntensity * distance_intensity;
-	}
-	
-	
-	OUT.color = float4(0.0, 0.0, 0.0, total_ao);
-	
-	return OUT;
-}
-
-
-//=======================================================================================
-
-
-technique render
-{
-	pass p0
-	{
-		VertexShader = compile vs_3_0 vs_render();
-		PixelShader = compile ps_3_0 ps_render();	
-	}
-}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/test2.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/test2.cg	(revision 2809)
+++ 	(revision )
@@ -1,27 +1,0 @@
-struct fragment
-{
-      float4 pos: WPOS; // world position
-      float4 color0  : COLOR0;
-      float4 texCoord: TEXCOORD0;      
-      float4 lindepth: TEXCOORD1;
-};
-
-
-struct pixel
-{
-      float4 color0: COLOR0;
-      float4 color1: COLOR1;
-};
-
-
-pixel main(fragment IN, uniform sampler2D tex, uniform float maxDepth)
-//pixel main(fragment IN, uniform sampler2D tex)
-{
-     pixel pix;
-      
-     pix.color0 = IN.color0 * tex2D(tex, IN.texCoord.xy);
-     pix.color1 = IN.lindepth.z * maxDepth;// * IN.pos.z / IN.pos.w;
-    // pix.color1.w = 1;
-
-     return pix;
-}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2816)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2818)
@@ -1,4 +1,3 @@
 #include "RenderState.h"
-#include "glInterface.h"
 #include "Geometry.h"
 #include "Material.h"
@@ -7,4 +6,7 @@
 namespace CHCDemoEngine 
 {
+
+CGprofile RenderState::sCgFragmentProfile;
+CGprofile RenderState::sCgVertexProfile; 
 
 
@@ -34,4 +36,7 @@
 			glDisable(GL_LIGHTING);
 			glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+
+			cgGLDisableProfile(sCgFragmentProfile);
+			cgGLDisableProfile(sCgVertexProfile);
 		}
 
@@ -49,4 +54,7 @@
 			glEnable(GL_LIGHTING);
 			glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+			cgGLEnableProfile(sCgFragmentProfile);
+			cgGLEnableProfile(sCgVertexProfile);
 		}
 
@@ -68,5 +76,5 @@
 	{
 		mAlphaTestEnabled = true;
-		//glEnable(GL_ALPHA_TEST);
+		glEnable(GL_ALPHA_TEST);
 	}
 
