Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg	(revision 3131)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg	(revision 3131)
@@ -0,0 +1,167 @@
+/*******************************************/
+/*    Shader for normal mapped geoemtry    */
+/*******************************************/
+
+/**************************************************************/
+/* Shader computing the MRT output for normal mapped geoemtry */
+/**************************************************************/
+
+
+// input
+struct vtxin 
+{
+  float4 position: POSITION;
+  float4 normal: NORMAL;
+  float4 tangent: COLOR0;
+  float4 texCoord: TEXCOORD0;
+};
+
+
+// vtx output
+struct vtxout
+{
+	float4 position: POSITION;
+	float4 texCoord: TEXCOORD0;    
+
+	float4 tangent: COLOR0;  
+	 // eye position
+	float4 eyePos: TEXCOORD1;
+	float4 normal: TEXCOORD2;
+
+	float4 worldPos: TEXCOORD3;
+	float4 oldWorldPos: TEXCOORD4;
+	float4 bitangent: TEXCOORD5
+};
+
+
+// fragment input
+struct fragin
+{
+	float4 tangent: COLOR0;  
+	float4 texCoord: TEXCOORD0;    
+
+	float4 winPos: WPOS;
+	// eye position
+	float4 eyePos: TEXCOORD1;
+	float4 normal: TEXCOORD2;
+	float4 worldPos: TEXCOORD3;
+	float4 oldWorldPos: TEXCOORD4;
+	float4 bitangent: TEXCOORD5
+};
+
+
+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;
+
+	OUT.color = 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
+	OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal);
+	OUT.tangent = mul(glstate.matrix.invtrans.modelview[0], IN.color); 
+
+	OUT.bitangent = cross(IN.tangent, IN.normal);
+
+	return OUT;
+}
+
+
+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, IN.bitangent, IN.normal));
+	const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy).xyz);
+	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+
+	return pix;
+}
+
+
+pixel frag(fragin IN, uniform float4x4 viewMatrix)
+{
+	pixel pix;
+	// hack: use comination of emmisive + diffuse (emmisive used as constant ambient term)
+	pix.col = glstate.material.diffuse + glstate.material.emission;
+	// save world space normal in rt => transform 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)
+	pix.norm = mul(transpose(viewMatrix), IN.normal).xyz;
+	// eye space depth
+	pix.col.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;
+
+	pixel pix;
+	// 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, IN.bitangent, IN.normal));
+	const float3 tangentSpaceNorm = tex2Dlod(normalMap, float4(IN.texCoord.xy).xyz);
+	pix.normal = mul(tangToWorldTrafo, tangentSpaceNorm);
+
+	return pix;
+}
