--- ray/src/rt/raytrace.c 1991/01/12 14:05:01 1.13 +++ ray/src/rt/raytrace.c 1991/05/02 11:58:20 1.16 @@ -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 */ @@ -118,6 +129,16 @@ int mod; error(USER, errmsg); } ******/ + /* hack for irradiance calculation */ + if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) { + if (irr_ignore(m->otype)) { + depth--; + raytrans(r); + return; + } + if (m->otype != MAT_ILLUM) + m = &Lamb; + } (*ofun[m->otype].funp)(m, r); /* execute function */ m->lastrno = r->rno; if (ismaterial(m->otype)) { /* materials call raytexture */ @@ -252,7 +273,7 @@ RAY *r; if (rp->rox == &xp->xf) { /* xp in use */ xp = xp->next; /* move to next */ if (xp == xflast) { /* need new one */ - xp = (struct xfn *)malloc(sizeof(struct xfn)); + xp = (struct xfn *)bmalloc(sizeof(struct xfn)); if (xp == NULL) error(SYSTEM, "out of memory in newrayxf");