Ok here is a basic shader for this.. let me know if you have problems.
Code:
float4x4 matWorld;
float4x4 matWorldViewProj;
float4 vecSunDir;
float4 vecFog;
float4 vecViewPos;
texture entSkin1;
//these are sunlight and ambient colors
//you should pass these values in scrips.. how you get those colors in the script
//is up to you because I dont know of a way to directly pass them or get them in the shader.
//Maybe there is a way i dont know about...
float4 vecSkill9; //ambient color
float4 vecSkill5; //sunlight color
//color skin texture with alpha channel for transparency
sampler base = sampler_state
{
Texture = <entSkin1>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = clamp;
Addressv = clamp;
//you can change this or comment it out..
//this sharpens up the texture at far distances
MIPMAPLODBIAS=-0.5;
};
half4 DoSunLight(half3 N)
{
return (dot(N,normalize(-vecSunDir)));
};
//////////////////////////////////////////////////////////////////////
struct TMULTI_VS_OUT // Output to the pixelshader fragment
{
float4 Pos : POSITION;
float Fog: FOG;
float2 tex : TEXCOORD0;
float light : TEXCOORD1;
};
TMULTI_VS_OUT TMulti_VS(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTexCoord0 : TEXCOORD0)
{
TMULTI_VS_OUT Out;
// transform the vector position to screen coordinates
Out.Pos = mul(inPos,matWorldViewProj);
// Calculate fogging
float3 PositionWorld = mul(inPos, matWorld);
float ofog = 1 - (distance(PositionWorld, vecViewPos) - vecFog.x) * vecFog.z;
Out.Fog = ofog;
// output tex coords
Out.tex = inTexCoord0.xy;
//calculate normal for spherical lighting
float4 vPos=mul(float4(0,0,0,1),matWorld);
vPos.y+=10;
half3 N=normalize(PositionWorld-vPos);
Out.light = DoSunLight(N);
return Out;
}
half4 TMulti_PS(TMULTI_VS_OUT In): COLOR
{
half4 Color = tex2D(base,In.tex);
float4 finalcolor=Color;
finalcolor.rgb=(finalcolor.rgb*vecSkill9) +
((vecSkill5 * finalcolor.rgb)*saturate(In.light));
return finalcolor;
}
DWORD ref=128.0f;
technique treelight
{
pass one
{
cullmode=none;
zenable=true;
zwriteenable=true;
alphablendenable=false;
alphatestenable=true;
AlphaRef=<ref>;
AlphaFunc=Greater;
VertexShader = compile vs_1_1 TMulti_VS();
PixelShader = compile ps_1_1 TMulti_PS();
}
}