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.9 by greg, Tue Jun 25 13:11:53 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 158 | Line 161 | MAT4  pm;
161                          return(-1);             /* at source!! */
162                  if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
163                          return(-1);             /* too far away */
161                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+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 <                        d = ourspot.siz;
173 <                        if (!commonspot(&ourspot, &theirspot, nsloc))
174 <                                return(-1);     /* no overlap */
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)
# Line 175 | Line 188 | MAT4  pm;
188                                          VCOPY(ocent, v);
189                                  }
190                          }
178                        ourspot.flen = theirspot.flen;
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 195 | 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 254 | Line 268 | register int  sn;      /* target source number */
268          double  or, d;
269          int  infront;
270          int  ssn;
271 <        int  nhit;
271 >        int  nhit, nok;
272          register int  i, n;
273                                  /* return if pretesting disabled */
274          if (vspretest <= 0)
# Line 272 | Line 286 | register int  sn;      /* target source number */
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 = 25*n;
297 <        nhit = 0;
296 >        ssn = STESTMAX*n;
297 >        nhit = nok = 0;
298          while (n-- > 0) {
299                                          /* get sample point */
300                  do {
# Line 316 | Line 330 | register int  sn;      /* target source number */
330                  rayvalue(&sr);
331                  if (bright(sr.rcol) <= FTINY)
332                          continue;
333 +                nok++;
334                                          /* check against obstructions */
335                  srcray(&sr, NULL, sn);
336                  rayvalue(&sr);
337 <                if (bright(sr.rcol) <= FTINY) {
337 >                if (bright(sr.rcol) > FTINY)
338 >                        nhit++;
339 >                if (nhit > 0 && nhit < nok) {
340   #ifdef DEBUG
341 <                        fprintf(stderr, "\tfound an occlusion\n");
341 >                        fprintf(stderr, "\tpartially occluded\n");
342   #endif
343 <                        return(f);      /* need to shadow test */
343 >                        return(f);              /* need to shadow test */
344                  }
328                nhit++;
345          }
346          if (nhit == 0) {
347   #ifdef DEBUG

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines