2 PARAM sunColor = program.local[0];
3 PARAM textureTransform = program.local[1];
4 PARAM losTransform = program.local[2];
5 PARAM shadowTransform[4] = { program.local[3..6] };
6 PARAM sunDir = program.local[8];
7 PARAM transform[4] = { program.local[9..12] };
9 #if USE_FP_SHADOW && USE_SHADOW_PCF
10 PARAM shadowScale = program.local[7];
15 TEMP terrainTextureTransform;
16 MOV terrainTextureTransform, textureTransform;
17 MOV terrainTextureTransform.z, -textureTransform.y;
18 MOV terrainTextureTransform.w, 0;
20 //// Compute position and normal:
22 ATTRIB position = vertex.position;
24 DP4 result.position.x, transform[0], position;
25 DP4 result.position.y, transform[1], position;
26 DP4 result.position.z, transform[2], position;
27 DP4 result.position.w, transform[3], position;
29 //// Compute lighting:
31 // Diffuse factor is precomputed in vertex attribute
32 // Scale diffuse to allow overbrightness (since result.color will be clamped to [0, 1])
34 DP3 lighting, -sunDir, vertex.normal;
35 MAX lighting, 0.0, lighting; // DP3_SAT isn't available here.
36 MUL lighting, lighting, 0.5;
38 MUL result.color, lighting, sunColor;
40 //// Texture coordinates:
43 MOV result.texcoord[0], vertex.texcoord[0];
45 // Compute texcoords from position and terrain-texture-dependent transform.
46 // textureTransform is stored as [c, -s, s, 0],
47 // and we want texcoord = (x*c + z*-s, x*-s + z*-c, 0, 1)
48 DP3 result.texcoord[0].x, terrainTextureTransform.xyww, position.xzww;
49 DP3 result.texcoord[0].y, -terrainTextureTransform.zxww, position.xzww;
50 MOV result.texcoord[0].z, 0;
51 MOV result.texcoord[0].w, 1;
55 MOV result.texcoord[1], vertex.texcoord[1];
59 #if USE_FP_SHADOW && USE_SHADOW_PCF
61 DP4 shadowtc.x, shadowTransform[0], position;
62 DP4 shadowtc.y, shadowTransform[1], position;
63 MUL result.texcoord[2].xy, shadowtc, shadowScale;
65 DP4 result.texcoord[2].x, shadowTransform[0], position;
66 DP4 result.texcoord[2].y, shadowTransform[1], position;
68 DP4 result.texcoord[2].z, shadowTransform[2], position;
69 DP4 result.texcoord[2].w, shadowTransform[3], position;
72 MAD result.texcoord[3], position.xzzz, losTransform.x, losTransform.y;