vs.1.1 // version instruction /////////////////////////////////////////////////////////////// // PARTICLE.VSH // A vertex shader for rendering particles, with a global lightmap // multiplied on top to simulate lighting. // TimS, June 23 2003 // INPUT: // v0 - The position of the vertex // v1 - The diffuse color of the vertex // v2 - The UV coordinates of the base texture // // c[0-3] - The view projection matrix // c[9] - c[9].x = 1.0 / WorldDimensions.x // c[9].y = 1.0 / WorldDimensions.z // c[9].z = 1.0 // /////////////////////////////////////////////////////////////// mov r0, v0 /////////////////////////////////////////////////////////////// // Transform the vertex position /////////////////////////////////////////////////////////////// dp4 oPos.x, v0, c[0] // Matrix multiply row 0 dp4 oPos.y, v0, c[1] // Matrix multiply row 1 dp4 oPos.z, v0, c[2] // Matrix multiply row 2 dp4 oPos.w, v0, c[3] // Matrix multiply row 3 /////////////////////////////////////////////////////////////// // Generate the lightmap UV coordinates. This is done by // dividing the vertex's position by the dimensions of the // world. The dimensions are predivided as 1/dimensions, so // we just need to multiply by them. /////////////////////////////////////////////////////////////// mul r1, v0.xzww, c[9].xyzw sub r1.y, c[9].z, r1.y // Flip the V coordinate by V = 1.0 - V mov oT0, v2 // Set up UV stage 0 mov oT1, r1 // Set up UV stage 1 mov oT2, r1 // Set up UV stage 2 mov oT3, r1 // Set up UV stage 3 mov oD0, v1 // Diffuse color /////////////////////////////////////////////////////////////// // Apply Depth-fog // Input: c19.y = Fog start Y // c19.z = 1.0f / (fogEndY - fogStartY) // r0 = Vertex position // c2 = Current View Z vector // c17 = 1,1,1 // c18 = 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, c18.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: c20.y = Fog start Y // c20.z = 1.0f / (fogEndY - fogStartY) // r0 = Vertex position // c17 = 1,1,1 // c18 = 0,0,0 // // Output: r2.x = 1 if completely fogged, 0 if not fogged /////////////////////////////////////////////////////////////// sub r1.x, r0.y, c20.y // r1.x = (vertex.y - fogStart) mul r2.x, r1.x, c20.z // r2.x = (vertex.y - fogStart) / (fogEnd - fogStart) max r2.x, r2.x, c18.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 // c17 = 1,1,1 // c18 = 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, c18.x // Clamp fog at 0 min r2.x, r2.x, c17.x // Clamp fog at 1 sub oFog.x, c17.x, r2.x // Fog = 1 - r2 (so 0 is completely fogged, 1 is not fogged)