22 |
|
|
23 |
|
long nrays = 0L; /* number of rays traced */ |
24 |
|
|
25 |
< |
#define MAXLOOP 32 /* modifier loop detection */ |
25 |
> |
#define MAXLOOP 128 /* modifier loop detection */ |
26 |
|
|
27 |
|
#define RAYHIT (-1) /* return value for intercepted ray */ |
28 |
|
|
56 |
|
r->newcset = r->clipset; |
57 |
|
r->ro = NULL; |
58 |
|
r->rot = FHUGE; |
59 |
– |
r->ros = 1.0; setident4(r->rox); |
59 |
|
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
60 |
|
setcolor(r->pcol, 1.0, 1.0, 1.0); |
61 |
|
setcolor(r->rcol, 0.0, 0.0, 0.0); |
62 |
+ |
r->rt = 0.0; |
63 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
rayvalue(r) /* compute a ray's value */ |
68 |
< |
register RAY *r; |
68 |
> |
RAY *r; |
69 |
|
{ |
70 |
|
extern int (*trace)(); |
71 |
|
|
72 |
< |
if (localhit(r, &thescene)) |
73 |
< |
if (r->clipset != NULL && inset(r->clipset, r->ro->omod)) |
74 |
< |
raytrans(r); /* object is clipped */ |
75 |
< |
else |
76 |
< |
rayshade(r, r->ro->omod); |
77 |
< |
else if (sourcehit(r)) |
78 |
< |
rayshade(r, r->ro->omod); |
72 |
> |
if (localhit(r, &thescene) || sourcehit(r)) |
73 |
> |
raycont(r); |
74 |
|
|
75 |
|
if (trace != NULL) |
76 |
|
(*trace)(r); /* trace execution */ |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
+ |
raycont(r) /* check for clipped object and continue */ |
81 |
+ |
register RAY *r; |
82 |
+ |
{ |
83 |
+ |
if (r->clipset != NULL && inset(r->clipset, r->ro->omod)) |
84 |
+ |
raytrans(r); |
85 |
+ |
else |
86 |
+ |
rayshade(r, r->ro->omod); |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
|
90 |
|
raytrans(r) /* transmit ray as is */ |
91 |
< |
RAY *r; |
91 |
> |
register RAY *r; |
92 |
|
{ |
93 |
|
RAY tr; |
94 |
|
|
96 |
|
VCOPY(tr.rdir, r->rdir); |
97 |
|
rayvalue(&tr); |
98 |
|
copycolor(r->rcol, tr.rcol); |
99 |
+ |
r->rt = r->rot + tr.rt; |
100 |
|
} |
101 |
|
} |
102 |
|
|
109 |
|
register OBJREC *m; |
110 |
|
/* check for infinite loop */ |
111 |
|
if (depth++ >= MAXLOOP) |
112 |
< |
objerror(r->ro, USER, "material loop"); |
112 |
> |
objerror(r->ro, USER, "possible modifier loop"); |
113 |
|
for ( ; mod != OVOID; mod = m->omod) { |
114 |
|
m = objptr(mod); |
115 |
+ |
/****** unnecessary test since modifier() is always called |
116 |
|
if (!ismodifier(m->otype)) { |
117 |
|
sprintf(errmsg, "illegal modifier \"%s\"", m->oname); |
118 |
|
error(USER, errmsg); |
119 |
|
} |
120 |
+ |
******/ |
121 |
|
(*ofun[m->otype].funp)(m, r); /* execute function */ |
122 |
|
m->lastrno = r->rno; |
123 |
|
if (ismaterial(m->otype)) { /* materials call raytexture */ |
212 |
|
* still fraught with problems since reflected rays and similar |
213 |
|
* directions calculated from the surface normal may spawn rays behind |
214 |
|
* the surface. The only solution is to curb textures at high |
215 |
< |
* incidence (Rdot << 1). |
215 |
> |
* incidence (namely, keep DOT(rdir,pert) < Rdot). |
216 |
|
*/ |
217 |
|
|
218 |
|
for (i = 0; i < 3; i++) |