| 1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1994 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 34 |
|
{0, 5, NULL, Lambfa}, NULL, |
| 35 |
|
}; /* a Lambertian surface */ |
| 36 |
|
|
| 37 |
+ |
OBJREC Aftplane; /* aft clipping plane object */ |
| 38 |
+ |
|
| 39 |
|
static int raymove(), checkset(), checkhit(); |
| 40 |
|
|
| 41 |
|
#define MAXLOOP 128 /* modifier loop detection */ |
| 69 |
|
r->rweight = ro->rweight * rw; |
| 70 |
|
r->crtype = ro->crtype | (r->rtype = rt); |
| 71 |
|
VCOPY(r->rorg, ro->rop); |
| 72 |
+ |
r->rmax = 0.0; |
| 73 |
|
} |
| 74 |
|
rayclear(r); |
| 75 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
| 94 |
|
RAY *r; |
| 95 |
|
{ |
| 96 |
|
extern int (*trace)(); |
| 97 |
+ |
int gotmat; |
| 98 |
|
|
| 99 |
|
if (localhit(r, &thescene)) |
| 100 |
< |
raycont(r); |
| 101 |
< |
else if (sourcehit(r)) |
| 102 |
< |
rayshade(r, r->ro->omod); |
| 100 |
> |
gotmat = raycont(r); |
| 101 |
> |
else if (r->ro == &Aftplane) { |
| 102 |
> |
r->ro = NULL; |
| 103 |
> |
r->rot = FHUGE; |
| 104 |
> |
} else if (sourcehit(r)) |
| 105 |
> |
gotmat = rayshade(r, r->ro->omod); |
| 106 |
|
|
| 107 |
+ |
if (r->ro != NULL && !gotmat) |
| 108 |
+ |
objerror(r->ro, USER, "material not found"); |
| 109 |
+ |
|
| 110 |
|
if (trace != NULL) |
| 111 |
|
(*trace)(r); /* trace execution */ |
| 112 |
|
} |
| 116 |
|
register RAY *r; |
| 117 |
|
{ |
| 118 |
|
if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || |
| 119 |
< |
r->ro->omod == OVOID) |
| 119 |
> |
r->ro->omod == OVOID) { |
| 120 |
|
raytrans(r); |
| 121 |
< |
else |
| 122 |
< |
rayshade(r, r->ro->omod); |
| 121 |
> |
return(1); |
| 122 |
> |
} |
| 123 |
> |
return(rayshade(r, r->ro->omod)); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 131 |
|
|
| 132 |
|
if (rayorigin(&tr, r, TRANS, 1.0) == 0) { |
| 133 |
|
VCOPY(tr.rdir, r->rdir); |
| 134 |
+ |
if (r->rmax > FTINY) |
| 135 |
+ |
tr.rmax = r->rmax - r->rot; |
| 136 |
|
rayvalue(&tr); |
| 137 |
|
copycolor(r->rcol, tr.rcol); |
| 138 |
|
r->rt = r->rot + tr.rt; |
| 145 |
|
int mod; |
| 146 |
|
{ |
| 147 |
|
static int depth = 0; |
| 148 |
+ |
int gotmat; |
| 149 |
|
register OBJREC *m; |
| 150 |
|
/* check for infinite loop */ |
| 151 |
|
if (depth++ >= MAXLOOP) |
| 152 |
|
objerror(r->ro, USER, "possible modifier loop"); |
| 153 |
|
r->rt = r->rot; /* set effective ray length */ |
| 154 |
< |
for ( ; mod != OVOID; mod = m->omod) { |
| 154 |
> |
for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) { |
| 155 |
|
m = objptr(mod); |
| 156 |
|
/****** unnecessary test since modifier() is always called |
| 157 |
|
if (!ismodifier(m->otype)) { |
| 164 |
|
if (irr_ignore(m->otype)) { |
| 165 |
|
depth--; |
| 166 |
|
raytrans(r); |
| 167 |
< |
return; |
| 167 |
> |
return(1); |
| 168 |
|
} |
| 169 |
|
if (!islight(m->otype)) |
| 170 |
|
m = &Lamb; |
| 171 |
|
} |
| 172 |
< |
(*ofun[m->otype].funp)(m, r); /* execute function */ |
| 173 |
< |
if (ismaterial(m->otype)) { /* materials call raytexture */ |
| 160 |
< |
depth--; |
| 161 |
< |
return; /* we're done */ |
| 162 |
< |
} |
| 172 |
> |
/* materials call raytexture */ |
| 173 |
> |
gotmat = (*ofun[m->otype].funp)(m, r); |
| 174 |
|
} |
| 175 |
< |
objerror(r->ro, USER, "material not found"); |
| 175 |
> |
depth--; |
| 176 |
> |
return(gotmat); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
|
| 189 |
|
/* execute textures and patterns */ |
| 190 |
|
for ( ; mod != OVOID; mod = m->omod) { |
| 191 |
|
m = objptr(mod); |
| 192 |
< |
if (!istexture(m->otype)) { |
| 192 |
> |
/****** unnecessary test since modifier() is always called |
| 193 |
> |
if (!ismodifier(m->otype)) { |
| 194 |
|
sprintf(errmsg, "illegal modifier \"%s\"", m->oname); |
| 195 |
|
error(USER, errmsg); |
| 196 |
|
} |
| 197 |
< |
(*ofun[m->otype].funp)(m, r); |
| 197 |
> |
******/ |
| 198 |
> |
if ((*ofun[m->otype].funp)(m, r)) |
| 199 |
> |
objerror(r->ro, USER, "conflicting materials"); |
| 200 |
|
} |
| 201 |
|
depth--; /* end here */ |
| 202 |
|
} |
| 207 |
|
OBJECT fore, back; |
| 208 |
|
double coef; |
| 209 |
|
{ |
| 210 |
< |
FVECT curpert, forepert, backpert; |
| 211 |
< |
COLOR curpcol, forepcol, backpcol; |
| 210 |
> |
RAY fr, br; |
| 211 |
> |
int foremat, backmat; |
| 212 |
|
register int i; |
| 213 |
|
/* clip coefficient */ |
| 214 |
|
if (coef > 1.0) |
| 215 |
|
coef = 1.0; |
| 216 |
|
else if (coef < 0.0) |
| 217 |
|
coef = 0.0; |
| 218 |
< |
/* save current mods */ |
| 219 |
< |
VCOPY(curpert, r->pert); |
| 220 |
< |
copycolor(curpcol, r->pcol); |
| 221 |
< |
/* compute new mods */ |
| 207 |
< |
/* foreground */ |
| 208 |
< |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
| 209 |
< |
setcolor(r->pcol, 1.0, 1.0, 1.0); |
| 218 |
> |
/* compute foreground and background */ |
| 219 |
> |
foremat = backmat = -1; |
| 220 |
> |
/* foreground */ |
| 221 |
> |
copystruct(&fr, r); |
| 222 |
|
if (fore != OVOID && coef > FTINY) |
| 223 |
< |
raytexture(r, fore); |
| 224 |
< |
VCOPY(forepert, r->pert); |
| 225 |
< |
copycolor(forepcol, r->pcol); |
| 214 |
< |
/* background */ |
| 215 |
< |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
| 216 |
< |
setcolor(r->pcol, 1.0, 1.0, 1.0); |
| 223 |
> |
foremat = rayshade(&fr, fore); |
| 224 |
> |
/* background */ |
| 225 |
> |
copystruct(&br, r); |
| 226 |
|
if (back != OVOID && coef < 1.0-FTINY) |
| 227 |
< |
raytexture(r, back); |
| 228 |
< |
VCOPY(backpert, r->pert); |
| 229 |
< |
copycolor(backpcol, r->pcol); |
| 230 |
< |
/* sum perturbations */ |
| 227 |
> |
backmat = rayshade(&br, back); |
| 228 |
> |
/* check */ |
| 229 |
> |
if (foremat < 0) |
| 230 |
> |
if (backmat < 0) |
| 231 |
> |
foremat = backmat = 0; |
| 232 |
> |
else |
| 233 |
> |
foremat = backmat; |
| 234 |
> |
else if (backmat < 0) |
| 235 |
> |
backmat = foremat; |
| 236 |
> |
if ((foremat==0) != (backmat==0)) |
| 237 |
> |
objerror(r->ro, USER, "mixing material with non-material"); |
| 238 |
> |
/* mix perturbations */ |
| 239 |
|
for (i = 0; i < 3; i++) |
| 240 |
< |
r->pert[i] = curpert[i] + coef*forepert[i] + |
| 241 |
< |
(1.0-coef)*backpert[i]; |
| 242 |
< |
/* multiply colors */ |
| 243 |
< |
setcolor(r->pcol, coef*colval(forepcol,RED) + |
| 244 |
< |
(1.0-coef)*colval(backpcol,RED), |
| 245 |
< |
coef*colval(forepcol,GRN) + |
| 246 |
< |
(1.0-coef)*colval(backpcol,GRN), |
| 247 |
< |
coef*colval(forepcol,BLU) + |
| 248 |
< |
(1.0-coef)*colval(backpcol,BLU)); |
| 249 |
< |
multcolor(r->pcol, curpcol); |
| 240 |
> |
r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i]; |
| 241 |
> |
/* mix pattern colors */ |
| 242 |
> |
scalecolor(fr.pcol, coef); |
| 243 |
> |
scalecolor(br.pcol, 1.0-coef); |
| 244 |
> |
copycolor(r->pcol, fr.pcol); |
| 245 |
> |
addcolor(r->pcol, br.pcol); |
| 246 |
> |
/* mix returned ray values */ |
| 247 |
> |
if (foremat) { |
| 248 |
> |
scalecolor(fr.rcol, coef); |
| 249 |
> |
scalecolor(br.rcol, 1.0-coef); |
| 250 |
> |
copycolor(r->rcol, fr.rcol); |
| 251 |
> |
addcolor(r->rcol, br.rcol); |
| 252 |
> |
r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt; |
| 253 |
> |
} |
| 254 |
> |
/* return value tells if material */ |
| 255 |
> |
return(foremat); |
| 256 |
|
} |
| 257 |
|
|
| 258 |
|
|
| 361 |
|
} |
| 362 |
|
if (sflags == 0) |
| 363 |
|
error(CONSISTENCY, "zero ray direction in localhit"); |
| 364 |
+ |
/* start off assuming nothing hit */ |
| 365 |
+ |
if (r->rmax > FTINY) { /* except aft plane if one */ |
| 366 |
+ |
r->ro = &Aftplane; |
| 367 |
+ |
r->rot = r->rmax; |
| 368 |
+ |
for (i = 0; i < 3; i++) |
| 369 |
+ |
r->rop[i] = r->rorg[i] + r->rot*r->rdir[i]; |
| 370 |
+ |
} |
| 371 |
+ |
/* find global cube entrance point */ |
| 372 |
|
t = 0.0; |
| 373 |
|
if (!incube(scene, curpos)) { |
| 374 |
|
/* find distance to entry */ |
| 386 |
|
t = dt; /* farthest face is the one */ |
| 387 |
|
} |
| 388 |
|
t += FTINY; /* fudge to get inside cube */ |
| 389 |
+ |
if (t >= r->rot) /* clipped already */ |
| 390 |
+ |
return(0); |
| 391 |
|
/* advance position */ |
| 392 |
|
for (i = 0; i < 3; i++) |
| 393 |
|
curpos[i] += r->rdir[i]*t; |
| 396 |
|
return(0); |
| 397 |
|
} |
| 398 |
|
cxset[0] = 0; |
| 399 |
< |
return(raymove(curpos, cxset, sflags, r, scene) == RAYHIT); |
| 399 |
> |
return(raymove(curpos, cxset, sflags, r, scene) == RAYHIT && |
| 400 |
> |
r->ro != &Aftplane); |
| 401 |
|
} |
| 402 |
|
|
| 403 |
|
|