qvolray

changeset 20:68c6eb619d1c

normals from gradient map
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 11 Apr 2012 06:43:34 +0300
parents 9d2396738b60
children 4c62be57fc1a
files sdr/slice.p.glsl sdr/volray.p.glsl
diffstat 2 files changed, 11 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/sdr/slice.p.glsl	Sun Apr 08 14:31:03 2012 +0300
     1.2 +++ b/sdr/slice.p.glsl	Wed Apr 11 06:43:34 2012 +0300
     1.3 @@ -3,6 +3,7 @@
     1.4  
     1.5  void main()
     1.6  {
     1.7 -	float val = texture3D(volume, gl_TexCoord[0].xyz).a;
     1.8 -	gl_FragColor = vec4(texture1D(xfer_tex, val).xxx, 1.0);
     1.9 +	vec3 val = texture3D(volume, gl_TexCoord[0].xyz).xyz * 0.5 + 0.5;
    1.10 +	//gl_FragColor = vec4(texture1D(xfer_tex, val).xxx, 1.0);
    1.11 +	gl_FragColor = vec4(val, 1.0);
    1.12  }
     2.1 --- a/sdr/volray.p.glsl	Sun Apr 08 14:31:03 2012 +0300
     2.2 +++ b/sdr/volray.p.glsl	Wed Apr 11 06:43:34 2012 +0300
     2.3 @@ -40,15 +40,19 @@
     2.4  	gl_FragColor = vec4(color, 1.0);
     2.5  }
     2.6  
     2.7 -float eval(vec3 pos)
     2.8 +float eval(vec3 pos, out vec3 grad)
     2.9  {
    2.10  	vec3 tc = pos * 0.5 + 0.5;
    2.11  
    2.12  	if(tc.x < 0.0 || tc.y < 0.0 || tc.z < zclip || tc.x > 1.0 || tc.y > 1.0 || tc.z > 1.0) {
    2.13 +		grad = vec3(0.0, 0.0, 0.0);
    2.14  		return 0.0;
    2.15  	}
    2.16  
    2.17 -	return texture1D(xfer_tex, texture3D(volume, tc).a).x;
    2.18 +	vec4 texel = texture3D(volume, tc);
    2.19 +	grad = texel.xyz;
    2.20 +
    2.21 +	return texture1D(xfer_tex, texel.a).x;
    2.22  }
    2.23  
    2.24  #define OFFS	0.01
    2.25 @@ -63,14 +67,10 @@
    2.26  		vec3 pos = ray.origin + ray.dir * t;
    2.27  		t += ray_step;
    2.28  
    2.29 -		float val = eval(pos);
    2.30  		vec3 norm;
    2.31 +		float val = eval(pos, norm);
    2.32  
    2.33 -		norm.x = eval(pos + vec3(OFFS, 0.0, 0.0)) - val;
    2.34 -		norm.y = eval(pos + vec3(0.0, OFFS, 0.0)) - val;
    2.35 -		norm.z = eval(pos + vec3(0.0, 0.0, OFFS)) - val;
    2.36 -
    2.37 -		col += shade(ray, pos, normalize(norm)) * val * energy;
    2.38 +		col += /*shade(ray, pos, normalize(norm))*/ norm * val * energy;
    2.39  		energy -= val;
    2.40  		if(energy < 0.001) {
    2.41  			break;