--- ray/src/rt/raytrace.c 1990/08/18 04:25:59 1.11 +++ ray/src/rt/raytrace.c 1991/05/10 08:51:06 1.17 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 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 */ @@ -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 */ @@ -233,6 +254,42 @@ register RAY *r; } +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; +} + + flipsurface(r) /* reverse surface orientation */ register RAY *r; { @@ -265,6 +322,8 @@ register CUBE *scene; else if (r->rdir[i] < -FTINY) sflags |= 0x10 << i; } + if (sflags == 0) + error(CONSISTENCY, "zero ray direction in localhit"); t = 0.0; if (!incube(scene, curpos)) { /* find distance to entry */