ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/virtuals.c
(Generate patch)

Comparing ray/src/rt/virtuals.c (file contents):
Revision 1.1 by greg, Wed Jun 19 16:36:14 1991 UTC vs.
Revision 1.9 by greg, Tue Jun 25 13:11:53 1991 UTC

# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11  
12   #include  "ray.h"
13  
14 < #include  "source.h"
14 > #include  "octree.h"
15  
16   #include  "otypes.h"
17  
18 < #include  "cone.h"
18 > #include  "source.h"
19  
20 < #include  "face.h"
20 > #include  "random.h"
21  
22 extern int  directrelay;                /* maximum number of source relays */
22  
23 < double  getplaneq();
25 < double  getmaxdisk();
26 < double  intercircle();
27 < SRCREC  *makevsrc();
23 > double  getdisk();
24  
25   static OBJECT  *vobject;                /* virtual source objects */
26   static int  nvobjects = 0;              /* number of virtual source objects */
# Line 40 | Line 36 | markvirtuals()                 /* find and mark virtual sources */
36                                          /* find virtual source objects */
37          for (i = 0; i < nobjects; i++) {
38                  o = objptr(i);
39 <                if (o->omod == OVOID)
39 >                if (!issurface(o->otype) || o->omod == OVOID)
40                          continue;
41                  if (!isvlight(objptr(o->omod)->otype))
42                          continue;
43 +                if (sfun[o->otype].of == NULL ||
44 +                                sfun[o->otype].of->getpleq == NULL)
45 +                        objerror(o, USER, "illegal material");
46                  if (nvobjects == 0)
47                          vobject = (OBJECT *)malloc(sizeof(OBJECT));
48                  else
# Line 55 | Line 54 | markvirtuals()                 /* find and mark virtual sources */
54          }
55          if (nvobjects == 0)
56                  return;
57 + #ifdef DEBUG
58 +        fprintf(stderr, "found %d virtual source objects\n", nvobjects);
59 + #endif
60                                          /* append virtual sources */
61          for (i = nsources; i-- > 0; )
62 <                if (!(source[i].sflags & SSKIP))
61 <                        addvirtuals(&source[i], directrelay);
62 >                addvirtuals(i, directrelay);
63                                          /* done with our object list */
64          free((char *)vobject);
65          nvobjects = 0;
66   }
67  
68  
69 < addvirtuals(sr, nr)             /* add virtual sources associated with sr */
70 < SRCREC  *sr;
69 > addvirtuals(sn, nr)             /* add virtuals associated with source */
70 > int  sn;
71   int  nr;
72   {
73          register int  i;
74                                  /* check relay limit first */
75          if (nr <= 0)
76                  return;
77 +        if (source[sn].sflags & SSKIP)
78 +                return;
79                                  /* check each virtual object for projection */
80          for (i = 0; i < nvobjects; i++)
81 <                vproject(objptr(i), sr, nr-1);  /* calls us recursively */
81 >                                        /* vproject() calls us recursively */
82 >                vproject(objptr(vobject[i]), sn, nr-1);
83   }
84  
85  
86 < SRCREC *
87 < makevsrc(op, sp, pm)            /* make virtual source if reasonable */
86 > vproject(o, sn, n)              /* create projected source(s) if they exist */
87 > OBJREC  *o;
88 > int  sn;
89 > int  n;
90 > {
91 >        register int  i;
92 >        register VSMATERIAL  *vsmat;
93 >        MAT4  proj;
94 >        int  ns;
95 >
96 >        if (o == source[sn].so) /* objects cannot project themselves */
97 >                return;
98 >                                /* get virtual source material */
99 >        vsmat = sfun[objptr(o->omod)->otype].mf;
100 >                                /* project virtual sources */
101 >        for (i = 0; i < vsmat->nproj; i++)
102 >                if ((*vsmat->vproj)(proj, o, &source[sn], i))
103 >                        if ((ns = makevsrc(o, sn, proj)) >= 0) {
104 > #ifdef DEBUG
105 >                                virtverb(ns, stderr);
106 > #endif
107 >                                addvirtuals(ns, n);
108 >                        }
109 > }
110 >
111 >
112 > int
113 > makevsrc(op, sn, pm)            /* make virtual source if reasonable */
114   OBJREC  *op;
115 < register SRCREC  *sp;
115 > register int  sn;
116   MAT4  pm;
117   {
118 <        register SRCREC  *newsrc;
119 <        FVECT  nsloc, ocent, nsnorm;
120 <        double  maxrad2;
91 <        double  d1, d2;
118 >        FVECT  nsloc, nsnorm, ocent, v;
119 >        double  maxrad2, d;
120 >        int  nsflags;
121          SPOT  theirspot, ourspot;
122          register int  i;
123 +
124 +        nsflags = source[sn].sflags | (SVIRTUAL|SSPOT|SFOLLOW);
125                                          /* get object center and max. radius */
126 <        maxrad2 = getmaxdisk(ocent, op);
126 >        maxrad2 = getdisk(ocent, op, sn);
127          if (maxrad2 <= FTINY)                   /* too small? */
128 <                return(NULL);
128 >                return(-1);
129                                          /* get location and spot */
130 <        if (sp->sflags & SDISTANT) {            /* distant source */
131 <                if (sp->sflags & SPROX)
132 <                        return(NULL);           /* should never get here! */
133 <                multv3(nsloc, sp->sloc, pm);
130 >        if (source[sn].sflags & SDISTANT) {             /* distant source */
131 >                if (source[sn].sflags & SPROX)
132 >                        return(-1);             /* should never get here! */
133 >                multv3(nsloc, source[sn].sloc, pm);
134                  VCOPY(ourspot.aim, ocent);
135                  ourspot.siz = PI*maxrad2;
136                  ourspot.flen = 0.;
137 <                if (sp->sflags & SSPOT) {
138 <                        copystruct(&theirspot, sp->sl.s);
139 <                        multp3(theirspot.aim, sp->sl.s->aim, pm);
137 >                if (source[sn].sflags & SSPOT) {
138 >                        copystruct(&theirspot, source[sn].sl.s);
139 >                        multp3(theirspot.aim, source[sn].sl.s->aim, pm);
140 >                        d = ourspot.siz;
141                          if (!commonbeam(&ourspot, &theirspot, nsloc))
142 <                                return(NULL);           /* no overlap */
143 <                }
144 <        } else {                                /* local source */
145 <                multp3(nsloc, sp->sloc, pm);
146 <                if (sp->sflags & SPROX) {
147 <                        d2 = 0.;
148 <                        for (i = 0; i < 3; i++) {
149 <                                d1 = ocent[i] - nsloc[i];
150 <                                d2 += d1*d1;
142 >                                return(-1);     /* no overlap */
143 >                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
144 >                                d = beamdisk(v, op, &ourspot, nsloc);
145 >                                if (d <= FTINY)
146 >                                        return(-1);
147 >                                if (d < maxrad2) {
148 >                                        maxrad2 = d;
149 >                                        VCOPY(ocent, v);
150 >                                }
151                          }
120                        if (d2 > sp->sl.prox*sp->sl.prox)
121                                return(NULL);   /* too far away */
152                  }
153 +        } else {                                /* local source */
154 +                multp3(nsloc, source[sn].sloc, pm);
155                  for (i = 0; i < 3; i++)
156                          ourspot.aim[i] = ocent[i] - nsloc[i];
157 <                if ((d1 = normalize(ourspot.aim)) == 0.)
158 <                        return(NULL);           /* at source!! */
159 <                ourspot.siz = 2.*PI*(1. - d1/sqrt(d1*d1+maxrad2));
157 >                if ((d = normalize(ourspot.aim)) == 0.)
158 >                        return(-1);             /* at source!! */
159 >                if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
160 >                        return(-1);             /* too far away */
161 >                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2));
162                  ourspot.flen = 0.;
163 <                if (sp->sflags & SSPOT) {
164 <                        copystruct(&theirspot, sp->sl.s);
165 <                        multv3(theirspot.aim, sp->sl.s->aim, pm);
163 >                if (source[sn].sflags & SSPOT) {
164 >                        copystruct(&theirspot, source[sn].sl.s);
165 >                        multv3(theirspot.aim, source[sn].sl.s->aim, pm);
166 >                        d = ourspot.siz;
167                          if (!commonspot(&ourspot, &theirspot, nsloc))
168 <                                return(NULL);           /* no overlap */
168 >                                return(-1);     /* no overlap */
169 >                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
170 >                                d = spotdisk(v, op, &ourspot, nsloc);
171 >                                if (d <= FTINY)
172 >                                        return(-1);
173 >                                if (d < maxrad2) {
174 >                                        maxrad2 = d;
175 >                                        VCOPY(ocent, v);
176 >                                }
177 >                        }
178                          ourspot.flen = theirspot.flen;
179                  }
180 <                if (sp->sflags & SFLAT) {       /* check for behind source */
181 <                        multv3(nsnorm, sp->snorm, pm);
180 >                if (source[sn].sflags & SFLAT) {        /* behind source? */
181 >                        multv3(nsnorm, source[sn].snorm, pm);
182                          if (checkspot(&ourspot, nsnorm) < 0)
183 <                                return(NULL);
183 >                                return(-1);
184                  }
185          }
186 <                                        /* everything is OK, make source */
187 <        if ((newsrc = newsource()) == NULL)
186 >                                        /* pretest visibility */
187 >        nsflags = vstestvis(nsflags, op, ocent, maxrad2, sn);
188 >        if (nsflags & SSKIP)
189 >                return(-1);     /* obstructed */
190 >                                        /* it all checks out, so make it */
191 >        if ((i = newsource()) < 0)
192                  goto memerr;
193 <        newsrc->sflags = sp->sflags | (SVIRTUAL|SSPOT|SFOLLOW);
194 <        VCOPY(newsrc->sloc, nsloc);
195 <        if (newsrc->sflags & SFLAT)
196 <                VCOPY(newsrc->snorm, nsnorm);
197 <        newsrc->ss = sp->ss; newsrc->ss2 = sp->ss2;
198 <        if ((newsrc->sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
193 >        source[i].sflags = nsflags;
194 >        VCOPY(source[i].sloc, nsloc);
195 >        if (nsflags & SFLAT)
196 >                VCOPY(source[i].snorm, nsnorm);
197 >        source[i].ss = source[sn].ss; source[i].ss2 = source[sn].ss2;
198 >        if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
199                  goto memerr;
200 <        copystruct(newsrc->sl.s, &ourspot);
201 <        if (newsrc->sflags & SPROX)
202 <                newsrc->sl.prox = sp->sl.prox;
203 <        newsrc->sa.svnext = sp - source;
204 <        return(newsrc);
200 >        copystruct(source[i].sl.s, &ourspot);
201 >        if (nsflags & SPROX)
202 >                source[i].sl.prox = source[sn].sl.prox;
203 >        source[i].sa.svnext = sn;
204 >        source[i].so = op;
205 >        return(i);
206   memerr:
207          error(SYSTEM, "out of memory in makevsrc");
208   }
209  
210  
211 < commonspot(sp1, sp2, org)       /* set sp1 to intersection of sp1 and sp2 */
212 < register SPOT  *sp1, *sp2;
213 < FVECT  org;
211 > double
212 > getdisk(oc, op, sn)             /* get visible object disk */
213 > FVECT  oc;
214 > OBJREC  *op;
215 > register int  sn;
216   {
217 <        FVECT  cent;
218 <        double  rad2, d1r2, d2r2;
219 <
220 <        d1r2 = 1. - sp1->siz/(2.*PI);
221 <        d2r2 = 1. - sp2->siz/(2.*PI);
222 <        if (sp2->siz >= 2.*PI-FTINY)            /* BIG, just check overlap */
223 <                return(DOT(sp1->aim,sp2->aim) >= d1r2*d2r2 -
224 <                                        sqrt((1.-d1r2*d1r2)*(1.-d2r2*d2r2)));
225 <                                /* compute and check disks */
226 <        d1r2 = 1./(d1r2*d1r2) - 1.;
227 <        d2r2 = 1./(d2r2*d2r2) - 1.;
228 <        rad2 = intercircle(cent, sp1->aim, sp2->aim, d1r2, d2r2);
229 <        if (rad2 <= FTINY || normalize(cent) == 0.)
230 <                return(0);
231 <        VCOPY(sp1->aim, cent);
232 <        sp1->siz = 2.*PI*(1. - 1./sqrt(1.+rad2));
233 <        return(1);
217 >        double  rad2, roffs, offs, d, rd, rdoto;
218 >        FVECT  rnrm, nrm;
219 >                                /* first, use object getdisk function */
220 >        rad2 = getmaxdisk(oc, op);
221 >        if (!(source[sn].sflags & SVIRTUAL))
222 >                return(rad2);           /* all done for normal source */
223 >                                /* check for correct side of relay surface */
224 >        roffs = getplaneq(rnrm, source[sn].so);
225 >        rd = DOT(rnrm, source[sn].sloc);        /* source projection */
226 >        if (!(source[sn].sflags & SDISTANT))
227 >                rd -= roffs;
228 >        d = DOT(rnrm, oc) - roffs;      /* disk distance to relay plane */
229 >        if ((d > 0.) ^ (rd > 0.))
230 >                return(rad2);           /* OK if opposite sides */
231 >        if (d*d >= rad2)
232 >                return(0.);             /* no relay is possible */
233 >                                /* we need a closer look */
234 >        offs = getplaneq(nrm, op);
235 >        rdoto = DOT(rnrm, nrm);
236 >        if (d*d >= rad2*(1.-rdoto*rdoto))
237 >                return(0.);             /* disk entirely on projection side */
238 >                                /* should shrink disk but I'm lazy */
239 >        return(rad2);
240   }
241  
242  
243 < commonbeam(sp1, sp2, dir)       /* set sp1 to intersection of sp1 and sp2 */
244 < register SPOT  *sp1, *sp2;
245 < FVECT  dir;
243 > int
244 > vstestvis(f, o, oc, or2, sn)            /* pretest source visibility */
245 > int  f;                 /* virtual source flags */
246 > OBJREC  *o;             /* relay object */
247 > FVECT  oc;              /* relay object center */
248 > double  or2;            /* relay object radius squared */
249 > register int  sn;       /* target source number */
250   {
251 <        FVECT  cent, c1, c2;
252 <        double  rad2, d;
253 <        register int  i;
254 <                                        /* move centers to common plane */
255 <        d = DOT(sp1->aim, dir);
256 <        for (i = 0; i < 3; i++)
257 <                c1[i] = sp2->aim[i] - d*dir[i];
258 <        d = DOT(sp2->aim, dir);
259 <        for (i = 0; i < 3; i++)
260 <                c2[i] = sp2->aim[i] - d*dir[i];
261 <                                        /* compute overlap */
262 <        rad2 = intercircle(cent, c1, c2, sp1->siz/PI, sp2->siz/PI);
263 <        if (rad2 <= FTINY)
264 <                return(0);
265 <        VCOPY(sp1->aim, cent);
266 <        sp1->siz = PI*rad2;
267 <        return(1);
268 < }
208 <
209 <
210 < checkspot(sp, nrm)              /* check spotlight for behind source */
211 < register SPOT  *sp;
212 < FVECT  nrm;
213 < {
214 <        double  d, d1;
215 <
216 <        d = DOT(sp->aim, nrm);
217 <        if (d > FTINY)                  /* center in front? */
218 <                return(0);
219 <                                        /* else check horizon */
220 <        d1 = 1. - sp->siz/(2.*PI);
221 <        return(1.-FTINY-d*d > d1*d1);
222 < }
223 <
224 <
225 < mirrorproj(m, nv, offs)         /* get mirror projection for surface */
226 < register MAT4  m;
227 < FVECT  nv;
228 < double  offs;
229 < {
230 <        register int  i, j;
231 <                                        /* assign matrix */
232 <        setident4(m);
233 <        for (i = 0; i < 3; i++)
234 <                for (j = 0; j < 3; j++)
235 <                        m[i][j] -= 2.*nv[i]*nv[j];
236 <        for (j = 0; j < 3; j++)
237 <                m[3][j] = 2.*offs*nv[j];
238 < }
239 <
240 <
241 < double
242 < intercircle(cc, c1, c2, r1s, r2s)       /* intersect two circles */
243 < FVECT  cc;                      /* midpoint (return value) */
244 < FVECT  c1, c2;                  /* circle centers */
245 < double  r1s, r2s;               /* radii squared */
246 < {
247 <        double  a2, d2, l;
248 <        FVECT  disp;
249 <        register int  i;
250 <
251 <        for (i = 0; i < 3; i++)
252 <                disp[i] = c2[i] - c1[i];
253 <        d2 = DOT(disp,disp);
254 <                                        /* circle within overlap? */
255 <        if (r1s < r2s) {
256 <                if (r2s >= r1s + d2) {
257 <                        VCOPY(cc, c1);
258 <                        return(r1s);
259 <                }
251 >        RAY  sr;
252 >        FVECT  onorm;
253 >        FVECT  offsdir;
254 >        double  or, d;
255 >        int  infront;
256 >        int  ssn;
257 >        int  nhit;
258 >        register int  i, n;
259 >                                /* return if pretesting disabled */
260 >        if (vspretest <= 0)
261 >                return(f);
262 >                                /* get surface normal */
263 >        getplaneq(onorm, o);
264 >                                /* set number of rays to sample */
265 >        if (source[sn].sflags & SDISTANT) {
266 >                n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)*
267 >                                vspretest + .5;
268 >                infront = DOT(onorm, source[sn].sloc) > 0.;
269          } else {
270 <                if (r1s >= r2s + d2) {
271 <                        VCOPY(cc, c2);
272 <                        return(r2s);
273 <                }
270 >                for (i = 0; i < 3; i++)
271 >                        offsdir[i] = source[sn].sloc[i] - oc[i];
272 >                n = or2/DOT(offsdir,offsdir)*vspretest + .5;
273 >                infront = DOT(onorm, offsdir) > 0.;
274          }
275 <        a2 = .25*(2.*(r1s+r2s) - d2 - (r2s-r1s)*(r2s-r1s)/d2);
276 <                                        /* no overlap? */
277 <        if (a2 <= 0.)
278 <                return(0.);
279 <        l = sqrt((r1s - a2)/d2);
280 <        for (i = 0; i < 3; i++)
281 <                cc[i] = c1[i] + l*disp[i];
282 <        return(a2);
283 < }
284 <
285 <
286 < /*
287 < * The following routines depend on the supported OBJECTS:
288 < */
289 <
290 <
291 < double
283 < getmaxdisk(ocent, op)           /* get object center and squared radius */
284 < FVECT  ocent;
285 < register OBJREC  *op;
286 < {
287 <        double  maxrad2;
288 <
289 <        switch (op->otype) {
290 <        case OBJ_FACE:
291 <                {
292 <                        double  d1, d2;
293 <                        register int  i, j;
294 <                        register FACE  *f = getface(op);
295 <
296 <                        for (i = 0; i < 3; i++) {
297 <                                ocent[i] = 0.;
298 <                                for (j = 0; j < f->nv; j++)
299 <                                        ocent[i] += VERTEX(f,j)[i];
300 <                                ocent[i] /= (double)f->nv;
275 >        if (n < 1) n = 1;
276 > #ifdef DEBUG
277 >        fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
278 >                        sn, o->oname, n);
279 > #endif
280 >                                /* sample */
281 >        or = sqrt(or2);
282 >        ssn = 25*n;
283 >        nhit = 0;
284 >        while (n-- > 0) {
285 >                                        /* get sample point */
286 >                do {
287 >                        if (--ssn < 0) {
288 > #ifdef DEBUG
289 >                                fprintf(stderr, "\ttoo hard to hit\n");
290 > #endif
291 >                                return(f);      /* too small a target! */
292                          }
293 <                        maxrad2 = 0.;
294 <                        for (j = 0; j < f->nv; j++) {
295 <                                d2 = 0.;
293 >                        for (i = 0; i < 3; i++)
294 >                                offsdir[i] = or*(1. -
295 >                                                2.*urand(931*i+5827+ssn));
296 >                        for (i = 0; i < 3; i++)
297 >                                sr.rorg[i] = oc[i] + offsdir[i];
298 >                        d = DOT(offsdir,onorm);
299 >                        if (infront)
300                                  for (i = 0; i < 3; i++) {
301 <                                        d1 = VERTEX(f,j)[i] - ocent[i];
302 <                                        d2 += d1*d1;
301 >                                        sr.rorg[i] -= (d-.0001)*onorm[i];
302 >                                        sr.rdir[i] = -onorm[i];
303                                  }
304 <                                if (d2 > maxrad2)
305 <                                        maxrad2 = d2;
306 <                        }
304 >                        else
305 >                                for (i = 0; i < 3; i++) {
306 >                                        sr.rorg[i] -= (d+.0001)*onorm[i];
307 >                                        sr.rdir[i] = onorm[i];
308 >                                }
309 >                        rayorigin(&sr, NULL, PRIMARY, 1.0);
310 >                } while (!(*ofun[o->otype].funp)(o, &sr));
311 >                                        /* check against source */
312 >                samplendx++;
313 >                if (srcray(&sr, NULL, sn) == 0.)
314 >                        continue;
315 >                sr.revf = srcvalue;
316 >                rayvalue(&sr);
317 >                if (bright(sr.rcol) <= FTINY)
318 >                        continue;
319 >                                        /* check against obstructions */
320 >                srcray(&sr, NULL, sn);
321 >                rayvalue(&sr);
322 >                if (bright(sr.rcol) <= FTINY) {
323 > #ifdef DEBUG
324 >                        fprintf(stderr, "\tfound an occlusion\n");
325 > #endif
326 >                        return(f);      /* need to shadow test */
327                  }
328 <                return(maxrad2);
314 <        case OBJ_RING:
315 <                {
316 <                        register CONE  *co = getcone(op, 0);
317 <
318 <                        VCOPY(ocent, CO_P0(co));
319 <                        maxrad2 = CO_R1(co);
320 <                        maxrad2 *= maxrad2;
321 <                }
322 <                return(maxrad2);
328 >                nhit++;
329          }
330 <        objerror(op, USER, "illegal material");
325 < }
326 <
327 <
328 < double
329 < getplaneq(nvec, op)                     /* get plane equation for object */
330 < FVECT  nvec;
331 < OBJREC  *op;
332 < {
333 <        register FACE  *fo;
334 <        register CONE  *co;
335 <
336 <        switch (op->otype) {
337 <        case OBJ_FACE:
338 <                fo = getface(op);
339 <                VCOPY(nvec, fo->norm);
340 <                return(fo->offset);
341 <        case OBJ_RING:
342 <                co = getcone(op, 0);
343 <                VCOPY(nvec, co->ad);
344 <                return(DOT(nvec, CO_P0(co)));
345 <        }
346 <        objerror(op, USER, "illegal material");
347 < }
348 <
349 <
350 < /*
351 < * The following routines depend on the supported MATERIALS:
352 < */
353 <
354 <
355 < vproject(o, s, n)               /* create projected source(s) if they exist */
356 < OBJREC  *o;
357 < SRCREC  *s;
358 < int  n;
359 < {
360 <        SRCREC  *ns;
361 <        FVECT  norm;
362 <        double  offset;
363 <        MAT4  proj;
364 <                                /* get surface normal and offset */
365 <        offset = getplaneq(norm, o);
366 <        switch (objptr(o->omod)->otype) {
367 <        case MAT_MIRROR:                        /* mirror source */
368 <                if (DOT(s->sloc, norm) <= (s->sflags & SDISTANT ?
369 <                                        FTINY : offset+FTINY))
370 <                        return;                 /* behind mirror */
371 <                mirrorproj(proj, norm, offset);
372 <                if ((ns = makevsrc(o, s, proj)) != NULL)
373 <                        addvirtuals(ns, n);
374 <                break;
375 <        }
376 < }
377 <
378 <
379 < vsrcrelay(rn, rv)               /* relay virtual source ray */
380 < register RAY  *rn, *rv;
381 < {
382 <        int  snext;
383 <        register int  i;
384 <                                        /* source we're aiming for here */
385 <        snext = source[rv->rsrc].sa.svnext;
386 <                                        /* compute relayed ray direction */
387 <        switch (objptr(rv->ro->omod)->otype) {
388 <        case MAT_MIRROR:                /* mirror: singular reflection */
389 <                rayorigin(rn, rv, REFLECTED, 1.);
390 <                                        /* ignore textures */
391 <                for (i = 0; i < 3; i++)
392 <                        rn->rdir[i] = rv->rdir[i] + 2.*rv->rod*rv->ron[i];
393 <                break;
330 >        if (nhit == 0) {
331   #ifdef DEBUG
332 <        default:
396 <                error(CONSISTENCY, "inappropriate material in vsrcrelay");
332 >                fprintf(stderr, "\t0%% hit rate\n");
333   #endif
334 +                return(f | SSKIP);      /* 0% hit rate:  totally occluded */
335          }
336 <        rn->rsrc = snext;
336 > #ifdef DEBUG
337 >        fprintf(stderr, "\t100%% hit rate\n");
338 > #endif
339 >        return(f & ~SFOLLOW);           /* 100% hit rate:  no occlusion */
340   }
341 +        
342  
343 <
344 < m_mirror(m, r)                  /* shade mirrored ray */
345 < register OBJREC  *m;
346 < register RAY  *r;
343 > #ifdef DEBUG
344 > virtverb(sn, fp)        /* print verbose description of virtual source */
345 > register int  sn;
346 > FILE  *fp;
347   {
407        COLOR  mcolor;
408        RAY  nr;
348          register int  i;
349  
350 <        if (m->oargs.nfargs != 3 || m->oargs.nsargs > 1)
351 <                objerror(m, USER, "bad number of arguments");
352 <        if (r->rsrc >= 0) {                     /* aiming for somebody */
353 <                if (source[r->rsrc].so != r->ro)
354 <                        return;                         /* but not us */
355 <        } else if (m->oargs.nsargs > 0) {       /* else call substitute? */
356 <                rayshade(r, modifier(m->oargs.sarg[0]));
350 >        fprintf(fp, "%s virtual source %d in %s %s\n",
351 >                        source[sn].sflags & SDISTANT ? "distant" : "local",
352 >                        sn, ofun[source[sn].so->otype].funame,
353 >                        source[sn].so->oname);
354 >        fprintf(fp, "\tat (%f,%f,%f)\n",
355 >                source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]);
356 >        fprintf(fp, "\tlinked to source %d (%s)\n",
357 >                source[sn].sa.svnext, source[source[sn].sa.svnext].so->oname);
358 >        if (source[sn].sflags & SFOLLOW)
359 >                fprintf(fp, "\talways followed\n");
360 >        else
361 >                fprintf(fp, "\tnever followed\n");
362 >        if (!(source[sn].sflags & SSPOT))
363                  return;
364 <        }
365 <        if (r->rod < 0.)                        /* back is black */
366 <                return;
422 <                                        /* get modifiers */
423 <        raytexture(r, m->omod);
424 <                                        /* assign material color */
425 <        setcolor(mcolor, m->oargs.farg[0],
426 <                        m->oargs.farg[1],
427 <                        m->oargs.farg[2]);
428 <        multcolor(mcolor, r->pcol);
429 <                                        /* compute reflected ray */
430 <        if (r->rsrc >= 0)                       /* relayed light source */
431 <                vsrcrelay(&nr, r);
432 <        else {                                  /* ordinary reflection */
433 <                FVECT  pnorm;
434 <                double  pdot;
435 <
436 <                if (rayorigin(&nr, r, REFLECTED, bright(mcolor)) < 0)
437 <                        return;
438 <                pdot = raynormal(pnorm, r);     /* use textures */
439 <                for (i = 0; i < 3; i++)
440 <                        nr.rdir[i] = r->rdir[i] + 2.*pdot*pnorm[i];
441 <        }
442 <        rayvalue(&nr);
443 <        multcolor(nr.rcol, mcolor);
444 <        addcolor(r->rcol, nr.rcol);
364 >        fprintf(fp, "\twith spot aim (%f,%f,%f) and size %f\n",
365 >                        source[sn].sl.s->aim[0], source[sn].sl.s->aim[1],
366 >                        source[sn].sl.s->aim[2], source[sn].sl.s->siz);
367   }
368 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines