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