clray

diff src/rt.cc @ 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 d3c46803242e
line diff
     1.1 --- a/src/rt.cc	Sun Aug 29 14:02:37 2010 +0100
     1.2 +++ b/src/rt.cc	Tue Aug 31 01:47:27 2010 +0100
     1.3 @@ -2,6 +2,7 @@
     1.4  #include <string.h>
     1.5  #include <math.h>
     1.6  #include <assert.h>
     1.7 +#include "rt.h"
     1.8  #include "ogl.h"
     1.9  #include "ocl.h"
    1.10  #include "scene.h"
    1.11 @@ -28,7 +29,7 @@
    1.12  	int xsz, ysz;
    1.13  	int num_faces, num_lights;
    1.14  	int max_iter;
    1.15 -	int kd_depth;
    1.16 +	int cast_shadows;
    1.17  };
    1.18  
    1.19  struct Ray {
    1.20 @@ -39,6 +40,7 @@
    1.21  	float pos[4], color[4];
    1.22  };
    1.23  
    1.24 +static void update_render_info();
    1.25  static Ray get_primary_ray(int x, int y, int w, int h, float vfov_deg);
    1.26  static float *create_kdimage(const KDNodeGPU *kdtree, int num_nodes, int *xsz_ret, int *ysz_ret);
    1.27  
    1.28 @@ -53,6 +55,7 @@
    1.29  
    1.30  
    1.31  static RendInfo rinf;
    1.32 +static int saved_iter_val;
    1.33  
    1.34  static long timing_sample_sum;
    1.35  static long num_timing_samples;
    1.36 @@ -68,8 +71,8 @@
    1.37  	rinf.ysz = ysz;
    1.38  	rinf.num_faces = scn->get_num_faces();
    1.39  	rinf.num_lights = sizeof lightlist / sizeof *lightlist;
    1.40 -	rinf.max_iter = 6;
    1.41 -	rinf.kd_depth = kdtree_depth(scn->kdtree);
    1.42 +	rinf.max_iter = saved_iter_val = 6;
    1.43 +	rinf.cast_shadows = true;
    1.44  
    1.45  	/* calculate primary rays */
    1.46  	prim_rays = new Ray[xsz * ysz];
    1.47 @@ -279,6 +282,101 @@
    1.48  	unmap_mem_buffer(mbuf_invtrans);
    1.49  }
    1.50  
    1.51 +void set_render_option(int opt, bool val)
    1.52 +{
    1.53 +	switch(opt) {
    1.54 +	case ROPT_ITER:
    1.55 +	case ROPT_REFL:
    1.56 +		rinf.max_iter = val ? saved_iter_val : 0;
    1.57 +		break;
    1.58 +
    1.59 +	case ROPT_SHAD:
    1.60 +		rinf.cast_shadows = val;
    1.61 +		break;
    1.62 +
    1.63 +	default:
    1.64 +		return;
    1.65 +	}
    1.66 +
    1.67 +	update_render_info();
    1.68 +}
    1.69 +
    1.70 +void set_render_option(int opt, int val)
    1.71 +{
    1.72 +	switch(opt) {
    1.73 +	case ROPT_ITER:
    1.74 +		rinf.max_iter = saved_iter_val = val;
    1.75 +		break;
    1.76 +
    1.77 +	case ROPT_SHAD:
    1.78 +		rinf.cast_shadows = val;
    1.79 +		break;
    1.80 +
    1.81 +	case ROPT_REFL:
    1.82 +		rinf.max_iter = val ? saved_iter_val : 0;
    1.83 +		break;
    1.84 +
    1.85 +	default:
    1.86 +		return;
    1.87 +	}
    1.88 +
    1.89 +	update_render_info();
    1.90 +}
    1.91 +
    1.92 +void set_render_option(int opt, float val)
    1.93 +{
    1.94 +	set_render_option(opt, (int)val);
    1.95 +}
    1.96 +
    1.97 +bool get_render_option_bool(int opt)
    1.98 +{
    1.99 +	switch(opt) {
   1.100 +	case ROPT_ITER:
   1.101 +		return rinf.max_iter;
   1.102 +	case ROPT_SHAD:
   1.103 +		return rinf.cast_shadows;
   1.104 +	case ROPT_REFL:
   1.105 +		return rinf.max_iter == saved_iter_val;
   1.106 +	default:
   1.107 +		break;
   1.108 +	}
   1.109 +	return false;
   1.110 +}
   1.111 +
   1.112 +int get_render_option_int(int opt)
   1.113 +{
   1.114 +	switch(opt) {
   1.115 +	case ROPT_ITER:
   1.116 +		return rinf.max_iter;
   1.117 +	case ROPT_SHAD:
   1.118 +		return rinf.cast_shadows ? 1 : 0;
   1.119 +	case ROPT_REFL:
   1.120 +		return rinf.max_iter == saved_iter_val ? 1 : 0;
   1.121 +	default:
   1.122 +		break;
   1.123 +	}
   1.124 +	return -1;
   1.125 +}
   1.126 +
   1.127 +float get_render_option_float(int opt)
   1.128 +{
   1.129 +	return (float)get_render_option_int(opt);
   1.130 +}
   1.131 +
   1.132 +static void update_render_info()
   1.133 +{
   1.134 +	if(!prog) {
   1.135 +		return;
   1.136 +	}
   1.137 +
   1.138 +	CLMemBuffer *mbuf = prog->get_arg_buffer(KARG_RENDER_INFO);
   1.139 +	assert(mbuf);
   1.140 +
   1.141 +	RendInfo *rinf_ptr = (RendInfo*)map_mem_buffer(mbuf, MAP_WR);
   1.142 +	*rinf_ptr = rinf;
   1.143 +	unmap_mem_buffer(mbuf);
   1.144 +}
   1.145 +
   1.146  static Ray get_primary_ray(int x, int y, int w, int h, float vfov_deg)
   1.147  {
   1.148  	float vfov = M_PI * vfov_deg / 180.0;