--- ray/src/rt/m_mirror.c 1991/06/20 13:44:35 1.1 +++ ray/src/rt/m_mirror.c 1998/08/10 18:37:05 2.7 @@ -1,7 +1,7 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static char SCCSid[] = "$SunId$ SGI"; #endif /* @@ -36,20 +36,26 @@ register RAY *r; { COLOR mcolor; RAY nr; + int rpure = 1; register int i; /* 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, lastmod(objndx(m), 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 */ @@ -64,37 +70,54 @@ register RAY *r; for (i = 0; i < 3; i++) nr.rdir[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; /* source we're aiming for next */ - nr.rsrc = source[r->rsrc].sa.svnext; + nr.rsrc = source[r->rsrc].sa.sv.sn; } else { /* ordinary reflection */ FVECT pnorm; double pdot; if (rayorigin(&nr, r, REFLECTED, bright(mcolor)) < 0) - return; - pdot = raynormal(pnorm, r); /* use textures */ - for (i = 0; i < 3; i++) - nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i]; + return(1); + if (DOT(r->pert,r->pert) > FTINY*FTINY) { + pdot = raynormal(pnorm, r); /* use textures */ + for (i = 0; i < 3; i++) + nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i]; + rpure = 0; + } + /* check for penetration */ + if (rpure || 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); + if (rpure && r->ro != NULL && isflat(r->ro->otype)) + r->rt = r->rot + nr.rt; + return(1); } mir_proj(pm, o, s, n) /* compute a mirror's projection */ MAT4 pm; register OBJREC *o; -register SRCREC *s; +SRCREC *s; int n; { - FVECT nv; + FVECT nv, sc; double od; + register int i, j; /* get surface normal and offset */ - if (sfun[o->otype].of->getpleq == NULL) - return(0); /* reject non-planar case */ - od = (*sfun[o->otype].of->getpleq)(nv, o); - /* check for behind */ - if (DOT(s->sloc, nv) <= (s->sflags & SDISTANT ? FTINY : od+FTINY)) + od = getplaneq(nv, o); + /* 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); @@ -110,9 +133,9 @@ double offs; register int i, j; /* assign matrix */ setident4(m); - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (j = 0; j < 3; j++) { + for (i = 0; i < 3; i++) m[i][j] -= 2.*nv[i]*nv[j]; - for (j = 0; j < 3; j++) m[3][j] = 2.*offs*nv[j]; + } }