vs.1.1 ; version instruction mov oD0, v2 ; Diffuse color ; Get the x and z index, from -32768 to 32767 and add 32768 to bring back to 0 - 65535 add r0.xyzw, v1.xzyz, c[16].wywy ; r0.xyzw = (x 0 z 0) + (32768.0f 1.0 32768.0f 1.0) mov r0.y, v0.x ; Get the terrain height for that vertex from v0, note: Y is actually stored in x :) ; Bring r0 in world space multiplying by terrain square size. mul r0.xyz, r0.xyz, c[16].xyz ; Store r0 into 0..1 space in r4, for the texture coordinates later, mul r4, r0, c[17] ; r4 = r0 * 1/mTerrainDimension ; Transform the vertex position dp4 oPos.x, r0, c[0] ; Matrix multiply row 0 dp4 oPos.y, r0, c[1] ; Matrix multiply row 1 dp4 oPos.z, r0, c[2] ; Matrix multiply row 2 dp4 oPos.w, r0, c[3] ; Matrix multiply row 3 dp4 r11.x, r0, c[2] ; Fog mul oFog.x, r11.x, c11.x ; r4 has to be a value between 0.0f and 1.0f. ; calculate the tiling of the terrain texture and the lightmap mul r1, r4.xzww, c[9] sub r1.y, c[9].y, r1.y ; Transform the texture coordinates dp4 r0.x, r1, c[4] ; Transform the UVs dp4 r0.y, r1, c[5] ; Transform the UVs dp4 r0.z, r1, c[6] ; Transform the UVs dp4 r0.w, r1, c[7] ; Transform the UVs mov oT0, r0 ; Set up UV stage 0 mov oT1, r0 ; Set up UV stage 1 mov oT2, r0 ; Set up UV stage 2 mov oT3, r0 ; Set up UV stage 3