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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines