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.20 by greg, Fri Aug 2 10:30:27 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.;
142                  if (source[sn].sflags & SSPOT) {
138                        copystruct(&theirspot, source[sn].sl.s);
143                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
144 +                        d = sqrt(dist2(ourspot.aim, theirspot.aim));
145 +                        d = sqrt(source[sn].sl.s->siz/PI) + d*source[sn].ss;
146 +                        theirspot.siz = PI*d*d;
147 +                        ourspot.flen = theirspot.flen = source[sn].sl.s->flen;
148                          d = ourspot.siz;
149                          if (!commonbeam(&ourspot, &theirspot, nsloc))
150                                  return(-1);     /* no overlap */
# Line 158 | Line 166 | MAT4  pm;
166                          return(-1);             /* at source!! */
167                  if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
168                          return(-1);             /* too far away */
161                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2));
169                  ourspot.flen = 0.;
170 +                d = (sqrt(maxrad2) + source[sn].ss) / d;
171 +                if (d < 1.-FTINY)
172 +                        ourspot.siz = 2.*PI*(1. - sqrt(1.-d*d));
173 +                else
174 +                        nsflags &= ~SSPOT;
175                  if (source[sn].sflags & SSPOT) {
176                          copystruct(&theirspot, source[sn].sl.s);
177                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
178 <                        d = ourspot.siz;
179 <                        if (!commonspot(&ourspot, &theirspot, nsloc))
180 <                                return(-1);     /* no overlap */
178 >                        normalize(theirspot.aim);
179 >                        if (nsflags & SSPOT) {
180 >                                ourspot.flen = theirspot.flen;
181 >                                d = ourspot.siz;
182 >                                if (!commonspot(&ourspot, &theirspot, nsloc))
183 >                                        return(-1);     /* no overlap */
184 >                        } else {
185 >                                nsflags |= SSPOT;
186 >                                copystruct(&ourspot, &theirspot);
187 >                                d = 2.*ourspot.siz;
188 >                        }
189                          if (ourspot.siz < d-FTINY) {    /* it shrunk */
190                                  d = spotdisk(v, op, &ourspot, nsloc);
191                                  if (d <= FTINY)
# Line 175 | Line 195 | MAT4  pm;
195                                          VCOPY(ocent, v);
196                                  }
197                          }
178                        ourspot.flen = theirspot.flen;
198                  }
199                  if (source[sn].sflags & SFLAT) {        /* behind source? */
200                          multv3(nsnorm, source[sn].snorm, pm);
201 <                        if (checkspot(&ourspot, nsnorm) < 0)
201 >                        normalize(nsnorm);
202 >                        if (nsflags & SSPOT && !checkspot(&ourspot, nsnorm))
203                                  return(-1);
204                  }
205          }
# Line 195 | Line 215 | MAT4  pm;
215          if (nsflags & SFLAT)
216                  VCOPY(source[i].snorm, nsnorm);
217          source[i].ss = source[sn].ss; source[i].ss2 = source[sn].ss2;
218 <        if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
219 <                goto memerr;
220 <        copystruct(source[i].sl.s, &ourspot);
218 >        if (nsflags & SSPOT) {
219 >                if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
220 >                        goto memerr;
221 >                copystruct(source[i].sl.s, &ourspot);
222 >        }
223          if (nsflags & SPROX)
224                  source[i].sl.prox = source[sn].sl.prox;
225 <        source[i].sa.svnext = sn;
225 >        source[i].sa.sv.sn = sn;
226          source[i].so = op;
227          return(i);
228   memerr:
# Line 253 | Line 275 | register int  sn;      /* target source number */
275          FVECT  offsdir;
276          double  or, d;
277          int  infront;
278 <        int  ssn;
279 <        int  nhit;
278 >        int  stestlim, ssn;
279 >        int  nhit, nok;
280          register int  i, n;
281                                  /* return if pretesting disabled */
282          if (vspretest <= 0)
# Line 269 | Line 291 | register int  sn;      /* target source number */
291          } else {
292                  for (i = 0; i < 3; i++)
293                          offsdir[i] = source[sn].sloc[i] - oc[i];
294 <                n = or2/DOT(offsdir,offsdir)*vspretest + .5;
294 >                d = DOT(offsdir,offsdir);
295 >                if (d <= FTINY)
296 >                        n = 2.*PI * vspretest + .5;
297 >                else
298 >                        n = 2.*PI * (1.-sqrt(1./(1.+or2/d)))*vspretest + .5;
299                  infront = DOT(onorm, offsdir) > 0.;
300          }
301 <        if (n < 1) n = 1;
301 >        if (n < MINSAMPLES) n = MINSAMPLES;
302   #ifdef DEBUG
303          fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
304                          sn, o->oname, n);
305   #endif
306                                  /* sample */
307          or = sqrt(or2);
308 <        ssn = 25*n;
309 <        nhit = 0;
308 >        stestlim = n*STESTMAX;
309 >        ssn = 0;
310 >        nhit = nok = 0;
311          while (n-- > 0) {
312                                          /* get sample point */
313                  do {
314 <                        if (--ssn < 0) {
314 >                        if (ssn >= stestlim) {
315   #ifdef DEBUG
316                                  fprintf(stderr, "\ttoo hard to hit\n");
317   #endif
# Line 292 | Line 319 | register int  sn;      /* target source number */
319                          }
320                          for (i = 0; i < 3; i++)
321                                  offsdir[i] = or*(1. -
322 <                                                2.*urand(931*i+5827+ssn));
322 >                                        2.*urand(urind(931*i+5827,ssn)));
323 >                        ssn++;
324                          for (i = 0; i < 3; i++)
325                                  sr.rorg[i] = oc[i] + offsdir[i];
326                          d = DOT(offsdir,onorm);
# Line 316 | Line 344 | register int  sn;      /* target source number */
344                  rayvalue(&sr);
345                  if (bright(sr.rcol) <= FTINY)
346                          continue;
347 +                nok++;
348                                          /* check against obstructions */
349 <                srcray(&sr, NULL, sn);
349 >                rayclear(&sr);
350 >                sr.revf = raytrace;
351                  rayvalue(&sr);
352 <                if (bright(sr.rcol) <= FTINY) {
352 >                if (bright(sr.rcol) > FTINY)
353 >                        nhit++;
354 >                if (nhit > 0 && nhit < nok) {
355   #ifdef DEBUG
356 <                        fprintf(stderr, "\tfound an occlusion\n");
356 >                        fprintf(stderr, "\tpartially occluded\n");
357   #endif
358 <                        return(f);      /* need to shadow test */
358 >                        return(f);              /* need to shadow test */
359                  }
328                nhit++;
360          }
361          if (nhit == 0) {
362   #ifdef DEBUG
# Line 354 | Line 385 | FILE  *fp;
385          fprintf(fp, "\tat (%f,%f,%f)\n",
386                  source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]);
387          fprintf(fp, "\tlinked to source %d (%s)\n",
388 <                source[sn].sa.svnext, source[source[sn].sa.svnext].so->oname);
388 >                source[sn].sa.sv.sn, source[source[sn].sa.sv.sn].so->oname);
389          if (source[sn].sflags & SFOLLOW)
390                  fprintf(fp, "\talways followed\n");
391          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines