# HG changeset patch # User John Tsiombikas # Date 1281421458 -3600 # Node ID bd6c2b25f6e7a13bb191ad629ada132b2a76c06f # Parent 63a6b46f58a07eb0964c123d1234466e88fc0783 fixed, now we need to start with optimizations diff -r 63a6b46f58a0 -r bd6c2b25f6e7 rt.cl --- a/rt.cl Mon Aug 09 12:55:40 2010 +0100 +++ b/rt.cl Tue Aug 10 07:24:18 2010 +0100 @@ -53,7 +53,7 @@ }; #define MIN_ENERGY 0.001 -#define EPSILON 1e-6 +#define EPSILON 1e-5 float4 shade(struct Ray ray, struct Scene *scn, const struct SurfPoint *sp); bool find_intersection(struct Ray ray, const struct Scene *scn, struct SurfPoint *sp); @@ -204,7 +204,7 @@ sp->t = t; sp->pos = pt; - sp->norm = -normalize(face->v[0].normal * bc.x + face->v[1].normal * bc.y + face->v[2].normal * bc.z); + sp->norm = normalize(face->v[0].normal * bc.x + face->v[1].normal * bc.y + face->v[2].normal * bc.z); sp->obj = face; sp->dbg = bc; return true; diff -r 63a6b46f58a0 -r bd6c2b25f6e7 src/clray.cc --- a/src/clray.cc Mon Aug 09 12:55:40 2010 +0100 +++ b/src/clray.cc Tue Aug 10 07:24:18 2010 +0100 @@ -167,7 +167,9 @@ case 'd': dbg_glrender = !dbg_glrender; if(dbg_glrender) { - printf("DEBUG GL RENDER\n"); + printf("Debug OpenGL rendering\n"); + } else { + printf("Raytracing\n"); } glutPostRedisplay(); break; diff -r 63a6b46f58a0 -r bd6c2b25f6e7 src/mesh.cc --- a/src/mesh.cc Mon Aug 09 12:55:40 2010 +0100 +++ b/src/mesh.cc Tue Aug 10 07:24:18 2010 +0100 @@ -165,7 +165,6 @@ for(size_t i=0; ifaces.size(); } - printf("get_num_faces() = %d\n", num_faces); return num_faces; } diff -r 63a6b46f58a0 -r bd6c2b25f6e7 src/rt.cc --- a/src/rt.cc Mon Aug 09 12:55:40 2010 +0100 +++ b/src/rt.cc Tue Aug 10 07:24:18 2010 +0100 @@ -115,7 +115,7 @@ bool render() { - printf("Running kernel..."); + printf("Running kernel... "); fflush(stdout); if(!prog->run(1, global_size)) { return false; @@ -135,17 +135,35 @@ return true; } +static void dbg_set_gl_material(Material *mat) +{ + static Material def_mat = {{0.7, 0.7, 0.7, 1}, {0, 0, 0, 0}, 0, 0, 0}; + + if(!mat) mat = &def_mat; + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat->kd); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat->ks); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat->spow); +} + void dbg_render_gl(Scene *scn) { - float lpos[] = {-1, 1, 10, 0}; glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT); + for(int i=0; iget_materials(); - glBegin(GL_TRIANGLES); int num_faces = scn->get_num_faces(); + int cur_mat = -1; + for(int i=0; ikd[0], mat->kd[1], mat->kd[2]); - } else { - glColor3f(1, 1, 1); + if(faces[i].matid != cur_mat) { + if(cur_mat != -1) { + glEnd(); + } + dbg_set_gl_material(materials ? materials + faces[i].matid : 0); + cur_mat = faces[i].matid; + glBegin(GL_TRIANGLES); } for(int j=0; j<3; j++) { - float *pos = faces[i].v[j].pos; - float *norm = faces[i].normal; - glNormal3fv(norm); - glVertex3fv(pos); + glNormal3fv(faces[i].v[j].normal); + glVertex3fv(faces[i].v[j].pos); } } glEnd();