| 1 |
uniform extern float4x4 WorldViewProj : WORLDVIEWPROJECTION; |
| 2 |
uniform extern float4x4 World; |
| 3 |
uniform extern float3 LightPosition; |
| 4 |
uniform extern float3 LightDirection; |
| 5 |
uniform extern bool UseLighting; |
| 6 |
|
| 7 |
uniform extern float4 LightColor = float4(1, 1, 1, 1); //half4(0.8945f, 0.8867f, 0.4453f, 1.f); |
| 8 |
uniform extern float4 AmbientColor = float4(0.25, 0.25, 0.25, 1); //half4(0.375f, 0.379f, 0.391f, 1.f); |
| 9 |
|
| 10 |
uniform extern texture ColorTexture; |
| 11 |
uniform extern texture ColorDataTexture0; |
| 12 |
uniform extern texture ColorDataTexture1; |
| 13 |
uniform extern texture ColorDataTexture2; |
| 14 |
|
| 15 |
struct VS_INPUT |
| 16 |
{ |
| 17 |
float4 Pos : POSITION; |
| 18 |
float4 TexCoord : TEXCOORD0; |
| 19 |
float3 Normal : NORMAL; |
| 20 |
}; |
| 21 |
|
| 22 |
struct VS_OUTPUT |
| 23 |
{ |
| 24 |
float4 Pos : POSITION; |
| 25 |
float4 TexCoord : TEXCOORD0; |
| 26 |
float3 Normal : TEXCOORD1; |
| 27 |
float3 LightDirection : TEXCOORD2; |
| 28 |
}; |
| 29 |
|
| 30 |
sampler colorSampler = sampler_state |
| 31 |
{ |
| 32 |
Texture = <ColorTexture>; |
| 33 |
mipfilter = LINEAR; |
| 34 |
minfilter = LINEAR; |
| 35 |
magfilter = LINEAR; |
| 36 |
}; |
| 37 |
|
| 38 |
sampler colorDataSampler0 = sampler_state |
| 39 |
{ |
| 40 |
Texture = <ColorDataTexture0>; |
| 41 |
mipfilter = LINEAR; |
| 42 |
minfilter = LINEAR; |
| 43 |
magfilter = LINEAR; |
| 44 |
}; |
| 45 |
|
| 46 |
sampler colorDataSampler1 = sampler_state |
| 47 |
{ |
| 48 |
Texture = <ColorDataTexture1>; |
| 49 |
mipfilter = LINEAR; |
| 50 |
minfilter = LINEAR; |
| 51 |
magfilter = LINEAR; |
| 52 |
}; |
| 53 |
|
| 54 |
sampler colorDataSampler2 = sampler_state |
| 55 |
{ |
| 56 |
Texture = <ColorDataTexture2>; |
| 57 |
mipfilter = LINEAR; |
| 58 |
minfilter = LINEAR; |
| 59 |
magfilter = LINEAR; |
| 60 |
}; |
| 61 |
|
| 62 |
VS_OUTPUT Transform(VS_INPUT In) |
| 63 |
{ |
| 64 |
VS_OUTPUT Out = (VS_OUTPUT)0; |
| 65 |
|
| 66 |
Out.Pos = mul(In.Pos, WorldViewProj); |
| 67 |
Out.TexCoord = In.TexCoord; |
| 68 |
Out.Normal = In.Normal; /* = mul(In.Normal, World);*/ |
| 69 |
|
| 70 |
Out.LightDirection = LightPosition - In.Pos; /* - mul(In.Pos, World);*/ |
| 71 |
|
| 72 |
return Out; |
| 73 |
} |
| 74 |
|
| 75 |
float4 ApplyTexture(VS_OUTPUT Input) : COLOR |
| 76 |
{ |
| 77 |
float4 TextureColor = tex2D(colorSampler, Input.TexCoord).rgba; |
| 78 |
|
| 79 |
float4 FinalColor; |
| 80 |
|
| 81 |
FinalColor = saturate( |
| 82 |
tex2D(colorDataSampler0, Input.TexCoord * 8) * TextureColor.r + |
| 83 |
tex2D(colorDataSampler1, Input.TexCoord * 8) * TextureColor.g + |
| 84 |
tex2D(colorDataSampler2, Input.TexCoord * 8) * TextureColor.b |
| 85 |
); |
| 86 |
|
| 87 |
if(UseLighting) |
| 88 |
{ |
| 89 |
float3 LightDirection = normalize(Input.LightDirection); |
| 90 |
|
| 91 |
float3 Normal = normalize(Input.Normal); |
| 92 |
float NDotL = dot(LightDirection, Normal); |
| 93 |
|
| 94 |
float4 DiffuseAverage = float4(1, 1, 1, 1); |
| 95 |
float4 TotalDiffuse = DiffuseAverage * saturate(NDotL); |
| 96 |
|
| 97 |
//FinalColor = saturate(FinalColor * TotalDiffuse + FinalColor * 0.25); |
| 98 |
|
| 99 |
//FinalColor = saturate((Ambient + TotalDiffuse) * FinalColor); |
| 100 |
|
| 101 |
FinalColor = (AmbientColor + (LightColor * max(0.f, NDotL))) * FinalColor; |
| 102 |
} |
| 103 |
else |
| 104 |
FinalColor = TextureColor; |
| 105 |
|
| 106 |
return FinalColor; |
| 107 |
} |
| 108 |
|
| 109 |
technique TransformAndTexture |
| 110 |
{ |
| 111 |
pass P0 |
| 112 |
{ |
| 113 |
ZEnable = true; |
| 114 |
ZWriteEnable = true; |
| 115 |
vertexShader = compile vs_2_0 Transform(); |
| 116 |
pixelShader = compile ps_2_0 ApplyTexture(); |
| 117 |
} |
| 118 |
} |