vs.1.1 // version instruction /////////////////////////////////////////////////////////////// // Calculate the vertex's world position. This is done by multiplying // the vertex's normalized position by the heightmap's dimensions. // Input: v0 = The vertex's normalized position. Each component ranges from 0..1 // c[8] = The dimensions of the heightmap // // Output: r0 = The world position of the vertex /////////////////////////////////////////////////////////////// mul r0, v0, c[8] /////////////////////////////////////////////////////////////// // Transform the vertex position // Input: r0 = Vertex world position // c[0..3] = View matrix; // // Output: oPos = Camera space 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 /////////////////////////////////////////////////////////////// // Apply Depth-fog // Input: c19.y = Fog start Y // c19.z = 1.0f / (fogEndY - fogStartY) // r0 = Vertex position // c2 = Current View Z vector // c10 = 1,1,1 // c14 = 0,0,0 // // Output: r11.x = 1 if completely fogged, 0 if not fogged /////////////////////////////////////////////////////////////// dp4 r11.x, r0, c[2] // Get the current depth of this vertex sub r1.x, r11.x, c19.y // r1.x = (vertex.y - fogStart) mul r11.x, r1.x, c19.z // r2.x = (vertex.y - fogStart) / (fogEnd - fogStart) max r11.x, r11.x, c14.x // Clamp fog at 0. We have to do this here, as a negative value might wipe out other types of fog /////////////////////////////////////////////////////////////// // Apply Height-fog // Input: c11.y = Fog start Y // c11.z = 1.0f / (fogEndY - fogStartY) // r0 = Vertex position // c10 = 1,1,1 // c14 = 0,0,0 // // Output: r2.x = 1 if completely fogged, 0 if not fogged /////////////////////////////////////////////////////////////// sub r1.x, r0.y, c11.y // r1.x = (vertex.y - fogStart) mul r2.x, r1.x, c11.z // r2.x = (vertex.y - fogStart) / (fogEnd - fogStart) max r2.x, r2.x, c14.x // Clamp fog at 0. We have to do this here, as a negative value might wipe out other types of fog /////////////////////////////////////////////////////////////// // Combine fogs // This is done by simply adding the various types of fogs // Input: r2.x = Height fog. 1 if completely fogged, 0 if not fogged // r11.x = Depth fog. 1 if completely fogged, 0 if not fogged // c10 = 1,1,1 // c14 = 0,0,0 // // Output: oFog.x = 1 if completely fogged, 0 if not fogged /////////////////////////////////////////////////////////////// add r2.x, r2.x, r11.x // Add the fogs max r2.x, r2.x, c14.x // Clamp fog at 0 min r2.x, r2.x, c10.x // Clamp fog at 1 mul r2.x, r2.x, c11.x sub oFog.x, c10.x, r2.x // Fog = 1 - r2 (so 0 is completely fogged, 1 is not fogged) mov oD0, v1 // Diffuse color /////////////////////////////////////////////////////////////// // Generate the u,v coordinates of the vertex // Input: v0.xz = The X,Z coordinates of the vertex, normalized to 0,1 // c9 = The number of times to tile the texture // // Output: r1.xy = The UV coordinates of the vertex /////////////////////////////////////////////////////////////// mul r1, v0.xzww, c[9] mov r1.z, c10.z //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 //#mul oT2.xy, r0.xy, c[18].xy // Scale UV stage 3