ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rtrace.c
(Generate patch)

Comparing ray/src/rt/rtrace.c (file contents):
Revision 2.8 by greg, Thu Oct 15 21:13:21 1992 UTC vs.
Revision 2.24 by gregl, Wed Jul 9 11:25:49 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1997 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# Line 42 | Line 42 | int  inform = 'a';                     /* input format */
42   int  outform = 'a';                     /* output format */
43   char  *outvals = "v";                   /* output specification */
44  
45 + char  *tralist[128];                    /* list of modifers to trace (or no) */
46 + int  traincl = -1;                      /* include == 1, exclude == 0 */
47 + #define  MAXTSET        511             /* maximum number in trace set */
48 + OBJECT  traset[MAXTSET+1]={0};          /* trace include/exclude set */
49 +
50   int  hresolu = 0;                       /* horizontal (scan) size */
51   int  vresolu = 0;                       /* vertical resolution */
52  
53   double  dstrsrc = 0.0;                  /* square source distribution */
54   double  shadthresh = .05;               /* shadow threshold */
55   double  shadcert = .5;                  /* shadow certainty */
56 < int  directrelay = 1;                   /* number of source relays */
56 > int  directrelay = 2;                   /* number of source relays */
57   int  vspretest = 512;                   /* virtual source pretest density */
58 < int  directinvis = 0;                   /* sources invisible? */
59 < double  srcsizerat = .25;               /* maximum ratio source size/dist. */
58 > int  directvis = 1;                     /* sources visible? */
59 > double  srcsizerat = .2;                /* maximum ratio source size/dist. */
60  
61 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
62 + COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
63 + double  seccg = 0.;                     /* global scattering eccentricity */
64 + double  ssampdist = 0.;                 /* scatter sampling distance */
65 +
66   double  specthresh = .15;               /* specular sampling threshold */
67   double  specjitter = 1.;                /* specular sampling jitter */
68  
69 + int  backvis = 1;                       /* back face visibility */
70 +
71   int  maxdepth = 6;                      /* maximum recursion depth */
72   double  minweight = 4e-3;               /* minimum ray weight */
73  
74   COLOR  ambval = BLKCOLOR;               /* ambient value */
75 + int  ambvwt = 0;                        /* initial weight for ambient value */
76   double  ambacc = 0.2;                   /* ambient accuracy */
77 < int  ambres = 32;                       /* ambient resolution */
78 < int  ambdiv = 128;                      /* ambient divisions */
77 > int  ambres = 128;                      /* ambient resolution */
78 > int  ambdiv = 512;                      /* ambient divisions */
79   int  ambssamp = 0;                      /* ambient super-samples */
80   int  ambounce = 0;                      /* ambient bounces */
81   char  *amblist[128];                    /* ambient include/exclude list */
# Line 73 | Line 86 | extern OBJREC  Lamb;                   /* a Lambertian surface */
86   static RAY  thisray;                    /* for our convenience */
87  
88   static int  oputo(), oputd(), oputv(), oputl(), oputL(),
89 <                oputp(), oputn(), oputs(), oputw(), oputm();
89 >                oputp(), oputn(), oputN(), oputs(), oputw(), oputm();
90  
91 < static int  (*ray_out[10])(), (*every_out[10])();
92 < static int  castonly;
91 > static int  ourtrace(), tabin();
92 > static int  (*ray_out[16])(), (*every_out[16])();
93 > static int  castonly = 0;
94  
95   static int  puta(), putf(), putd();
96  
# Line 86 | Line 100 | static int  (*putreal)();
100   quit(code)                      /* quit program */
101   int  code;
102   {
103 + #ifndef  NIX
104 +        headclean();            /* delete header file */
105 +        pfclean();              /* clean up persist files */
106 + #endif
107          exit(code);
108   }
109  
# Line 135 | Line 153 | char  *fname;
153          default:
154                  error(CONSISTENCY, "botched output format");
155          }
156 <        if (hresolu > 0 && vresolu > 0)
157 <                fprtresolu(hresolu, vresolu, stdout);
156 >        if (hresolu > 0) {
157 >                if (vresolu > 0)
158 >                        fprtresolu(hresolu, vresolu, stdout);
159 >                fflush(stdout);
160 >        }
161                                          /* process file */
162          while (getvec(orig, inform, fp) == 0 &&
163                          getvec(direc, inform, fp) == 0) {
164  
165                  if (normalize(direc) == 0.0) {          /* zero ==> flush */
166 <                        fflush(stdout);
167 <                        continue;
168 <                }
169 <                samplendx++;
166 >                        bogusray();
167 >                        if (--nextflush <= 0) {
168 >                                fflush(stdout);
169 >                                nextflush = hresolu;
170 >                        }
171 >                } else {
172 >                        samplendx++;
173                                                          /* compute and print */
174 <                if (imm_irrad)
175 <                        irrad(orig, direc);
176 <                else
177 <                        traceray(orig, direc);
174 >                        if (imm_irrad)
175 >                                irrad(orig, direc);
176 >                        else
177 >                                rad(orig, direc);
178                                                          /* flush if time */
179 <                if (--nextflush == 0) {
180 <                        fflush(stdout);
181 <                        nextflush = hresolu;
179 >                        if (--nextflush == 0) {
180 >                                fflush(stdout);
181 >                                nextflush = hresolu;
182 >                        }
183                  }
184                  if (ferror(stdout))
185                          error(SYSTEM, "write error");
186                  if (--vcount == 0)                      /* check for end */
187                          break;
188          }
189 +        fflush(stdout);
190          if (vcount > 0)
191                  error(USER, "read error");
192 <        fclose(fp);
192 >        if (fname != NULL)
193 >                fclose(fp);
194   }
195  
196  
197   setoutput(vs)                           /* set up output tables */
198   register char  *vs;
199   {
200 <        extern int  ourtrace(), (*trace)();
200 >        extern int  (*trace)();
201          register int (**table)() = ray_out;
202  
203          castonly = 1;
# Line 202 | Line 229 | register char  *vs;
229                  case 'p':                               /* point */
230                          *table++ = oputp;
231                          break;
232 <                case 'n':                               /* normal */
232 >                case 'n':                               /* perturbed normal */
233                          *table++ = oputn;
234 +                        castonly = 0;
235                          break;
236 +                case 'N':                               /* unperturbed normal */
237 +                        *table++ = oputN;
238 +                        break;
239                  case 's':                               /* surface */
240                          *table++ = oputs;
241                          break;
# Line 219 | Line 250 | register char  *vs;
250   }
251  
252  
253 < traceray(org, dir)              /* compute and print ray value(s) */
223 < FVECT  org, dir;
253 > bogusray()                      /* print out empty record */
254   {
255 <        register int  (**tp)();
255 >        thisray.rorg[0] = thisray.rorg[1] = thisray.rorg[2] =
256 >        thisray.rdir[0] = thisray.rdir[1] = thisray.rdir[2] = 0.0;
257 >        rayorigin(&thisray, NULL, PRIMARY, 1.0);
258 >        printvals(&thisray);
259 > }
260  
261 +
262 + rad(org, dir)                   /* compute and print ray value(s) */
263 + FVECT  org, dir;
264 + {
265          VCOPY(thisray.rorg, org);
266          VCOPY(thisray.rdir, dir);
267 +        thisray.rmax = 0.0;
268          rayorigin(&thisray, NULL, PRIMARY, 1.0);
269          if (castonly)
270                  localhit(&thisray, &thescene) || sourcehit(&thisray);
271          else
272                  rayvalue(&thisray);
273 <
235 <        if (ray_out[0] == NULL)
236 <                return;
237 <        for (tp = ray_out; *tp != NULL; tp++)
238 <                (**tp)(&thisray);
239 <        if (outform == 'a')
240 <                putchar('\n');
273 >        printvals(&thisray);
274   }
275  
276  
# Line 252 | Line 285 | FVECT  org, dir;
285          }
286          rayorigin(&thisray, NULL, PRIMARY, 1.0);
287                                          /* pretend we hit surface */
288 <        thisray.rot = 1.0;
288 >        thisray.rot = 1.0-1e-4;
289          thisray.rod = 1.0;
290          VCOPY(thisray.ron, dir);
291          for (i = 0; i < 3; i++)         /* fudge factor */
292                  thisray.rop[i] = org[i] + 1e-4*dir[i];
293                                          /* compute and print */
294          (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
295 <        oputv(&thisray);
295 >        printvals(&thisray);
296 > }
297 >
298 >
299 > printvals(r)                    /* print requested ray values */
300 > RAY  *r;
301 > {
302 >        register int  (**tp)();
303 >
304 >        if (ray_out[0] == NULL)
305 >                return;
306 >        for (tp = ray_out; *tp != NULL; tp++)
307 >                (**tp)(r);
308          if (outform == 'a')
309                  putchar('\n');
310   }
# Line 302 | Line 347 | FILE  *fp;
347   }
348  
349  
350 + tranotify(obj)                  /* record new modifier */
351 + OBJECT  obj;
352 + {
353 +        static int  hitlimit = 0;
354 +        register OBJREC  *o = objptr(obj);
355 +        register char  **tralp;
356 +
357 +        if (hitlimit || !ismodifier(o->otype))
358 +                return;
359 +        for (tralp = tralist; *tralp != NULL; tralp++)
360 +                if (!strcmp(o->oname, *tralp)) {
361 +                        if (traset[0] >= MAXTSET) {
362 +                                error(WARNING, "too many modifiers in trace list");
363 +                                hitlimit++;
364 +                                return;         /* should this be fatal? */
365 +                        }
366 +                        insertelem(traset, obj);
367 +                        return;
368 +                }
369 + }
370 +
371 +
372   static
373   ourtrace(r)                             /* print ray values */
374   RAY  *r;
# Line 310 | Line 377 | RAY  *r;
377  
378          if (every_out[0] == NULL)
379                  return;
380 +        if (r->ro == NULL) {
381 +                if (traincl == 1)
382 +                        return;
383 +        } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
384 +                return;
385          tabin(r);
386          for (tp = every_out; *tp != NULL; tp++)
387                  (**tp)(r);
# Line 400 | Line 472 | register RAY  *r;
472  
473  
474   static
475 < oputn(r)                                /* print normal */
475 > oputN(r)                                /* print unperturbed normal */
476   register RAY  *r;
477   {
478          if (r->rot < FHUGE) {
# Line 416 | Line 488 | register RAY  *r;
488  
489  
490   static
491 + oputn(r)                                /* print perturbed normal */
492 + RAY  *r;
493 + {
494 +        FVECT  pnorm;
495 +
496 +        if (r->rot >= FHUGE) {
497 +                (*putreal)(0.0);
498 +                (*putreal)(0.0);
499 +                (*putreal)(0.0);
500 +                return;
501 +        }
502 +        raynormal(pnorm, r);
503 +        (*putreal)(pnorm[0]);
504 +        (*putreal)(pnorm[1]);
505 +        (*putreal)(pnorm[2]);
506 + }
507 +
508 +
509 + static
510   oputs(r)                                /* print name */
511   register RAY  *r;
512   {
# Line 440 | Line 531 | oputm(r)                               /* print modifier */
531   register RAY  *r;
532   {
533          if (r->ro != NULL)
534 <                fputs(objptr(r->ro->omod)->oname, stdout);
534 >                if (r->ro->omod != OVOID)
535 >                        fputs(objptr(r->ro->omod)->oname, stdout);
536 >                else
537 >                        fputs(VOIDID, stdout);
538          else
539                  putchar('*');
540          putchar('\t');

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines