Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3151)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3154)
@@ -13,5 +13,6 @@
 //#define SAMPLE_INTENSITY 0.07f
 
-#define SAMPLE_INTENSITY 0.075f
+//#define SAMPLE_INTENSITY 0.075f
+#define SAMPLE_INTENSITY 0.2f
 
 #define SAMPLE_RADIUS 8e-1f
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp	(revision 3153)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp	(revision 3154)
@@ -86,11 +86,9 @@
 			Vector3 normal =  Normalize(mNormals[i]);
 
-			float dotProd = DotProd(tangent,normal);
-
-			tangent -= normal * dotProd;
-			tangent = Normalize(tangent);
+			float dotProd = DotProd(tangent, normal);
+			//tangent -= normal * dotProd;tangent = Normalize(tangent);
 
 			//mTangents[i] = tangent;
-			mTangents[i] = Vector3(0,1,0);//tangent * 0.5f + Vector3(0.5f);
+			mTangents[i] = tangent * 0.5f + Vector3(0.5f);
 		}
 
@@ -98,7 +96,4 @@
 			((Vector3 *)data)[mNumVertices * 2 + i] = mTangents[i];
 
-		for (int i = 0; i < 3; ++ i)
-			cout << ((Vector3 *)data)[mNumVertices * 2 + i] << " ";
-
 		currentPData += mNumVertices * 3;
 	}
@@ -125,7 +120,7 @@
 	if (mTangents)
 	{
-		cout << "dotprods: " << endl;
-
-		for (int i = 0; i < 1000; ++ i)
+		//cout << "dotprods: " << endl;
+
+		/*for (int i = 0; i < 100; ++ i)
 		{
 			//cout << mTangents[i] << " " << mNormals[i] << " " << DotProd(Normalize(mTangents[i]), Normalize(mNormals[i])) << endl;
@@ -135,5 +130,11 @@
 		}
 		cout << endl;
+		*/
 	
+		for (int i = 0; i < 50; ++ i)
+		{
+			cout << mTexCoords[i].first << "," << mTexCoords[i].second << " ";
+		}
+
 		glColorPointer(3, GL_FLOAT, 0, (char *)NULL + currentPVbo);
 		currentPVbo += mNumVertices * sizeof(Vector3);
@@ -159,7 +160,7 @@
 	if (mHasTangents)
 	{
-		cout<<"x";
 		glEnableClientState(GL_COLOR_ARRAY);
 	}
+
 	if (state->GetCurrentVboId() != mVboId)
 	{
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3153)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3154)
@@ -74,5 +74,5 @@
 	// store scaled view vector so wie don't have to normalize for e.g., ssao
 	OUT.color.w = color.w;// / length(IN.view);
-	OUT.color = color;
+	//OUT.color = color;
 	return OUT;
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 3147)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg	(revision 3154)
@@ -97,4 +97,5 @@
 	//float4 col = float4(w, w, w, 0);
 	//float4 col = float4(centerNormal * 0.5f + float3(0.5f), 0);
+	//col = step(.0f, col);
 	//float4 col = float4(centerNormal, 0);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg	(revision 3153)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg	(revision 3154)
@@ -64,7 +64,6 @@
 	vtxout OUT;
 
-	//float4 tangent =  float4(IN.color.xyz * 2.0f - 1.0f, 1.0f);
-	//float4 tangent = float4(1,0,0,1);
-	float4 tangent = IN.color;
+	float4 tangent = float4(IN.color.xyz * 2.0f - float3(1.0f), 1.0f);
+	//float4 tangent = IN.color;
 
 	//float4 tangent = IN.color;
@@ -79,11 +78,12 @@
 	// transform the old vertex position into world space
 	OUT.oldWorldPos = mul(oldModelMatrix, IN.position);
+
 	// the normal has to be correctly transformed with the inverse transpose
+	// convert to view space
 	OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
