float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLightPos[8];
float4 vecLightColor[8];
float4 vecViewPos;
float4 vecFog;
float4 vecAmbient;
float4 vecDiffuse;
float4 vecSpecular;
float4 vecEmissive;
texture entSkin1;
texture entSkin2;
sampler texts = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};
sampler bumps = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};
// -------------------------------------------------------------
// 2.0
// -------------------------------------------------------------
//
struct VS_INPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 Normal : NORMAL;
float3 Tangent : TEXCOORD2;
};
//
struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;
float4 Light1 : TEXCOORD2;
float4 Light2 : TEXCOORD3;
float Fog : FOG;
};
//
struct PS_INPUT
{
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;
float4 Light1 : TEXCOORD2;
float4 Light2 : TEXCOORD3;
};
//
//
//
//
VS_OUTPUT VS_PASS(VS_INPUT In ,uniform float passs )
{
VS_OUTPUT Out = (VS_OUTPUT)0;
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(In.Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(In.Tangent, In.Normal), matWorld);
worldToTangentSpace[2] = mul(In.Normal, matWorld);
float3 PosWorld = mul(In.Pos, matWorld);
//misc
Out.Pos = mul(In.Pos, matWorldViewProj);
Out.Tex = In.Tex;
Out.View = mul(worldToTangentSpace, - (PosWorld - vecViewPos));
//Light 0, 2, 4
Out.Light1.xyz = mul(worldToTangentSpace, - (PosWorld - vecLightPos[passs*2]));
Out.Light1.w = distance(PosWorld,vecLightPos[passs*2])/vecLightPos[passs*2].w;
//Light 1, 3, 5
Out.Light2.xyz = mul(worldToTangentSpace, -(PosWorld - vecLightPos[passs*2+1]));
Out.Light2.w = distance(PosWorld,vecLightPos[passs*2+1])/vecLightPos[passs*2+1].w;
//
Out.Fog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
//
return Out;
}
//
//
float4 PS_PASS( PS_INPUT In ,uniform float passs ) : COLOR
{
//misc
float4 color = tex2D(texts, In.Tex);
float3 bumpNormal = 2 * (tex2D(bumps, In.Tex) - 0.5);
float4 gloss = tex2D( bumps, In.Tex );
float3 ViewDir = normalize(In.View);
//Light 0, 2, 4
float3 dir_1 = normalize(In.Light1);
float4 diff1 = saturate(dot(bumpNormal, dir_1));
float shad1 = saturate(4 * diff1);
float3 refl1 = normalize(2 * diff1 * bumpNormal - dir_1);
float4 spec1 = pow(saturate(dot(refl1, ViewDir)), 15);
float4 attn1 = saturate(dot(In.Light1.w, In.Light1.w));
//Light 1, 3, 5
float3 dir_2 = normalize(In.Light2);
float4 diff2 = saturate(dot(bumpNormal, dir_2));
float shad2 = saturate(4 * diff2);
float3 refl2 = normalize(2 * diff2 * bumpNormal - dir_2);
float4 spec2 = pow(saturate(dot(refl2, ViewDir)), 15);
float4 attn2 = saturate(dot(In.Light2.w, In.Light2.w));
//
return
(
////// VecAmbient APPEARS to never get any value from the material ambient values. WHY!
( vecAmbient * color ) + //////////////
///////////////////////////////////////////////
((shad1 * (color * diff1 + (spec1*gloss.w)) * (1-attn1))*vecLightColor[passs*2]) +
((shad2 * (color * diff2 + (spec2*gloss.w)) * (1-attn2))*vecLightColor[passs*2+1])
);
}
//
//
//
// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
//
// 2.0
technique SpecularNormalMapping_20
{
pass P0
{
alphablendenable=false;
srcblend=zero;
// compile shaders
VertexShader = compile vs_2_0 VS_PASS(0);
PixelShader = compile ps_2_0 PS_PASS(0);
}
//
pass P1
{
//blend second pass additively with first
alphablendenable=true;
srcblend=one;
destblend=one;
// compile shaders
VertexShader = compile vs_2_0 VS_PASS(1);
PixelShader = compile ps_2_0 PS_PASS(1);
}
pass P2
{
//blend second pass additively with first and second
alphablendenable=true;
srcblend=one;
destblend=one;
// compile shaders
VertexShader = compile vs_2_0 VS_PASS(2);
PixelShader = compile ps_2_0 PS_PASS(2);
}
}
//
//
// Fallback; If nothing works
technique fallback { pass one { } }
//