-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtoon.frag
50 lines (36 loc) · 1.08 KB
/
toon.frag
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
39
40
41
42
43
44
45
46
47
48
49
50
// toon fragment shader
// normal vector, passed from vertex shader
varying vec3 n;
// grab lighting term
varying vec4 light;
// from main program, get threshold value
uniform float t;
// from main program, get threshold value 2
uniform float t2;
// from main program, get threshold value 3
uniform float t3;
// from main program, get threshold value
uniform float s;
void main(){
// color for this fragment
vec4 c;
// get the light's direction
vec3 l = normalize(vec3(gl_LightSource[0].position));
// compute the fragment intensity
// be sure to re-normalize n for the fragment
float i = dot(l, normalize(n));
// for brightly lit fragments
if(i > (1.00 - t / (15.0 - 7.0 * s)))
c = vec4(1.00, 0.67, 0.00, 1.00);
// for somewhat lit fragments
else if(i > (1.00 - 2.0 * t2))
c = vec4(0.75, 0.50, 0.00, 1.00);
// for barely lit fragments
else if(i > (1.00 - 3.0 * t3))
c = vec4(0.50, 0.34, 0.00, 1.00);
// for nearly unlit fragments
else
c = vec4(0.25, 0.17, 0.00, 1.00);
// set the fragment color
gl_FragColor = light * c;
}