-	OUT.tangent = tangent;//mul(glstate.matrix.invtrans.modelview[0], tangent); 
-
-	//OUT.bitangent = float4(cross(IN.color.xyz, IN.normal.xyz), 1);
-	//OUT.bitangent = float4(cross(OUT.tangent.xyz, OUT.normal.xyz), 1);
-	OUT.bitangent = float4(cross(OUT.normal.xyz, tangent.xyz), 1);
+	OUT.tangent = mul(glstate.matrix.invtrans.modelview[0], tangent); 
+	
+	OUT.bitangent = float4(cross(OUT.tangent.xyz, OUT.normal.xyz), 1);
+	//OUT.bitangent = float4(cross(OUT.normal.xyz, OUT.tangent.xyz), 1);
 
 	return OUT;
@@ -111,25 +111,36 @@
 	pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz;
 
-	// compute tanget space in world space => transform basis vectors back into world space by
-	// multiplying with inverse view. since transforming normal with T means to 
+	// compute tanget space to world space trafo =>
+	// transform basis vectors back into world space by multiplying with inverse view. 
+	// since transforming normal with T means to 
 	// multiply with the inverse transpose of T, we multiple with 
 	// Transp(Inv(Inv(view))) = Transp(view)
-	float3 normal = mul(transpose(viewMatrix), IN.normal).xyz;
-	float3 tangent = mul(transpose(viewMatrix), IN.tangent).xyz;
-	float3 bitangent = mul(transpose(viewMatrix), IN.bitangent).xyz;
+	const float3 normal = normalize(mul(transpose(viewMatrix), IN.normal).xyz);
+	const float3 tangent = normalize(mul(transpose(viewMatrix), IN.tangent).xyz);
+	const float3 bitangent = normalize(mul(transpose(viewMatrix), IN.bitangent).xyz);
 
 	// compute tangent space - world space transform which is the transpose,
 	// as it is the inverse of a rotation matrix 
-	float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz));
-	const float3 tangentSpaceNorm = normalize(tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz);
-	//const float3 tangentSpaceNorm = tex2D(normalMap, IN.texCoord.xy).xyz;
+	float3x3 tangToWorldTrafo = transpose(float3x3(tangent, bitangent, normal));
+	//float3x3 tangToWorldTrafo = transpose(float3x3(bitangent, tangent, normal));
+	//float3x3 tangToWorldTrafo = transpose(float3x3(tangent, normal, bitangent));
+	//float3x3 tangToWorldTrafo = transpose(float3x3(normal, bitangent, tangent));
+	//float3x3 tangToWorldTrafo = transpose(float3x3(normal, tangent, bitangent));
 
-	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+	const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz * 2.0f - float3(1.0f);
+	//const float3 tangentSpaceNorm = float3(0, 1, 0);
+	//const float3 tangentSpaceNorm = float3(0, 0, 1);
+	
+	pix.normal = normalize(mul(tangToWorldTrafo, tangentSpaceNorm));
+	//pix.normal = normalize(tangentSpaceNorm);
 	//pix.color.xyz = float3(abs(dot(tangent.xyz, normal.xyz)));
+	//pix.color.xyz = float3(abs(dot(bitangent.xyz, tangent.xyz)));
 	//pix.color.xyz = float3(abs(dot(normalize(IN.normal.xyz), normalize(IN.tangent.xyz))));
-	pix.color.xyz = float3(abs(dot(IN.normal.xyz, IN.tangent.xyz)));
+	//pix.color.xyz = float3(abs(dot(IN.normal.xyz, IN.tangent.xyz)));
 	//pix.color.xyz = normal.xyz;
-	pix.color.xyz = IN.tangent.xyz;
-
+	//pix.color.xyz = IN.tangent.xyz;
+	//pix.color.xyz = float3(IN.texCoord.x,0,0);
+	//pix.color.xyz = float3(0,IN.texCoord.y,0);
+	
 	return pix;
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMappingFwd.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMappingFwd.cg	(revision 3154)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMappingFwd.cg	(revision 3154)
@@ -0,0 +1,188 @@
+/*******************************************/
+/*    Shader for normal mapped geoemtry    */
+/*******************************************/
+
+// input
+struct vtxin 
+{
+  float4 position: POSITION;
+  float4 normal: NORMAL;
+  float4 color: COLOR0;
+  float4 texCoord: TEXCOORD0;
+};
+
+
+// vtx output
+struct vtxout
+{
+	float4 position: POSITION;
+	float4 texCoord: TEXCOORD0;    
+
+	 // eye position
+	float4 eyePos: TEXCOORD1;
+	float4 normal: TEXCOORD2;
+
+	float4 worldPos: TEXCOORD3;
+	float4 oldWorldPos: TEXCOORD4;
+	float4 tangent: TEXCOORD5;  
+	float4 bitangent: TEXCOORD6;
+};
+
+
+// fragment input
+struct fragin
+{
+	float4 texCoord: TEXCOORD0;    
+
+	float4 winPos: WPOS;
+	// eye position
+	float4 eyePos: TEXCOORD1;
+	float4 normal: TEXCOORD2;
+	float4 worldPos: TEXCOORD3;
+	float4 oldWorldPos: TEXCOORD4;
+	float4 tangent: TEXCOORD5;  
+	float4 bitangent: TEXCOORD6;
+};
+
+
+struct pixel
+{
+	float4 color: COLOR0;
+	float3 normal: COLOR1;
+	float3 offsVec: COLOR2;
+};
+
+
+#pragma position_invariant vtx
+
+vtxout vtx(vtxin IN, 
+		   uniform float4x4 viewMatrix,
+		   uniform float4x4 modelMatrix,
+		   uniform float4x4 oldModelMatrix
+		   )
+{
+	vtxout OUT;
+
+	float4 tangent = float4(IN.color.xyz * 2.0f - 1.0f, 1.0f);
+	//float4 tangent = IN.color;
+
+	//float4 tangent = IN.color;
+	OUT.texCoord = IN.texCoord;
+
+	// transform the vertex position into eye space
+	OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position);
+	// transform the vertex position into post projection space
+	OUT.position = mul(glstate.matrix.mvp, IN.position);
+	// transform the old vertex position into world space
+	OUT.worldPos = mul(modelMatrix, IN.position);
+	// transform the old vertex position into world space
+	OUT.oldWorldPos = mul(oldModelMatrix, IN.position);
+
+	// the normal has to be correctly transformed with the inverse transpose
+	// convert to view space
+	OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
+	OUT.tangent = mul(glstate.matrix.invtrans.modelview[0], tangent); 
+	
+	OUT.bitangent = float4(cross(OUT.tangent.xyz, OUT.normal.xyz), 1);
+	//OUT.bitangent = float4(cross(OUT.normal.xyz, OUT.tangent.xyz), 1);
+
+	return OUT;
+}
+
+
+
+/******************************************************************/
+/*   Shader computing the MRT output for normal mapped geometry   */
+/******************************************************************/
+
+pixel frag(fragin IN,
+		   uniform float4x4 viewMatrix,
+		   uniform sampler2D normalMap: TEXUNIT0)
+{
+	pixel pix;
+	// hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
+	pix.color = glstate.material.diffuse + glstate.material.emission;
+	
+	// eye space depth
+	pix.color.w = length(IN.eyePos.xyz);
+	// the scene entity id
+	//pix.id = glstate.fog.color.xyz;
+	// the offset to the world pos from old frame
+	pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz;
+
+	// compute tanget space to world space trafo =>
+	// transform basis vectors back into world space by multiplying with inverse view. 
+	// since transforming normal with T means to 
+	// multiply with the inverse transpose of T, we multiple with 
+	// Transp(Inv(Inv(view))) = Transp(view)
+	float3 normal = normalize(mul(transpose(viewMatrix), IN.normal).xyz);
+	float3 tangent = normalize(mul(transpose(viewMatrix), IN.tangent).xyz);
+	float3 bitangent = normalize(mul(transpose(viewMatrix), IN.bitangent).xyz);
+
+	// compute tangent space - world space transform which is the transpose,
+	// as it is the inverse of a rotation matrix 
+	//float3x3 tangToWorldTrafo = transpose(float3x3(tangent, bitangent, normal));
+	//float3x3 tangToWorldTrafo = transpose(float3x3(bitangent, tangent, normal));
+	//float3x3 tangToWorldTrafo = transpose(float3x3(tangent, normal, bitangent));
+	//float3x3 tangToWorldTrafo = transpose(float3x3(normal, bitangent, tangent));
+	float3x3 tangToWorldTrafo = transpose(float3x3(normal, tangent, bitangent));
+
+	//const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz;
+	//const float3 tangentSpaceNorm = float3(0, 1, 0);
+	const float3 tangentSpaceNorm = float3(0, 0, 1);
+	
+	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+	//pix.color.xyz = float3(abs(dot(tangent.xyz, normal.xyz)));
+	//pix.color.xyz = float3(abs(dot(bitangent.xyz, tangent.xyz)));
+	//pix.color.xyz = float3(abs(dot(normalize(IN.normal.xyz), normalize(IN.tangent.xyz))));
+	//pix.color.xyz = float3(abs(dot(IN.normal.xyz, IN.tangent.xyz)));
+	//pix.color.xyz = normal.xyz;
+	//pix.color.xyz = IN.tangent.xyz;
+
+	return pix;
+}
+
+
+
+pixel fragtex(fragin IN, 
+			  uniform sampler2D tex: TEXUNIT0,
+			  uniform float4x4 viewMatrix,
+			  uniform sampler2D normalMap: TEXUNIT1
+			  )
+{
+	float4 texColor = tex2D(tex, IN.texCoord.xy);
+
+	// account for alpha blending
+	if (texColor.w < 0.5f) discard;
+
+	pixel pix;
+
+	// save color in first render target
+	// hack: use combination of emmisive + diffuse (emmisive used as constant ambient term)
+	pix.color = (glstate.material.emission + glstate.material.diffuse) * texColor; 
+	
+	// compute eye linear depth
+	pix.color.w = length(IN.eyePos.xyz);
+
+	// the scene entity id
+	//pix.id = glstate.fog.color.xyz;
+	// the offset to the world pos from old frame
+	pix.offsVec = IN.oldWorldPos.xyz - IN.worldPos.xyz;
+
+	// compute tanget space in world space => transform basis vectors back into world space by
+	// multiplying with inverse view. since transforming normal with T means to 
+	// multiply with the inverse transpose of T, we multiple with 
+	// Transp(Inv(Inv(view))) = Transp(view)
+	float3 normal = mul(transpose(viewMatrix), IN.normal).xyz;
+	float3 tangent = mul(transpose(viewMatrix), IN.tangent).xyz;
+	float3 bitangent = mul(transpose(viewMatrix), IN.bitangent).xyz;
+
+	// compute tangent space - world space transform which is the transpose,
+	// as it is the inverse of a rotation matrix 
+	float3x3 tangToWorldTrafo = transpose(float3x3(IN.tangent.xyz, IN.bitangent.xyz, IN.normal.xyz));
+	const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz;
+	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+
+	return pix;
+}
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3153)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3154)
@@ -377,5 +377,5 @@
 
 	const bool delGeometry = false;
-	return new Geometry(vertices, normals, texcoords, vertexCount, delGeometry, tangents);
+	return new Geometry(vertices, normals, texcoords, vertexCount, delGeometry, NULL);//tangents);
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3153)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3154)
@@ -115,8 +115,8 @@
 		geom->mTangents[line].z = tangent.y;
 
-		geom->mTexcoords[line] = tex;
+		geom->mTexcoords[line].first = tex.first;
+		geom->mTexcoords[line].second = 1.0f - tex.second;
 
 		static int dummy = 0;
-
 		if (dummy ++ < 5) cout << "tangent: " << geom->mTangents[line] << endl;
 		++ line;
@@ -176,6 +176,7 @@
 
 		ambient.x = ambient.y = ambient.z = 0.2f;
-		diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f;
-		spec.x   = spec.y   = spec.z   =  .0f;
+		//diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f;
+		diffuse.x = diffuse.y = diffuse.z = 1.0f;
+		spec.x = spec.y = spec.z = .0f;
 		emm = spec;
 
@@ -217,5 +218,6 @@
 
 		// set boundary to repeat
-		int boundS = 1; int boundT = 1;
+		int boundS, boundT;
+		boundS = boundT = 1;
 		
 		ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int));
