--- ray/src/rt/m_mirror.c 1992/11/20 12:09:16 2.2 +++ ray/src/rt/m_mirror.c 2003/02/25 02:47:22 2.9 @@ -1,13 +1,12 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: m_mirror.c,v 2.9 2003/02/25 02:47:22 greg Exp $"; #endif - /* * Routines for mirror material supporting virtual light sources */ +#include "copyright.h" + #include "ray.h" #include "otypes.h" @@ -26,16 +25,19 @@ static char SCCSid[] = "$SunId$ LBL"; */ -int mir_proj(); +static int mir_proj(), mirrorproj(); + VSMATERIAL mirror_vs = {mir_proj, 1}; +int m_mirror(m, r) /* shade mirrored ray */ register OBJREC *m; register RAY *r; { COLOR mcolor; RAY nr; + int rpure = 1; register int i; /* check arguments */ if (m->oargs.nfargs != 3 || m->oargs.nsargs > 1) @@ -43,15 +45,18 @@ register RAY *r; /* check for substitute material */ if (m->oargs.nsargs > 0 && (r->rsrc < 0 || source[r->rsrc].so != r->ro)) { - rayshade(r, modifier(m->oargs.sarg[0])); - return; + 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; + return(1); if (r->rod < 0.) /* back is black */ - return; + return(1); /* get modifiers */ raytexture(r, m->omod); /* assign material color */ @@ -72,33 +77,49 @@ register RAY *r; 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 (DOT(nr.rdir, r->ron) <= FTINY) + 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); } +static int mir_proj(pm, o, s, n) /* compute a mirror's projection */ MAT4 pm; 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); @@ -106,6 +127,7 @@ int n; } +static int mirrorproj(m, nv, offs) /* get mirror projection for surface */ register MAT4 m; FVECT nv;