-
Notifications
You must be signed in to change notification settings - Fork 25
/
gooch.fs
executable file
·55 lines (42 loc) · 1.5 KB
/
gooch.fs
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
51
52
53
54
55
#ifdef GL_ES
precision highp float;
#endif
float DiffuseWarm = 0.5;
float DiffuseCool = 0.5;
// parameters
uniform vec3 surfaceColor;
uniform vec3 warmColor;
uniform vec3 coolColor;
varying vec3 ViewVec;
varying vec3 ecPos1;
varying vec3 tnorm;
void pointLight(in vec3 pos, in vec3 nviewVec, in vec3 ntnorm, inout float NdotL, inout float spec){
vec3 lightVec = normalize(pos - ecPos1);
vec3 ReflectVec = normalize(reflect(lightVec, ntnorm));
NdotL = (dot(lightVec, ntnorm) + 1.0) * 0.5;
spec += max(dot(ReflectVec, -nviewVec), 0.0);
}
void c3dl_goochDirLight(in vec3 pos, in vec3 nviewVec, in vec3 ntnorm, inout float NdotL, inout float spec){
// when the user specifies the the direction of the light, they are
// specifying the direction the light is going towards.
vec3 lightVec = vec3(-pos);
// calculate how intense the light is. NdotL is added for each light.
NdotL = (dot(lightVec, ntnorm) + 1.0) * 0.5;
vec3 ReflectVec = normalize(reflect(lightVec, ntnorm));
spec += max(dot(ReflectVec, -nviewVec), 0.0);
}
/*
*/
void main(void) {
vec3 kcool = min(coolColor + DiffuseCool * surfaceColor, 1.0);
vec3 kwarm = min(warmColor + DiffuseWarm * surfaceColor, 1.0);
vec3 nviewVec = normalize(ViewVec);
vec3 ntnorm = normalize(tnorm);
float NdotL = 0.0;
float spec = 0.0;
pointLight(vec3(0.0, 10.0, -40.0), nviewVec, ntnorm, NdotL, spec);
NdotL = clamp(NdotL, 0.0, 1.0);
vec3 kfinal = mix(kcool, kwarm, NdotL);
spec = pow(spec, 17.0);
gl_FragColor = vec4(min(kfinal + spec, 1.0), 1.0);
}