volmetrics
diff data/shaders/vol.f.glsl @ 25:4b6c952a83bd
works
todo:
1- ta quads na nai to res tou volume * 2
2- conservative quad
3- to aspect ratio tou preview
author | Eleni Maria Stea <elene.mst@gmail.com> |
---|---|
date | Sun, 27 Apr 2014 18:13:44 +0300 |
parents | |
children | e548d95e0667 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/data/shaders/vol.f.glsl Sun Apr 27 18:13:44 2014 +0300 1.3 @@ -0,0 +1,40 @@ 1.4 +varying vec3 pt; 1.5 + 1.6 +uniform sampler3D tex; 1.7 +uniform float tmin; 1.8 +uniform float tmax; 1.9 +uniform vec3 res; 1.10 + 1.11 +float transfer(float x, float tmin, float tmax) 1.12 +{ 1.13 + float dt = 0.25 * (tmax - tmin); 1.14 + return smoothstep(tmin - dt, tmin + dt, x) * 1.15 + (1.0 - smoothstep(tmax - dt, tmax + dt, x)); 1.16 +} 1.17 + 1.18 +vec3 calc_normal(vec3 p, float texel) 1.19 +{ 1.20 + vec3 offs = 1.0 / res; 1.21 + 1.22 + float dfdx = texture3D(tex, p + vec3(offs.x, 0.0, 0.0)).x - texel; 1.23 + float dfdy = texture3D(tex, p + vec3(0.0, offs.y, 0.0)).x - texel; 1.24 + float dfdz = texture3D(tex, p + vec3(0.0, 0.0, offs.z)).x - texel; 1.25 + 1.26 + return normalize(vec3(dfdx, dfdy, dfdz)); 1.27 +} 1.28 + 1.29 +void main() 1.30 +{ 1.31 + const vec3 ldir = vec3(-1.0, 1.0, 2.0); 1.32 + 1.33 + if(max(pt.x, max(pt.y, pt.z)) > 1.0 || min(pt.x, min(pt.y, pt.z)) < 0.0) 1.34 + discard; 1.35 + 1.36 + float texel = texture3D(tex, pt).x; 1.37 + float val = transfer(texel, tmin, tmax); 1.38 + 1.39 + vec3 normal = calc_normal(pt, texel); 1.40 + float ndotl = max(dot(normalize(ldir), normal), 0.0); 1.41 + 1.42 + gl_FragColor = vec4(ndotl, ndotl, ndotl, val); 1.43 +}