static const float AmbientIntensity = 1.0f;
static const float DiffuseIntensity = 1.0f;
static const float SpecularIntensity = 1.0f;
static const float SpecularPower = 9.0f;
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecAmbient;
float4 vecViewPos;
float4 vecLightColor[8];
float4 vecLightPos[8];
float3x3 matTangent;
texture entSkin1;
sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MipFilter = LINEAR;
};
texture entSkin2;
sampler NormalMapSampler = sampler_state
{
Texture = <entSkin2>;
MipFilter = NONE;
};
void NormalMapVS( in float4 InPos : POSITION,
in float3 InNormal : NORMAL,
in float2 InTex : TEXCOORD0,
in float4 InTangent : TEXCOORD2,
out float4 OutPos : POSITION,
out float2 OutTex : TEXCOORD0,
out float3 OutViewDir: TEXCOORD1,
out float3 OutLightDir0: TEXCOORD2,)
{
OutPos = mul(InPos, matWorldViewProj);
OutTex = InTex;
matTangent[0] = mul(InTangent.xyz, matWorld);
matTangent[1] = mul(cross(InTangent.xyz,InNormal)*InTangent.w, matWorld);
matTangent[2] = mul(InNormal, matWorld);
OutViewDir = normalize(mul(matTangent, vecViewPos - mul(InPos, matWorld)));
OutLightDir0 = normalize(mul(matTangent, vecLightPos[0]-InPos.xyz));
}
float4 NormalMapPS( in float2 InTex : TEXCOORD0, in float3 InViewDir : TEXCOORD1, in float3 inPos : TEXCOORD3,
in float3 InLightDir0 : TEXCOORD4) : COLOR
{
float3 BumpNormal = 2 * tex2D(NormalMapSampler, InTex) - 1;
float4 Ambient = AmbientIntensity * vecAmbient;
float4 Diffuse[8];
float Specular[8];
float3 R;
Diffuse[0] = DiffuseIntensity * saturate(dot(InLightDir0, BumpNormal));
Diffuse[0] *= vecLightColor[0];
R = normalize(2 * dot(BumpNormal, InLightDir0) * BumpNormal - InLightDir0);
InViewDir = normalize(InViewDir);
Specular[0] = pow(saturate(dot(R, InViewDir)), SpecularPower) * SpecularIntensity;
float4 Color = tex2D(ColorMapSampler, InTex);
return (Ambient + Diffuse[0] + Specular[0]) * Color;
}
technique SpecularTechnique
{
pass P0
{
VertexShader = compile vs_3_0 NormalMapVS();
PixelShader = compile ps_3_0 NormalMapPS();
}
}