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
Fragment Shader
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?
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?