matTangent

If a matrix with this name appears in a shader, the engine calculates the tangents for the 3rd texture coordinate set (TEXCOORD2) for all models using that shader.

Type:

float3x3

Remarks:

Edition:

A6.60  C 

Example:

// normal mapping effect for vs 1.1 / ps 1.1
texture entSkin1;	// texture
texture entSkin2;	// normal map

sampler sBaseTex = sampler_state { Texture = <entSkin1>; };
sampler sBump = sampler_state { Texture = <entSkin2>; };

float4 vecSunDir;
float4x4 matWorldViewProj; float3x3 matTangent; // hint for the engine to create tangents in TEXCOORD2 // create a matrix for conversion to tangent space void CreateTangents(float3 inNormal,float3 inTangent) { matTangent[0] = mul(inTangent,matWorld); matTangent[1] = mul(cross(inTangent,inNormal),matWorld); // binormal matTangent[2] = mul(inNormal,matWorld); } struct out_bump { float4 Pos: POSITION; float2 Tex: TEXCOORD0; float2 Bump: TEXCOORD1; float3 Light: TEXCOORD2; }; out_bump vs_bump( in float4 inPos: POSITION, in float3 inNormal: NORMAL, in float2 inTex: TEXCOORD0, in float3 inTangent: TEXCOORD2) { out_bump Out; Out.Pos = mul(inPos,matWorldViewProj); Out.Tex = inTex; Out.Bump = inTex; // must be different coordinates for ps_1_1 CreateTangents(inNormal,inTangent); // convert the sun vector to tangent space // and transform the output values to the 0..1 range
// that is required for passing them to the pixel shader
Out.Light = normalize(mul(matTangent,-vecSunDir)) * 0.5 + 0.5; return Out; } float4 ps_bump(out_bump In): COLOR { float4 texture = tex2D(sBaseTex,In.Tex); float3 bumpNormal = tex2D(sBump,In.Bump); // transform values back to the -1..+1 range float diffuse = saturate(dot(In.Light*2 - 1,bumpNormal*2 - 1)); return texture * diffuse; } technique NormalMapping { pass One { VertexShader = compile vs_1_1 vs_bump(); PixelShader = compile ps_1_1 ps_bump(); } }

See also:

Shader variables, matBones

► latest version online