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 1.2 by greg, Wed Mar 15 13:47:57 1989 UTC vs.
Revision 1.12 by greg, Thu Mar 28 10:16:35 1991 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16   *      xorg    yorg    zorg    xdir    ydir    zdir
17   *
18   *  The direction need not be normalized.  Output is flexible.
19 + *  If the direction vector is (0,0,0), then the output is flushed.
20   *  All values default to ascii representation of real
21   *  numbers.  Binary representations can be selected
22   *  with '-ff' for float or '-fd' for double.  By default,
23 < *  radiance is computed.  The '-i' option indicates that
23 > *  radiance is computed.  The '-oi' or '-oI' options indicate that
24   *  irradiance values are desired.
25   */
26  
27   #include  "ray.h"
28  
29 + #include  "octree.h"
30 +
31   #include  "otypes.h"
32  
33   int  inform = 'a';                      /* input format */
# Line 35 | Line 38 | int  hresolu = 0;                      /* horizontal (scan) size */
38   int  vresolu = 0;                       /* vertical resolution */
39  
40   double  dstrsrc = 0.0;                  /* square source distribution */
41 + double  shadthresh = .05;               /* shadow threshold */
42 + double  shadcert = .5;                  /* shadow certainty */
43  
44   int  maxdepth = 6;                      /* maximum recursion depth */
45   double  minweight = 4e-3;               /* minimum ray weight */
46  
47   COLOR  ambval = BLKCOLOR;               /* ambient value */
48   double  ambacc = 0.2;                   /* ambient accuracy */
49 < int  ambres = 128;                      /* ambient resolution */
49 > int  ambres = 32;                       /* ambient resolution */
50   int  ambdiv = 128;                      /* ambient divisions */
51   int  ambssamp = 0;                      /* ambient super-samples */
52   int  ambounce = 0;                      /* ambient bounces */
# Line 50 | Line 55 | int  ambincl = -1;                     /* include == 1, exclude == 0 */
55  
56   static RAY  thisray;                    /* for our convenience */
57  
58 < extern int  oputo(), oputd(), oputv(), oputl(),
58 > static int  oputo(), oputd(), oputv(), oputl(),
59                  oputp(), oputn(), oputs(), oputw(), oputm();
60  
61   static int  (*ray_out[10])(), (*every_out[10])();
62 + static int  castonly;
63  
64 < extern int  puta(), putf(), putd();
64 > static int  puta(), putf(), putd();
65  
66   static int  (*putreal)();
67  
68 + static double  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
69 + static OBJREC  Lamb = {
70 +        OVOID, MAT_PLASTIC, "Lambertian",
71 +        {0, 5, NULL, Lambfa}, NULL, -1,
72 + };                                      /* a Lambertian surface */
73  
74 +
75   quit(code)                      /* quit program */
76   int  code;
77   {
# Line 92 | Line 104 | char  *fname;
104          while (getvec(orig, inform, fp) == 0 &&
105                          getvec(direc, inform, fp) == 0) {
106  
107 <                if (normalize(direc) == 0.0)
108 <                        error(USER, "zero direction vector");
107 >                if (normalize(direc) == 0.0) {          /* zero ==> flush */
108 >                        fflush(stdout);
109 >                        continue;
110 >                }
111                                                          /* compute and print */
112                  if (outvals[0] == 'i')
113                          irrad(orig, direc);
114 +                else if (outvals[0] == 'I')
115 +                        Irrad(orig, direc);
116                  else
117                          radiance(orig, direc);
118 <                                                        /* flush if requested */
118 >                                                        /* flush if time */
119                  if (--nextflush == 0) {
120                          fflush(stdout);
121                          nextflush = hresolu;
# Line 121 | Line 137 | register char  *vs;
137          extern int  ourtrace(), (*trace)();
138          register int (**table)() = ray_out;
139  
140 +        castonly = 1;
141          while (*vs)
142                  switch (*vs++) {
143                  case 't':                               /* trace */
144                          *table = NULL;
145                          table = every_out;
146                          trace = ourtrace;
147 +                        castonly = 0;
148                          break;
149                  case 'o':                               /* origin */
150                          *table++ = oputo;
# Line 136 | Line 154 | register char  *vs;
154                          break;
155                  case 'v':                               /* value */
156                          *table++ = oputv;
157 +                        castonly = 0;
158                          break;
159                  case 'l':                               /* length */
160                          *table++ = oputl;
161 +                        castonly = 0;
162                          break;
163                  case 'p':                               /* point */
164                          *table++ = oputp;
# Line 168 | Line 188 | FVECT  org, dir;
188          VCOPY(thisray.rorg, org);
189          VCOPY(thisray.rdir, dir);
190          rayorigin(&thisray, NULL, PRIMARY, 1.0);
191 <        rayvalue(&thisray);
191 >        if (castonly)
192 >                localhit(&thisray, &thescene) || sourcehit(&thisray);
193 >        else
194 >                rayvalue(&thisray);
195  
196          if (ray_out[0] == NULL)
197                  return;
# Line 182 | Line 205 | FVECT  org, dir;
205   irrad(org, dir)                 /* compute irradiance value */
206   FVECT  org, dir;
207   {
185        static double  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
186        static OBJREC  Lamb = {
187                OVOID, MAT_PLASTIC, "Lambertian",
188                {0, 5, NULL, Lambfa}, NULL, -1,
189        };
208          register int  i;
209  
210          for (i = 0; i < 3; i++) {
# Line 208 | Line 226 | FVECT  org, dir;
226   }
227  
228  
229 + Irrad(org, dir)         /* compute irradiance value after intersection */
230 + FVECT  org, dir;
231 + {
232 +                                        /* compute intersection */
233 +        VCOPY(thisray.rorg, org);
234 +        VCOPY(thisray.rdir, dir);
235 +        rayorigin(&thisray, NULL, PRIMARY, 1.0);
236 +        localhit(&thisray, &thescene);
237 +        if (thisray.ro != NULL)         /* pretend we hit Lambertian surf. */
238 +                (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
239 +        oputv(&thisray);
240 +        if (outform == 'a')
241 +                putchar('\n');
242 + }
243 +
244 +
245   getvec(vec, fmt, fp)            /* get a vector from fp */
246   register FVECT  vec;
247   int  fmt;
# Line 221 | Line 255 | FILE  *fp;
255                          return(-1);
256                  break;
257          case 'f':                                       /* binary float */
258 <                if (fread(vf, sizeof(float), 3, fp) != 3)
258 >                if (fread((char *)vf, sizeof(float), 3, fp) != 3)
259                          return(-1);
260                  vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2];
261                  break;
262          case 'd':                                       /* binary double */
263 <                if (fread(vec, sizeof(double), 3, fp) != 3)
263 >                if (fread((char *)vec, sizeof(double), 3, fp) != 3)
264                          return(-1);
265                  break;
266          }
# Line 294 | Line 328 | static
328   oputl(r)                                /* print length */
329   register RAY  *r;
330   {
331 <        if (r->rot < FHUGE)
298 <                (*putreal)(r->rot);
299 <        else
300 <                (*putreal)(0.0);
331 >        (*putreal)(r->rt);
332   }
333  
334  
# Line 377 | Line 408 | static
408   putd(v)                         /* print binary double */
409   double  v;
410   {
411 <        fwrite(&v, sizeof(v), 1, stdout);
411 >        fwrite((char *)&v, sizeof(v), 1, stdout);
412   }
413  
414  
# Line 387 | Line 418 | double  v;
418   {
419          float f = v;
420  
421 <        fwrite(&f, sizeof(f), 1, stdout);
421 >        fwrite((char *)&f, sizeof(f), 1, stdout);
422   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines