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.11 by greg, Tue Jun 25 15:48:11 1991 UTC vs.
Revision 1.28 by greg, Mon Oct 21 12:58:18 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #include  "random.h"
21  
22 + #define  MINSAMPLES     16              /* minimum number of pretest samples */
23 + #define  STESTMAX       32              /* maximum seeks per sample */
24  
25 +
26   double  getdisk();
27  
28   static OBJECT  *vobject;                /* virtual source objects */
# Line 41 | Line 44 | markvirtuals()                 /* find and mark virtual sources */
44                  if (!isvlight(objptr(o->omod)->otype))
45                          continue;
46                  if (sfun[o->otype].of == NULL ||
47 <                                sfun[o->otype].of->getpleq == NULL)
48 <                        objerror(o, USER, "illegal material");
47 >                                sfun[o->otype].of->getpleq == NULL) {
48 >                        objerror(o,WARNING,"secondary sources not supported");
49 >                        continue;
50 >                }
51                  if (nvobjects == 0)
52                          vobject = (OBJECT *)malloc(sizeof(OBJECT));
53                  else
# Line 101 | Line 106 | int  n;
106          for (i = 0; i < vsmat->nproj; i++)
107                  if ((*vsmat->vproj)(proj, o, &source[sn], i))
108                          if ((ns = makevsrc(o, sn, proj)) >= 0) {
109 +                                source[ns].sa.sv.pn = i;
110   #ifdef DEBUG
111                                  virtverb(ns, stderr);
112   #endif
# Line 131 | Line 137 | MAT4  pm;
137                  if (source[sn].sflags & SPROX)
138                          return(-1);             /* should never get here! */
139                  multv3(nsloc, source[sn].sloc, pm);
140 +                normalize(nsloc);
141                  VCOPY(ourspot.aim, ocent);
142                  ourspot.siz = PI*maxrad2;
143                  ourspot.flen = 0.;
144                  if (source[sn].sflags & SSPOT) {
138                        copystruct(&theirspot, source[sn].sl.s);
145                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
146 +                        d = sqrt(dist2(ourspot.aim, theirspot.aim));
147 +                        d = sqrt(source[sn].sl.s->siz/PI) + d*source[sn].srad;
148 +                        theirspot.siz = PI*d*d;
149 +                        ourspot.flen = theirspot.flen = source[sn].sl.s->flen;
150                          d = ourspot.siz;
151                          if (!commonbeam(&ourspot, &theirspot, nsloc))
152                                  return(-1);     /* no overlap */
# Line 158 | Line 168 | MAT4  pm;
168                          return(-1);             /* at source!! */
169                  if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
170                          return(-1);             /* too far away */
161                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2));
171                  ourspot.flen = 0.;
172 +                d = (sqrt(maxrad2) + source[sn].srad) / d;
173 +                if (d < 1.-FTINY)
174 +                        ourspot.siz = 2.*PI*(1. - sqrt(1.-d*d));
175 +                else
176 +                        nsflags &= ~SSPOT;
177                  if (source[sn].sflags & SSPOT) {
178                          copystruct(&theirspot, source[sn].sl.s);
179                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
180 <                        d = ourspot.siz;
181 <                        if (!commonspot(&ourspot, &theirspot, nsloc))
182 <                                return(-1);     /* no overlap */
180 >                        normalize(theirspot.aim);
181 >                        if (nsflags & SSPOT) {
182 >                                ourspot.flen = theirspot.flen;
183 >                                d = ourspot.siz;
184 >                                if (!commonspot(&ourspot, &theirspot, nsloc))
185 >                                        return(-1);     /* no overlap */
186 >                        } else {
187 >                                nsflags |= SSPOT;
188 >                                copystruct(&ourspot, &theirspot);
189 >                                d = 2.*ourspot.siz;
190 >                        }
191                          if (ourspot.siz < d-FTINY) {    /* it shrunk */
192                                  d = spotdisk(v, op, &ourspot, nsloc);
193                                  if (d <= FTINY)
# Line 175 | Line 197 | MAT4  pm;
197                                          VCOPY(ocent, v);
198                                  }
199                          }
178                        ourspot.flen = theirspot.flen;
200                  }
201                  if (source[sn].sflags & SFLAT) {        /* behind source? */
202                          multv3(nsnorm, source[sn].snorm, pm);
203 <                        if (checkspot(&ourspot, nsnorm) < 0)
203 >                        normalize(nsnorm);
204 >                        if (nsflags & SSPOT && !checkspot(&ourspot, nsnorm))
205                                  return(-1);
206                  }
207          }
# Line 192 | Line 214 | MAT4  pm;
214                  goto memerr;
215          source[i].sflags = nsflags;
216          VCOPY(source[i].sloc, nsloc);
217 +        multv3(source[i].ss[SU], source[sn].ss[SU], pm);
218 +        multv3(source[i].ss[SV], source[sn].ss[SV], pm);
219          if (nsflags & SFLAT)
220                  VCOPY(source[i].snorm, nsnorm);
221 <        source[i].ss = source[sn].ss; source[i].ss2 = source[sn].ss2;
222 <        if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
223 <                goto memerr;
224 <        copystruct(source[i].sl.s, &ourspot);
221 >        else
222 >                multv3(source[i].ss[SW], source[sn].ss[SW], pm);
223 >        source[i].ss2 = source[sn].ss2;
224 >        if (nsflags & SSPOT) {
225 >                if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
226 >                        goto memerr;
227 >                copystruct(source[i].sl.s, &ourspot);
228 >        }
229          if (nsflags & SPROX)
230                  source[i].sl.prox = source[sn].sl.prox;
231 <        source[i].sa.svnext = sn;
231 >        source[i].sa.sv.sn = sn;
232          source[i].so = op;
233          return(i);
234   memerr:
# Line 251 | Line 279 | register int  sn;      /* target source number */
279          RAY  sr;
280          FVECT  onorm;
281          FVECT  offsdir;
282 +        SRCINDEX  si;
283          double  or, d;
284          int  infront;
285 <        int  ssn;
285 >        int  stestlim, ssn;
286          int  nhit, nok;
287          register int  i, n;
288                                  /* return if pretesting disabled */
# Line 263 | Line 292 | register int  sn;      /* target source number */
292          getplaneq(onorm, o);
293                                  /* set number of rays to sample */
294          if (source[sn].sflags & SDISTANT) {
295 <                n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)*
296 <                                vspretest + .5;
295 >                                        /* 32. == heuristic constant */
296 >                n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5;
297                  infront = DOT(onorm, source[sn].sloc) > 0.;
298          } else {
299                  for (i = 0; i < 3; i++)
300                          offsdir[i] = source[sn].sloc[i] - oc[i];
301 <                n = or2/DOT(offsdir,offsdir)*vspretest + .5;
301 >                d = DOT(offsdir,offsdir);
302 >                if (d <= FTINY)
303 >                        n = 2.*PI * vspretest + .5;
304 >                else
305 >                        n = 2.*PI * (1.-sqrt(1./(1.+or2/d)))*vspretest + .5;
306                  infront = DOT(onorm, offsdir) > 0.;
307          }
308 <        if (n < 1) n = 1;
308 >        if (n < MINSAMPLES) n = MINSAMPLES;
309   #ifdef DEBUG
310          fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
311                          sn, o->oname, n);
312   #endif
313                                  /* sample */
314          or = sqrt(or2);
315 <        ssn = 25*n;
315 >        stestlim = n*STESTMAX;
316 >        ssn = 0;
317          nhit = nok = 0;
318          while (n-- > 0) {
319                                          /* get sample point */
320                  do {
321 <                        if (--ssn < 0) {
321 >                        if (ssn >= stestlim) {
322   #ifdef DEBUG
323                                  fprintf(stderr, "\ttoo hard to hit\n");
324   #endif
325                                  return(f);      /* too small a target! */
326                          }
327 +                        multisamp(offsdir, 3, urand(sn*931+5827+ssn));
328                          for (i = 0; i < 3; i++)
329 <                                offsdir[i] = or*(1. -
330 <                                                2.*urand(931*i+5827+ssn));
329 >                                offsdir[i] = or*(1. - 2.*offsdir[i]);
330 >                        ssn++;
331                          for (i = 0; i < 3; i++)
332                                  sr.rorg[i] = oc[i] + offsdir[i];
333                          d = DOT(offsdir,onorm);
# Line 309 | Line 344 | register int  sn;      /* target source number */
344                          rayorigin(&sr, NULL, PRIMARY, 1.0);
345                  } while (!(*ofun[o->otype].funp)(o, &sr));
346                                          /* check against source */
347 +                initsrcindex(&si);
348 +                si.sn = sn;
349 +                nopart(&si, sr.rorg);
350                  samplendx++;
351 <                if (srcray(&sr, NULL, sn) == 0.)
351 >                if (!srcray(&sr, NULL, &si) || sr.rsrc != sn)
352                          continue;
353                  sr.revf = srcvalue;
354                  rayvalue(&sr);
# Line 318 | Line 356 | register int  sn;      /* target source number */
356                          continue;
357                  nok++;
358                                          /* check against obstructions */
359 <                srcray(&sr, NULL, sn);
359 >                rayclear(&sr);
360 >                sr.revf = raytrace;
361                  rayvalue(&sr);
362                  if (bright(sr.rcol) > FTINY)
363                          nhit++;
# Line 356 | Line 395 | FILE  *fp;
395          fprintf(fp, "\tat (%f,%f,%f)\n",
396                  source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]);
397          fprintf(fp, "\tlinked to source %d (%s)\n",
398 <                source[sn].sa.svnext, source[source[sn].sa.svnext].so->oname);
398 >                source[sn].sa.sv.sn, source[source[sn].sa.sv.sn].so->oname);
399          if (source[sn].sflags & SFOLLOW)
400                  fprintf(fp, "\talways followed\n");
401          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines