Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp	(revision 3127)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp	(revision 3153)
@@ -82,4 +82,18 @@
 	{
 		for (int i = 0; i < mNumVertices; ++ i)
+		{
+			Vector3 tangent = Normalize(mTangents[i]);
+			Vector3 normal =  Normalize(mNormals[i]);
+
+			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);
+		}
+
+		for (int i = 0; i < mNumVertices; ++ i)
 			((Vector3 *)data)[mNumVertices * 2 + i] = mTangents[i];
 
@@ -111,4 +125,15 @@
 	if (mTangents)
 	{
+		cout << "dotprods: " << endl;
+
+		for (int i = 0; i < 1000; ++ i)
+		{
+			//cout << mTangents[i] << " " << mNormals[i] << " " << DotProd(Normalize(mTangents[i]), Normalize(mNormals[i])) << endl;
+			float d = fabs(DotProd(Normalize(mTangents[i]), Normalize(mNormals[i])));
+			if (d > 0.01) cout << d << " ";
+			//cout << d << " ";
+		}
+		cout << endl;
+	
 		glColorPointer(3, GL_FLOAT, 0, (char *)NULL + currentPVbo);
 		currentPVbo += mNumVertices * sizeof(Vector3);
@@ -133,6 +158,8 @@
 {
 	if (mHasTangents)
+	{
+		cout<<"x";
 		glEnableClientState(GL_COLOR_ARRAY);
-
+	}
 	if (state->GetCurrentVboId() != mVboId)
 	{
@@ -145,6 +172,11 @@
 		if (mHasTangents)
 		{
-			glColorPointer(3, GL_FLOAT, 0, (char *)NULL + mNumVertices * sizeof(Vector3));
+			//glClientActiveTextureARB(GL_TEXTURE1_ARB);
+			//glTexCoordPointer(2, GL_FLOAT, (char *)NULL + mNumVertices * sizeof(Vector3));
+
+			glColorPointer(3, GL_FLOAT, 0, (char *)NULL + mNumVertices * 2 * sizeof(Vector3));
 			currentPointer = mNumVertices * 3 * sizeof(Vector3);
+			//glClientActiveTextureARB(GL_TEXTURE0_ARB);
+
 		}
 		else
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3137)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 3153)
@@ -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;
 	return OUT;
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg	(revision 3152)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg	(revision 3153)
@@ -19,5 +19,4 @@
 	float4 texCoord: TEXCOORD0;    
 
-	float4 tangent: TEXCOORD6;  
 	 // eye position
 	float4 eyePos: TEXCOORD1;
@@ -26,5 +25,6 @@
 	float4 worldPos: TEXCOORD3;
 	float4 oldWorldPos: TEXCOORD4;
-	float4 bitangent: TEXCOORD5;
+	float4 tangent: TEXCOORD5;  
+	float4 bitangent: TEXCOORD6;
 };
 
@@ -33,5 +33,4 @@
 struct fragin
 {
-	float4 tangent: TEXCOORD6;  
 	float4 texCoord: TEXCOORD0;    
 
@@ -42,5 +41,6 @@
 	float4 worldPos: TEXCOORD3;
 	float4 oldWorldPos: TEXCOORD4;
-	float4 bitangent: TEXCOORD5;
+	float4 tangent: TEXCOORD5;  
+	float4 bitangent: TEXCOORD6;
 };
 
@@ -64,5 +64,9 @@
 	vtxout OUT;
 
-	OUT.tangent = IN.color;
+	//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 = IN.color;
 	OUT.texCoord = IN.texCoord;
 
@@ -77,7 +81,9 @@
 	// the normal has to be correctly transformed with the inverse transpose
 	OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
-	OUT.tangent = mul(glstate.matrix.invtrans.modelview[0], IN.color); 
+	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(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);
 
 	return OUT;
@@ -89,4 +95,44 @@
 /*   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 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 = normalize(tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz);
+	//const float3 tangentSpaceNorm = tex2D(normalMap, IN.texCoord.xy).xyz;
+
+	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+	//pix.color.xyz = float3(abs(dot(tangent.xyz, normal.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;
+}
+
 
 
@@ -133,37 +179,2 @@
 }
 
-
-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 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 = normalize(tex2Dlod(normalMap, float4(IN.texCoord.xy, 0, 0)).xyz);
-	//const float3 tangentSpaceNorm = tex2D(normalMap, IN.texCoord.xy).xyz;
-
-	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
-	//pix.color.xyz = tangentSpaceNorm;
-
-	return pix;
-}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3146)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3153)
@@ -267,5 +267,5 @@
 		}
 
-		if (1)//frag != mCurrentFragmentProgram)
+		if (frag != mCurrentFragmentProgram)
 		{			
 			mCurrentFragmentProgram = frag;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3152)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3153)
@@ -344,6 +344,4 @@
 	if (str.eof()) return NULL;
 
-	//cout << "vertexcount: " << vertexCount << endl;
-
 	vertices = new Vector3[vertexCount];
     str.read(reinterpret_cast<char *>(vertices), sizeof(Vector3) * vertexCount);
@@ -367,5 +365,5 @@
 	str.read(reinterpret_cast<char *>(&texCoordCount), sizeof(int));
 
-	cout<<"here3" << texCoordCount << endl;
+
 	if (texCoordCount)
 	{
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3152)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3153)
@@ -477,5 +477,5 @@
 	//LoadModel("hbuddha.dem", dynamicObjects);
 	//LoadModel("venusm.dem", dynamicObjects);
-	LoadModel("camel.dem", dynamicObjects);
+	//LoadModel("camel.dem", dynamicObjects);
 	//LoadModel("toyplane2.dem", dynamicObjects);
 	//LoadModel("elephal.dem", dynamicObjects);
@@ -485,6 +485,4 @@
 	buddha = dynamicObjects.back();
 	
-	cout << "here3 " << buddha->GetWorldCenter() << " " << buddha->GetBoundingBox().Center() << endl;
-
 	const Vector3 sceneCenter(470.398f, 240.364f, 182.5f);
 	
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp	(revision 3107)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/main.cpp	(revision 3153)
@@ -22,5 +22,6 @@
 		exit(0);
 	}
-
+	
+	std::cin.get();
 	cout << "conversion successful" << endl;
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3152)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp	(revision 3153)
@@ -82,4 +82,6 @@
 	// convert the triangles to geometry
 	geom->mVertexCount = numElements;
+	geom->mTexcoordCount = numElements;
+
 	geom->mVertices = new SimpleVec[numElements];
 	geom->mNormals = new SimpleVec[numElements];
@@ -94,19 +96,28 @@
 	{
 		sscanf(str, "%f %f %f %f %f %f %f %f %f %f %f", 
-		       &vtx.x, &vtx.z, &vtx.y, 
-			   &normal.x, &normal.z, &normal.y, 
+		       &vtx.x, &vtx.y, &vtx.z, 
+			   &normal.x, &normal.y, &normal.z, 
 			   &tex.first, &tex.second,
 			   &tangent.x, &tangent.y, &tangent.z);
 
 		const float scale = 0.05f;
-		vtx.x *= scale;
-		vtx.y *= scale;
-		vtx.z *= scale;
-
-		geom->mVertices[line] = vtx;
-		geom->mNormals[line] = normal;
+		
+		geom->mVertices[line].x = vtx.x * scale;
+		geom->mVertices[line].y = vtx.z * scale;
+		geom->mVertices[line].z = vtx.y * scale;
+	
+		geom->mNormals[line].x = normal.x;
+		geom->mNormals[line].y = normal.z;
+		geom->mNormals[line].z = normal.y;
+
+		geom->mTangents[line].x = tangent.x;
+		geom->mTangents[line].y = tangent.z;
+		geom->mTangents[line].z = tangent.y;
+
 		geom->mTexcoords[line] = tex;
-		geom->mTangents[line] = tangent;
-
+
+		static int dummy = 0;
+
+		if (dummy ++ < 5) cout << "tangent: " << geom->mTangents[line] << endl;
 		++ line;
 	}
@@ -134,6 +145,8 @@
 
 	if (texCoordCount)
+	{
 		str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2);
-	
+	}
+
 
 	///////
@@ -163,5 +176,5 @@
 
 		ambient.x = ambient.y = ambient.z = 0.2f;
-		diffuse.x = diffuse.y = diffuse.z = 1.0f;
+		diffuse.x = 0.7f; diffuse.y = 0.4f; diffuse.z = 0.2f;
 		spec.x   = spec.y   = spec.z   =  .0f;
 		emm = spec;
