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.9 by greg, Tue Jun 25 13:11:53 1991 UTC

# Line 115 | Line 115 | OBJREC  *op;
115   register int  sn;
116   MAT4  pm;
117   {
118 <        FVECT  nsloc, nsnorm, ocent;
119 <        double  maxrad2;
118 >        FVECT  nsloc, nsnorm, ocent, v;
119 >        double  maxrad2, d;
120          int  nsflags;
121        double  d1;
121          SPOT  theirspot, ourspot;
122          register int  i;
123  
# Line 138 | Line 137 | MAT4  pm;
137                  if (source[sn].sflags & SSPOT) {
138                          copystruct(&theirspot, source[sn].sl.s);
139                          multp3(theirspot.aim, source[sn].sl.s->aim, pm);
140 +                        d = ourspot.siz;
141                          if (!commonbeam(&ourspot, &theirspot, nsloc))
142 <                                return(-1);             /* no overlap */
142 >                                return(-1);     /* no overlap */
143 >                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
144 >                                d = beamdisk(v, op, &ourspot, nsloc);
145 >                                if (d <= FTINY)
146 >                                        return(-1);
147 >                                if (d < maxrad2) {
148 >                                        maxrad2 = d;
149 >                                        VCOPY(ocent, v);
150 >                                }
151 >                        }
152                  }
153          } else {                                /* local source */
154                  multp3(nsloc, source[sn].sloc, pm);
155                  for (i = 0; i < 3; i++)
156                          ourspot.aim[i] = ocent[i] - nsloc[i];
157 <                if ((d1 = normalize(ourspot.aim)) == 0.)
157 >                if ((d = normalize(ourspot.aim)) == 0.)
158                          return(-1);             /* at source!! */
159 <                if (source[sn].sflags & SPROX && d1 > source[sn].sl.prox)
159 >                if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
160                          return(-1);             /* too far away */
161 <                ourspot.siz = 2.*PI*(1. - d1/sqrt(d1*d1+maxrad2));
161 >                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2));
162                  ourspot.flen = 0.;
163                  if (source[sn].sflags & SSPOT) {
164                          copystruct(&theirspot, source[sn].sl.s);
165                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
166 +                        d = ourspot.siz;
167                          if (!commonspot(&ourspot, &theirspot, nsloc))
168                                  return(-1);     /* no overlap */
169 +                        if (ourspot.siz < d-FTINY) {    /* it shrunk */
170 +                                d = spotdisk(v, op, &ourspot, nsloc);
171 +                                if (d <= FTINY)
172 +                                        return(-1);
173 +                                if (d < maxrad2) {
174 +                                        maxrad2 = d;
175 +                                        VCOPY(ocent, v);
176 +                                }
177 +                        }
178                          ourspot.flen = theirspot.flen;
179                  }
180                  if (source[sn].sflags & SFLAT) {        /* behind source? */
# Line 198 | Line 217 | register int  sn;
217          double  rad2, roffs, offs, d, rd, rdoto;
218          FVECT  rnrm, nrm;
219                                  /* first, use object getdisk function */
220 <        rad2 = (*sfun[op->otype].of->getdisk)(oc, op);
220 >        rad2 = getmaxdisk(oc, op);
221          if (!(source[sn].sflags & SVIRTUAL))
222                  return(rad2);           /* all done for normal source */
223                                  /* check for correct side of relay surface */
224 <        roffs = (*sfun[source[sn].so->otype].of->getpleq)(rnrm, source[sn].so);
224 >        roffs = getplaneq(rnrm, source[sn].so);
225          rd = DOT(rnrm, source[sn].sloc);        /* source projection */
226          if (!(source[sn].sflags & SDISTANT))
227                  rd -= roffs;
# Line 210 | Line 229 | register int  sn;
229          if ((d > 0.) ^ (rd > 0.))
230                  return(rad2);           /* OK if opposite sides */
231          if (d*d >= rad2)
232 <                return(.0);             /* no relay is possible */
232 >                return(0.);             /* no relay is possible */
233                                  /* we need a closer look */
234 <        offs = (*sfun[op->otype].of->getpleq)(nrm, op);
234 >        offs = getplaneq(nrm, op);
235          rdoto = DOT(rnrm, nrm);
236          if (d*d >= rad2*(1.-rdoto*rdoto))
237                  return(0.);             /* disk entirely on projection side */
# Line 235 | Line 254 | register int  sn;      /* target source number */
254          double  or, d;
255          int  infront;
256          int  ssn;
257 <        int  nok, nhit;
257 >        int  nhit;
258          register int  i, n;
259                                  /* return if pretesting disabled */
260          if (vspretest <= 0)
261                  return(f);
262                                  /* get surface normal */
263 <        (*sfun[o->otype].of->getpleq)(onorm, o);
263 >        getplaneq(onorm, o);
264                                  /* set number of rays to sample */
265          if (source[sn].sflags & SDISTANT) {
266                  n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)*
267                                  vspretest + .5;
268                  infront = DOT(onorm, source[sn].sloc) > 0.;
269          } else {
251                n = or2/dist2(oc,source[sn].sloc)*vspretest + .5;
270                  for (i = 0; i < 3; i++)
271                          offsdir[i] = source[sn].sloc[i] - oc[i];
272 +                n = or2/DOT(offsdir,offsdir)*vspretest + .5;
273                  infront = DOT(onorm, offsdir) > 0.;
274          }
275          if (n < 1) n = 1;
276 + #ifdef DEBUG
277 +        fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
278 +                        sn, o->oname, n);
279 + #endif
280                                  /* sample */
281          or = sqrt(or2);
282 <        ssn = 7*n;
283 <        nhit = nok = 0;
282 >        ssn = 25*n;
283 >        nhit = 0;
284          while (n-- > 0) {
285                                          /* get sample point */
286                  do {
287 <                        if (--ssn < 0)
287 >                        if (--ssn < 0) {
288 > #ifdef DEBUG
289 >                                fprintf(stderr, "\ttoo hard to hit\n");
290 > #endif
291                                  return(f);      /* too small a target! */
292 +                        }
293                          for (i = 0; i < 3; i++)
294                                  offsdir[i] = or*(1. -
295                                                  2.*urand(931*i+5827+ssn));
# Line 283 | Line 310 | register int  sn;      /* target source number */
310                  } while (!(*ofun[o->otype].funp)(o, &sr));
311                                          /* check against source */
312                  samplendx++;
313 <                if (srcray(&sr, NULL, sn) == 0.0)
313 >                if (srcray(&sr, NULL, sn) == 0.)
314                          continue;
315                  sr.revf = srcvalue;
316                  rayvalue(&sr);
317                  if (bright(sr.rcol) <= FTINY)
318                          continue;
292                nok++;
319                                          /* check against obstructions */
320                  srcray(&sr, NULL, sn);
321                  rayvalue(&sr);
322 <                if (bright(sr.rcol) <= FTINY)
323 <                        continue;
322 >                if (bright(sr.rcol) <= FTINY) {
323 > #ifdef DEBUG
324 >                        fprintf(stderr, "\tfound an occlusion\n");
325 > #endif
326 >                        return(f);      /* need to shadow test */
327 >                }
328                  nhit++;
329          }
330 <                                /* interpret results */
331 <        if (nhit == 0)
330 >        if (nhit == 0) {
331 > #ifdef DEBUG
332 >                fprintf(stderr, "\t0%% hit rate\n");
333 > #endif
334                  return(f | SSKIP);      /* 0% hit rate:  totally occluded */
335 <        if (nhit == nok)
336 <                return(f & ~SFOLLOW);   /* 100% hit rate:  no occlusion */
337 <        return(f);              /* no comment */
335 >        }
336 > #ifdef DEBUG
337 >        fprintf(stderr, "\t100%% hit rate\n");
338 > #endif
339 >        return(f & ~SFOLLOW);           /* 100% hit rate:  no occlusion */
340   }
341          
342  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines