glviewvol
view sdr/fast.p.glsl @ 9:931a6b35f1cd
added lighting and openmp normal calculation
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 30 Dec 2014 21:20:57 +0200 |
parents | fb6d93471352 |
children | 89efc666105c |
line source
1 uniform sampler3D vol_tex;
2 uniform sampler1D xfer_tex;
4 const vec3 light_dir[3] = {
5 vec3(0.5, 0.5, 1.0),
6 vec3(-1.0, 0.2, 0.5),
7 vec3(-0.2, 0.0, -7.0)
8 };
9 const vec3 light_color[3] = {
10 vec3(0.9, 0.7, 0.68),
11 vec3(0.5, 0.6, 0.9),
12 vec3(0.3, 0.3, 0.3)
13 };
15 const vec3 ambient = vec3(0.1, 0.1, 0.1);
16 const vec3 vdir = vec3(0.0, 0.0, 1.0);
17 const float dimmer = 0.7;
19 void main()
20 {
21 vec3 tc = gl_TexCoord[0].xyz;
22 float max_manh_dist = max(tc.x, max(tc.y, tc.z));
23 float min_manh_dist = min(tc.x, min(tc.y, tc.z));
24 float border = step(0.0, min_manh_dist) * (1.0 - step(1.0, max_manh_dist));
26 vec4 voxel = texture3D(vol_tex, gl_TexCoord[0].xyz);
27 vec4 color = texture1D(xfer_tex, voxel.a);
29 float alpha = color.a * border;
30 if(alpha < 0.001) discard;
32 vec3 norm = normalize(voxel.rgb * 2.0 - 1.0);
34 vec3 diffuse = vec3(0.0, 0.0, 0.0);
35 vec3 specular = vec3(0.0, 0.0, 0.0);
37 for(int i=0; i<3; i++) {
38 vec3 ldir = normalize(light_dir[i]);
39 vec3 hdir = normalize(vdir + ldir);
41 float ndotl = max(dot(norm, ldir), 0.0);
42 float ndoth = max(dot(norm, hdir), 0.0);
44 diffuse += light_color[i] * color.rgb * ndotl;
45 specular += light_color[i] * vec3(0.6, 0.6, 0.6) * pow(ndoth, 50.0);
46 }
48 gl_FragColor.rgb = ambient + (diffuse + specular) * dimmer;
49 gl_FragColor.a = alpha;
50 }