forked from mckennapsean/code-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture-p.vert
38 lines (29 loc) · 996 Bytes
/
texture-p.vert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// texture vertex shader with Phong shading
// store lighting vars
varying vec3 ldir;
varying vec3 lhalf;
varying float ldist;
// store vertex normal
varying vec3 n;
// store ambient and diffuse lighting terms
varying vec4 diff;
varying vec4 amb;
void main(){
// set the texture coordinate
gl_TexCoord[0] = gl_MultiTexCoord0;
// calculate ambient and diffuse lighting
amb = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
amb += gl_LightModel.ambient * gl_FrontMaterial.ambient;
diff = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
// normal for vertex, in eye coords
n = normalize(gl_NormalMatrix * gl_Normal);
// light position for vertex
vec4 vPos = gl_ModelViewMatrix * gl_Vertex;
vec3 aux = vec3(gl_LightSource[0].position - vPos);
ldir = normalize(aux);
ldist = length(aux);
// calculate the light half vector
lhalf = normalize(gl_LightSource[0].halfVector.xyz);
// keep the position the same
gl_Position = ftransform();
}