1 | float backProjectionCut;
|
---|
2 | float Ka;
|
---|
3 | float Kd;
|
---|
4 | float Ks;
|
---|
5 | float4 platformColor;
|
---|
6 | float shadowBias;
|
---|
7 | sampler ShadowMapLeaves;
|
---|
8 | sampler SpotLight;
|
---|
9 | sampler PlataformMap;
|
---|
10 |
|
---|
11 | float4 main( float3 normal: TEXCOORD0,
|
---|
12 | float3 lightVec: TEXCOORD1,
|
---|
13 | float3 viewVec: TEXCOORD2,
|
---|
14 | float4 shadowCrd: TEXCOORD3,
|
---|
15 | float3 texCoord: TEXCOORD4) : COLOR
|
---|
16 | {
|
---|
17 | normal = normalize(normal);
|
---|
18 |
|
---|
19 | // Radial distance
|
---|
20 | float depth = length(lightVec);
|
---|
21 | // Normalizes light vector
|
---|
22 | lightVec /= depth;
|
---|
23 |
|
---|
24 | // Standard lighting
|
---|
25 | float diffuse = saturate(dot(lightVec, normal));
|
---|
26 | float specular = pow(saturate(dot(reflect(-normalize(viewVec), normal), lightVec)), 16);
|
---|
27 |
|
---|
28 | // The depth of the fragment closest to the light
|
---|
29 | float fShadowMapLeaves = tex2Dproj(ShadowMapLeaves, shadowCrd).x;
|
---|
30 | // A spot image of the spotlight
|
---|
31 | float spotLight = tex2Dproj(SpotLight, shadowCrd);
|
---|
32 | // If the depth is larger than the stored depth, this fragment
|
---|
33 | // is not the closest to the light, that is we are in shadow.
|
---|
34 | // Otherwise, we're lit. Add a bias to avoid precision issues.
|
---|
35 | float shadow;
|
---|
36 | shadow = (depth < fShadowMapLeaves + shadowBias);
|
---|
37 |
|
---|
38 | // Cut back-projection, that is, make sure we don't lit
|
---|
39 | // anything behind the light. Theoretically, you should just
|
---|
40 | // cut at w = 0, but in practice you'll have to cut at a
|
---|
41 | // fairly high positive number to avoid precision issue when
|
---|
42 | // coordinates approaches zero.
|
---|
43 | shadow *= (shadowCrd.w > backProjectionCut);
|
---|
44 | // Modulate with spotlight image
|
---|
45 | shadow *= spotLight;
|
---|
46 |
|
---|
47 | // Shadow any light contribution except ambient
|
---|
48 | //return Ka * platformColor + (Kd * diffuse * platformColor + Ks * specular) * shadow;
|
---|
49 | return Ka * tex2D(PlataformMap,texCoord) + (Kd * diffuse * platformColor + Ks * specular) * shadow;
|
---|
50 |
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|