1!!ARBvp1.0
2
3# Set up for phong shading fragment program.
4
5ATTRIB iPos          = vertex.position;
6ATTRIB iNormal       = vertex.normal;
7ATTRIB iTex0         = vertex.texcoord[0];
8PARAM  mvp[4]        = { state.matrix.mvp };
9PARAM  lightDir      = program.env[0];
10PARAM  eyePos        = program.env[1];
11PARAM  diffuse       = program.env[2];
12PARAM  specExp       = program.env[4];
13PARAM  specular      = program.env[3];
14PARAM  ambient       = program.env[5];
15PARAM  zero          = 0;
16PARAM  one           = 1;
17OUTPUT oPos          = result.position;
18OUTPUT oColor        = result.color;
19OUTPUT oSpecColor    = result.color.secondary;
20OUTPUT oTex0         = result.texcoord[0];
21OUTPUT oNormal       = result.texcoord[1];
22OUTPUT oHalfAngle    = result.texcoord[2];
23OUTPUT oFog          = result.fogcoord;
24
25TEMP   diffuseFactor;
26TEMP   eyeVec;
27TEMP   halfAngle;
28TEMP   dotProds;
29
30# Transform the vertex by the modelview matrix
31DP4   oPos.x, mvp[0], iPos;
32DP4   oPos.y, mvp[1], iPos;
33DP4   oPos.z, mvp[2], iPos;
34DP4   oPos.w, mvp[3], iPos;
35
36# Compute the diffuse light component
37DP3   diffuseFactor, iNormal, lightDir;
38# Clamp the diffuse component to zero
39MAX   diffuseFactor, diffuseFactor, zero;
40
41# Get the vector from the eye to the vertex
42SUB   eyeVec, eyePos, iPos;
43
44# Normalize it
45DP3   eyeVec.w, eyeVec, eyeVec;
46RSQ   eyeVec.w, eyeVec.w;
47MUL   eyeVec, eyeVec, eyeVec.w;
48
49# Haze
50DP3   diffuseFactor.y, iNormal, eyeVec;
51SUB   diffuseFactor.y, one, diffuseFactor.y;
52MUL   oFog.x, diffuseFactor.x, diffuseFactor.y;
53
54# Compute the half angle vector for specular lighting
55ADD   halfAngle, eyeVec, lightDir;
56DP3   halfAngle.w, halfAngle, halfAngle;
57RSQ   halfAngle.w, halfAngle.w;
58MUL   halfAngle, halfAngle, halfAngle.w;
59
60# Output the texture
61MOV   oTex0, iTex0;
62MOV   oNormal, iNormal;
63MOV   oHalfAngle, halfAngle;
64
65END
66