rev |
line source |
elene@25
|
1 varying vec3 pt;
|
elene@25
|
2
|
elene@25
|
3 uniform sampler3D tex;
|
elene@25
|
4 uniform float tmin;
|
elene@25
|
5 uniform float tmax;
|
elene@25
|
6 uniform vec3 res;
|
elene@25
|
7
|
elene@25
|
8 float transfer(float x, float tmin, float tmax)
|
elene@25
|
9 {
|
elene@25
|
10 float dt = 0.25 * (tmax - tmin);
|
elene@25
|
11 return smoothstep(tmin - dt, tmin + dt, x) *
|
elene@25
|
12 (1.0 - smoothstep(tmax - dt, tmax + dt, x));
|
elene@25
|
13 }
|
elene@25
|
14
|
elene@25
|
15 vec3 calc_normal(vec3 p, float texel)
|
elene@25
|
16 {
|
elene@25
|
17 vec3 offs = 1.0 / res;
|
elene@25
|
18
|
elene@25
|
19 float dfdx = texture3D(tex, p + vec3(offs.x, 0.0, 0.0)).x - texel;
|
elene@25
|
20 float dfdy = texture3D(tex, p + vec3(0.0, offs.y, 0.0)).x - texel;
|
elene@25
|
21 float dfdz = texture3D(tex, p + vec3(0.0, 0.0, offs.z)).x - texel;
|
elene@25
|
22
|
elene@30
|
23 return -normalize(vec3(dfdx, dfdy, dfdz));
|
elene@25
|
24 }
|
elene@25
|
25
|
elene@25
|
26 void main()
|
elene@25
|
27 {
|
elene@25
|
28 const vec3 ldir = vec3(-1.0, 1.0, 2.0);
|
elene@25
|
29
|
elene@25
|
30 if(max(pt.x, max(pt.y, pt.z)) > 1.0 || min(pt.x, min(pt.y, pt.z)) < 0.0)
|
elene@25
|
31 discard;
|
elene@25
|
32
|
elene@25
|
33 float texel = texture3D(tex, pt).x;
|
elene@25
|
34 float val = transfer(texel, tmin, tmax);
|
elene@25
|
35
|
elene@30
|
36 vec3 normal = gl_NormalMatrix * calc_normal(pt, texel);
|
elene@25
|
37 float ndotl = max(dot(normalize(ldir), normal), 0.0);
|
elene@25
|
38
|
elene@25
|
39 gl_FragColor = vec4(ndotl, ndotl, ndotl, val);
|
elene@25
|
40 }
|