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.18 by greg, Wed Jul 17 12:38: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 101 | Line 104 | int  n;
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 +                                source[ns].sa.sv.pn = i;
108   #ifdef DEBUG
109                                  virtverb(ns, stderr);
110   #endif
# Line 131 | Line 135 | MAT4  pm;
135                  if (source[sn].sflags & SPROX)
136                          return(-1);             /* should never get here! */
137                  multv3(nsloc, source[sn].sloc, pm);
138 +                normalize(nsloc);
139                  VCOPY(ourspot.aim, ocent);
140                  ourspot.siz = PI*maxrad2;
141                  ourspot.flen = 0.;
# Line 158 | Line 163 | MAT4  pm;
163                          return(-1);             /* at source!! */
164                  if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
165                          return(-1);             /* too far away */
161                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2));
166                  ourspot.flen = 0.;
167 +                if (d*d > maxrad2)
168 +                        ourspot.siz = 2.*PI*(1. - sqrt(1.-maxrad2/(d*d)));
169 +                else
170 +                        nsflags &= ~SSPOT;
171                  if (source[sn].sflags & SSPOT) {
172                          copystruct(&theirspot, source[sn].sl.s);
173                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
174 <                        d = ourspot.siz;
175 <                        if (!commonspot(&ourspot, &theirspot, nsloc))
176 <                                return(-1);     /* no overlap */
174 >                        normalize(theirspot.aim);
175 >                        if (nsflags & SSPOT) {
176 >                                ourspot.flen = theirspot.flen;
177 >                                d = ourspot.siz;
178 >                                if (!commonspot(&ourspot, &theirspot, nsloc))
179 >                                        return(-1);     /* no overlap */
180 >                        } else {
181 >                                nsflags |= SSPOT;
182 >                                copystruct(&ourspot, &theirspot);
183 >                                d = 2.*ourspot.siz;
184 >                        }
185                          if (ourspot.siz < d-FTINY) {    /* it shrunk */
186                                  d = spotdisk(v, op, &ourspot, nsloc);
187                                  if (d <= FTINY)
# Line 175 | Line 191 | MAT4  pm;
191                                          VCOPY(ocent, v);
192                                  }
193                          }
178                        ourspot.flen = theirspot.flen;
194                  }
195                  if (source[sn].sflags & SFLAT) {        /* behind source? */
196                          multv3(nsnorm, source[sn].snorm, pm);
197 <                        if (checkspot(&ourspot, nsnorm) < 0)
197 >                        normalize(nsnorm);
198 >                        if (!checkspot(&ourspot, nsnorm))
199                                  return(-1);
200                  }
201          }
# Line 195 | Line 211 | MAT4  pm;
211          if (nsflags & SFLAT)
212                  VCOPY(source[i].snorm, nsnorm);
213          source[i].ss = source[sn].ss; source[i].ss2 = source[sn].ss2;
214 <        if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
215 <                goto memerr;
216 <        copystruct(source[i].sl.s, &ourspot);
214 >        if (nsflags & SSPOT) {
215 >                if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
216 >                        goto memerr;
217 >                copystruct(source[i].sl.s, &ourspot);
218 >        }
219          if (nsflags & SPROX)
220                  source[i].sl.prox = source[sn].sl.prox;
221 <        source[i].sa.svnext = sn;
221 >        source[i].sa.sv.sn = sn;
222          source[i].so = op;
223          return(i);
224   memerr:
# Line 253 | Line 271 | register int  sn;      /* target source number */
271          FVECT  offsdir;
272          double  or, d;
273          int  infront;
274 <        int  ssn;
275 <        int  nhit;
274 >        int  stestlim, ssn;
275 >        int  nhit, nok;
276          register int  i, n;
277                                  /* return if pretesting disabled */
278          if (vspretest <= 0)
# Line 272 | Line 290 | register int  sn;      /* target source number */
290                  n = or2/DOT(offsdir,offsdir)*vspretest + .5;
291                  infront = DOT(onorm, offsdir) > 0.;
292          }
293 <        if (n < 1) n = 1;
293 >        if (n < MINSAMPLES) n = MINSAMPLES;
294   #ifdef DEBUG
295          fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
296                          sn, o->oname, n);
297   #endif
298                                  /* sample */
299          or = sqrt(or2);
300 <        ssn = 25*n;
301 <        nhit = 0;
300 >        stestlim = n*STESTMAX;
301 >        ssn = 0;
302 >        nhit = nok = 0;
303          while (n-- > 0) {
304                                          /* get sample point */
305                  do {
306 <                        if (--ssn < 0) {
306 >                        if (ssn >= stestlim) {
307   #ifdef DEBUG
308                                  fprintf(stderr, "\ttoo hard to hit\n");
309   #endif
# Line 292 | Line 311 | register int  sn;      /* target source number */
311                          }
312                          for (i = 0; i < 3; i++)
313                                  offsdir[i] = or*(1. -
314 <                                                2.*urand(931*i+5827+ssn));
314 >                                        2.*urand(urind(931*i+5827,ssn)));
315 >                        ssn++;
316                          for (i = 0; i < 3; i++)
317                                  sr.rorg[i] = oc[i] + offsdir[i];
318                          d = DOT(offsdir,onorm);
# Line 316 | Line 336 | register int  sn;      /* target source number */
336                  rayvalue(&sr);
337                  if (bright(sr.rcol) <= FTINY)
338                          continue;
339 +                nok++;
340                                          /* check against obstructions */
341 <                srcray(&sr, NULL, sn);
341 >                rayclear(&sr);
342 >                sr.revf = raytrace;
343                  rayvalue(&sr);
344 <                if (bright(sr.rcol) <= FTINY) {
344 >                if (bright(sr.rcol) > FTINY)
345 >                        nhit++;
346 >                if (nhit > 0 && nhit < nok) {
347   #ifdef DEBUG
348 <                        fprintf(stderr, "\tfound an occlusion\n");
348 >                        fprintf(stderr, "\tpartially occluded\n");
349   #endif
350 <                        return(f);      /* need to shadow test */
350 >                        return(f);              /* need to shadow test */
351                  }
328                nhit++;
352          }
353          if (nhit == 0) {
354   #ifdef DEBUG
# Line 354 | Line 377 | FILE  *fp;
377          fprintf(fp, "\tat (%f,%f,%f)\n",
378                  source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]);
379          fprintf(fp, "\tlinked to source %d (%s)\n",
380 <                source[sn].sa.svnext, source[source[sn].sa.svnext].so->oname);
380 >                source[sn].sa.sv.sn, source[source[sn].sa.sv.sn].so->oname);
381          if (source[sn].sflags & SFOLLOW)
382                  fprintf(fp, "\talways followed\n");
383          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines