--- ray/src/rt/raytrace.c 1990/08/18 04:25:59 1.11 +++ ray/src/rt/raytrace.c 1991/05/01 11:17:01 1.15 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1990 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -16,12 +16,21 @@ static char SCCSid[] = "$SunId$ LBL"; #include "otypes.h" +#include "otspecial.h" + extern CUBE thescene; /* our scene */ extern int maxdepth; /* maximum recursion depth */ extern double minweight; /* minimum ray weight */ +extern int do_irrad; /* compute irradiance? */ long nrays = 0L; /* number of rays traced */ +static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; +OBJREC Lamb = { + OVOID, MAT_PLASTIC, "Lambertian", + {0, 5, NULL, Lambfa}, NULL, -1, +}; /* a Lambertian surface */ + #define MAXLOOP 128 /* modifier loop detection */ #define RAYHIT (-1) /* return value for intercepted ray */ @@ -69,8 +78,10 @@ RAY *r; { extern int (*trace)(); - if (localhit(r, &thescene) || sourcehit(r)) + if (localhit(r, &thescene)) raycont(r); + else if (sourcehit(r)) + rayshade(r, r->ro->omod); if (trace != NULL) (*trace)(r); /* trace execution */ @@ -107,6 +118,14 @@ int mod; { static int depth = 0; register OBJREC *m; + /* check for irradiance calc. */ + if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) { + if (irr_ignore(objptr(mod)->otype)) + raytrans(r); + else + (*ofun[Lamb.otype].funp)(&Lamb, r); + return; + } /* check for infinite loop */ if (depth++ >= MAXLOOP) objerror(r->ro, USER, "possible modifier loop"); @@ -230,6 +249,42 @@ register RAY *r; newdot = -newdot; } return(newdot); +} + + +newrayxf(r) /* get new tranformation matrix for ray */ +RAY *r; +{ + static struct xfn { + struct xfn *next; + FULLXF xf; + } xfseed = { &xfseed }, *xflast = &xfseed; + register struct xfn *xp; + register RAY *rp; + + /* + * Search for transform in circular list that + * has no associated ray in the tree. + */ + xp = xflast; + for (rp = r->parent; rp != NULL; rp = rp->parent) + if (rp->rox == &xp->xf) { /* xp in use */ + xp = xp->next; /* move to next */ + if (xp == xflast) { /* need new one */ + xp = (struct xfn *)bmalloc(sizeof(struct xfn)); + if (xp == NULL) + error(SYSTEM, + "out of memory in newrayxf"); + /* insert in list */ + xp->next = xflast->next; + xflast->next = xp; + break; /* we're done */ + } + rp = r; /* start check over */ + } + /* got it */ + r->rox = &xp->xf; + xflast = xp; }