float3x3 matTangent;
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecViewDir;
float4 vecLight;
int iLights;
float4 vecLightPos[8];
float4 vecLightColor[8];
texture entSkin1;
sampler TexSampler = sampler_state { Texture = <entSkin1>; Mipfilter = Linear; Minfilter = Linear; Magfilter = Linear; };
texture entSkin2;
sampler TNSampler = sampler_state { Texture = <entSkin2>; Mipfilter = Linear; Minfilter = Linear; Magfilter = Linear; };
void VS (
in float4 inPos: POSITION,
in float3 inNormal: NORMAL,
in float2 inTex: TEXCOORD0,
in float3 inTangent: TEXCOORD2,
out float4 outPos: POSITION,
out float3 outNormal: TEXCOORD0,
out float3 outWorld: TEXCOORD1,
out float2 outTex: TEXCOORD2,
out float3 outTangent: TEXCOORD3) {
outPos = mul(inPos, matWorldViewProj);
outNormal = mul(inNormal, (float3x3)matWorld);
outWorld = mul(inPos, matWorld).xyz;
outTex.xy = inTex.xy;
outTangent = mul( inTangent.xyz, (float3x3)matWorld );
}
float4 PS (
in float3 inNormal: TEXCOORD0,
in float3 inWorld: TEXCOORD1,
in float2 inTex: TEXCOORD2,
in float3 inTangent: TEXCOORD3) : COLOR0 {
float4 Color = tex2D(TexSampler, inTex);
float4 TNormalTex = tex2D(TNSampler, inTex);
float3 bumpNormal = (TNormalTex.xyz * 2.0f) - 1.0f;
inTangent = normalize(inTangent);
inNormal = normalize(inNormal);
float3 binormal = cross(inNormal, inTangent);
float3 worldNormal = bumpNormal.x * inTangent + bumpNormal.y * binormal + bumpNormal.z * inNormal;
float3 fDiffuse = vecLight.rgb;
float3 fSpecular = 0;
for(float i=0; i<iLights; i+=1) {
float3 fDir = inWorld.xyz - vecLightPos[i].xyz;
float3 fReflect = normalize((2.0f * dot(worldNormal, fDir) * worldNormal) - fDir);
float fRadiance = saturate((vecLightPos[i].w - length(fDir)) / vecLightPos[i].w);
fSpecular += vecLightColor[i].rgb * pow(saturate(dot(fReflect, vecViewDir.xyz)), 8.0f) * TNormalTex.a;
fDiffuse += vecLightColor[i].rgb * saturate(dot(normalize(-fDir), worldNormal.xyz)) * fRadiance;
}
float4 FinalColor;
FinalColor.rgb = Color.rgb * fDiffuse;
FinalColor.rgb += fSpecular;
FinalColor.a = Color.a;
return FinalColor;
}
technique SpecTrans
{
pass p0
{
ZWriteEnable = True;
AlphaBlendEnable = True;
AlphaTestEnable = True;
VertexShader = compile vs_3_0 VS();
PixelShader = compile ps_3_0 PS();
}
}