-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbrain_fragment_shader.glsl
62 lines (50 loc) · 2.04 KB
/
brain_fragment_shader.glsl
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
56
57
58
59
60
61
#version 120
// vertex to fragment shader io
varying vec3 normal;
varying vec3 distance_to_center;
varying vec4 color;
varying vec4 vertex_position;
uniform int shader_mode;
float edgefalloff = 1.0;
float intensity = 0.5;
float ambient = 0.01;
vec4 blinn(gl_LightSourceParameters light) {
vec3 n = normalize(normal);
vec3 l = normalize((light.position - vertex_position).xyz);
float d = length(light.position - vertex_position);
vec3 v = -normalize((vertex_position).xyz);
vec3 h = normalize((l+v)/2.0);
// Note: for purposes of efficiency we could have computed l, v and h in the
// vertex shader and would only need to renormalize those here.
float attenuation = 1/(light.constantAttenuation +
light.linearAttenuation * d +
light.quadraticAttenuation * d * d);
return attenuation * (
gl_FrontMaterial.diffuse*light.diffuse*max(dot(l, n), 0) +
gl_FrontMaterial.specular*light.specular*pow(max(dot(h, n), 0), gl_FrontMaterial.shininess)
);
}
void main()
{
if (shader_mode == 0) {
gl_FragColor = color;
} else if (shader_mode == 1) {
vec4 c = gl_FrontMaterial.emission + gl_FrontMaterial.ambient * gl_LightModel.ambient + blinn(gl_LightSource[0]);
gl_FragColor = clamp(c, 0.0, 1.0);
} else if (shader_mode == 2) {
float opac = dot(normalize(-normal), normalize(-distance_to_center));
opac = abs(opac);
opac = ambient + intensity*(1.0-pow(opac, edgefalloff));
gl_FragColor = color;// * exp(0.02 * (vertex_position.z + 300));
gl_FragColor.a = opac;
} else if (shader_mode == 3) {
float opac = dot(normalize(-normal), normalize(-distance_to_center));
opac = abs(opac);
opac = ambient + intensity/20.0*(1.0-pow(opac, edgefalloff));
gl_FragColor = color;// * exp(0.02 * (vertex_position.z + 300));
gl_FragColor.a = opac;
}
else {
gl_FragColor = vec4(0.5,0.5,0.5,1.0);
}
}