!!ARBvp1.0 # # Demonstrates a simple vertex shader to compute world coordinates. # # Orion Sky Lawlor, olawlor@acm.org, 2005/2/7 (Public Domain) # # Program/vertex communication protocol PARAM camera =program.env[0]; # World-coordinates eye location # Vertex/fragment communication protocol OUTPUT world =result.texcoord[4]; # World-coordinates position OUTPUT worldN =result.texcoord[5]; # World-coordinates normal OUTPUT albedo =result.texcoord[6]; # Material "diffuse color" OUTPUT viewdir=result.texcoord[7]; # Viewing direction (points toward eye) # Compute clip coordinates by the multiplying by modelview & projection matrix. # To draw geometry, OpenGL requires vertex programs to do this. PARAM mvp[4] = { state.matrix.mvp }; # Map vertex to clip coordinates, by multiplying by mvp matrix: DP4 result.position.x, mvp[0], vertex.position; DP4 result.position.y, mvp[1], vertex.position; DP4 result.position.z, mvp[2], vertex.position; DP4 result.position.w, mvp[3], vertex.position; # Compute world position of vertex by multiplying by modelview PARAM mv[4] = { state.matrix.modelview }; TEMP W; DP4 W.x, mv[0], vertex.position; DP4 W.y, mv[1], vertex.position; DP4 W.z, mv[2], vertex.position; MOV W.w, 1; MOV world,W; # Compute world normal of vertex by multiplying by modelview inverse transpose PARAM mvi[4] = { state.matrix.modelview.invtrans}; TEMP N; DP4 N.x, mvi[0], vertex.normal; DP4 N.y, mvi[1], vertex.normal; DP4 N.z, mvi[2], vertex.normal; MOV N.w, 0; TEMP L; DP4 L.w,N,N; # Normalize N into worldN RSQ L,L.w; MUL worldN,N,L; # Copy over diffuse color MOV albedo, vertex.color; # Compute view direction=(camera-world).normalize(); TEMP view; SUB view,camera,W; MOV view.w,0; DP4 L.w,view,view; # Normalize view into viewdir RSQ L,L.w; MUL viewdir,view,L; END