float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecViewPos;
float4 vecViewDir;
float4 vecFog;
float4 vecFogColor;
float4 vecLight;
float4 vecColor;
float4 vecAmbient;
int iLights;
float4 vecLightColor[8];
float4 vecLightPos[8];
texture entSkin1;
sampler ColorSampler = sampler_state { Texture = <entSkin1>; Mipfilter = Linear; Minfilter = Linear; Magfilter = Linear; };
void VS (
in float4 inposition : POSITION,
in float3 innormal : NORMAL,
in float2 intex : TEXCOORD0,
out float4 outposition : POSITION,
out float3 outnormal : TEXCOORD0,
out float2 outtex : TEXCOORD1,
out float3 outworldPos : TEXCOORD2 )
{
inposition.w = 1.0f;
outposition = mul ( inposition, matWorldViewProj );
outnormal = mul ( innormal, (float3x3)matWorld );
outtex.xy = intex.xy;
outworldPos = mul ( inposition, matWorld ).xyz;
}
float4 PS (
float3 normal : TEXCOORD0,
float2 tex : TEXCOORD1,
float3 worldPos : TEXCOORD2 ) : COLOR0
{
normal.xyz = normalize ( normal.xyz );
float4 textureColor = tex2D ( ColorSampler, tex.xy );
float4 finalColor;
finalColor.rgb = vecAmbient.rgb * vecLight.rgb;
for ( int i=0; i<iLights; i++ )
{
float3 lightDir = normalize ( vecLightPos[i].xyz - worldPos.xyz );
float Distance = distance ( vecLightPos[i].xyz, worldPos.xyz );
float Radiance = saturate ( ( vecLightPos[i].w - Distance ) / vecLightPos[i].w );
finalColor.rgb += vecLightColor[i].rgb * saturate(dot(lightDir.xyz,normal.xyz)) * Radiance;
}
finalColor.rgb *= textureColor.rgb;
finalColor.rgb = lerp ( finalColor.rgb, textureColor.rgb, textureColor.a );
float Distance = distance ( vecViewPos.xyz, worldPos.xyz );
float Fog = saturate ( ( Distance - vecFog.x ) * vecFog.z );
finalColor.rgb = lerp ( color.rgb, vecFogColor, Fog );
finalColor.a = 1.0f;
return finalColor;
}
technique
{
pass pass0
{
ZWriteEnable = True;
AlphaBlendEnable = False;
VertexShader = compile vs_3_0 VS();
PixelShader = compile ps_3_0 PS();
}
}