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

Revision 1493, 2.8 KB checked in by igarcia, 18 years ago (diff)
Line 
1float backProjectionCut: register(c2);
2float Ka: register(c3);
3float Kd: register(c4);
4float Ks: register(c5);
5float4 modelColor: register(c0);
6float shadowBias: register(c1);
7sampler ImpostorMap;
8sampler RotatedLeaf;
9sampler ShadowMap;
10sampler SpotLight;
11
12float4 main(float3 normal: TEXCOORD0, float3 lightVec: TEXCOORD1, float3 viewVec: TEXCOORD2, float4 shadowCrd: TEXCOORD3, float4 texCoord: TEXCOORD4, float4 texCoordNormalized: TEXCOORD5) : COLOR {
13   normal = normalize(normal);
14   // Radial distance
15   float depth = length(lightVec);
16   // Normalizes light vector
17   lightVec /= depth;
18
19   // Standard lighting
20   float diffuse = saturate(dot(lightVec, normal));
21   float specular = pow(saturate(dot(reflect(-normalize(viewVec), normal), lightVec)), 16);
22
23   // The depth of the fragment closest to the light
24   float shadowMap = tex2Dproj(ShadowMap, shadowCrd);
25   // A spot image of the spotlight
26   float spotLight = tex2Dproj(SpotLight, shadowCrd);
27   // If the depth is larger than the stored depth, this fragment
28   // is not the closest to the light, that is we are in shadow.
29   // Otherwise, we're lit. Add a bias to avoid precision issues
30   float shadow;
31   shadow = (depth < shadowMap + shadowBias);
32
33   // Cut back-projection, that is, make sure we don't lit
34   // anything behind the light. Theoretically, you should just
35   // cut at w = 0, but in practice you'll have to cut at a
36   // fairly high positive number to avoid precision issue when
37   // coordinates approaches zero.
38   shadow *= (shadowCrd.w > backProjectionCut);
39   // Modulate with spotlight image
40   shadow *= spotLight;
41
42   // Shadow any light contribution except ambient
43   //return Ka * modelColor + (Kd * diffuse * modelColor + Ks * specular) * shadow;
44   float4 ocolor;
45   //ocolor = Ka * modelColor + (Kd * diffuse * modelColor + Ks * specular) * shadow;
46   float4 tempcolor = tex2D(ImpostorMap,texCoord);
47   float3 green = float3(0.0,0.8,0.0);
48   //ocolor = float4(Ka * tempcolor.xyz + (Kd * diffuse * tempcolor.xyz + Ks * specular) * shadow,tempcolor.z);
49   ocolor = float4(Ka * green + (Kd * diffuse * green + Ks * specular) * shadow,tempcolor.z);
50   
51   float scale_factor = 48.0;
52   float tex_atlas_size = 256;
53   float4 vis = tex2D(ImpostorMap, texCoord);
54   float index = vis.z;
55   if (vis.x >= 0.0)
56   {
57      float2 leafuv = (texCoordNormalized - vis.xy) * (tex_atlas_size/scale_factor);     
58      float divInt = floor(index/4.0);
59      float modInt = (index - (4.0 * divInt));
60      float col = divInt / 4.0;
61      float row = modInt / 4.0;
62      // Using the leaf atlas...
63      float2 leafuvr = float2(leafuv.x + row,leafuv.y + col);
64      tempcolor = tex2D(RotatedLeaf, leafuvr);
65   }   
66   ocolor = tempcolor;
67     
68   return ocolor;
69   //return ocolor = tempcolor;
70}
71
72
73
Note: See TracBrowser for help on using the repository browser.