X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=csgray;a=blobdiff_plain;f=src%2Fcsgray.c;h=44c7eb9818bdd25f25f0f7b0990ad73889827b6d;hp=fe0228a29eb85934953155bd55cf964ccefe198f;hb=f4f8d2071921bb09ff0408fe70f0599cb1263319;hpb=7abe0c51fc87e90674427c5ac5848f394af4575a diff --git a/src/csgray.c b/src/csgray.c index fe0228a..44c7eb9 100644 --- a/src/csgray.c +++ b/src/csgray.c @@ -350,7 +350,7 @@ static void shade(float *col, struct ray *ray, struct hit *hit) sray.dy = ldir[1]; sray.dz = ldir[2]; - if(1) {//!find_intersection(&sray, &tmphit) || tmphit.t > 1.0f) { + if(!find_intersection(&sray, &tmphit) || tmphit.t > 1.0f) { if((len = sqrt(ldir[0] * ldir[0] + ldir[1] * ldir[1] + ldir[2] * ldir[2])) != 0.0f) { float s = 1.0f / len; ldir[0] *= s; @@ -383,16 +383,32 @@ static void background(float *col, struct ray *ray) static int find_intersection(struct ray *ray, struct hit *best) { + int idx = 0; csg_object *o; - struct hit *hit; + struct hinterv *hit, *it; best->t = FLT_MAX; best->o = 0; o = oblist; while(o) { - if((hit = ray_intersect(ray, o)) && hit->t < best->t) { - *best = *hit; + if((hit = ray_intersect(ray, o))) { + it = hit; + while(it) { + if(it->end[0].t > 1e-6) { + idx = 0; + break; + } + if(it->end[1].t > 1e-6) { + idx = 1; + break; + } + it = it->next; + } + + if(it && it->end[idx].t < best->t) { + *best = it->end[idx]; + } } free_hit_list(hit); o = o->ob.next;