clray

diff src/rt.cc @ 9:a09622aaa043

moving to triangles
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 24 Jul 2010 06:28:17 +0100
parents deaf85acf6af
children d9a1bab1c3f5
line diff
     1.1 --- a/src/rt.cc	Fri Jul 23 19:48:43 2010 +0100
     1.2 +++ b/src/rt.cc	Sat Jul 24 06:28:17 2010 +0100
     1.3 @@ -3,21 +3,14 @@
     1.4  #include <math.h>
     1.5  #include <assert.h>
     1.6  #include "ocl.h"
     1.7 +#include "mesh.h"
     1.8  
     1.9  struct RendInfo {
    1.10  	int xsz, ysz;
    1.11 -	int num_sph, num_lights;
    1.12 +	int num_faces, num_lights;
    1.13  	int max_iter;
    1.14  } __attribute__((packed));
    1.15  
    1.16 -struct Sphere {
    1.17 -	float pos[4];
    1.18 -	float kd[4], ks[4];
    1.19 -	float radius;
    1.20 -	float spow;
    1.21 -	float kr, kt;
    1.22 -} __attribute__((packed));
    1.23 -
    1.24  struct Ray {
    1.25  	float origin[4], dir[4];
    1.26  } __attribute__((packed));
    1.27 @@ -32,9 +25,28 @@
    1.28  static CLProgram *prog;
    1.29  static int global_size;
    1.30  
    1.31 -static Sphere sphlist[] = {
    1.32 -	{{0, 0, 0, 1}, {0.7, 0.2, 0.15, 1}, {1, 1, 1, 1}, 1.0, 60, 0, 0},
    1.33 -	{{-0.2, 0.4, -3, 1}, {0.2, 0.9, 0.3, 1}, {1, 1, 1, 1}, 0.25, 40, 0, 0}
    1.34 +static Face faces[] = {
    1.35 +	{/* face0 */
    1.36 +		{
    1.37 +			{{-1, 0, 0, 1}, {0, 0, -1, 1}, {0, 0}},
    1.38 +			{{0, 1, 0, 1}, {0, 0, -1, 1}, {0, 0}},
    1.39 +			{{1, 0, 0, 1}, {0, 0, -1, 1}, {0, 0}}
    1.40 +		},
    1.41 +		{0, 0, -1, 1}, 0
    1.42 +	},
    1.43 +	{/* face1 */
    1.44 +		{
    1.45 +			{{-5, 0, -3, 1}, {0, 0, -1, 1}, {0, 0}},
    1.46 +			{{0, 0, 3, 1}, {0, 0, -1, 1}, {0, 0}},
    1.47 +			{{5, 0, -3, 1}, {0, 0, -1, 1}, {0, 0}}
    1.48 +		},
    1.49 +		{0, 0, -1, 1}, 1
    1.50 +	}
    1.51 +};
    1.52 +
    1.53 +static Material matlib[] = {
    1.54 +	{{1, 0, 0, 1}, {1, 1, 1, 1}, 0, 0, 60.0},
    1.55 +	{{0.2, 0.8, 0.3, 1}, {0, 0, 0, 0}, 0, 0, 0}
    1.56  };
    1.57  
    1.58  static Light lightlist[] = {
    1.59 @@ -53,7 +65,7 @@
    1.60  	// render info
    1.61  	rinf.xsz = xsz;
    1.62  	rinf.ysz = ysz;
    1.63 -	rinf.num_sph = sizeof sphlist / sizeof *sphlist;
    1.64 +	rinf.num_faces = sizeof faces / sizeof *faces;
    1.65  	rinf.num_lights = sizeof lightlist / sizeof *lightlist;
    1.66  	rinf.max_iter = 6;
    1.67  
    1.68 @@ -75,10 +87,11 @@
    1.69  	/* setup argument buffers */
    1.70  	prog->set_arg_buffer(0, ARG_WR, xsz * ysz * 4 * sizeof(float), fb);
    1.71  	prog->set_arg_buffer(1, ARG_RD, sizeof rinf, &rinf);
    1.72 -	prog->set_arg_buffer(2, ARG_RD, sizeof sphlist, sphlist);
    1.73 -	prog->set_arg_buffer(3, ARG_RD, sizeof lightlist, lightlist);
    1.74 -	prog->set_arg_buffer(4, ARG_RD, xsz * ysz * sizeof *prim_rays, prim_rays);
    1.75 -	prog->set_arg_buffer(5, ARG_RD, sizeof xform, &xform);
    1.76 +	prog->set_arg_buffer(2, ARG_RD, sizeof faces, faces);
    1.77 +	prog->set_arg_buffer(3, ARG_RD, sizeof matlib, matlib);
    1.78 +	prog->set_arg_buffer(4, ARG_RD, sizeof lightlist, lightlist);
    1.79 +	prog->set_arg_buffer(5, ARG_RD, xsz * ysz * sizeof *prim_rays, prim_rays);
    1.80 +	prog->set_arg_buffer(6, ARG_RD, sizeof xform, &xform);
    1.81  
    1.82  	global_size = xsz * ysz;
    1.83  	return true;
    1.84 @@ -98,16 +111,13 @@
    1.85  
    1.86  	CLMemBuffer *mbuf = prog->get_arg_buffer(0);
    1.87  	map_mem_buffer(mbuf, MAP_RD);
    1.88 -	/*if(!write_ppm("out.ppm", fb, xsz, ysz)) {
    1.89 -		return 1;
    1.90 -	}*/
    1.91  	unmap_mem_buffer(mbuf);
    1.92  	return true;
    1.93  }
    1.94  
    1.95  void set_xform(float *matrix)
    1.96  {
    1.97 -	CLMemBuffer *mbuf = prog->get_arg_buffer(5);
    1.98 +	CLMemBuffer *mbuf = prog->get_arg_buffer(6);
    1.99  	assert(mbuf);
   1.100  
   1.101  	assert(map_mem_buffer(mbuf, MAP_WR) == xform);