Move some engine required files to the mod mod.
[0ad.git] / binaries / data / mods / mod / shaders / arb / terrain_common.vp
blob5c8c5c30da3b8ca2b62b3194e5874f200e88a530
1 !!ARBvp1.0
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];
11 #endif
13 TEMP lighting;
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;
37 // Apply light color
38 MUL result.color, lighting, sunColor;
40 //// Texture coordinates:
42 #if DECAL
43   MOV result.texcoord[0], vertex.texcoord[0];
44 #else
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;
52 #endif
54 #if BLEND
55   MOV result.texcoord[1], vertex.texcoord[1];
56 #endif
58 #if USE_SHADOW
59   #if USE_FP_SHADOW && USE_SHADOW_PCF
60     TEMP shadowtc;
61     DP4 shadowtc.x, shadowTransform[0], position;
62     DP4 shadowtc.y, shadowTransform[1], position;
63     MUL result.texcoord[2].xy, shadowtc, shadowScale;
64   #else
65     DP4 result.texcoord[2].x, shadowTransform[0], position;
66     DP4 result.texcoord[2].y, shadowTransform[1], position;
67   #endif
68   DP4 result.texcoord[2].z, shadowTransform[2], position;
69   DP4 result.texcoord[2].w, shadowTransform[3], position;
70 #endif
72 MAD result.texcoord[3], position.xzzz, losTransform.x, losTransform.y;
74 END