14 |
|
#include "otypes.h" |
15 |
|
#include "otspecial.h" |
16 |
|
#include "random.h" |
17 |
+ |
#include "pmap.h" |
18 |
|
|
19 |
|
#define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ |
20 |
|
|
36 |
|
static void checkset(OBJECT *os, OBJECT *cs); |
37 |
|
|
38 |
|
|
39 |
< |
extern int |
39 |
> |
int |
40 |
|
rayorigin( /* start new ray from old one */ |
41 |
|
RAY *r, |
42 |
|
int rt, |
121 |
|
r->rweight = minweight; |
122 |
|
return(0); |
123 |
|
} |
124 |
< |
return(r->rlvl <= abs(maxdepth) && r->rweight >= minweight ? 0 : -1); |
124 |
> |
return(r->rweight >= minweight && r->rlvl <= abs(maxdepth) ? 0 : -1); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
< |
extern void |
128 |
> |
void |
129 |
|
rayclear( /* clear a ray for (re)evaluation */ |
130 |
< |
register RAY *r |
130 |
> |
RAY *r |
131 |
|
) |
132 |
|
{ |
133 |
|
r->rno = raynum++; |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
< |
extern void |
147 |
> |
void |
148 |
|
raytrace( /* trace a ray and compute its value */ |
149 |
|
RAY *r |
150 |
|
) |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
< |
extern void |
167 |
> |
void |
168 |
|
raycont( /* check for clipped object and continue */ |
169 |
< |
register RAY *r |
169 |
> |
RAY *r |
170 |
|
) |
171 |
|
{ |
172 |
|
if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
< |
extern void |
178 |
> |
void |
179 |
|
raytrans( /* transmit ray as is */ |
180 |
< |
register RAY *r |
180 |
> |
RAY *r |
181 |
|
) |
182 |
|
{ |
183 |
|
RAY tr; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
< |
extern int |
194 |
> |
int |
195 |
|
rayshade( /* shade ray r with material mod */ |
196 |
< |
register RAY *r, |
196 |
> |
RAY *r, |
197 |
|
int mod |
198 |
|
) |
199 |
|
{ |
200 |
< |
register OBJREC *m; |
200 |
> |
OBJREC *m; |
201 |
|
|
202 |
|
r->rt = r->rot; /* set effective ray length */ |
203 |
|
for ( ; mod != OVOID; mod = m->omod) { |
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
< |
extern void |
229 |
> |
void |
230 |
|
rayparticipate( /* compute ray medium participation */ |
231 |
< |
register RAY *r |
231 |
> |
RAY *r |
232 |
|
) |
233 |
|
{ |
234 |
|
COLOR ce, ca; |
250 |
|
multcolor(r->rcol, ce); /* path extinction */ |
251 |
|
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
252 |
|
return; /* no scattering */ |
253 |
< |
setcolor(ca, |
254 |
< |
colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)), |
255 |
< |
colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)), |
256 |
< |
colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU))); |
257 |
< |
addcolor(r->rcol, ca); /* ambient in scattering */ |
253 |
> |
|
254 |
> |
/* PMAP: indirect inscattering accounted for by volume photons? */ |
255 |
> |
if (!volumePhotonMapping) { |
256 |
> |
setcolor(ca, |
257 |
> |
colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)), |
258 |
> |
colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)), |
259 |
> |
colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU))); |
260 |
> |
addcolor(r->rcol, ca); /* ambient in scattering */ |
261 |
> |
} |
262 |
> |
|
263 |
|
srcscatter(r); /* source in scattering */ |
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
< |
extern void |
267 |
> |
void |
268 |
|
raytexture( /* get material modifiers */ |
269 |
|
RAY *r, |
270 |
|
OBJECT mod |
271 |
|
) |
272 |
|
{ |
273 |
< |
register OBJREC *m; |
273 |
> |
OBJREC *m; |
274 |
|
/* execute textures and patterns */ |
275 |
|
for ( ; mod != OVOID; mod = m->omod) { |
276 |
|
m = objptr(mod); |
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
< |
extern int |
292 |
> |
int |
293 |
|
raymixture( /* mix modifiers */ |
294 |
< |
register RAY *r, |
294 |
> |
RAY *r, |
295 |
|
OBJECT fore, |
296 |
|
OBJECT back, |
297 |
|
double coef |
299 |
|
{ |
300 |
|
RAY fr, br; |
301 |
|
int foremat, backmat; |
302 |
< |
register int i; |
302 |
> |
int i; |
303 |
|
/* bound coefficient */ |
304 |
|
if (coef > 1.0) |
305 |
|
coef = 1.0; |
349 |
|
} |
350 |
|
|
351 |
|
|
352 |
< |
extern double |
352 |
> |
double |
353 |
|
raydist( /* compute (cumulative) ray distance */ |
354 |
< |
register const RAY *r, |
355 |
< |
register int flags |
354 |
> |
const RAY *r, |
355 |
> |
int flags |
356 |
|
) |
357 |
|
{ |
358 |
|
double sum = 0.0; |
365 |
|
} |
366 |
|
|
367 |
|
|
368 |
< |
extern void |
368 |
> |
void |
369 |
|
raycontrib( /* compute (cumulative) ray contribution */ |
370 |
|
RREAL rc[3], |
371 |
|
const RAY *r, |
391 |
|
} |
392 |
|
|
393 |
|
|
394 |
< |
extern double |
394 |
> |
double |
395 |
|
raynormal( /* compute perturbed normal for ray */ |
396 |
|
FVECT norm, |
397 |
< |
register RAY *r |
397 |
> |
RAY *r |
398 |
|
) |
399 |
|
{ |
400 |
|
double newdot; |
401 |
< |
register int i; |
401 |
> |
int i; |
402 |
|
|
403 |
|
/* The perturbation is added to the surface normal to obtain |
404 |
|
* the new normal. If the new normal would affect the surface |
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
< |
extern void |
430 |
> |
void |
431 |
|
newrayxf( /* get new tranformation matrix for ray */ |
432 |
|
RAY *r |
433 |
|
) |
436 |
|
struct xfn *next; |
437 |
|
FULLXF xf; |
438 |
|
} xfseed = { &xfseed }, *xflast = &xfseed; |
439 |
< |
register struct xfn *xp; |
440 |
< |
register const RAY *rp; |
439 |
> |
struct xfn *xp; |
440 |
> |
const RAY *rp; |
441 |
|
|
442 |
|
/* |
443 |
|
* Search for transform in circular list that |
448 |
|
if (rp->rox == &xp->xf) { /* xp in use */ |
449 |
|
xp = xp->next; /* move to next */ |
450 |
|
if (xp == xflast) { /* need new one */ |
451 |
< |
xp = (struct xfn *)malloc(sizeof(struct xfn)); |
451 |
> |
xp = (struct xfn *)bmalloc(sizeof(struct xfn)); |
452 |
|
if (xp == NULL) |
453 |
|
error(SYSTEM, |
454 |
|
"out of memory in newrayxf"); |
465 |
|
} |
466 |
|
|
467 |
|
|
468 |
< |
extern void |
468 |
> |
void |
469 |
|
flipsurface( /* reverse surface orientation */ |
470 |
< |
register RAY *r |
470 |
> |
RAY *r |
471 |
|
) |
472 |
|
{ |
473 |
|
r->rod = -r->rod; |
480 |
|
} |
481 |
|
|
482 |
|
|
483 |
< |
extern void |
483 |
> |
void |
484 |
|
rayhit( /* standard ray hit test */ |
485 |
|
OBJECT *oset, |
486 |
|
RAY *r |
497 |
|
} |
498 |
|
|
499 |
|
|
500 |
< |
extern int |
500 |
> |
int |
501 |
|
localhit( /* check for hit in the octree */ |
502 |
< |
register RAY *r, |
503 |
< |
register CUBE *scene |
502 |
> |
RAY *r, |
503 |
> |
CUBE *scene |
504 |
|
) |
505 |
|
{ |
506 |
|
OBJECT cxset[MAXCSET+1]; /* set of checked objects */ |
507 |
|
FVECT curpos; /* current cube position */ |
508 |
|
int sflags; /* sign flags */ |
509 |
|
double t, dt; |
510 |
< |
register int i; |
510 |
> |
int i; |
511 |
|
|
512 |
|
nrays++; /* increment trace counter */ |
513 |
|
sflags = 0; |
565 |
|
FVECT pos, /* current position, modified herein */ |
566 |
|
OBJECT *cxs, /* checked objects, modified by checkhit */ |
567 |
|
int dirf, /* direction indicators to speed tests */ |
568 |
< |
register RAY *r, |
569 |
< |
register CUBE *cu |
568 |
> |
RAY *r, |
569 |
> |
CUBE *cu |
570 |
|
) |
571 |
|
{ |
572 |
|
int ax; |
574 |
|
|
575 |
|
if (istree(cu->cutree)) { /* recurse on subcubes */ |
576 |
|
CUBE cukid; |
577 |
< |
register int br, sgn; |
577 |
> |
int br, sgn; |
578 |
|
|
579 |
|
cukid.cusize = cu->cusize * 0.5; /* find subcube */ |
580 |
|
VCOPY(cukid.cuorg, cu->cuorg); |
647 |
|
|
648 |
|
static int |
649 |
|
checkhit( /* check for hit in full cube */ |
650 |
< |
register RAY *r, |
650 |
> |
RAY *r, |
651 |
|
CUBE *cu, |
652 |
|
OBJECT *cxs |
653 |
|
) |
668 |
|
|
669 |
|
static void |
670 |
|
checkset( /* modify checked set and set to check */ |
671 |
< |
register OBJECT *os, /* os' = os - cs */ |
672 |
< |
register OBJECT *cs /* cs' = cs + os */ |
671 |
> |
OBJECT *os, /* os' = os - cs */ |
672 |
> |
OBJECT *cs /* cs' = cs + os */ |
673 |
|
) |
674 |
|
{ |
675 |
|
OBJECT cset[MAXCSET+MAXSET+1]; |
676 |
< |
register int i, j; |
676 |
> |
int i, j; |
677 |
|
int k; |
678 |
|
/* copy os in place, cset <- cs */ |
679 |
|
cset[0] = 0; |