volmetrics
view data/shaders/vol.f.glsl @ 30:e548d95e0667
fixed lighting, added parameter for volume rotation
author | Eleni Maria Stea <elene.mst@gmail.com> |
---|---|
date | Thu, 01 May 2014 15:28:51 +0300 |
parents | 4b6c952a83bd |
children |
line source
1 varying vec3 pt;
3 uniform sampler3D tex;
4 uniform float tmin;
5 uniform float tmax;
6 uniform vec3 res;
8 float transfer(float x, float tmin, float tmax)
9 {
10 float dt = 0.25 * (tmax - tmin);
11 return smoothstep(tmin - dt, tmin + dt, x) *
12 (1.0 - smoothstep(tmax - dt, tmax + dt, x));
13 }
15 vec3 calc_normal(vec3 p, float texel)
16 {
17 vec3 offs = 1.0 / res;
19 float dfdx = texture3D(tex, p + vec3(offs.x, 0.0, 0.0)).x - texel;
20 float dfdy = texture3D(tex, p + vec3(0.0, offs.y, 0.0)).x - texel;
21 float dfdz = texture3D(tex, p + vec3(0.0, 0.0, offs.z)).x - texel;
23 return -normalize(vec3(dfdx, dfdy, dfdz));
24 }
26 void main()
27 {
28 const vec3 ldir = vec3(-1.0, 1.0, 2.0);
30 if(max(pt.x, max(pt.y, pt.z)) > 1.0 || min(pt.x, min(pt.y, pt.z)) < 0.0)
31 discard;
33 float texel = texture3D(tex, pt).x;
34 float val = transfer(texel, tmin, tmax);
36 vec3 normal = gl_NormalMatrix * calc_normal(pt, texel);
37 float ndotl = max(dot(normalize(ldir), normal), 0.0);
39 gl_FragColor = vec4(ndotl, ndotl, ndotl, val);
40 }