qvolray

diff volray.p.glsl @ 1:57072295eb83

progress
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 02 Apr 2012 02:11:35 +0300
parents b050ce167ff1
children 3e53a16d4667
line diff
     1.1 --- a/volray.p.glsl	Sat Mar 31 02:08:42 2012 +0300
     1.2 +++ b/volray.p.glsl	Mon Apr 02 02:11:35 2012 +0300
     1.3 @@ -12,6 +12,7 @@
     1.4  	vec3 normal;
     1.5  };
     1.6  
     1.7 +vec3 sky(Ray ray);
     1.8  vec3 ray_march(Ray ray);
     1.9  vec3 shade(Ray ray, ISect isect);
    1.10  Ray get_primary_ray();
    1.11 @@ -21,30 +22,37 @@
    1.12  	Ray ray = get_primary_ray();
    1.13  
    1.14  	gl_FragColor = vec4(ray_march(ray), 1.0);
    1.15 +	//gl_FragColor = vec4(sky(ray), 1.0);
    1.16  }
    1.17  
    1.18 -/*vec3 sky(Ray ray)
    1.19 +vec3 sky(Ray ray)
    1.20  {
    1.21  	vec3 col1 = vec3(0.75, 0.78, 0.8);
    1.22  	vec3 col2 = vec3(0.56, 0.7, 1.0);
    1.23  
    1.24  	float t = max(ray.dir.y, -0.5);
    1.25  	return mix(col1, col2, t);
    1.26 -}*/
    1.27 +}
    1.28  
    1.29  vec3 ray_march(Ray ray)
    1.30  {
    1.31 -	const float ray_step = 0.05;
    1.32 +	const float ray_step = 0.1;
    1.33  	float energy = 1.0;
    1.34  	vec3 pos = ray.origin;
    1.35 +	float col = 0.0;
    1.36  
    1.37 -	// assuming view space
    1.38 -	while(pos.z < 1.0) {
    1.39 -		energy -= texture3D(volume, pos).x;
    1.40 +	for(int i=0; i<40; i++) {
    1.41 +		float val = texture3D(volume, pos).x;
    1.42 +		val *= energy;
    1.43 +		col += val;
    1.44 +		energy -= val;
    1.45 +		if(energy < 0.001) {
    1.46 +			break;
    1.47 +		}
    1.48  		pos += ray.dir * ray_step;
    1.49  	}
    1.50  
    1.51 -	return vec3(energy, energy, energy);
    1.52 +	return vec3(col, col, col);
    1.53  }
    1.54  
    1.55  vec3 shade(Ray ray, ISect isect)