clray

diff rt.cl @ 47:30bf84881553

added interactive controls for turning shadows/reflections on and off as well as selecting maximum ray tracing iterations
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 31 Aug 2010 01:47:27 +0100
parents 8047637961a2
children
line diff
     1.1 --- a/rt.cl	Sun Aug 29 14:02:37 2010 +0100
     1.2 +++ b/rt.cl	Tue Aug 31 01:47:27 2010 +0100
     1.3 @@ -6,7 +6,7 @@
     1.4  	int xsz, ysz;
     1.5  	int num_faces, num_lights;
     1.6  	int max_iter;
     1.7 -	int kd_depth;
     1.8 +	int cast_shadows;
     1.9  };
    1.10  
    1.11  struct Vertex {
    1.12 @@ -53,6 +53,7 @@
    1.13  	int num_lights;
    1.14  	global const struct Material *matlib;
    1.15  	//global const struct KDNode *kdtree;
    1.16 +	bool cast_shadows;
    1.17  };
    1.18  
    1.19  struct AABBox {
    1.20 @@ -104,7 +105,7 @@
    1.21  	scn.lights = lights;
    1.22  	scn.num_lights = rinf->num_lights;
    1.23  	scn.matlib = matlib;
    1.24 -	//scn.kdtree_img = kdtree_img;
    1.25 +	scn.cast_shadows = rinf->cast_shadows;
    1.26  
    1.27  	struct Ray ray = primrays[idx];
    1.28  	transform_ray(&ray, xform, invtrans);
    1.29 @@ -113,7 +114,7 @@
    1.30  	float4 energy = (float4)(1.0, 1.0, 1.0, 0.0);
    1.31  	int iter = 0;
    1.32  
    1.33 -	while(iter++ < rinf->max_iter && mean(energy) > MIN_ENERGY) {
    1.34 +	while(iter++ <= rinf->max_iter && mean(energy) > MIN_ENERGY) {
    1.35  		struct SurfPoint sp;
    1.36  		if(find_intersection(ray, &scn, &sp, kdtree_img)) {
    1.37  			pixel += shade(ray, &scn, &sp, kdtree_img) * energy;
    1.38 @@ -156,7 +157,7 @@
    1.39  		shadowray.origin = sp->pos;
    1.40  		shadowray.dir = ldir;
    1.41  
    1.42 -		if(!find_intersection(shadowray, scn, 0, kdimg)) {
    1.43 +		if(!scn->cast_shadows || !find_intersection(shadowray, scn, 0, kdimg)) {
    1.44  			ldir = normalize(ldir);
    1.45  			float4 vdir = -ray.dir;
    1.46  			vdir.x = native_divide(vdir.x, RAY_MAG);