--- ray/src/rt/raytrace.c 1998/09/15 09:52:39 2.33 +++ ray/src/rt/raytrace.c 2003/05/09 22:18:03 2.39 @@ -1,36 +1,22 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: raytrace.c,v 2.39 2003/05/09 22:18:03 greg Exp $"; #endif - /* * raytrace.c - routines for tracing and shading rays. * - * 8/7/85 + * External symbols declared in ray.h */ +#include "copyright.h" + #include "ray.h" -#include "octree.h" - #include "otypes.h" #include "otspecial.h" #define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ -extern CUBE thescene; /* our scene */ -extern int maxdepth; /* maximum recursion depth */ -extern double minweight; /* minimum ray weight */ -extern int do_irrad; /* compute irradiance? */ -extern COLOR ambval; /* ambient value */ - -extern COLOR cextinction; /* global extinction coefficient */ -extern COLOR salbedo; /* global scattering albedo */ -extern double seccg; /* global scattering eccentricity */ -extern double ssampdist; /* scatter sampling distance */ - unsigned long raynum = 0; /* next unique ray number */ unsigned long nrays = 0; /* number of calls to localhit */ @@ -42,7 +28,8 @@ OBJREC Lamb = { OBJREC Aftplane; /* aft clipping plane object */ -static int raymove(), checkset(), checkhit(); +static int raymove(), checkhit(); +static void checkset(); #ifndef MAXLOOP #define MAXLOOP 0 /* modifier loop detection */ @@ -51,6 +38,7 @@ static int raymove(), checkset(), checkhit(); #define RAYHIT (-1) /* return value for intercepted ray */ +int rayorigin(r, ro, rt, rw) /* start new ray from old one */ register RAY *r, *ro; int rt; @@ -101,25 +89,28 @@ double rw; } +void rayclear(r) /* clear a ray for (re)evaluation */ register RAY *r; { r->rno = raynum++; r->newcset = r->clipset; + r->hitf = rayhit; r->robj = OVOID; r->ro = NULL; + r->rox = NULL; r->rt = r->rot = FHUGE; r->pert[0] = r->pert[1] = r->pert[2] = 0.0; + r->uv[0] = r->uv[1] = 0.0; setcolor(r->pcol, 1.0, 1.0, 1.0); setcolor(r->rcol, 0.0, 0.0, 0.0); } +void raytrace(r) /* trace a ray and compute its value */ RAY *r; { - extern int (*trace)(); - if (localhit(r, &thescene)) raycont(r); /* hit local surface, evaluate */ else if (r->ro == &Aftplane) { @@ -135,6 +126,7 @@ RAY *r; } +void raycont(r) /* check for clipped object and continue */ register RAY *r; { @@ -144,6 +136,7 @@ register RAY *r; } +void raytrans(r) /* transmit ray as is */ register RAY *r; { @@ -158,6 +151,7 @@ register RAY *r; } +int rayshade(r, mod) /* shade ray r with material mod */ register RAY *r; int mod; @@ -180,7 +174,8 @@ int mod; } ******/ /* hack for irradiance calculation */ - if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) { + if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) && + (ofun[m->otype].flags & (T_M|T_X))) { if (irr_ignore(m->otype)) { #if MAXLOOP depth--; @@ -201,6 +196,7 @@ int mod; } +void rayparticipate(r) /* compute ray medium participation */ register RAY *r; { @@ -232,9 +228,10 @@ register RAY *r; } +void raytexture(r, mod) /* get material modifiers */ RAY *r; -int mod; +OBJECT mod; { register OBJREC *m; #if MAXLOOP @@ -264,6 +261,7 @@ int mod; } +int raymixture(r, fore, back, coef) /* mix modifiers */ register RAY *r; OBJECT fore, back; @@ -364,6 +362,7 @@ register RAY *r; } +void newrayxf(r) /* get new tranformation matrix for ray */ RAY *r; { @@ -383,7 +382,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 *)bmalloc(sizeof(struct xfn)); + xp = (struct xfn *)malloc(sizeof(struct xfn)); if (xp == NULL) error(SYSTEM, "out of memory in newrayxf"); @@ -400,6 +399,7 @@ RAY *r; } +void flipsurface(r) /* reverse surface orientation */ register RAY *r; { @@ -413,6 +413,23 @@ register RAY *r; } +void +rayhit(oset, r) /* standard ray hit test */ +OBJECT *oset; +RAY *r; +{ + OBJREC *o; + int i; + + for (i = oset[0]; i > 0; i--) { + o = objptr(oset[i]); + if ((*ofun[o->otype].funp)(o, r)) + r->robj = oset[i]; + } +} + + +int localhit(r, scene) /* check for hit in the octree */ register RAY *r; register CUBE *scene; @@ -560,31 +577,27 @@ register CUBE *cu; } -static +static int checkhit(r, cu, cxs) /* check for hit in full cube */ register RAY *r; CUBE *cu; OBJECT *cxs; { OBJECT oset[MAXSET+1]; - register OBJREC *o; - register int i; objset(oset, cu->cutree); - checkset(oset, cxs); /* eliminate double-checking */ - for (i = oset[0]; i > 0; i--) { - o = objptr(oset[i]); - if ((*ofun[o->otype].funp)(o, r)) - r->robj = oset[i]; - } - if (r->ro == NULL) + checkset(oset, cxs); /* avoid double-checking */ + + (*r->hitf)(oset, r); /* test for hit in set */ + + if (r->robj == OVOID) return(0); /* no scores yet */ return(incube(cu, r->rop)); /* hit OK if in current cube */ } -static +static void checkset(os, cs) /* modify checked set and set to check */ register OBJECT *os; /* os' = os - cs */ register OBJECT *cs; /* cs' = cs + os */