Original Post
Now where I'm finished with my radiosity renderer, I wanted to write a photon tracer. I've been looking for a whole lot of time to find a fast ray triangle intersection code and ended up with the following. For some time it worked, but later I've encountered problems with it. I don't have a clue what the problem is, so I hope you could help me out of this. this is a picture of the result, I've drawn in the missing architecture of the room. http://home.arcor.de/irigyt/bild/failure.JPG first I thought that it may be a problem with my octree, but then I removed it and it still didn't look better, only slower. the strange thing is, when I get an intersection, half the time (during one rendering) the ray_lval that's returned does not have the right triangle based variables (photons LL, normal) and if i want to acces them outside of the code, it crashes. but now it's even worse, I can't remember to have changed anything in the intersection code, and now it even messes things up when there's no intersection. (the windows in the pic above) here's the code : class ray { public: vector *pos; vector *dir; ray() {pos = new vector();dir=new vector();} ~ray() {free(pos);free(dir);free(this);} }; class ray_lval { public: bool hit; float u,v; int r,g,b; float t; vertex *normal; LinkedList *photons; ray_lval() {r=0;g=0;b=0;} ~ray_lval() {free(this);}; }; ray_lval* ray_intersects_triangle(ray_lval *lval, ray *ray, triangle *t) { vector *E1, *E2, *H, *S, *Q; E1 = new vector(); E2 = new vector(); H = new vector(); S = new vector(); Q = new vector(); lval->r=0; lval->g=0; lval->b=0; lval->hit=false; E1->x = t->vp[1]->x - t->vp[0]->x; E1->y = t->vp[1]->y - t->vp[0]->y; E1->z = t->vp[1]->z - t->vp[0]->z; E2->x = t->vp[2]->x - t->vp[0]->x; E2->y = t->vp[2]->y - t->vp[0]->y; E2->z = t->vp[2]->z - t->vp[0]->z; cross(H,ray->dir,E2); float a = dot(E1,H); if (a > -0.00001 && a < 0.00001) return lval; float f = 1.0 / a; S->x = ray->pos->x - t->vp[0]->x; S->y = ray->pos->y - t->vp[0]->y; S->z = ray->pos->z - t->vp[0]->z; float u = f*dot(S,H); if (u < 0.0 || u > 1.0) return lval; cross(Q,S,E1); float v = f*dot(ray->dir,Q); if (v < 0.0 || (u + v) > 1.0) return lval; lval->t=dot(E2,Q)*f; lval->u=t->vp[0]->u+(t->vp[1]->u-t->vp[0]->u)*u+(t->vp[2]->u-t->vp[0]->u)*v; lval->v=t->vp[0]->v+(t->vp[1]->v-t->vp[0]->v)*u+(t->vp[2]->v-t->vp[0]->v *v; lval->r=(t->obj->texture[(int)u*3+(int)v*256*3]*t->light)>>8; lval->g=(t->obj->texture[(int)u*3+(int)v*256*3+1]*t->light)>>8; lval->b=(t->obj->texture[(int)u*3+(int)v*256*3+2]*t->light)>>8; lval->normal=t->normal; lval->photons = t->obj->photons; lval->hit=true; free(E1); free(E2); free(H); free(S); free(Q); return lval; } If the code is right, and someone wanted to look at the whole source, please tell me, I'd then upload it as soon as possible. but be warned, it's quite a mess ^^ and if someone's got a good tutorial btw of how to use an KD-Tree for fast photon gathering, I'd be very thankful if he'd postet it here.