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.8 by greg, Tue Jun 25 08:52:04 1991 UTC vs.
Revision 1.15 by greg, Wed Jun 26 14:26:52 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #include  "random.h"
21  
22 + #define  MINSAMPLES     5               /* minimum number of pretest samples */
23 + #define  STESTMAX       30              /* maximum seeks per sample */
24  
25 +
26   double  getdisk();
27  
28   static OBJECT  *vobject;                /* virtual source objects */
# Line 115 | Line 118 | OBJREC  *op;
118   register int  sn;
119   MAT4  pm;
120   {
121 <        FVECT  nsloc, nsnorm, ocent;
122 <        double  maxrad2;
121 >        FVECT  nsloc, nsnorm, ocent, v;
122 >        double  maxrad2, d;
123          int  nsflags;
121        double  d1;
124          SPOT  theirspot, ourspot;
125          register int  i;
126  
# Line 138 | Line 140 | MAT4  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(-1);             /* 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, 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.)
160 >                if ((d = normalize(ourspot.aim)) == 0.)
161                          return(-1);             /* at source!! */
162 <                if (source[sn].sflags & SPROX && d1 > source[sn].sl.prox)
162 >                if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
163                          return(-1);             /* too far away */
152                ourspot.siz = 2.*PI*(1. - d1/sqrt(d1*d1+maxrad2));
164                  ourspot.flen = 0.;
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 (!commonspot(&ourspot, &theirspot, nsloc))
173 <                                return(-1);     /* no overlap */
174 <                        ourspot.flen = theirspot.flen;
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 (source[sn].sflags & SFLAT) {        /* behind source? */
193                          multv3(nsnorm, source[sn].snorm, pm);
194 <                        if (checkspot(&ourspot, nsnorm) < 0)
194 >                        if (!checkspot(&ourspot, nsnorm))
195                                  return(-1);
196                  }
197          }
# Line 176 | Line 207 | MAT4  pm;
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 ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
211 <                goto memerr;
212 <        copystruct(source[i].sl.s, &ourspot);
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;
# Line 198 | Line 231 | register int  sn;
231          double  rad2, roffs, offs, d, rd, rdoto;
232          FVECT  rnrm, nrm;
233                                  /* first, use object getdisk function */
234 <        rad2 = (*sfun[op->otype].of->getdisk)(oc, op);
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 = (*sfun[source[sn].so->otype].of->getpleq)(rnrm, source[sn].so);
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;
# Line 210 | Line 243 | register int  sn;
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 */
246 >                return(0.);             /* no relay is possible */
247                                  /* we need a closer look */
248 <        offs = (*sfun[op->otype].of->getpleq)(nrm, op);
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 */
# Line 235 | Line 268 | register int  sn;      /* target source number */
268          double  or, d;
269          int  infront;
270          int  ssn;
271 <        int  nok, nhit;
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 <        (*sfun[o->otype].of->getpleq)(onorm, o);
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 {
251                n = or2/dist2(oc,source[sn].sloc)*vspretest + .5;
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 <        if (n < 1) n = 1;
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 <        ssn = 7*n;
296 >        ssn = STESTMAX*n;
297          nhit = nok = 0;
298          while (n-- > 0) {
299                                          /* get sample point */
300                  do {
301 <                        if (--ssn < 0)
301 >                        if (--ssn < 0) {
302 > #ifdef DEBUG
303 >                                fprintf(stderr, "\ttoo hard to hit\n");
304 > #endif
305                                  return(f);      /* too small a target! */
306 +                        }
307                          for (i = 0; i < 3; i++)
308                                  offsdir[i] = or*(1. -
309                                                  2.*urand(931*i+5827+ssn));
# Line 283 | Line 324 | register int  sn;      /* target source number */
324                  } while (!(*ofun[o->otype].funp)(o, &sr));
325                                          /* check against source */
326                  samplendx++;
327 <                if (srcray(&sr, NULL, sn) == 0.0)
327 >                if (srcray(&sr, NULL, sn) == 0.)
328                          continue;
329                  sr.revf = srcvalue;
330                  rayvalue(&sr);
# Line 293 | Line 334 | register int  sn;      /* target source number */
334                                          /* check against obstructions */
335                  srcray(&sr, NULL, sn);
336                  rayvalue(&sr);
337 <                if (bright(sr.rcol) <= FTINY)
338 <                        continue;
339 <                nhit++;
337 >                if (bright(sr.rcol) > FTINY)
338 >                        nhit++;
339 >                if (nhit > 0 && nhit < nok) {
340 > #ifdef DEBUG
341 >                        fprintf(stderr, "\tpartially occluded\n");
342 > #endif
343 >                        return(f);              /* need to shadow test */
344 >                }
345          }
346 <                                /* interpret results */
347 <        if (nhit == 0)
346 >        if (nhit == 0) {
347 > #ifdef DEBUG
348 >                fprintf(stderr, "\t0%% hit rate\n");
349 > #endif
350                  return(f | SSKIP);      /* 0% hit rate:  totally occluded */
351 <        if (nhit == nok)
352 <                return(f & ~SFOLLOW);   /* 100% hit rate:  no occlusion */
353 <        return(f);              /* no comment */
351 >        }
352 > #ifdef DEBUG
353 >        fprintf(stderr, "\t100%% hit rate\n");
354 > #endif
355 >        return(f & ~SFOLLOW);           /* 100% hit rate:  no occlusion */
356   }
357          
358  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines