--- ray/src/rt/rtrace.c 1989/06/07 08:35:23 1.3 +++ ray/src/rt/rtrace.c 1991/06/24 16:16:54 1.16 @@ -16,17 +16,26 @@ static char SCCSid[] = "$SunId$ LBL"; * xorg yorg zorg xdir ydir zdir * * The direction need not be normalized. Output is flexible. + * If the direction vector is (0,0,0), then the output is flushed. * All values default to ascii representation of real * numbers. Binary representations can be selected * with '-ff' for float or '-fd' for double. By default, - * radiance is computed. The '-i' option indicates that + * radiance is computed. The '-i' or '-I' options indicate that * irradiance values are desired. */ #include "ray.h" +#include "octree.h" + #include "otypes.h" +int dimlist[MAXDIM]; /* sampling dimensions */ +int ndims = 0; /* number of sampling dimensions */ +int samplendx = 0; /* index for this sample */ + +int imm_irrad = 0; /* compute immediate irradiance? */ + int inform = 'a'; /* input format */ int outform = 'a'; /* output format */ char *outvals = "v"; /* output specification */ @@ -35,28 +44,34 @@ int hresolu = 0; /* horizontal (scan) size */ int vresolu = 0; /* vertical resolution */ double dstrsrc = 0.0; /* square source distribution */ -double shadthresh = .01; /* shadow threshold */ +double shadthresh = .05; /* shadow threshold */ +double shadcert = .5; /* shadow certainty */ +int directrelay = 0; /* number of source relays */ +int vspretest = 128; /* virtual source pretest density */ int maxdepth = 6; /* maximum recursion depth */ double minweight = 4e-3; /* minimum ray weight */ COLOR ambval = BLKCOLOR; /* ambient value */ double ambacc = 0.2; /* ambient accuracy */ -int ambres = 128; /* ambient resolution */ +int ambres = 32; /* ambient resolution */ int ambdiv = 128; /* ambient divisions */ int ambssamp = 0; /* ambient super-samples */ int ambounce = 0; /* ambient bounces */ char *amblist[128]; /* ambient include/exclude list */ int ambincl = -1; /* include == 1, exclude == 0 */ +extern OBJREC Lamb; /* a Lambertian surface */ + static RAY thisray; /* for our convenience */ -extern int oputo(), oputd(), oputv(), oputl(), +static int oputo(), oputd(), oputv(), oputl(), oputp(), oputn(), oputs(), oputw(), oputm(); static int (*ray_out[10])(), (*every_out[10])(); +static int castonly; -extern int puta(), putf(), putd(); +static int puta(), putf(), putd(); static int (*putreal)(); @@ -93,14 +108,17 @@ char *fname; while (getvec(orig, inform, fp) == 0 && getvec(direc, inform, fp) == 0) { - if (normalize(direc) == 0.0) - error(USER, "zero direction vector"); + if (normalize(direc) == 0.0) { /* zero ==> flush */ + fflush(stdout); + continue; + } + samplendx++; /* compute and print */ - if (outvals[0] == 'i') + if (imm_irrad) irrad(orig, direc); else - radiance(orig, direc); - /* flush if requested */ + traceray(orig, direc); + /* flush if time */ if (--nextflush == 0) { fflush(stdout); nextflush = hresolu; @@ -122,12 +140,14 @@ register char *vs; extern int ourtrace(), (*trace)(); register int (**table)() = ray_out; + castonly = 1; while (*vs) switch (*vs++) { case 't': /* trace */ *table = NULL; table = every_out; trace = ourtrace; + castonly = 0; break; case 'o': /* origin */ *table++ = oputo; @@ -137,9 +157,11 @@ register char *vs; break; case 'v': /* value */ *table++ = oputv; + castonly = 0; break; case 'l': /* length */ *table++ = oputl; + castonly = 0; break; case 'p': /* point */ *table++ = oputp; @@ -161,7 +183,7 @@ register char *vs; } -radiance(org, dir) /* compute radiance value */ +traceray(org, dir) /* compute and print ray value(s) */ FVECT org, dir; { register int (**tp)(); @@ -169,7 +191,10 @@ FVECT org, dir; VCOPY(thisray.rorg, org); VCOPY(thisray.rdir, dir); rayorigin(&thisray, NULL, PRIMARY, 1.0); - rayvalue(&thisray); + if (castonly) + localhit(&thisray, &thescene) || sourcehit(&thisray); + else + rayvalue(&thisray); if (ray_out[0] == NULL) return; @@ -180,14 +205,9 @@ FVECT org, dir; } -irrad(org, dir) /* compute irradiance value */ +irrad(org, dir) /* compute immediate irradiance value */ FVECT org, dir; { - static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; - static OBJREC Lamb = { - OVOID, MAT_PLASTIC, "Lambertian", - {0, 5, NULL, Lambfa}, NULL, -1, - }; register int i; for (i = 0; i < 3; i++) { @@ -222,12 +242,12 @@ FILE *fp; return(-1); break; case 'f': /* binary float */ - if (fread(vf, sizeof(float), 3, fp) != 3) + if (fread((char *)vf, sizeof(float), 3, fp) != 3) return(-1); vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; break; case 'd': /* binary double */ - if (fread(vec, sizeof(double), 3, fp) != 3) + if (fread((char *)vec, sizeof(double), 3, fp) != 3) return(-1); break; } @@ -295,10 +315,7 @@ static oputl(r) /* print length */ register RAY *r; { - if (r->rot < FHUGE) - (*putreal)(r->rot); - else - (*putreal)(0.0); + (*putreal)(r->rt); } @@ -378,7 +395,7 @@ static putd(v) /* print binary double */ double v; { - fwrite(&v, sizeof(v), 1, stdout); + fwrite((char *)&v, sizeof(v), 1, stdout); } @@ -388,5 +405,5 @@ double v; { float f = v; - fwrite(&f, sizeof(f), 1, stdout); + fwrite((char *)&f, sizeof(f), 1, stdout); }