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.14 by greg, Wed Jun 26 11:54:43 1991 UTC vs.
Revision 1.27 by greg, Tue Oct 1 14:29:16 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #include  "random.h"
21  
22 < #define  MINSAMPLES     3               /* minimum number of pretest samples */
23 < #define  STESTMAX       30              /* maximum seeks per sample */
22 > #define  MINSAMPLES     16              /* minimum number of pretest samples */
23 > #define  STESTMAX       32              /* maximum seeks per sample */
24  
25  
26   double  getdisk();
# Line 44 | 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 104 | 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 134 | 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) {
141                        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].ss;
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 162 | Line 169 | MAT4  pm;
169                  if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
170                          return(-1);             /* too far away */
171                  ourspot.flen = 0.;
172 <                if (d*d > maxrad2)
173 <                        ourspot.siz = 2.*PI*(1. - sqrt(1.-maxrad2/(d*d)));
172 >                d = (sqrt(maxrad2) + source[sn].ss) / 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 +                        normalize(theirspot.aim);
181                          if (nsflags & SSPOT) {
182                                  ourspot.flen = theirspot.flen;
183                                  d = ourspot.siz;
# Line 191 | Line 200 | MAT4  pm;
200                  }
201                  if (source[sn].sflags & SFLAT) {        /* behind source? */
202                          multv3(nsnorm, source[sn].snorm, pm);
203 <                        if (!checkspot(&ourspot, nsnorm))
203 >                        normalize(nsnorm);
204 >                        if (nsflags & SSPOT && !checkspot(&ourspot, nsnorm))
205                                  return(-1);
206                  }
207          }
# Line 214 | Line 224 | MAT4  pm;
224          }
225          if (nsflags & SPROX)
226                  source[i].sl.prox = source[sn].sl.prox;
227 <        source[i].sa.svnext = sn;
227 >        source[i].sa.sv.sn = sn;
228          source[i].so = op;
229          return(i);
230   memerr:
# Line 267 | Line 277 | register int  sn;      /* target source number */
277          FVECT  offsdir;
278          double  or, d;
279          int  infront;
280 <        int  ssn;
280 >        int  stestlim, ssn;
281          int  nhit, nok;
282          register int  i, n;
283                                  /* return if pretesting disabled */
# Line 277 | Line 287 | register int  sn;      /* target source number */
287          getplaneq(onorm, o);
288                                  /* set number of rays to sample */
289          if (source[sn].sflags & SDISTANT) {
290 <                n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)*
291 <                                vspretest + .5;
290 >                                        /* 32. == heuristic constant */
291 >                n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5;
292                  infront = DOT(onorm, source[sn].sloc) > 0.;
293          } else {
294                  for (i = 0; i < 3; i++)
295                          offsdir[i] = source[sn].sloc[i] - oc[i];
296 <                n = or2/DOT(offsdir,offsdir)*vspretest + .5;
296 >                d = DOT(offsdir,offsdir);
297 >                if (d <= FTINY)
298 >                        n = 2.*PI * vspretest + .5;
299 >                else
300 >                        n = 2.*PI * (1.-sqrt(1./(1.+or2/d)))*vspretest + .5;
301                  infront = DOT(onorm, offsdir) > 0.;
302          }
303          if (n < MINSAMPLES) n = MINSAMPLES;
# Line 293 | Line 307 | register int  sn;      /* target source number */
307   #endif
308                                  /* sample */
309          or = sqrt(or2);
310 <        ssn = STESTMAX*n;
310 >        stestlim = n*STESTMAX;
311 >        ssn = 0;
312          nhit = nok = 0;
313          while (n-- > 0) {
314                                          /* get sample point */
315                  do {
316 <                        if (--ssn < 0) {
316 >                        if (ssn >= stestlim) {
317   #ifdef DEBUG
318                                  fprintf(stderr, "\ttoo hard to hit\n");
319   #endif
320                                  return(f);      /* too small a target! */
321                          }
322 +                        multisamp(offsdir, 3, urand(sn*931+5827+ssn));
323                          for (i = 0; i < 3; i++)
324 <                                offsdir[i] = or*(1. -
325 <                                                2.*urand(931*i+5827+ssn));
324 >                                offsdir[i] = or*(1. - 2.*offsdir[i]);
325 >                        ssn++;
326                          for (i = 0; i < 3; i++)
327                                  sr.rorg[i] = oc[i] + offsdir[i];
328                          d = DOT(offsdir,onorm);
# Line 332 | Line 348 | register int  sn;      /* target source number */
348                          continue;
349                  nok++;
350                                          /* check against obstructions */
351 <                srcray(&sr, NULL, sn);
351 >                rayclear(&sr);
352 >                sr.revf = raytrace;
353                  rayvalue(&sr);
354                  if (bright(sr.rcol) > FTINY)
355                          nhit++;
# Line 370 | Line 387 | FILE  *fp;
387          fprintf(fp, "\tat (%f,%f,%f)\n",
388                  source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]);
389          fprintf(fp, "\tlinked to source %d (%s)\n",
390 <                source[sn].sa.svnext, source[source[sn].sa.svnext].so->oname);
390 >                source[sn].sa.sv.sn, source[source[sn].sa.sv.sn].so->oname);
391          if (source[sn].sflags & SFOLLOW)
392                  fprintf(fp, "\talways followed\n");
393          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines