1 | #version 150 |
---|
2 | |
---|
3 | /* Cel shading vertex program for single-pass rendering |
---|
4 | In this program, we want to calculate the diffuse and specular |
---|
5 | ramp components, and the edge factor (for doing simple outlining) |
---|
6 | For the outlining to look good, we need a pretty well curved model. |
---|
7 | */ |
---|
8 | // Parameters |
---|
9 | in vec4 vertex; |
---|
10 | in vec3 normal; |
---|
11 | |
---|
12 | uniform vec3 lightPosition; // object space |
---|
13 | uniform vec3 eyePosition; // object space |
---|
14 | uniform vec4 shininess; |
---|
15 | uniform mat4 worldViewProj; |
---|
16 | |
---|
17 | //uniform transform |
---|
18 | //{ |
---|
19 | // vec4 shininess; |
---|
20 | //} MaterialShininess; |
---|
21 | |
---|
22 | out float diffuseIn; |
---|
23 | out float specularIn; |
---|
24 | out float edge; |
---|
25 | |
---|
26 | void main() |
---|
27 | { |
---|
28 | // calculate output position |
---|
29 | gl_Position = worldViewProj * vertex; |
---|
30 | |
---|
31 | // calculate light vector |
---|
32 | vec3 N = normalize(normal); |
---|
33 | vec3 L = normalize(lightPosition - vertex.xyz); |
---|
34 | |
---|
35 | // Calculate diffuse component |
---|
36 | diffuseIn = max(dot(N, L) , 0.0); |
---|
37 | |
---|
38 | // Mask off specular if diffuse is 0 |
---|
39 | if (diffuseIn == 0.0) |
---|
40 | specularIn = 0.0; |
---|
41 | |
---|
42 | // Calculate specular component |
---|
43 | vec3 E = normalize(eyePosition - vertex.xyz); |
---|
44 | vec3 H = normalize(L + E); |
---|
45 | specularIn = pow(max(dot(N, H), 0.0), shininess.x); |
---|
46 | // specularIn = pow(max(dot(N, H), 0.0), MaterialShininess.shininess.x); |
---|
47 | |
---|
48 | // Edge detection, dot eye and normal vectors |
---|
49 | edge = max(dot(N, E), 0.0); |
---|
50 | } |
---|