--- ray/src/rt/raytrace.c 1998/08/06 10:30:38 2.32 +++ ray/src/rt/raytrace.c 2003/02/25 02:47:23 2.35 @@ -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.35 2003/02/25 02:47:23 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,13 +28,17 @@ OBJREC Lamb = { OBJREC Aftplane; /* aft clipping plane object */ -static int raymove(), checkset(), checkhit(); +static int raymove(), checkhit(); +static void checkset(); -#define MAXLOOP 128 /* modifier loop detection */ +#ifndef MAXLOOP +#define MAXLOOP 0 /* modifier loop detection */ +#endif #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; @@ -99,6 +89,7 @@ double rw; } +void rayclear(r) /* clear a ray for (re)evaluation */ register RAY *r; { @@ -106,6 +97,7 @@ register RAY *r; r->newcset = r->clipset; 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; setcolor(r->pcol, 1.0, 1.0, 1.0); @@ -113,11 +105,10 @@ register RAY *r; } +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) { @@ -133,6 +124,7 @@ RAY *r; } +void raycont(r) /* check for clipped object and continue */ register RAY *r; { @@ -142,6 +134,7 @@ register RAY *r; } +void raytrans(r) /* transmit ray as is */ register RAY *r; { @@ -156,16 +149,19 @@ register RAY *r; } +int rayshade(r, mod) /* shade ray r with material mod */ register RAY *r; int mod; { - static int depth = 0; int gotmat; register OBJREC *m; +#if MAXLOOP + static int depth = 0; /* check for infinite loop */ if (depth++ >= MAXLOOP) objerror(r->ro, USER, "possible modifier loop"); +#endif r->rt = r->rot; /* set effective ray length */ for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) { m = objptr(mod); @@ -178,7 +174,9 @@ int mod; /* hack for irradiance calculation */ if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) { if (irr_ignore(m->otype)) { +#if MAXLOOP depth--; +#endif raytrans(r); return(1); } @@ -188,11 +186,14 @@ int mod; /* materials call raytexture */ gotmat = (*ofun[m->otype].funp)(m, r); } +#if MAXLOOP depth--; +#endif return(gotmat); } +void rayparticipate(r) /* compute ray medium participation */ register RAY *r; { @@ -228,11 +229,13 @@ raytexture(r, mod) /* get material modifiers */ RAY *r; int mod; { - static int depth = 0; register OBJREC *m; +#if MAXLOOP + static int depth = 0; /* check for infinite loop */ if (depth++ >= MAXLOOP) objerror(r->ro, USER, "modifier loop"); +#endif /* execute textures and patterns */ for ( ; mod != OVOID; mod = m->omod) { m = objptr(mod); @@ -248,10 +251,13 @@ int mod; objerror(r->ro, USER, errmsg); } } +#if MAXLOOP depth--; /* end here */ +#endif } +int raymixture(r, fore, back, coef) /* mix modifiers */ register RAY *r; OBJECT fore, back; @@ -277,9 +283,9 @@ double coef; backmat = rayshade(&br, back); /* check for transparency */ if (backmat ^ foremat) - if (!foremat && coef > FTINY) + if (backmat && coef > FTINY) raytrans(&fr); - else if (!backmat && coef < 1.0-FTINY) + else if (foremat && coef < 1.0-FTINY) raytrans(&br); /* mix perturbations */ for (i = 0; i < 3; i++) @@ -352,6 +358,7 @@ register RAY *r; } +void newrayxf(r) /* get new tranformation matrix for ray */ RAY *r; { @@ -371,7 +378,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"); @@ -388,6 +395,7 @@ RAY *r; } +void flipsurface(r) /* reverse surface orientation */ register RAY *r; { @@ -401,6 +409,7 @@ register RAY *r; } +int localhit(r, scene) /* check for hit in the octree */ register RAY *r; register CUBE *scene; @@ -548,7 +557,7 @@ register CUBE *cu; } -static +static int checkhit(r, cu, cxs) /* check for hit in full cube */ register RAY *r; CUBE *cu; @@ -572,7 +581,7 @@ OBJECT *cxs; } -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 */