--- ray/src/rt/raytrace.c 1994/01/25 10:18:25 2.14 +++ ray/src/rt/raytrace.c 1995/12/06 12:07:50 2.22 @@ -1,4 +1,4 @@ -/* Copyright (c) 1994 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -34,6 +34,8 @@ OBJREC Lamb = { {0, 5, NULL, Lambfa}, NULL, }; /* a Lambertian surface */ +OBJREC Aftplane; /* aft clipping plane object */ + static int raymove(), checkset(), checkhit(); #define MAXLOOP 128 /* modifier loop detection */ @@ -59,9 +61,11 @@ double rw; r->rlvl++; r->rsrc = -1; r->clipset = ro->clipset; + r->rmax = 0.0; } else { r->rsrc = ro->rsrc; r->clipset = ro->newcset; + r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot; } r->revf = ro->revf; r->rweight = ro->rweight * rw; @@ -95,7 +99,10 @@ RAY *r; if (localhit(r, &thescene)) gotmat = raycont(r); - else if (sourcehit(r)) + else if (r->ro == &Aftplane) { + r->ro = NULL; + r->rot = FHUGE; + } else if (sourcehit(r)) gotmat = rayshade(r, r->ro->omod); if (r->ro != NULL && !gotmat) @@ -156,7 +163,7 @@ int mod; if (irr_ignore(m->otype)) { depth--; raytrans(r); - return; + return(1); } if (!islight(m->otype)) m = &Lamb; @@ -187,8 +194,11 @@ int mod; error(USER, errmsg); } ******/ - if ((*ofun[m->otype].funp)(m, r)) - objerror(r->ro, USER, "conflicting materials"); + if ((*ofun[m->otype].funp)(m, r)) { + sprintf(errmsg, "conflicting material \"%s\"", + m->oname); + objerror(r->ro, USER, errmsg); + } } depth--; /* end here */ } @@ -249,6 +259,21 @@ double coef; double +raydist(r, flags) /* compute (cumulative) ray distance */ +register RAY *r; +register int flags; +{ + double sum = 0.0; + + while (r != NULL && r->crtype&flags) { + sum += r->rot; + r = r->parent; + } + return(sum); +} + + +double raynormal(norm, r) /* compute perturbed normal for ray */ FVECT norm; register RAY *r; @@ -353,6 +378,14 @@ register CUBE *scene; } if (sflags == 0) error(CONSISTENCY, "zero ray direction in localhit"); + /* start off assuming nothing hit */ + if (r->rmax > FTINY) { /* except aft plane if one */ + r->ro = &Aftplane; + r->rot = r->rmax; + for (i = 0; i < 3; i++) + r->rop[i] = r->rorg[i] + r->rot*r->rdir[i]; + } + /* find global cube entrance point */ t = 0.0; if (!incube(scene, curpos)) { /* find distance to entry */ @@ -370,6 +403,8 @@ register CUBE *scene; t = dt; /* farthest face is the one */ } t += FTINY; /* fudge to get inside cube */ + if (t >= r->rot) /* clipped already */ + return(0); /* advance position */ for (i = 0; i < 3; i++) curpos[i] += r->rdir[i]*t; @@ -378,7 +413,8 @@ register CUBE *scene; return(0); } cxset[0] = 0; - return(raymove(curpos, cxset, sflags, r, scene) == RAYHIT); + raymove(curpos, cxset, sflags, r, scene); + return(r->ro != NULL & r->ro != &Aftplane); } @@ -433,7 +469,10 @@ register CUBE *cu; } /*NOTREACHED*/ } - if (isfull(cu->cutree) && checkhit(r, cu, cxs)) + if (isfull(cu->cutree)) { + if (checkhit(r, cu, cxs)) + return(RAYHIT); + } else if (r->ro == &Aftplane && incube(cu, r->rop)) return(RAYHIT); /* advance to next cube */ if (dirf&0x11) {