This shader will do specular and diffuse normal mapping from the sun. Put color map+specmap in alpha channel in skin 1, normal map in skin 2.

define the material like this:
material mat_normalmap
{
flags=tangent;
}

after you load you level do this in a function:
effect_load(mat_normalmap,"normalmap.fx");
mat_normalmap.skill1=float(sun_pos.x);
mat_normalmap.skill2=float(sun_pos.z);
mat_normalmap.skill3=float(sun_pos.y);

then make an fx file called normalmap.fx with this code:

Code:
 
// -------------------------------------------------------------
// Diffuse and specular shader for models
// -------------------------------------------------------------
//Only does sun light, no dynamic lights..

float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecViewPos;
float4 vecFog;
float4 vecSkill1;

float4 ambientcolor={0.3,0.3,0.3,0.0}; //can also use vecLight here for true ambient color
float4 suncolor={0.8,0.8,0.7,0.0}; //define the suncolor here, couls al so pass it fomr the script in a mtl skill

texture entSkin1; //this is the color map with specular map in alpha ..32 bit
texture entSkin2; //this is the normal map .. 24 bit

sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};


sampler BumpMapSampler = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//sunlight
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 View4 : TEXCOORD3;

float3 Sun : TEXCOORD1;
float Fog : FOG;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT1 VS_PASS1(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 )
{
VS_OUTPUT1 Out = (VS_OUTPUT1)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);

// float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
// Out.Fog = ofog;
Out.Fog = 10000;


float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

//sunlight
Out.Sun.xyz = mul(worldToTangentSpace, vecSkill1); // L

return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;
float3 View4 : TEXCOORD3;
float3 Sun : TEXCOORD1;
float Fog : FOG;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
float4 PS_PASS1( PS_INPUT1 psInStruct ):COLOR
{

float4 color = tex2D(ColorMapSampler, psInStruct.Tex); // fetch color map
float3 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex) - 0.5); // fetch bump map
bumpNormal=normalize(bumpNormal);

float3 ViewDir4 = normalize(psInStruct.View4);

//sunlight
float3 Sun = normalize(psInStruct.Sun);
float4 diff7 = saturate(dot(bumpNormal, Sun)); // diffuse component
float3 Reflect7 = normalize(2 * diff7 * bumpNormal - Sun); // R
float4 spec7 = pow(saturate(dot(Reflect7, ViewDir4)), 15);
float shadow7 = saturate(4 * diff7);

return
(
(ambientcolor * color) + //ambient

((shadow7* (color * diff7 + (spec7*color.w))) * suncolor)
);
}

// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique two_pass
{

pass P0
{
alphablendenable=false;
zenable=true;
zwriteenable=true;


//compile shaders
VertexShader = compile vs_1_1 VS_PASS1();
PixelShader = compile ps_2_0 PS_PASS1();
}



}




Sphere Engine--the premier A6 graphics plugin.