source: GTP/trunk/App/Demos/Illum/IBRBillboardCloudTrees/OGRE/IBRTreesOGRE/media/oldgeneral/ground_fp.txt @ 1493

Revision 1493, 1.8 KB checked in by igarcia, 18 years ago (diff)
Line 
1float backProjectionCut;
2float Ka;
3float Kd;
4float Ks;
5float4 platformColor;
6float shadowBias;
7sampler ShadowMapLeaves;
8sampler SpotLight;
9sampler PlataformMap;
10
11float4 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
Note: See TracBrowser for help on using the repository browser.