elene@25: varying vec3 pt; elene@25: elene@25: uniform sampler3D tex; elene@25: uniform float tmin; elene@25: uniform float tmax; elene@25: uniform vec3 res; elene@25: elene@25: float transfer(float x, float tmin, float tmax) elene@25: { elene@25: float dt = 0.25 * (tmax - tmin); elene@25: return smoothstep(tmin - dt, tmin + dt, x) * elene@25: (1.0 - smoothstep(tmax - dt, tmax + dt, x)); elene@25: } elene@25: elene@25: vec3 calc_normal(vec3 p, float texel) elene@25: { elene@25: vec3 offs = 1.0 / res; elene@25: elene@25: float dfdx = texture3D(tex, p + vec3(offs.x, 0.0, 0.0)).x - texel; elene@25: float dfdy = texture3D(tex, p + vec3(0.0, offs.y, 0.0)).x - texel; elene@25: float dfdz = texture3D(tex, p + vec3(0.0, 0.0, offs.z)).x - texel; elene@25: elene@25: return normalize(vec3(dfdx, dfdy, dfdz)); elene@25: } elene@25: elene@25: void main() elene@25: { elene@25: const vec3 ldir = vec3(-1.0, 1.0, 2.0); elene@25: elene@25: if(max(pt.x, max(pt.y, pt.z)) > 1.0 || min(pt.x, min(pt.y, pt.z)) < 0.0) elene@25: discard; elene@25: elene@25: float texel = texture3D(tex, pt).x; elene@25: float val = transfer(texel, tmin, tmax); elene@25: elene@25: vec3 normal = calc_normal(pt, texel); elene@25: float ndotl = max(dot(normalize(ldir), normal), 0.0); elene@25: elene@25: gl_FragColor = vec4(ndotl, ndotl, ndotl, val); elene@25: }