- {$optimize-}
- program VertexProgram1;
- uses arb_vertex_program, arb_position_invariant;
- // input:
- // texture #0 = color map
- // texture #1 = normal map
- // texture #2 = offset map
- // vertex.attrib[6] = tangent
- // output:
- // texcoord[0] offset in texture map
- // texcoord[1] tangent space light0 vector
- // texcoord[2] tangent space eye vector
- // remarks
- // binormal is computed on the fly
- // light is taken from light source 0
- // viewer position is taken from modelview.invtrans
- var
- binormal, eyevec,
- light0pos, light0vec: vec4;
- begin
- // compute binormal
- binormal := cross(vertex.attrib[6], vertex.normal);
- // vector pointing to light 0
- with state do
- light0pos := MatrixMult4(matrix.modelview.inverse, light[0].position);
- light0vec := vertex.position - light0pos;
- // transform light0 vector into tangent space
- with vertex do
- result.texcoord[1] := MatrixMult3(Matrix(attrib[6], binormal, normal), light0vec);
- result.texcoord[1].w := 1.0;
- // vector pointing to eye
- eyevec := vertex.position - state.matrix.modelview.invtrans.row[3];
- // transform eye vector into tangent space
- with vertex do
- result.texcoord[2] := MatrixMult3(Matrix(attrib[6], binormal, normal), eyevec);
- result.texcoord[2].w := 1.0;
- result.color:=vertex.color;
- result.texcoord[0]:=vertex.texcoord[0];
- end;