glviewvol

view sdr/fast.p.glsl @ 10:89efc666105c

mostly done
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 31 Dec 2014 05:21:47 +0200
parents 931a6b35f1cd
children
line source
1 #version 120
3 uniform sampler3D vol_tex;
4 uniform sampler1D xfer_tex;
6 uniform vec3 light_dir[3] = vec3[3](
7 vec3(0.5, 0.5, 1.0),
8 vec3(-1.0, 0.2, 0.5),
9 vec3(-0.2, 0.0, -7.0)
10 );
11 uniform vec3 light_color[3] = vec3[3](
12 vec3(0.9, 0.7, 0.68),
13 vec3(0.5, 0.6, 0.9),
14 vec3(0.3, 0.3, 0.3)
15 );
17 const vec3 ambient = vec3(0.1, 0.1, 0.1);
18 const vec3 vdir = vec3(0.0, 0.0, 1.0);
19 const float dimmer = 0.7;
21 void main()
22 {
23 vec3 tc = gl_TexCoord[0].xyz;
24 float max_manh_dist = max(tc.x, max(tc.y, tc.z));
25 float min_manh_dist = min(tc.x, min(tc.y, tc.z));
26 float border = step(0.0, min_manh_dist) * (1.0 - step(1.0, max_manh_dist));
28 vec4 voxel = texture3D(vol_tex, gl_TexCoord[0].xyz);
29 vec4 color = texture1D(xfer_tex, voxel.a);
31 float alpha = color.a * border;
32 if(alpha < 0.001) discard;
34 vec3 norm = normalize(voxel.rgb * 2.0 - 1.0);
36 vec3 diffuse = vec3(0.0, 0.0, 0.0);
37 vec3 specular = vec3(0.0, 0.0, 0.0);
39 for(int i=0; i<3; i++) {
40 vec3 ldir = normalize(light_dir[i]);
41 vec3 hdir = normalize(vdir + ldir);
43 float ndotl = max(dot(norm, ldir), 0.0);
44 float ndoth = max(dot(norm, hdir), 0.0);
46 diffuse += light_color[i] * color.rgb * ndotl;
47 specular += light_color[i] * vec3(0.6, 0.6, 0.6) * pow(ndoth, 50.0);
48 }
50 gl_FragColor.rgb = ambient + (diffuse + specular) * dimmer;
51 gl_FragColor.a = alpha;
52 }