rev |
line source |
nuclear@10
|
1 #version 120
|
nuclear@10
|
2
|
nuclear@4
|
3 uniform sampler3D vol_tex;
|
nuclear@4
|
4 uniform sampler1D xfer_tex;
|
nuclear@4
|
5
|
nuclear@10
|
6 uniform vec3 light_dir[3] = vec3[3](
|
nuclear@9
|
7 vec3(0.5, 0.5, 1.0),
|
nuclear@9
|
8 vec3(-1.0, 0.2, 0.5),
|
nuclear@9
|
9 vec3(-0.2, 0.0, -7.0)
|
nuclear@10
|
10 );
|
nuclear@10
|
11 uniform vec3 light_color[3] = vec3[3](
|
nuclear@9
|
12 vec3(0.9, 0.7, 0.68),
|
nuclear@9
|
13 vec3(0.5, 0.6, 0.9),
|
nuclear@9
|
14 vec3(0.3, 0.3, 0.3)
|
nuclear@10
|
15 );
|
nuclear@9
|
16
|
nuclear@9
|
17 const vec3 ambient = vec3(0.1, 0.1, 0.1);
|
nuclear@9
|
18 const vec3 vdir = vec3(0.0, 0.0, 1.0);
|
nuclear@9
|
19 const float dimmer = 0.7;
|
nuclear@9
|
20
|
nuclear@4
|
21 void main()
|
nuclear@4
|
22 {
|
nuclear@8
|
23 vec3 tc = gl_TexCoord[0].xyz;
|
nuclear@8
|
24 float max_manh_dist = max(tc.x, max(tc.y, tc.z));
|
nuclear@8
|
25 float min_manh_dist = min(tc.x, min(tc.y, tc.z));
|
nuclear@8
|
26 float border = step(0.0, min_manh_dist) * (1.0 - step(1.0, max_manh_dist));
|
nuclear@8
|
27
|
nuclear@4
|
28 vec4 voxel = texture3D(vol_tex, gl_TexCoord[0].xyz);
|
nuclear@4
|
29 vec4 color = texture1D(xfer_tex, voxel.a);
|
nuclear@4
|
30
|
nuclear@8
|
31 float alpha = color.a * border;
|
nuclear@8
|
32 if(alpha < 0.001) discard;
|
nuclear@8
|
33
|
nuclear@9
|
34 vec3 norm = normalize(voxel.rgb * 2.0 - 1.0);
|
nuclear@9
|
35
|
nuclear@9
|
36 vec3 diffuse = vec3(0.0, 0.0, 0.0);
|
nuclear@9
|
37 vec3 specular = vec3(0.0, 0.0, 0.0);
|
nuclear@9
|
38
|
nuclear@9
|
39 for(int i=0; i<3; i++) {
|
nuclear@9
|
40 vec3 ldir = normalize(light_dir[i]);
|
nuclear@9
|
41 vec3 hdir = normalize(vdir + ldir);
|
nuclear@9
|
42
|
nuclear@9
|
43 float ndotl = max(dot(norm, ldir), 0.0);
|
nuclear@9
|
44 float ndoth = max(dot(norm, hdir), 0.0);
|
nuclear@9
|
45
|
nuclear@9
|
46 diffuse += light_color[i] * color.rgb * ndotl;
|
nuclear@9
|
47 specular += light_color[i] * vec3(0.6, 0.6, 0.6) * pow(ndoth, 50.0);
|
nuclear@9
|
48 }
|
nuclear@9
|
49
|
nuclear@9
|
50 gl_FragColor.rgb = ambient + (diffuse + specular) * dimmer;
|
nuclear@8
|
51 gl_FragColor.a = alpha;
|
nuclear@4
|
52 }
|