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.17 by greg, Tue Jul 16 15:56:51 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 115 | Line 119 | OBJREC  *op;
119   register int  sn;
120   MAT4  pm;
121   {
122 <        FVECT  nsloc, nsnorm, ocent;
123 <        double  maxrad2;
122 >        FVECT  nsloc, nsnorm, ocent, v;
123 >        double  maxrad2, d;
124          int  nsflags;
121        double  d1;
125          SPOT  theirspot, ourspot;
126          register int  i;
127  
# Line 132 | 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) {
143                          copystruct(&theirspot, source[sn].sl.s);
144                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
145 +                        d = ourspot.siz;
146                          if (!commonbeam(&ourspot, &theirspot, nsloc))
147 <                                return(-1);             /* no overlap */
147 >                                return(-1);     /* no overlap */
148 >                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
149 >                                d = beamdisk(v, op, &ourspot, nsloc);
150 >                                if (d <= FTINY)
151 >                                        return(-1);
152 >                                if (d < maxrad2) {
153 >                                        maxrad2 = d;
154 >                                        VCOPY(ocent, v);
155 >                                }
156 >                        }
157                  }
158          } else {                                /* local source */
159                  multp3(nsloc, source[sn].sloc, pm);
160                  for (i = 0; i < 3; i++)
161                          ourspot.aim[i] = ocent[i] - nsloc[i];
162 <                if ((d1 = normalize(ourspot.aim)) == 0.)
162 >                if ((d = normalize(ourspot.aim)) == 0.)
163                          return(-1);             /* at source!! */
164 <                if (source[sn].sflags & SPROX && d1 > source[sn].sl.prox)
164 >                if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
165                          return(-1);             /* too far away */
152                ourspot.siz = 2.*PI*(1. - d1/sqrt(d1*d1+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 <                        if (!commonspot(&ourspot, &theirspot, nsloc))
175 <                                return(-1);     /* no overlap */
176 <                        ourspot.flen = theirspot.flen;
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)
188 >                                        return(-1);
189 >                                if (d < maxrad2) {
190 >                                        maxrad2 = d;
191 >                                        VCOPY(ocent, v);
192 >                                }
193 >                        }
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 176 | 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 198 | Line 235 | register int  sn;
235          double  rad2, roffs, offs, d, rd, rdoto;
236          FVECT  rnrm, nrm;
237                                  /* first, use object getdisk function */
238 <        rad2 = (*sfun[op->otype].of->getdisk)(oc, op);
238 >        rad2 = getmaxdisk(oc, op);
239          if (!(source[sn].sflags & SVIRTUAL))
240                  return(rad2);           /* all done for normal source */
241                                  /* check for correct side of relay surface */
242 <        roffs = (*sfun[source[sn].so->otype].of->getpleq)(rnrm, source[sn].so);
242 >        roffs = getplaneq(rnrm, source[sn].so);
243          rd = DOT(rnrm, source[sn].sloc);        /* source projection */
244          if (!(source[sn].sflags & SDISTANT))
245                  rd -= roffs;
# Line 210 | Line 247 | register int  sn;
247          if ((d > 0.) ^ (rd > 0.))
248                  return(rad2);           /* OK if opposite sides */
249          if (d*d >= rad2)
250 <                return(.0);             /* no relay is possible */
250 >                return(0.);             /* no relay is possible */
251                                  /* we need a closer look */
252 <        offs = (*sfun[op->otype].of->getpleq)(nrm, op);
252 >        offs = getplaneq(nrm, op);
253          rdoto = DOT(rnrm, nrm);
254          if (d*d >= rad2*(1.-rdoto*rdoto))
255                  return(0.);             /* disk entirely on projection side */
# Line 234 | Line 271 | register int  sn;      /* target source number */
271          FVECT  offsdir;
272          double  or, d;
273          int  infront;
274 <        int  ssn;
275 <        int  nok, nhit;
274 >        int  stestlim, ssn;
275 >        int  nhit, nok;
276          register int  i, n;
277                                  /* return if pretesting disabled */
278          if (vspretest <= 0)
279                  return(f);
280                                  /* get surface normal */
281 <        (*sfun[o->otype].of->getpleq)(onorm, o);
281 >        getplaneq(onorm, o);
282                                  /* set number of rays to sample */
283          if (source[sn].sflags & SDISTANT) {
284                  n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)*
285                                  vspretest + .5;
286                  infront = DOT(onorm, source[sn].sloc) > 0.;
287          } else {
251                n = or2/dist2(oc,source[sn].sloc)*vspretest + .5;
288                  for (i = 0; i < 3; i++)
289                          offsdir[i] = source[sn].sloc[i] - oc[i];
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 = 7*n;
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
310                                  return(f);      /* too small a target! */
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 283 | Line 330 | register int  sn;      /* target source number */
330                  } while (!(*ofun[o->otype].funp)(o, &sr));
331                                          /* check against source */
332                  samplendx++;
333 <                if (srcray(&sr, NULL, sn) == 0.0)
333 >                if (srcray(&sr, NULL, sn) == 0.)
334                          continue;
335                  sr.revf = srcvalue;
336                  rayvalue(&sr);
# Line 293 | Line 340 | register int  sn;      /* target source number */
340                                          /* check against obstructions */
341                  srcray(&sr, NULL, sn);
342                  rayvalue(&sr);
343 <                if (bright(sr.rcol) <= FTINY)
344 <                        continue;
345 <                nhit++;
343 >                if (bright(sr.rcol) > FTINY)
344 >                        nhit++;
345 >                if (nhit > 0 && nhit < nok) {
346 > #ifdef DEBUG
347 >                        fprintf(stderr, "\tpartially occluded\n");
348 > #endif
349 >                        return(f);              /* need to shadow test */
350 >                }
351          }
352 <                                /* interpret results */
353 <        if (nhit == 0)
352 >        if (nhit == 0) {
353 > #ifdef DEBUG
354 >                fprintf(stderr, "\t0%% hit rate\n");
355 > #endif
356                  return(f | SSKIP);      /* 0% hit rate:  totally occluded */
357 <        if (nhit == nok)
358 <                return(f & ~SFOLLOW);   /* 100% hit rate:  no occlusion */
359 <        return(f);              /* no comment */
357 >        }
358 > #ifdef DEBUG
359 >        fprintf(stderr, "\t100%% hit rate\n");
360 > #endif
361 >        return(f & ~SFOLLOW);           /* 100% hit rate:  no occlusion */
362   }
363          
364  
# Line 320 | Line 376 | FILE  *fp;
376          fprintf(fp, "\tat (%f,%f,%f)\n",
377                  source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]);
378          fprintf(fp, "\tlinked to source %d (%s)\n",
379 <                source[sn].sa.svnext, source[source[sn].sa.svnext].so->oname);
379 >                source[sn].sa.sv.sn, source[source[sn].sa.sv.sn].so->oname);
380          if (source[sn].sflags & SFOLLOW)
381                  fprintf(fp, "\talways followed\n");
382          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines