| 1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 16 |
|
|
| 17 |
|
#include "otypes.h" |
| 18 |
|
|
| 19 |
+ |
#include "otspecial.h" |
| 20 |
+ |
|
| 21 |
|
extern CUBE thescene; /* our scene */ |
| 22 |
|
extern int maxdepth; /* maximum recursion depth */ |
| 23 |
|
extern double minweight; /* minimum ray weight */ |
| 24 |
+ |
extern int do_irrad; /* compute irradiance? */ |
| 25 |
|
|
| 26 |
< |
long nrays = 0L; /* number of rays traced */ |
| 26 |
> |
long raynum = 0L; /* next unique ray number */ |
| 27 |
> |
long nrays = 0L; /* number of calls to localhit */ |
| 28 |
|
|
| 29 |
+ |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
| 30 |
+ |
OBJREC Lamb = { |
| 31 |
+ |
OVOID, MAT_PLASTIC, "Lambertian", |
| 32 |
+ |
{0, 5, NULL, Lambfa}, NULL, -1, |
| 33 |
+ |
}; /* a Lambertian surface */ |
| 34 |
+ |
|
| 35 |
|
#define MAXLOOP 128 /* modifier loop detection */ |
| 36 |
|
|
| 37 |
|
#define RAYHIT (-1) /* return value for intercepted ray */ |
| 48 |
|
r->crtype = r->rtype = rt; |
| 49 |
|
r->rsrc = -1; |
| 50 |
|
r->clipset = NULL; |
| 51 |
+ |
r->revf = raytrace; |
| 52 |
|
} else { /* spawned ray */ |
| 53 |
|
r->rlvl = ro->rlvl; |
| 54 |
|
if (rt & RAYREFL) { |
| 59 |
|
r->rsrc = ro->rsrc; |
| 60 |
|
r->clipset = ro->newcset; |
| 61 |
|
} |
| 62 |
+ |
r->revf = ro->revf; |
| 63 |
|
r->rweight = ro->rweight * rw; |
| 64 |
|
r->crtype = ro->crtype | (r->rtype = rt); |
| 65 |
|
VCOPY(r->rorg, ro->rop); |
| 66 |
|
} |
| 67 |
< |
r->rno = nrays; |
| 67 |
> |
r->rno = raynum++; |
| 68 |
|
r->newcset = r->clipset; |
| 69 |
|
r->ro = NULL; |
| 70 |
|
r->rot = FHUGE; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
|
| 79 |
< |
rayvalue(r) /* compute a ray's value */ |
| 79 |
> |
raytrace(r) /* trace a ray and compute its value */ |
| 80 |
|
RAY *r; |
| 81 |
|
{ |
| 82 |
|
extern int (*trace)(); |
| 83 |
|
|
| 84 |
< |
if (localhit(r, &thescene) || sourcehit(r)) |
| 84 |
> |
if (localhit(r, &thescene)) |
| 85 |
|
raycont(r); |
| 86 |
+ |
else if (sourcehit(r)) |
| 87 |
+ |
rayshade(r, r->ro->omod); |
| 88 |
|
|
| 89 |
|
if (trace != NULL) |
| 90 |
|
(*trace)(r); /* trace execution */ |
| 124 |
|
/* check for infinite loop */ |
| 125 |
|
if (depth++ >= MAXLOOP) |
| 126 |
|
objerror(r->ro, USER, "possible modifier loop"); |
| 127 |
+ |
r->rt = r->rot; /* set effective ray length */ |
| 128 |
|
for ( ; mod != OVOID; mod = m->omod) { |
| 129 |
|
m = objptr(mod); |
| 130 |
|
/****** unnecessary test since modifier() is always called |
| 133 |
|
error(USER, errmsg); |
| 134 |
|
} |
| 135 |
|
******/ |
| 136 |
+ |
/* hack for irradiance calculation */ |
| 137 |
+ |
if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) { |
| 138 |
+ |
if (irr_ignore(m->otype)) { |
| 139 |
+ |
depth--; |
| 140 |
+ |
raytrans(r); |
| 141 |
+ |
return; |
| 142 |
+ |
} |
| 143 |
+ |
if (!islight(m->otype)) |
| 144 |
+ |
m = &Lamb; |
| 145 |
+ |
} |
| 146 |
|
(*ofun[m->otype].funp)(m, r); /* execute function */ |
| 147 |
|
m->lastrno = r->rno; |
| 148 |
|
if (ismaterial(m->otype)) { /* materials call raytexture */ |
| 258 |
|
} |
| 259 |
|
|
| 260 |
|
|
| 261 |
+ |
newrayxf(r) /* get new tranformation matrix for ray */ |
| 262 |
+ |
RAY *r; |
| 263 |
+ |
{ |
| 264 |
+ |
static struct xfn { |
| 265 |
+ |
struct xfn *next; |
| 266 |
+ |
FULLXF xf; |
| 267 |
+ |
} xfseed = { &xfseed }, *xflast = &xfseed; |
| 268 |
+ |
register struct xfn *xp; |
| 269 |
+ |
register RAY *rp; |
| 270 |
+ |
|
| 271 |
+ |
/* |
| 272 |
+ |
* Search for transform in circular list that |
| 273 |
+ |
* has no associated ray in the tree. |
| 274 |
+ |
*/ |
| 275 |
+ |
xp = xflast; |
| 276 |
+ |
for (rp = r->parent; rp != NULL; rp = rp->parent) |
| 277 |
+ |
if (rp->rox == &xp->xf) { /* xp in use */ |
| 278 |
+ |
xp = xp->next; /* move to next */ |
| 279 |
+ |
if (xp == xflast) { /* need new one */ |
| 280 |
+ |
xp = (struct xfn *)bmalloc(sizeof(struct xfn)); |
| 281 |
+ |
if (xp == NULL) |
| 282 |
+ |
error(SYSTEM, |
| 283 |
+ |
"out of memory in newrayxf"); |
| 284 |
+ |
/* insert in list */ |
| 285 |
+ |
xp->next = xflast->next; |
| 286 |
+ |
xflast->next = xp; |
| 287 |
+ |
break; /* we're done */ |
| 288 |
+ |
} |
| 289 |
+ |
rp = r; /* start check over */ |
| 290 |
+ |
} |
| 291 |
+ |
/* got it */ |
| 292 |
+ |
r->rox = &xp->xf; |
| 293 |
+ |
xflast = xp; |
| 294 |
+ |
} |
| 295 |
+ |
|
| 296 |
+ |
|
| 297 |
|
flipsurface(r) /* reverse surface orientation */ |
| 298 |
|
register RAY *r; |
| 299 |
|
{ |
| 317 |
|
register int i; |
| 318 |
|
|
| 319 |
|
nrays++; /* increment trace counter */ |
| 259 |
– |
|
| 320 |
|
sflags = 0; |
| 321 |
|
for (i = 0; i < 3; i++) { |
| 322 |
|
curpos[i] = r->rorg[i]; |
| 325 |
|
else if (r->rdir[i] < -FTINY) |
| 326 |
|
sflags |= 0x10 << i; |
| 327 |
|
} |
| 328 |
+ |
if (sflags == 0) |
| 329 |
+ |
error(CONSISTENCY, "zero ray direction in localhit"); |
| 330 |
|
t = 0.0; |
| 331 |
|
if (!incube(scene, curpos)) { |
| 332 |
|
/* find distance to entry */ |