# HG changeset patch # User John Tsiombikas # Date 1281257505 -3600 # Node ID 754faf15ba36959ec882349af7eab355026c2cbc # Parent 29f9330cfa4b32f9bd6d068093984c48b9a8482b burp diff -r 29f9330cfa4b -r 754faf15ba36 rt.cl --- a/rt.cl Sat Aug 07 03:36:36 2010 +0100 +++ b/rt.cl Sun Aug 08 09:51:45 2010 +0100 @@ -4,6 +4,7 @@ int xsz, ysz; int num_faces, num_lights; int max_iter; + int dbg; }; struct Vertex { @@ -59,17 +60,26 @@ global const struct Light *lights, global const struct Ray *primrays, global const float *xform, - global const float *invtrans) + global const float *invtrans, + global struct Face *outfaces) { int idx = get_global_id(0); + + if(idx == 0) { + for(int i=0; inum_faces; i++) { + outfaces[i] = faces[i]; + } + } struct Ray ray = transform_ray(primrays + idx, xform, invtrans); struct SurfPoint sp, sp0; sp0.t = FLT_MAX; sp0.obj = 0; + + int max_faces = min(rinf->num_faces, rinf->dbg); - for(int i=0; inum_faces; i++) { + for(int i=0; i #include #include +#include #include #include #include @@ -115,6 +116,26 @@ static map matnames; + +#define FEQ(a, b) (fabs((a) - (b)) < 1e-8) +bool Face::operator ==(const Face &f) const +{ + for(int i=0; i<3; i++) { + for(int j=0; j<3; j++) { + if(!FEQ(v[i].pos[j], f.v[i].pos[j])) { + return false; + } + if(!FEQ(v[i].normal[j], f.v[i].normal[j])) { + return false; + } + } + if(!FEQ(normal[i], f.normal[i])) { + return false; + } + } + return true; +} + bool Scene::add_mesh(Mesh *m) { // make sure triangles have material ids diff -r 29f9330cfa4b -r 754faf15ba36 src/mesh.h --- a/src/mesh.h Sat Aug 07 03:36:36 2010 +0100 +++ b/src/mesh.h Sun Aug 08 09:51:45 2010 +0100 @@ -15,6 +15,8 @@ float normal[4]; int matid; int padding[3]; + + bool operator ==(const Face &f) const; }; struct Material { diff -r 29f9330cfa4b -r 754faf15ba36 src/rt.cc --- a/src/rt.cc Sat Aug 07 03:36:36 2010 +0100 +++ b/src/rt.cc Sun Aug 08 09:51:45 2010 +0100 @@ -16,6 +16,7 @@ KARG_PRIM_RAYS, KARG_XFORM, KARG_INVTRANS_XFORM, + KARG_OUTFACES, /* DBG */ NUM_KERNEL_ARGS }; @@ -24,6 +25,7 @@ int xsz, ysz; int num_faces, num_lights; int max_iter; + int dbg; }; struct Ray { @@ -58,6 +60,7 @@ rinf.num_faces = scn->get_num_faces(); rinf.num_lights = sizeof lightlist / sizeof *lightlist; rinf.max_iter = 6; + rinf.dbg = 8; /* calculate primary rays */ prim_rays = new Ray[xsz * ysz]; @@ -89,6 +92,7 @@ prog->set_arg_buffer(KARG_PRIM_RAYS, ARG_RD, xsz * ysz * sizeof *prim_rays, prim_rays); prog->set_arg_buffer(KARG_XFORM, ARG_RD, 16 * sizeof(float)); prog->set_arg_buffer(KARG_INVTRANS_XFORM, ARG_RD, 16 * sizeof(float)); + prog->set_arg_buffer(KARG_OUTFACES, ARG_WR, rinf.num_faces * sizeof(Face)); if(prog->get_num_args() < NUM_KERNEL_ARGS) { return false; @@ -114,6 +118,20 @@ } printf("done\n"); + /* DEBUG */ + CLMemBuffer *dbgbuf = prog->get_arg_buffer(KARG_OUTFACES); + Face *outfaces = (Face*)map_mem_buffer(dbgbuf, MAP_RD); + for(int i=0; iget_arg_buffer(KARG_FRAMEBUFFER); void *fb = map_mem_buffer(mbuf, MAP_RD); if(!fb) { @@ -126,12 +144,27 @@ return true; } +void dbg_set_dbg(int dbg) +{ + printf("setting dbg: %d\n", dbg); + + CLMemBuffer *mbuf = prog->get_arg_buffer(KARG_RENDER_INFO); + RendInfo *rinf = (RendInfo*)map_mem_buffer(mbuf, MAP_WR); + rinf->dbg = dbg; + unmap_mem_buffer(mbuf); +} + void dbg_render_gl(Scene *scn) { + float lpos[] = {-1, 1, 10, 0}; glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT); glDisable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_POSITION, lpos); + glEnable(GL_COLOR_MATERIAL); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -153,7 +186,9 @@ for(int j=0; j<3; j++) { float *pos = faces[i].v[j].pos; - glVertex3f(pos[0], pos[1], pos[2]); + float *norm = faces[i].normal; + glNormal3fv(norm); + glVertex3fv(pos); } } diff -r 29f9330cfa4b -r 754faf15ba36 src/rt.h --- a/src/rt.h Sat Aug 07 03:36:36 2010 +0100 +++ b/src/rt.h Sun Aug 08 09:51:45 2010 +0100 @@ -8,6 +8,7 @@ bool render(); void set_xform(float *matrix, float *invtrans); +void dbg_set_dbg(int dbg); void dbg_render_gl(Scene *scn); #endif /* RT_H_ */