1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Support routines for source objects and materials |
6 |
+ |
* |
7 |
+ |
* External symbols declared in source.h |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "copyright.h" |
11 |
+ |
|
12 |
|
#include "ray.h" |
13 |
|
|
14 |
|
#include "otypes.h" |
19 |
|
|
20 |
|
#include "face.h" |
21 |
|
|
22 |
< |
#define SRCINC 4 /* realloc increment for array */ |
22 |
> |
#define SRCINC 32 /* realloc increment for array */ |
23 |
|
|
24 |
|
SRCREC *source = NULL; /* our list of sources */ |
25 |
|
int nsources = 0; /* the number of sources */ |
27 |
|
SRCFUNC sfun[NUMOTYPE]; /* source dispatch table */ |
28 |
|
|
29 |
|
|
30 |
< |
initstypes() /* initialize source dispatch table */ |
30 |
> |
void |
31 |
> |
initstypes(void) /* initialize source dispatch table */ |
32 |
|
{ |
33 |
|
extern VSMATERIAL mirror_vs, direct1_vs, direct2_vs; |
32 |
– |
extern int fsetsrc(), ssetsrc(), sphsetsrc(), cylsetsrc(), rsetsrc(); |
33 |
– |
extern int nopart(), flatpart(), cylpart(); |
34 |
– |
extern double fgetplaneq(), rgetplaneq(); |
35 |
– |
extern double fgetmaxdisk(), rgetmaxdisk(); |
34 |
|
static SOBJECT fsobj = {fsetsrc, flatpart, fgetplaneq, fgetmaxdisk}; |
35 |
|
static SOBJECT ssobj = {ssetsrc, nopart}; |
36 |
|
static SOBJECT sphsobj = {sphsetsrc, nopart}; |
49 |
|
|
50 |
|
|
51 |
|
int |
52 |
< |
newsource() /* allocate new source in our array */ |
52 |
> |
newsource(void) /* allocate new source in our array */ |
53 |
|
{ |
54 |
|
if (nsources == 0) |
55 |
|
source = (SRCREC *)malloc(SRCINC*sizeof(SRCREC)); |
56 |
|
else if (nsources%SRCINC == 0) |
57 |
< |
source = (SRCREC *)realloc((char *)source, |
57 |
> |
source = (SRCREC *)realloc((void *)source, |
58 |
|
(unsigned)(nsources+SRCINC)*sizeof(SRCREC)); |
59 |
|
if (source == NULL) |
60 |
|
return(-1); |
61 |
|
source[nsources].sflags = 0; |
62 |
|
source[nsources].nhits = 1; |
63 |
< |
source[nsources].ntests = 2; /* initial hit probability = 1/2 */ |
63 |
> |
source[nsources].ntests = 2; /* initial hit probability = 50% */ |
64 |
> |
#if SHADCACHE |
65 |
> |
source[nsources].obscache = NULL; |
66 |
> |
#endif |
67 |
|
return(nsources++); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
< |
setflatss(src) /* set sampling for a flat source */ |
72 |
< |
register SRCREC *src; |
71 |
> |
void |
72 |
> |
setflatss( /* set sampling for a flat source */ |
73 |
> |
SRCREC *src |
74 |
> |
) |
75 |
|
{ |
76 |
|
double mult; |
77 |
< |
register int i; |
77 |
> |
int i; |
78 |
|
|
79 |
|
src->ss[SV][0] = src->ss[SV][1] = src->ss[SV][2] = 0.0; |
80 |
|
for (i = 0; i < 3; i++) |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
< |
fsetsrc(src, so) /* set a face as a source */ |
93 |
< |
register SRCREC *src; |
94 |
< |
OBJREC *so; |
92 |
> |
void |
93 |
> |
fsetsrc( /* set a face as a source */ |
94 |
> |
SRCREC *src, |
95 |
> |
OBJREC *so |
96 |
> |
) |
97 |
|
{ |
98 |
< |
register FACE *f; |
99 |
< |
register int i, j; |
98 |
> |
FACE *f; |
99 |
> |
int i, j; |
100 |
|
double d; |
101 |
|
|
102 |
|
src->sa.success = 2*AIMREQT-1; /* bitch on second failure */ |
103 |
|
src->so = so; |
104 |
|
/* get the face */ |
105 |
|
f = getface(so); |
106 |
+ |
if (f->area == 0.0) |
107 |
+ |
objerror(so, USER, "zero source area"); |
108 |
|
/* find the center */ |
109 |
|
for (j = 0; j < 3; j++) { |
110 |
|
src->sloc[j] = 0.0; |
113 |
|
src->sloc[j] /= (double)f->nv; |
114 |
|
} |
115 |
|
if (!inface(src->sloc, f)) |
116 |
< |
objerror(so, USER, "cannot hit center"); |
116 |
> |
objerror(so, USER, "cannot hit source center"); |
117 |
|
src->sflags |= SFLAT; |
118 |
|
VCOPY(src->snorm, f->norm); |
119 |
|
src->ss2 = f->area; |
126 |
|
} |
127 |
|
src->srad = sqrt(src->srad); |
128 |
|
/* compute size vectors */ |
129 |
< |
if (f->nv == 4 || (f->nv == 5 && /* parallelogram case */ |
123 |
< |
dist2(VERTEX(f,0),VERTEX(f,4)) <= FTINY*FTINY)) |
129 |
> |
if (f->nv == 4) /* parallelogram case */ |
130 |
|
for (j = 0; j < 3; j++) { |
131 |
|
src->ss[SU][j] = .5*(VERTEX(f,1)[j]-VERTEX(f,0)[j]); |
132 |
|
src->ss[SV][j] = .5*(VERTEX(f,3)[j]-VERTEX(f,0)[j]); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
< |
ssetsrc(src, so) /* set a source as a source */ |
140 |
< |
register SRCREC *src; |
141 |
< |
register OBJREC *so; |
139 |
> |
void |
140 |
> |
ssetsrc( /* set a source as a source */ |
141 |
> |
SRCREC *src, |
142 |
> |
OBJREC *so |
143 |
> |
) |
144 |
|
{ |
145 |
|
double theta; |
146 |
|
|
148 |
|
src->so = so; |
149 |
|
if (so->oargs.nfargs != 4) |
150 |
|
objerror(so, USER, "bad arguments"); |
151 |
< |
src->sflags |= SDISTANT; |
151 |
> |
src->sflags |= (SDISTANT|SCIR); |
152 |
|
VCOPY(src->sloc, so->oargs.farg); |
153 |
|
if (normalize(src->sloc) == 0.0) |
154 |
|
objerror(so, USER, "zero direction"); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
< |
sphsetsrc(src, so) /* set a sphere as a source */ |
168 |
< |
register SRCREC *src; |
169 |
< |
register OBJREC *so; |
167 |
> |
void |
168 |
> |
sphsetsrc( /* set a sphere as a source */ |
169 |
> |
SRCREC *src, |
170 |
> |
OBJREC *so |
171 |
> |
) |
172 |
|
{ |
173 |
< |
register int i; |
173 |
> |
int i; |
174 |
|
|
175 |
|
src->sa.success = 2*AIMREQT-1; /* bitch on second failure */ |
176 |
|
src->so = so; |
177 |
|
if (so->oargs.nfargs != 4) |
178 |
|
objerror(so, USER, "bad # arguments"); |
179 |
|
if (so->oargs.farg[3] <= FTINY) |
180 |
< |
objerror(so, USER, "illegal radius"); |
180 |
> |
objerror(so, USER, "illegal source radius"); |
181 |
> |
src->sflags |= SCIR; |
182 |
|
VCOPY(src->sloc, so->oargs.farg); |
183 |
|
src->srad = so->oargs.farg[3]; |
184 |
|
src->ss2 = PI * src->srad * src->srad; |
185 |
|
for (i = 0; i < 3; i++) |
186 |
|
src->ss[SU][i] = src->ss[SV][i] = src->ss[SW][i] = 0.0; |
187 |
|
for (i = 0; i < 3; i++) |
188 |
< |
src->ss[i][i] = .7236 * so->oargs.farg[3]; |
188 |
> |
src->ss[i][i] = 0.7236 * so->oargs.farg[3]; |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
< |
rsetsrc(src, so) /* set a ring (disk) as a source */ |
193 |
< |
register SRCREC *src; |
194 |
< |
OBJREC *so; |
192 |
> |
void |
193 |
> |
rsetsrc( /* set a ring (disk) as a source */ |
194 |
> |
SRCREC *src, |
195 |
> |
OBJREC *so |
196 |
> |
) |
197 |
|
{ |
198 |
< |
register CONE *co; |
198 |
> |
CONE *co; |
199 |
|
|
200 |
|
src->sa.success = 2*AIMREQT-1; /* bitch on second failure */ |
201 |
|
src->so = so; |
202 |
|
/* get the ring */ |
203 |
|
co = getcone(so, 0); |
204 |
+ |
if (CO_R1(co) <= FTINY) |
205 |
+ |
objerror(so, USER, "illegal source radius"); |
206 |
|
VCOPY(src->sloc, CO_P0(co)); |
207 |
|
if (CO_R0(co) > 0.0) |
208 |
< |
objerror(so, USER, "cannot hit center"); |
209 |
< |
src->sflags |= SFLAT; |
208 |
> |
objerror(so, USER, "cannot hit source center"); |
209 |
> |
src->sflags |= (SFLAT|SCIR); |
210 |
|
VCOPY(src->snorm, co->ad); |
211 |
|
src->srad = CO_R1(co); |
212 |
|
src->ss2 = PI * src->srad * src->srad; |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
< |
cylsetsrc(src, so) /* set a cylinder as a source */ |
218 |
< |
register SRCREC *src; |
219 |
< |
OBJREC *so; |
217 |
> |
void |
218 |
> |
cylsetsrc( /* set a cylinder as a source */ |
219 |
> |
SRCREC *src, |
220 |
> |
OBJREC *so |
221 |
> |
) |
222 |
|
{ |
223 |
< |
register CONE *co; |
224 |
< |
register int i; |
223 |
> |
CONE *co; |
224 |
> |
int i; |
225 |
|
|
226 |
|
src->sa.success = 4*AIMREQT-1; /* bitch on fourth failure */ |
227 |
|
src->so = so; |
228 |
|
/* get the cylinder */ |
229 |
|
co = getcone(so, 0); |
230 |
+ |
if (CO_R0(co) <= FTINY) |
231 |
+ |
objerror(so, USER, "illegal source radius"); |
232 |
|
if (CO_R0(co) > .2*co->al) /* heuristic constraint */ |
233 |
|
objerror(so, WARNING, "source aspect too small"); |
234 |
|
src->sflags |= SCYL; |
253 |
|
|
254 |
|
|
255 |
|
SPOT * |
256 |
< |
makespot(m) /* make a spotlight */ |
257 |
< |
register OBJREC *m; |
256 |
> |
makespot( /* make a spotlight */ |
257 |
> |
OBJREC *m |
258 |
> |
) |
259 |
|
{ |
260 |
< |
register SPOT *ns; |
260 |
> |
SPOT *ns; |
261 |
|
|
262 |
+ |
if ((ns = (SPOT *)m->os) != NULL) |
263 |
+ |
return(ns); |
264 |
|
if ((ns = (SPOT *)malloc(sizeof(SPOT))) == NULL) |
265 |
|
return(NULL); |
266 |
+ |
if (m->oargs.farg[3] <= FTINY) |
267 |
+ |
objerror(m, USER, "zero angle"); |
268 |
|
ns->siz = 2.0*PI * (1.0 - cos(PI/180.0/2.0 * m->oargs.farg[3])); |
269 |
|
VCOPY(ns->aim, m->oargs.farg+4); |
270 |
|
if ((ns->flen = normalize(ns->aim)) == 0.0) |
271 |
|
objerror(m, USER, "zero focus vector"); |
272 |
+ |
m->os = (char *)ns; |
273 |
|
return(ns); |
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
+ |
int |
278 |
+ |
spotout( /* check if we're outside spot region */ |
279 |
+ |
RAY *r, |
280 |
+ |
SPOT *s |
281 |
+ |
) |
282 |
+ |
{ |
283 |
+ |
double d; |
284 |
+ |
FVECT vd; |
285 |
+ |
|
286 |
+ |
if (s == NULL) |
287 |
+ |
return(0); |
288 |
+ |
if (s->flen < -FTINY) { /* distant source */ |
289 |
+ |
vd[0] = s->aim[0] - r->rorg[0]; |
290 |
+ |
vd[1] = s->aim[1] - r->rorg[1]; |
291 |
+ |
vd[2] = s->aim[2] - r->rorg[2]; |
292 |
+ |
d = DOT(r->rdir,vd); |
293 |
+ |
/* wrong side? |
294 |
+ |
if (d <= FTINY) |
295 |
+ |
return(1); */ |
296 |
+ |
d = DOT(vd,vd) - d*d; |
297 |
+ |
if (PI*d > s->siz) |
298 |
+ |
return(1); /* out */ |
299 |
+ |
return(0); /* OK */ |
300 |
+ |
} |
301 |
+ |
/* local source */ |
302 |
+ |
if (s->siz < 2.0*PI * (1.0 + DOT(s->aim,r->rdir))) |
303 |
+ |
return(1); /* out */ |
304 |
+ |
return(0); /* OK */ |
305 |
+ |
} |
306 |
+ |
|
307 |
+ |
|
308 |
|
double |
309 |
< |
fgetmaxdisk(ocent, op) /* get center and squared radius of face */ |
310 |
< |
FVECT ocent; |
311 |
< |
OBJREC *op; |
309 |
> |
fgetmaxdisk( /* get center and squared radius of face */ |
310 |
> |
FVECT ocent, |
311 |
> |
OBJREC *op |
312 |
> |
) |
313 |
|
{ |
314 |
|
double maxrad2; |
315 |
|
double d; |
316 |
< |
register int i, j; |
317 |
< |
register FACE *f; |
316 |
> |
int i, j; |
317 |
> |
FACE *f; |
318 |
|
|
319 |
|
f = getface(op); |
320 |
|
if (f->area == 0.) |
339 |
|
|
340 |
|
|
341 |
|
double |
342 |
< |
rgetmaxdisk(ocent, op) /* get center and squared radius of ring */ |
343 |
< |
FVECT ocent; |
344 |
< |
OBJREC *op; |
342 |
> |
rgetmaxdisk( /* get center and squared radius of ring */ |
343 |
> |
FVECT ocent, |
344 |
> |
OBJREC *op |
345 |
> |
) |
346 |
|
{ |
347 |
< |
register CONE *co; |
347 |
> |
CONE *co; |
348 |
|
|
349 |
|
co = getcone(op, 0); |
350 |
|
VCOPY(ocent, CO_P0(co)); |
353 |
|
|
354 |
|
|
355 |
|
double |
356 |
< |
fgetplaneq(nvec, op) /* get plane equation for face */ |
357 |
< |
FVECT nvec; |
358 |
< |
OBJREC *op; |
356 |
> |
fgetplaneq( /* get plane equation for face */ |
357 |
> |
FVECT nvec, |
358 |
> |
OBJREC *op |
359 |
> |
) |
360 |
|
{ |
361 |
< |
register FACE *fo; |
361 |
> |
FACE *fo; |
362 |
|
|
363 |
|
fo = getface(op); |
364 |
|
VCOPY(nvec, fo->norm); |
367 |
|
|
368 |
|
|
369 |
|
double |
370 |
< |
rgetplaneq(nvec, op) /* get plane equation for ring */ |
371 |
< |
FVECT nvec; |
372 |
< |
OBJREC *op; |
370 |
> |
rgetplaneq( /* get plane equation for ring */ |
371 |
> |
FVECT nvec, |
372 |
> |
OBJREC *op |
373 |
> |
) |
374 |
|
{ |
375 |
< |
register CONE *co; |
375 |
> |
CONE *co; |
376 |
|
|
377 |
|
co = getcone(op, 0); |
378 |
|
VCOPY(nvec, co->ad); |
380 |
|
} |
381 |
|
|
382 |
|
|
383 |
< |
commonspot(sp1, sp2, org) /* set sp1 to intersection of sp1 and sp2 */ |
384 |
< |
register SPOT *sp1, *sp2; |
385 |
< |
FVECT org; |
383 |
> |
int |
384 |
> |
commonspot( /* set sp1 to intersection of sp1 and sp2 */ |
385 |
> |
SPOT *sp1, |
386 |
> |
SPOT *sp2, |
387 |
> |
FVECT org |
388 |
> |
) |
389 |
|
{ |
390 |
|
FVECT cent; |
391 |
|
double rad2, cos1, cos2; |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
< |
commonbeam(sp1, sp2, dir) /* set sp1 to intersection of sp1 and sp2 */ |
410 |
< |
register SPOT *sp1, *sp2; |
411 |
< |
FVECT dir; |
409 |
> |
int |
410 |
> |
commonbeam( /* set sp1 to intersection of sp1 and sp2 */ |
411 |
> |
SPOT *sp1, |
412 |
> |
SPOT *sp2, |
413 |
> |
FVECT dir |
414 |
> |
) |
415 |
|
{ |
416 |
|
FVECT cent, c1, c2; |
417 |
|
double rad2, d; |
352 |
– |
register int i; |
418 |
|
/* move centers to common plane */ |
419 |
|
d = DOT(sp1->aim, dir); |
420 |
< |
for (i = 0; i < 3; i++) |
356 |
< |
c1[i] = sp1->aim[i] - d*dir[i]; |
420 |
> |
VSUM(c1, sp1->aim, dir, -d); |
421 |
|
d = DOT(sp2->aim, dir); |
422 |
< |
for (i = 0; i < 3; i++) |
359 |
< |
c2[i] = sp2->aim[i] - d*dir[i]; |
422 |
> |
VSUM(c2, sp2->aim, dir, -d); |
423 |
|
/* compute overlap */ |
424 |
|
rad2 = intercircle(cent, c1, c2, sp1->siz/PI, sp2->siz/PI); |
425 |
|
if (rad2 <= FTINY) |
430 |
|
} |
431 |
|
|
432 |
|
|
433 |
< |
checkspot(sp, nrm) /* check spotlight for behind source */ |
434 |
< |
register SPOT *sp; /* spotlight */ |
435 |
< |
FVECT nrm; /* source surface normal */ |
433 |
> |
int |
434 |
> |
checkspot( /* check spotlight for behind source */ |
435 |
> |
SPOT *sp, /* spotlight */ |
436 |
> |
FVECT nrm /* source surface normal */ |
437 |
> |
) |
438 |
|
{ |
439 |
|
double d, d1; |
440 |
|
|
448 |
|
|
449 |
|
|
450 |
|
double |
451 |
< |
spotdisk(oc, op, sp, pos) /* intersect spot with object op */ |
452 |
< |
FVECT oc; |
453 |
< |
OBJREC *op; |
454 |
< |
register SPOT *sp; |
455 |
< |
FVECT pos; |
451 |
> |
spotdisk( /* intersect spot with object op */ |
452 |
> |
FVECT oc, |
453 |
> |
OBJREC *op, |
454 |
> |
SPOT *sp, |
455 |
> |
FVECT pos |
456 |
> |
) |
457 |
|
{ |
458 |
|
FVECT onorm; |
459 |
|
double offs, d, dist; |
394 |
– |
register int i; |
460 |
|
|
461 |
|
offs = getplaneq(onorm, op); |
462 |
|
d = -DOT(onorm, sp->aim); |
465 |
|
dist = (DOT(pos, onorm) - offs)/d; |
466 |
|
if (dist < 0.) |
467 |
|
return(0.); |
468 |
< |
for (i = 0; i < 3; i++) |
404 |
< |
oc[i] = pos[i] + dist*sp->aim[i]; |
468 |
> |
VSUM(oc, pos, sp->aim, dist); |
469 |
|
return(sp->siz*dist*dist/PI/(d*d)); |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
double |
474 |
< |
beamdisk(oc, op, sp, dir) /* intersect beam with object op */ |
475 |
< |
FVECT oc; |
476 |
< |
OBJREC *op; |
477 |
< |
register SPOT *sp; |
478 |
< |
FVECT dir; |
474 |
> |
beamdisk( /* intersect beam with object op */ |
475 |
> |
FVECT oc, |
476 |
> |
OBJREC *op, |
477 |
> |
SPOT *sp, |
478 |
> |
FVECT dir |
479 |
> |
) |
480 |
|
{ |
481 |
|
FVECT onorm; |
482 |
|
double offs, d, dist; |
418 |
– |
register int i; |
483 |
|
|
484 |
|
offs = getplaneq(onorm, op); |
485 |
|
d = -DOT(onorm, dir); |
486 |
|
if (d >= -FTINY && d <= FTINY) |
487 |
|
return(0.); |
488 |
|
dist = (DOT(sp->aim, onorm) - offs)/d; |
489 |
< |
for (i = 0; i < 3; i++) |
426 |
< |
oc[i] = sp->aim[i] + dist*dir[i]; |
489 |
> |
VSUM(oc, sp->aim, dir, dist); |
490 |
|
return(sp->siz/PI/(d*d)); |
491 |
|
} |
492 |
|
|
493 |
|
|
494 |
|
double |
495 |
< |
intercircle(cc, c1, c2, r1s, r2s) /* intersect two circles */ |
496 |
< |
FVECT cc; /* midpoint (return value) */ |
497 |
< |
FVECT c1, c2; /* circle centers */ |
498 |
< |
double r1s, r2s; /* radii squared */ |
495 |
> |
intercircle( /* intersect two circles */ |
496 |
> |
FVECT cc, /* midpoint (return value) */ |
497 |
> |
FVECT c1, /* circle centers */ |
498 |
> |
FVECT c2, |
499 |
> |
double r1s, /* radii squared */ |
500 |
> |
double r2s |
501 |
> |
) |
502 |
|
{ |
503 |
|
double a2, d2, l; |
504 |
|
FVECT disp; |
439 |
– |
register int i; |
505 |
|
|
506 |
< |
for (i = 0; i < 3; i++) |
442 |
< |
disp[i] = c2[i] - c1[i]; |
506 |
> |
VSUB(disp, c2, c1); |
507 |
|
d2 = DOT(disp,disp); |
508 |
|
/* circle within overlap? */ |
509 |
|
if (r1s < r2s) { |
523 |
|
return(0.); |
524 |
|
/* overlap, compute center */ |
525 |
|
l = sqrt((r1s - a2)/d2); |
526 |
< |
for (i = 0; i < 3; i++) |
463 |
< |
cc[i] = c1[i] + l*disp[i]; |
526 |
> |
VSUM(cc, c1, disp, l); |
527 |
|
return(a2); |
465 |
– |
} |
466 |
– |
|
467 |
– |
|
468 |
– |
sourcehit(r) /* check to see if ray hit distant source */ |
469 |
– |
register RAY *r; |
470 |
– |
{ |
471 |
– |
int first, last; |
472 |
– |
register int i; |
473 |
– |
|
474 |
– |
if (r->rsrc >= 0) { /* check only one if aimed */ |
475 |
– |
first = last = r->rsrc; |
476 |
– |
} else { /* otherwise check all */ |
477 |
– |
first = 0; last = nsources-1; |
478 |
– |
} |
479 |
– |
for (i = first; i <= last; i++) |
480 |
– |
if ((source[i].sflags & (SDISTANT|SVIRTUAL)) == SDISTANT) |
481 |
– |
/* |
482 |
– |
* Check to see if ray is within |
483 |
– |
* solid angle of source. |
484 |
– |
*/ |
485 |
– |
if (2.0*PI * (1.0 - DOT(source[i].sloc,r->rdir)) |
486 |
– |
<= source[i].ss2) { |
487 |
– |
r->ro = source[i].so; |
488 |
– |
if (!(source[i].sflags & SSKIP)) |
489 |
– |
break; |
490 |
– |
} |
491 |
– |
|
492 |
– |
if (r->ro != NULL) { |
493 |
– |
for (i = 0; i < 3; i++) |
494 |
– |
r->ron[i] = -r->rdir[i]; |
495 |
– |
r->rod = 1.0; |
496 |
– |
r->rox = NULL; |
497 |
– |
return(1); |
498 |
– |
} |
499 |
– |
return(0); |
500 |
– |
} |
501 |
– |
|
502 |
– |
|
503 |
– |
#define wrongsource(m, r) (r->rsrc>=0 && \ |
504 |
– |
source[r->rsrc].so!=r->ro && \ |
505 |
– |
(m->otype!=MAT_ILLUM || \ |
506 |
– |
objptr(source[r->rsrc].so->omod)->otype==MAT_ILLUM)) |
507 |
– |
|
508 |
– |
#define distglow(m, r) (m->otype==MAT_GLOW && \ |
509 |
– |
r->rot > m->oargs.farg[3]) |
510 |
– |
|
511 |
– |
#define badambient(m, r) ((r->crtype&(AMBIENT|SHADOW))==AMBIENT && \ |
512 |
– |
!distglow(m, r)) |
513 |
– |
|
514 |
– |
#define passillum(m, r) (m->otype==MAT_ILLUM && \ |
515 |
– |
!(r->rsrc>=0&&source[r->rsrc].so==r->ro)) |
516 |
– |
|
517 |
– |
#define srcignore(m, r) (directinvis && !(r->crtype&SHADOW) && \ |
518 |
– |
!distglow(m, r)) |
519 |
– |
|
520 |
– |
|
521 |
– |
m_light(m, r) /* ray hit a light source */ |
522 |
– |
register OBJREC *m; |
523 |
– |
register RAY *r; |
524 |
– |
{ |
525 |
– |
/* check for over-counting */ |
526 |
– |
if (wrongsource(m, r) || badambient(m, r)) |
527 |
– |
return; |
528 |
– |
/* check for passed illum */ |
529 |
– |
if (passillum(m, r)) { |
530 |
– |
if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID)) |
531 |
– |
raytrans(r); |
532 |
– |
else |
533 |
– |
rayshade(r, modifier(m->oargs.sarg[0])); |
534 |
– |
return; |
535 |
– |
} |
536 |
– |
/* otherwise treat as source */ |
537 |
– |
/* check for behind */ |
538 |
– |
if (r->rod < 0.0) |
539 |
– |
return; |
540 |
– |
/* check for invisibility */ |
541 |
– |
if (srcignore(m, r)) |
542 |
– |
return; |
543 |
– |
/* get distribution pattern */ |
544 |
– |
raytexture(r, m->omod); |
545 |
– |
/* get source color */ |
546 |
– |
setcolor(r->rcol, m->oargs.farg[0], |
547 |
– |
m->oargs.farg[1], |
548 |
– |
m->oargs.farg[2]); |
549 |
– |
/* modify value */ |
550 |
– |
multcolor(r->rcol, r->pcol); |
528 |
|
} |