--- ray/src/rt/m_mirror.c 1991/07/16 15:56:46 1.2 +++ ray/src/rt/m_mirror.c 1995/08/26 15:15:51 2.5 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -40,16 +40,21 @@ register RAY *r; /* check arguments */ if (m->oargs.nfargs != 3 || m->oargs.nsargs > 1) objerror(m, USER, "bad number of arguments"); - /* check if source ray */ - if (r->rsrc >= 0) { /* aiming for somebody */ - if (source[r->rsrc].so != r->ro) - return; /* but not us */ - } else if (m->oargs.nsargs > 0) { /* else call substitute? */ - rayshade(r, modifier(m->oargs.sarg[0])); - return; + /* check for substitute material */ + if (m->oargs.nsargs > 0 && + (r->rsrc < 0 || source[r->rsrc].so != r->ro)) { + if (!strcmp(m->oargs.sarg[0], VOIDID)) { + raytrans(r); + return(1); + } + return(rayshade(r, modifier(m->oargs.sarg[0]))); } + /* check for bad source ray */ + if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) + return(1); + if (r->rod < 0.) /* back is black */ - return; + return(1); /* get modifiers */ raytexture(r, m->omod); /* assign material color */ @@ -70,14 +75,19 @@ register RAY *r; double pdot; if (rayorigin(&nr, r, REFLECTED, bright(mcolor)) < 0) - return; + return(1); pdot = raynormal(pnorm, r); /* use textures */ for (i = 0; i < 3; i++) nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i]; + /* check for penetration */ + if (DOT(nr.rdir, r->ron) <= FTINY) + for (i = 0; i < 3; i++) + nr.rdir[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; } rayvalue(&nr); multcolor(nr.rcol, mcolor); addcolor(r->rcol, nr.rcol); + return(1); } @@ -87,12 +97,21 @@ register OBJREC *o; SRCREC *s; int n; { - FVECT nv; + FVECT nv, sc; double od; + register int i, j; /* get surface normal and offset */ od = getplaneq(nv, o); - /* check for behind */ - if (DOT(s->sloc, nv) <= (s->sflags & SDISTANT ? FTINY : od+FTINY)) + /* check for extreme point for behind */ + VCOPY(sc, s->sloc); + for (i = s->sflags & SFLAT ? SV : SW; i >= 0; i--) + if (DOT(nv, s->ss[i]) > 0.) + for (j = 0; j < 3; j++) + sc[j] += s->ss[i][j]; + else + for (j = 0; j < 3; j++) + sc[j] -= s->ss[i][j]; + if (DOT(sc, nv) <= (s->sflags & SDISTANT ? FTINY : od+FTINY)) return(0); /* everything OK -- compute projection */ mirrorproj(pm, nv, od);