Tangent vector

DeTan

23-11-2007 14:28:13

Hi all,

I'm trying to set up a normal map shader but I can't access the tangent vector (CE version with CG). I tried TEXCOORD1 and TANGENT but it gives me only a null vector. I used the following shader to test it:

Vertex Shader

void bump_vertex( float4 position: POSITION,
float3 normal: NORMAL,
float2 texcoord: TEXCOORD0,
float3 tangent: TEXCOORD1,
uniform float4x4 modelViewProj,
uniform float4x4 modelView,
uniform float4 lightPos,
out float4 outPosition: POSITION,
out float2 outTexCoord: TEXCOORD0,
out float3 outTangent: TEXCOORD1,
out float3 outBinormal: TEXCOORD2,
out float3 outNormal: TEXCOORD3,
out float3 outLight: TEXCOORD4,
out float3 outEye: TEXCOORD5)
{
outPosition = mul(modelViewProj, position);

outTexCoord = texcoord;

float3 binormal = cross(normal, tangent);
// outTangent = mul(modelView, float4(tangent, 0.0)).xyz;
outTangent = tangent;
outBinormal = mul(modelView, float4(binormal, 0.0)).xyz;
outNormal = mul(modelView, float4(normal, 0.0)).xyz;

float3 light = normalize(lightPos.xyz - lightPos.w*position.xyz);
outLight = mul(modelView, float4(light, 0.0)).xyz;
outEye = normalize(mul(modelView, position).xyz);
}


Fragment Shader

void bump_diffuse_fragment( float2 texcoord: TEXCOORD0,
float3 tangent: TEXCOORD1,
float3 binormal: TEXCOORD2,
float3 normal: TEXCOORD3,
float3 light: TEXCOORD4,
float3 eye: TEXCOORD5,
uniform float4 diffuse,
uniform sampler bumpMap,
out float4 outColor: COLOR)
{
float3 n = 2.0*tex2D(bumpMap, texcoord) - 1.0;
// n = mul(transpose(float3x3(tangent, binormal, normal)), n);
outColor.xyz = tangent;
}


It should simply print out the tangent vector.
I have already checked the "Generate Tangent Vectors" in the "Object Properties" dialog and "Generate Mapping Coords" is on.
Any ideas?

Lioric

23-11-2007 14:49:36

Do your model has any other UV mapping channel (as several textures, or any vertex data modifier)?

When you export your mesh, what is the channel tangent vectors are created in (see the export log)?

DeTan

23-11-2007 15:01:48

Hi Lioric,

Thanks for the reply.
My modifier list is empty and tangent vectors are generated in texture coordinate 1. I'm using just one normal map texture.


== Exporting Objects ==
Exporting Object: Teapot01
Object has 1 texture sets
Compiling material 01_-_Default
New texture unit CONCGRAY.JPG
Mesh: Teapot01_mesh.... done
Exporting Object: Teapot02
Object has 1 texture sets
Compiling material 02_-_Default
New texture unit normal.jpg
Building Tangent Vectors.... Tangent Vectors generated in texture coordinate set 1
Mesh: Teapot02_mesh.... done

== Exporting Materials ==
01_-_Default
02_-_Default
2 material(s) exported to teapot.material

DeTan

23-11-2007 18:07:42

It worked ok using Ogre3D+osm loader. But I really wanted it to work in Max's viewport.

Lioric

26-11-2007 15:15:54

Post or send me the scene file with the shaders and i will review it