--- ray/src/rt/raytrace.c 2003/07/27 22:12:03 2.42 +++ ray/src/rt/raytrace.c 2005/03/10 22:37:00 2.46 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raytrace.c,v 2.42 2003/07/27 22:12:03 schorsch Exp $"; +static const char RCSid[] = "$Id: raytrace.c,v 2.46 2005/03/10 22:37:00 greg Exp $"; #endif /* * raytrace.c - routines for tracing and shading rays. @@ -10,9 +10,8 @@ static const char RCSid[] = "$Id: raytrace.c,v 2.42 20 #include "copyright.h" #include "ray.h" - +#include "source.h" #include "otypes.h" - #include "otspecial.h" #define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ @@ -28,21 +27,20 @@ OBJREC Lamb = { OBJREC Aftplane; /* aft clipping plane object */ -static int raymove(), checkhit(); -static void checkset(); - -#ifndef MAXLOOP -#define MAXLOOP 0 /* modifier loop detection */ -#endif - #define RAYHIT (-1) /* return value for intercepted ray */ +static int raymove(FVECT pos, OBJECT *cxs, int dirf, RAY *r, CUBE *cu); +static int checkhit(RAY *r, CUBE *cu, OBJECT *cxs); +static void checkset(OBJECT *os, OBJECT *cs); -int -rayorigin(r, ro, rt, rw) /* start new ray from old one */ -register RAY *r, *ro; -int rt; -double rw; + +extern int +rayorigin( /* start new ray from old one */ + register RAY *r, + register RAY *ro, + int rt, + double rw +) { double re; @@ -57,6 +55,9 @@ double rw; copycolor(r->albedo, salbedo); r->gecc = seccg; r->slights = NULL; + } else if (ro->rot >= FHUGE) { /* illegal continuation */ + memset(r, 0, sizeof(RAY)); + return(-1); } else { /* spawned ray */ r->rlvl = ro->rlvl; if (rt & RAYREFL) { @@ -89,9 +90,10 @@ double rw; } -void -rayclear(r) /* clear a ray for (re)evaluation */ -register RAY *r; +extern void +rayclear( /* clear a ray for (re)evaluation */ + register RAY *r +) { r->rno = raynum++; r->newcset = r->clipset; @@ -107,9 +109,10 @@ register RAY *r; } -void -raytrace(r) /* trace a ray and compute its value */ -RAY *r; +extern void +raytrace( /* trace a ray and compute its value */ + RAY *r +) { if (localhit(r, &thescene)) raycont(r); /* hit local surface, evaluate */ @@ -126,9 +129,10 @@ RAY *r; } -void -raycont(r) /* check for clipped object and continue */ -register RAY *r; +extern void +raycont( /* check for clipped object and continue */ + register RAY *r +) { if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || !rayshade(r, r->ro->omod)) @@ -136,9 +140,10 @@ register RAY *r; } -void -raytrans(r) /* transmit ray as is */ -register RAY *r; +extern void +raytrans( /* transmit ray as is */ + register RAY *r +) { RAY tr; @@ -151,19 +156,14 @@ register RAY *r; } -int -rayshade(r, mod) /* shade ray r with material mod */ -register RAY *r; -int mod; +extern int +rayshade( /* shade ray r with material mod */ + register RAY *r, + int mod +) { 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); @@ -175,11 +175,9 @@ int mod; ******/ /* hack for irradiance calculation */ if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) && + m->otype != MAT_CLIP && (ofun[m->otype].flags & (T_M|T_X))) { if (irr_ignore(m->otype)) { -#if MAXLOOP - depth--; -#endif raytrans(r); return(1); } @@ -189,16 +187,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; +extern void +rayparticipate( /* compute ray medium participation */ + register RAY *r +) { COLOR ce, ca; double re, ge, be; @@ -228,18 +224,13 @@ register RAY *r; } -void -raytexture(r, mod) /* get material modifiers */ -RAY *r; -OBJECT mod; +extern void +raytexture( /* get material modifiers */ + RAY *r, + OBJECT mod +) { 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); @@ -255,17 +246,16 @@ OBJECT 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; -double coef; +extern int +raymixture( /* mix modifiers */ + register RAY *r, + OBJECT fore, + OBJECT back, + double coef +) { RAY fr, br; int foremat, backmat; @@ -313,10 +303,11 @@ double coef; } -double -raydist(r, flags) /* compute (cumulative) ray distance */ -register RAY *r; -register int flags; +extern double +raydist( /* compute (cumulative) ray distance */ + register RAY *r, + register int flags +) { double sum = 0.0; @@ -328,10 +319,11 @@ register int flags; } -double -raynormal(norm, r) /* compute perturbed normal for ray */ -FVECT norm; -register RAY *r; +extern double +raynormal( /* compute perturbed normal for ray */ + FVECT norm, + register RAY *r +) { double newdot; register int i; @@ -363,9 +355,10 @@ register RAY *r; } -void -newrayxf(r) /* get new tranformation matrix for ray */ -RAY *r; +extern void +newrayxf( /* get new tranformation matrix for ray */ + RAY *r +) { static struct xfn { struct xfn *next; @@ -400,9 +393,10 @@ RAY *r; } -void -flipsurface(r) /* reverse surface orientation */ -register RAY *r; +extern void +flipsurface( /* reverse surface orientation */ + register RAY *r +) { r->rod = -r->rod; r->ron[0] = -r->ron[0]; @@ -414,10 +408,11 @@ register RAY *r; } -void -rayhit(oset, r) /* standard ray hit test */ -OBJECT *oset; -RAY *r; +extern void +rayhit( /* standard ray hit test */ + OBJECT *oset, + RAY *r +) { OBJREC *o; int i; @@ -430,10 +425,11 @@ RAY *r; } -int -localhit(r, scene) /* check for hit in the octree */ -register RAY *r; -register CUBE *scene; +extern int +localhit( /* check for hit in the octree */ + register RAY *r, + register CUBE *scene +) { OBJECT cxset[MAXCSET+1]; /* set of checked objects */ FVECT curpos; /* current cube position */ @@ -493,12 +489,13 @@ register CUBE *scene; static int -raymove(pos, cxs, dirf, r, cu) /* check for hit as we move */ -FVECT pos; /* current position, modified herein */ -OBJECT *cxs; /* checked objects, modified by checkhit */ -int dirf; /* direction indicators to speed tests */ -register RAY *r; -register CUBE *cu; +raymove( /* check for hit as we move */ + FVECT pos, /* current position, modified herein */ + OBJECT *cxs, /* checked objects, modified by checkhit */ + int dirf, /* direction indicators to speed tests */ + register RAY *r, + register CUBE *cu +) { int ax; double dt, t; @@ -579,10 +576,11 @@ register CUBE *cu; static int -checkhit(r, cu, cxs) /* check for hit in full cube */ -register RAY *r; -CUBE *cu; -OBJECT *cxs; +checkhit( /* check for hit in full cube */ + register RAY *r, + CUBE *cu, + OBJECT *cxs +) { OBJECT oset[MAXSET+1]; @@ -599,9 +597,10 @@ OBJECT *cxs; static void -checkset(os, cs) /* modify checked set and set to check */ -register OBJECT *os; /* os' = os - cs */ -register OBJECT *cs; /* cs' = cs + os */ +checkset( /* modify checked set and set to check */ + register OBJECT *os, /* os' = os - cs */ + register OBJECT *cs /* cs' = cs + os */ +) { OBJECT cset[MAXCSET+MAXSET+1]; register int i, j;