1 |
– |
/* Copyright (c) 1986 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 |
|
* source.c - routines dealing with illumination sources. |
6 |
|
* |
7 |
< |
* 8/20/85 |
7 |
> |
* External symbols declared in source.h |
8 |
|
*/ |
9 |
|
|
10 |
|
#include "ray.h" |
11 |
+ |
#include "otypes.h" |
12 |
+ |
#include "rtotypes.h" |
13 |
+ |
#include "source.h" |
14 |
+ |
#include "random.h" |
15 |
|
|
16 |
< |
#include "octree.h" |
16 |
> |
extern double ssampdist; /* scatter sampling distance */ |
17 |
|
|
18 |
< |
#include "source.h" |
18 |
> |
#ifndef MAXSSAMP |
19 |
> |
#define MAXSSAMP 16 /* maximum samples per ray */ |
20 |
> |
#endif |
21 |
|
|
22 |
< |
#include "otypes.h" |
22 |
> |
/* |
23 |
> |
* Structures used by direct() |
24 |
> |
*/ |
25 |
|
|
26 |
< |
#include "cone.h" |
26 |
> |
typedef struct { |
27 |
> |
int sno; /* source number */ |
28 |
> |
FVECT dir; /* source direction */ |
29 |
> |
COLOR coef; /* material coefficient */ |
30 |
> |
COLOR val; /* contribution */ |
31 |
> |
} CONTRIB; /* direct contribution */ |
32 |
|
|
33 |
< |
#include "face.h" |
33 |
> |
typedef struct { |
34 |
> |
int sndx; /* source index (to CONTRIB array) */ |
35 |
> |
float brt; /* brightness (for comparison) */ |
36 |
> |
} CNTPTR; /* contribution pointer */ |
37 |
|
|
38 |
< |
#include "random.h" |
38 |
> |
static CONTRIB *srccnt; /* source contributions in direct() */ |
39 |
> |
static CNTPTR *cntord; /* source ordering in direct() */ |
40 |
> |
static int maxcntr = 0; /* size of contribution arrays */ |
41 |
|
|
42 |
+ |
static int cntcmp(const void *p1, const void *p2); |
43 |
|
|
28 |
– |
extern double dstrsrc; /* source distribution amount */ |
29 |
– |
extern double shadthresh; /* relative shadow threshold */ |
30 |
– |
extern double shadcert; /* shadow testing certainty */ |
44 |
|
|
45 |
< |
SRCREC *source = NULL; /* our list of sources */ |
46 |
< |
int nsources = 0; /* the number of sources */ |
45 |
> |
extern OBJREC * /* find an object's actual material */ |
46 |
> |
findmaterial(register OBJREC *o) |
47 |
> |
{ |
48 |
> |
while (!ismaterial(o->otype)) { |
49 |
> |
if (ismixture(o->otype)) |
50 |
> |
return(NULL); /* reject mixed materials */ |
51 |
> |
if (o->otype == MOD_ALIAS && o->oargs.nsargs) { |
52 |
> |
OBJECT aobj; |
53 |
> |
OBJREC *ao; |
54 |
> |
aobj = lastmod(objndx(o), o->oargs.sarg[0]); |
55 |
> |
if (aobj < 0) |
56 |
> |
objerror(o, USER, "bad reference"); |
57 |
> |
ao = objptr(aobj); |
58 |
> |
if (ismaterial(ao->otype)) |
59 |
> |
return(ao); |
60 |
> |
} |
61 |
> |
if (o->omod == OVOID) |
62 |
> |
return(NULL); |
63 |
> |
o = objptr(o->omod); |
64 |
> |
} |
65 |
> |
return(o); |
66 |
> |
} |
67 |
|
|
68 |
|
|
69 |
< |
marksources() /* find and mark source objects */ |
69 |
> |
extern void |
70 |
> |
marksources(void) /* find and mark source objects */ |
71 |
|
{ |
72 |
+ |
int foundsource = 0; |
73 |
+ |
int i; |
74 |
|
register OBJREC *o, *m; |
75 |
< |
register int i; |
76 |
< |
|
77 |
< |
for (i = 0; i < nobjects; i++) { |
75 |
> |
register int ns; |
76 |
> |
/* initialize dispatch table */ |
77 |
> |
initstypes(); |
78 |
> |
/* find direct sources */ |
79 |
> |
for (i = 0; i < nsceneobjs; i++) { |
80 |
|
|
81 |
|
o = objptr(i); |
82 |
|
|
83 |
< |
if (o->omod == OVOID) |
83 |
> |
if (!issurface(o->otype) || o->omod == OVOID) |
84 |
|
continue; |
85 |
< |
|
86 |
< |
m = objptr(o->omod); |
87 |
< |
|
88 |
< |
if (m->otype != MAT_LIGHT && |
51 |
< |
m->otype != MAT_ILLUM && |
52 |
< |
m->otype != MAT_GLOW && |
53 |
< |
m->otype != MAT_SPOT) |
54 |
< |
continue; |
85 |
> |
/* find material */ |
86 |
> |
m = findmaterial(objptr(o->omod)); |
87 |
> |
if (m == NULL || !islight(m->otype)) |
88 |
> |
continue; /* not source modifier */ |
89 |
|
|
90 |
|
if (m->oargs.nfargs != (m->otype == MAT_GLOW ? 4 : |
91 |
|
m->otype == MAT_SPOT ? 7 : 3)) |
95 |
|
o->otype != OBJ_SOURCE && |
96 |
|
m->oargs.farg[3] <= FTINY) |
97 |
|
continue; /* don't bother */ |
98 |
+ |
if (m->oargs.farg[0] <= FTINY && m->oargs.farg[1] <= FTINY && |
99 |
+ |
m->oargs.farg[2] <= FTINY) |
100 |
+ |
continue; /* don't bother */ |
101 |
|
|
102 |
< |
if (source == NULL) |
103 |
< |
source = (SRCREC *)malloc(sizeof(SRCREC)); |
104 |
< |
else |
68 |
< |
source = (SRCREC *)realloc((char *)source, |
69 |
< |
(unsigned)(nsources+1)*sizeof(SRCREC)); |
70 |
< |
if (source == NULL) |
71 |
< |
error(SYSTEM, "out of memory in marksources"); |
102 |
> |
if (sfun[o->otype].of == NULL || |
103 |
> |
sfun[o->otype].of->setsrc == NULL) |
104 |
> |
objerror(o, USER, "illegal material"); |
105 |
|
|
106 |
< |
newsource(&source[nsources], o); |
106 |
> |
if ((ns = newsource()) < 0) |
107 |
> |
goto memerr; |
108 |
|
|
109 |
+ |
setsource(&source[ns], o); |
110 |
+ |
|
111 |
|
if (m->otype == MAT_GLOW) { |
112 |
< |
source[nsources].sflags |= SPROX; |
113 |
< |
source[nsources].sl.prox = m->oargs.farg[3]; |
114 |
< |
if (o->otype == OBJ_SOURCE) |
115 |
< |
source[nsources].sflags |= SSKIP; |
112 |
> |
source[ns].sflags |= SPROX; |
113 |
> |
source[ns].sl.prox = m->oargs.farg[3]; |
114 |
> |
if (source[ns].sflags & SDISTANT) |
115 |
> |
source[ns].sflags |= SSKIP; |
116 |
|
} else if (m->otype == MAT_SPOT) { |
117 |
< |
source[nsources].sflags |= SSPOT; |
118 |
< |
source[nsources].sl.s = makespot(m); |
117 |
> |
source[ns].sflags |= SSPOT; |
118 |
> |
if ((source[ns].sl.s = makespot(m)) == NULL) |
119 |
> |
goto memerr; |
120 |
> |
if (source[ns].sflags & SFLAT && |
121 |
> |
!checkspot(source[ns].sl.s,source[ns].snorm)) { |
122 |
> |
objerror(o, WARNING, |
123 |
> |
"invalid spotlight direction"); |
124 |
> |
source[ns].sflags |= SSKIP; |
125 |
> |
} |
126 |
|
} |
127 |
< |
nsources++; |
127 |
> |
#if SHADCACHE |
128 |
> |
initobscache(ns); |
129 |
> |
#endif |
130 |
> |
if (!(source[ns].sflags & SSKIP)) |
131 |
> |
foundsource++; |
132 |
|
} |
133 |
+ |
if (!foundsource) { |
134 |
+ |
error(WARNING, "no light sources found"); |
135 |
+ |
return; |
136 |
+ |
} |
137 |
+ |
markvirtuals(); /* find and add virtual sources */ |
138 |
+ |
/* allocate our contribution arrays */ |
139 |
+ |
maxcntr = nsources + MAXSPART; /* start with this many */ |
140 |
+ |
srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB)); |
141 |
+ |
cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR)); |
142 |
+ |
if ((srccnt == NULL) | (cntord == NULL)) |
143 |
+ |
goto memerr; |
144 |
+ |
return; |
145 |
+ |
memerr: |
146 |
+ |
error(SYSTEM, "out of memory in marksources"); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
< |
newsource(src, so) /* add a source to the array */ |
151 |
< |
register SRCREC *src; |
91 |
< |
register OBJREC *so; |
150 |
> |
extern void |
151 |
> |
freesources(void) /* free all source structures */ |
152 |
|
{ |
153 |
< |
double cos(), tan(), sqrt(); |
154 |
< |
double theta; |
155 |
< |
FACE *f; |
156 |
< |
CONE *co; |
157 |
< |
int j; |
158 |
< |
register int i; |
159 |
< |
|
160 |
< |
src->sflags = 0; |
101 |
< |
src->nhits = 1; src->ntests = 2; /* start probability = 1/2 */ |
102 |
< |
src->so = so; |
103 |
< |
|
104 |
< |
switch (so->otype) { |
105 |
< |
case OBJ_SOURCE: |
106 |
< |
if (so->oargs.nfargs != 4) |
107 |
< |
objerror(so, USER, "bad arguments"); |
108 |
< |
src->sflags |= SDISTANT; |
109 |
< |
VCOPY(src->sloc, so->oargs.farg); |
110 |
< |
if (normalize(src->sloc) == 0.0) |
111 |
< |
objerror(so, USER, "zero direction"); |
112 |
< |
theta = PI/180.0/2.0 * so->oargs.farg[3]; |
113 |
< |
if (theta <= FTINY) |
114 |
< |
objerror(so, USER, "zero size"); |
115 |
< |
src->ss = theta >= PI/4 ? 1.0 : tan(theta); |
116 |
< |
src->ss2 = 2.0*PI * (1.0 - cos(theta)); |
117 |
< |
break; |
118 |
< |
case OBJ_SPHERE: |
119 |
< |
VCOPY(src->sloc, so->oargs.farg); |
120 |
< |
src->ss = so->oargs.farg[3]; |
121 |
< |
src->ss2 = PI * src->ss * src->ss; |
122 |
< |
break; |
123 |
< |
case OBJ_FACE: |
124 |
< |
/* get the face */ |
125 |
< |
f = getface(so); |
126 |
< |
/* find the center */ |
127 |
< |
for (j = 0; j < 3; j++) { |
128 |
< |
src->sloc[j] = 0.0; |
129 |
< |
for (i = 0; i < f->nv; i++) |
130 |
< |
src->sloc[j] += VERTEX(f,i)[j]; |
131 |
< |
src->sloc[j] /= f->nv; |
132 |
< |
} |
133 |
< |
if (!inface(src->sloc, f)) |
134 |
< |
objerror(so, USER, "cannot hit center"); |
135 |
< |
src->ss = sqrt(f->area / PI); |
136 |
< |
src->ss2 = f->area; |
137 |
< |
break; |
138 |
< |
case OBJ_RING: |
139 |
< |
/* get the ring */ |
140 |
< |
co = getcone(so, 0); |
141 |
< |
VCOPY(src->sloc, CO_P0(co)); |
142 |
< |
if (CO_R0(co) > 0.0) |
143 |
< |
objerror(so, USER, "cannot hit center"); |
144 |
< |
src->ss = CO_R1(co); |
145 |
< |
src->ss2 = PI * src->ss * src->ss; |
146 |
< |
break; |
147 |
< |
default: |
148 |
< |
objerror(so, USER, "illegal material"); |
153 |
> |
if (nsources > 0) { |
154 |
> |
#if SHADCACHE |
155 |
> |
while (nsources--) |
156 |
> |
freeobscache(&source[nsources]); |
157 |
> |
#endif |
158 |
> |
free((void *)source); |
159 |
> |
source = NULL; |
160 |
> |
nsources = 0; |
161 |
|
} |
162 |
+ |
if (maxcntr <= 0) |
163 |
+ |
return; |
164 |
+ |
free((void *)srccnt); |
165 |
+ |
srccnt = NULL; |
166 |
+ |
free((void *)cntord); |
167 |
+ |
cntord = NULL; |
168 |
+ |
maxcntr = 0; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
< |
SPOT * |
173 |
< |
makespot(m) /* make a spotlight */ |
174 |
< |
register OBJREC *m; |
172 |
> |
extern int |
173 |
> |
srcray( /* send a ray to a source, return domega */ |
174 |
> |
register RAY *sr, /* returned source ray */ |
175 |
> |
RAY *r, /* ray which hit object */ |
176 |
> |
SRCINDEX *si /* source sample index */ |
177 |
> |
) |
178 |
|
{ |
179 |
< |
extern double cos(); |
180 |
< |
register SPOT *ns; |
179 |
> |
double d; /* distance to source */ |
180 |
> |
register SRCREC *srcp; |
181 |
|
|
182 |
< |
if ((ns = (SPOT *)malloc(sizeof(SPOT))) == NULL) |
183 |
< |
error(SYSTEM, "out of memory in makespot"); |
184 |
< |
ns->siz = 2.0*PI * (1.0 - cos(PI/180.0/2.0 * m->oargs.farg[3])); |
185 |
< |
VCOPY(ns->aim, m->oargs.farg+4); |
186 |
< |
if ((ns->flen = normalize(ns->aim)) == 0.0) |
187 |
< |
objerror(m, USER, "zero focus vector"); |
188 |
< |
return(ns); |
182 |
> |
rayorigin(sr, r, SHADOW, 1.0); /* ignore limits */ |
183 |
> |
|
184 |
> |
while ((d = nextssamp(sr, si)) != 0.0) { |
185 |
> |
sr->rsrc = si->sn; /* remember source */ |
186 |
> |
srcp = source + si->sn; |
187 |
> |
if (srcp->sflags & SDISTANT) { |
188 |
> |
if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s)) |
189 |
> |
continue; |
190 |
> |
return(1); /* sample OK */ |
191 |
> |
} |
192 |
> |
/* local source */ |
193 |
> |
/* check proximity */ |
194 |
> |
if (srcp->sflags & SPROX && d > srcp->sl.prox) |
195 |
> |
continue; |
196 |
> |
/* check angle */ |
197 |
> |
if (srcp->sflags & SSPOT) { |
198 |
> |
if (spotout(sr, srcp->sl.s)) |
199 |
> |
continue; |
200 |
> |
/* adjust solid angle */ |
201 |
> |
si->dom *= d*d; |
202 |
> |
d += srcp->sl.s->flen; |
203 |
> |
si->dom /= d*d; |
204 |
> |
} |
205 |
> |
return(1); /* sample OK */ |
206 |
> |
} |
207 |
> |
return(0); /* no more samples */ |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
< |
double |
212 |
< |
srcray(sr, r, sn) /* send a ray to a source, return domega */ |
213 |
< |
register RAY *sr; /* returned source ray */ |
214 |
< |
RAY *r; /* ray which hit object */ |
174 |
< |
register int sn; /* source number */ |
211 |
> |
extern void |
212 |
> |
srcvalue( /* punch ray to source and compute value */ |
213 |
> |
register RAY *r |
214 |
> |
) |
215 |
|
{ |
216 |
< |
register double *norm = NULL; /* plane normal */ |
177 |
< |
double ddot; /* (distance times) cosine */ |
178 |
< |
FVECT vd; |
179 |
< |
double d; |
180 |
< |
register int i; |
216 |
> |
register SRCREC *sp; |
217 |
|
|
218 |
< |
if (source[sn].sflags & SSKIP) |
219 |
< |
return(0.0); /* skip this source */ |
220 |
< |
|
221 |
< |
rayorigin(sr, r, SHADOW, 1.0); /* ignore limits */ |
222 |
< |
|
223 |
< |
sr->rsrc = sn; /* remember source */ |
224 |
< |
/* get source direction */ |
225 |
< |
if (source[sn].sflags & SDISTANT) |
226 |
< |
/* constant direction */ |
191 |
< |
VCOPY(sr->rdir, source[sn].sloc); |
192 |
< |
else { /* compute direction */ |
193 |
< |
for (i = 0; i < 3; i++) |
194 |
< |
sr->rdir[i] = source[sn].sloc[i] - sr->rorg[i]; |
195 |
< |
|
196 |
< |
if (source[sn].so->otype == OBJ_FACE) |
197 |
< |
norm = getface(source[sn].so)->norm; |
198 |
< |
else if (source[sn].so->otype == OBJ_RING) |
199 |
< |
norm = getcone(source[sn].so,0)->ad; |
200 |
< |
|
201 |
< |
if (norm != NULL && (ddot = -DOT(sr->rdir, norm)) <= FTINY) |
202 |
< |
return(0.0); /* behind surface! */ |
218 |
> |
sp = &source[r->rsrc]; |
219 |
> |
if (sp->sflags & SVIRTUAL) { /* virtual source */ |
220 |
> |
/* check intersection */ |
221 |
> |
if (!(*ofun[sp->so->otype].funp)(sp->so, r)) |
222 |
> |
return; |
223 |
> |
if (!rayshade(r, r->ro->omod)) /* compute contribution */ |
224 |
> |
goto nomat; |
225 |
> |
rayparticipate(r); |
226 |
> |
return; |
227 |
|
} |
228 |
< |
if (dstrsrc > FTINY) { |
229 |
< |
/* distribute source direction */ |
230 |
< |
for (i = 0; i < 3; i++) |
231 |
< |
vd[i] = dstrsrc * source[sn].ss * (1.0 - 2.0*frandom()); |
228 |
> |
/* compute intersection */ |
229 |
> |
if (sp->sflags & SDISTANT ? sourcehit(r) : |
230 |
> |
(*ofun[sp->so->otype].funp)(sp->so, r)) { |
231 |
> |
if (sp->sa.success >= 0) |
232 |
> |
sp->sa.success++; |
233 |
> |
if (!rayshade(r, r->ro->omod)) /* compute contribution */ |
234 |
> |
goto nomat; |
235 |
> |
rayparticipate(r); |
236 |
> |
return; |
237 |
> |
} |
238 |
> |
/* we missed our mark! */ |
239 |
> |
if (sp->sa.success < 0) |
240 |
> |
return; /* bitched already */ |
241 |
> |
sp->sa.success -= AIMREQT; |
242 |
> |
if (sp->sa.success >= 0) |
243 |
> |
return; /* leniency */ |
244 |
> |
sprintf(errmsg, "aiming failure for light source \"%s\"", |
245 |
> |
sp->so->oname); |
246 |
> |
error(WARNING, errmsg); /* issue warning */ |
247 |
> |
return; |
248 |
> |
nomat: |
249 |
> |
objerror(r->ro, USER, "material not found"); |
250 |
> |
} |
251 |
|
|
209 |
– |
if (norm != NULL) { /* project offset */ |
210 |
– |
d = DOT(vd, norm); |
211 |
– |
for (i = 0; i < 3; i++) |
212 |
– |
vd[i] -= d * norm[i]; |
213 |
– |
} |
214 |
– |
for (i = 0; i < 3; i++) /* offset source direction */ |
215 |
– |
sr->rdir[i] += vd[i]; |
252 |
|
|
253 |
< |
} else if (source[sn].sflags & SDISTANT) |
254 |
< |
/* already normalized */ |
255 |
< |
return(source[sn].ss2); |
256 |
< |
|
257 |
< |
if ((d = normalize(sr->rdir)) == 0.0) |
258 |
< |
/* at source! */ |
223 |
< |
return(0.0); |
253 |
> |
static int |
254 |
> |
transillum( /* check if material is transparent illum */ |
255 |
> |
OBJECT obj |
256 |
> |
) |
257 |
> |
{ |
258 |
> |
OBJREC *m = findmaterial(objptr(obj)); |
259 |
|
|
260 |
< |
if (source[sn].sflags & SDISTANT) |
261 |
< |
/* domega constant */ |
262 |
< |
return(source[sn].ss2); |
263 |
< |
|
264 |
< |
else { |
230 |
< |
/* check proximity */ |
231 |
< |
if (source[sn].sflags & SPROX && |
232 |
< |
d > source[sn].sl.prox) |
233 |
< |
return(0.0); |
234 |
< |
|
235 |
< |
if (norm != NULL) |
236 |
< |
ddot /= d; |
237 |
< |
else |
238 |
< |
ddot = 1.0; |
239 |
< |
/* check angle */ |
240 |
< |
if (source[sn].sflags & SSPOT) { |
241 |
< |
if (source[sn].sl.s->siz < 2.0*PI * |
242 |
< |
(1.0 + DOT(source[sn].sl.s->aim,sr->rdir))) |
243 |
< |
return(0.0); |
244 |
< |
d += source[sn].sl.s->flen; |
245 |
< |
} |
246 |
< |
/* return domega */ |
247 |
< |
return(ddot*source[sn].ss2/(d*d)); |
248 |
< |
} |
260 |
> |
if (m == NULL) |
261 |
> |
return(1); |
262 |
> |
if (m->otype != MAT_ILLUM) |
263 |
> |
return(0); |
264 |
> |
return(!m->oargs.nsargs || !strcmp(m->oargs.sarg[0], VOIDID)); |
265 |
|
} |
266 |
|
|
267 |
|
|
268 |
< |
sourcehit(r) /* check to see if ray hit distant source */ |
269 |
< |
register RAY *r; |
268 |
> |
extern int |
269 |
> |
sourcehit( /* check to see if ray hit distant source */ |
270 |
> |
register RAY *r |
271 |
> |
) |
272 |
|
{ |
273 |
+ |
int glowsrc = -1; |
274 |
+ |
int transrc = -1; |
275 |
|
int first, last; |
276 |
|
register int i; |
277 |
|
|
280 |
|
} else { /* otherwise check all */ |
281 |
|
first = 0; last = nsources-1; |
282 |
|
} |
283 |
< |
for (i = first; i <= last; i++) |
284 |
< |
if (source[i].sflags & SDISTANT) |
285 |
< |
/* |
286 |
< |
* Check to see if ray is within |
287 |
< |
* solid angle of source. |
288 |
< |
*/ |
289 |
< |
if (2.0*PI * (1.0 - DOT(source[i].sloc,r->rdir)) |
290 |
< |
<= source[i].ss2) { |
291 |
< |
r->ro = source[i].so; |
292 |
< |
if (!(source[i].sflags & SSKIP)) |
293 |
< |
break; |
294 |
< |
} |
295 |
< |
|
296 |
< |
if (r->ro != NULL) { |
297 |
< |
for (i = 0; i < 3; i++) |
298 |
< |
r->ron[i] = -r->rdir[i]; |
299 |
< |
r->rod = 1.0; |
300 |
< |
r->rofs = 1.0; setident4(r->rofx); |
301 |
< |
r->robs = 1.0; setident4(r->robx); |
302 |
< |
return(1); |
283 |
> |
for (i = first; i <= last; i++) { |
284 |
> |
if ((source[i].sflags & (SDISTANT|SVIRTUAL)) != SDISTANT) |
285 |
> |
continue; |
286 |
> |
/* |
287 |
> |
* Check to see if ray is within |
288 |
> |
* solid angle of source. |
289 |
> |
*/ |
290 |
> |
if (2.*PI*(1. - DOT(source[i].sloc,r->rdir)) > source[i].ss2) |
291 |
> |
continue; |
292 |
> |
/* is it the only possibility? */ |
293 |
> |
if (first == last) { |
294 |
> |
r->ro = source[i].so; |
295 |
> |
break; |
296 |
> |
} |
297 |
> |
/* |
298 |
> |
* If it's a glow or transparent illum, just remember it. |
299 |
> |
*/ |
300 |
> |
if (source[i].sflags & SSKIP) { |
301 |
> |
glowsrc = i; |
302 |
> |
continue; |
303 |
> |
} |
304 |
> |
if (transillum(source[i].so->omod)) { |
305 |
> |
transrc = i; |
306 |
> |
continue; |
307 |
> |
} |
308 |
> |
r->ro = source[i].so; /* otherwise, use first hit */ |
309 |
> |
break; |
310 |
|
} |
311 |
< |
return(0); |
311 |
> |
/* |
312 |
> |
* Do we need fallback? |
313 |
> |
*/ |
314 |
> |
if (r->ro == NULL) { |
315 |
> |
if (transrc >= 0 && r->crtype & (AMBIENT|SPECULAR)) |
316 |
> |
return(0); /* avoid overcounting */ |
317 |
> |
if (glowsrc >= 0) |
318 |
> |
r->ro = source[glowsrc].so; |
319 |
> |
else |
320 |
> |
return(0); /* nothing usable */ |
321 |
> |
} |
322 |
> |
/* |
323 |
> |
* Make assignments. |
324 |
> |
*/ |
325 |
> |
r->robj = objndx(r->ro); |
326 |
> |
for (i = 0; i < 3; i++) |
327 |
> |
r->ron[i] = -r->rdir[i]; |
328 |
> |
r->rod = 1.0; |
329 |
> |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
330 |
> |
r->uv[0] = r->uv[1] = 0.0; |
331 |
> |
r->rox = NULL; |
332 |
> |
return(1); |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
|
static int |
337 |
< |
cntcmp(sc1, sc2) /* contribution compare (descending) */ |
338 |
< |
register CNTPTR *sc1, *sc2; |
337 |
> |
cntcmp( /* contribution compare (descending) */ |
338 |
> |
const void *p1, |
339 |
> |
const void *p2 |
340 |
> |
) |
341 |
|
{ |
342 |
+ |
register const CNTPTR *sc1 = (const CNTPTR *)p1; |
343 |
+ |
register const CNTPTR *sc2 = (const CNTPTR *)p2; |
344 |
+ |
|
345 |
|
if (sc1->brt > sc2->brt) |
346 |
|
return(-1); |
347 |
|
if (sc1->brt < sc2->brt) |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
< |
direct(r, f, p) /* add direct component */ |
354 |
< |
RAY *r; /* ray that hit surface */ |
355 |
< |
int (*f)(); /* direct component coefficient function */ |
356 |
< |
char *p; /* data for f */ |
353 |
> |
extern void |
354 |
> |
direct( /* add direct component */ |
355 |
> |
RAY *r, /* ray that hit surface */ |
356 |
> |
srcdirf_t *f, /* direct component coefficient function */ |
357 |
> |
void *p /* data for f */ |
358 |
> |
) |
359 |
|
{ |
305 |
– |
extern double pow(); |
360 |
|
register int sn; |
361 |
< |
register CONTRIB *srccnt; |
362 |
< |
register CNTPTR *cntord; |
361 |
> |
register CONTRIB *scp; |
362 |
> |
SRCINDEX si; |
363 |
|
int nshadcheck, ncnts; |
364 |
< |
double prob, ourthresh, hwt, test2, hit2; |
364 |
> |
int nhits; |
365 |
> |
double prob, ourthresh, hwt; |
366 |
|
RAY sr; |
367 |
< |
|
368 |
< |
srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB)); |
369 |
< |
cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR)); |
315 |
< |
if (srccnt == NULL || cntord == NULL) |
316 |
< |
error(SYSTEM, "out of memory in direct"); |
317 |
< |
/* compute number to check */ |
318 |
< |
nshadcheck = pow((double)nsources, shadcert) + .5; |
319 |
< |
/* modify threshold */ |
320 |
< |
ourthresh = shadthresh / r->rweight; |
367 |
> |
/* NOTE: srccnt and cntord global so no recursion */ |
368 |
> |
if (nsources <= 0) |
369 |
> |
return; /* no sources?! */ |
370 |
|
/* potential contributions */ |
371 |
< |
for (sn = 0; sn < nsources; sn++) { |
372 |
< |
cntord[sn].sno = sn; |
373 |
< |
cntord[sn].brt = 0.0; |
374 |
< |
/* get source ray */ |
375 |
< |
if ((srccnt[sn].dom = srcray(&sr, r, sn)) == 0.0) |
376 |
< |
continue; |
377 |
< |
VCOPY(srccnt[sn].dir, sr.rdir); |
371 |
> |
initsrcindex(&si); |
372 |
> |
for (sn = 0; srcray(&sr, r, &si); sn++) { |
373 |
> |
if (sn >= maxcntr) { |
374 |
> |
maxcntr = sn + MAXSPART; |
375 |
> |
srccnt = (CONTRIB *)realloc((void *)srccnt, |
376 |
> |
maxcntr*sizeof(CONTRIB)); |
377 |
> |
cntord = (CNTPTR *)realloc((void *)cntord, |
378 |
> |
maxcntr*sizeof(CNTPTR)); |
379 |
> |
if ((srccnt == NULL) | (cntord == NULL)) |
380 |
> |
error(SYSTEM, "out of memory in direct"); |
381 |
> |
} |
382 |
> |
cntord[sn].sndx = sn; |
383 |
> |
scp = srccnt + sn; |
384 |
> |
scp->sno = sr.rsrc; |
385 |
|
/* compute coefficient */ |
386 |
< |
(*f)(srccnt[sn].val, p, srccnt[sn].dir, srccnt[sn].dom); |
387 |
< |
cntord[sn].brt = bright(srccnt[sn].val); |
386 |
> |
(*f)(scp->coef, p, sr.rdir, si.dom); |
387 |
> |
cntord[sn].brt = bright(scp->coef); |
388 |
|
if (cntord[sn].brt <= 0.0) |
389 |
|
continue; |
390 |
< |
/* compute intersection */ |
391 |
< |
if (!( source[sn].sflags & SDISTANT ? |
392 |
< |
sourcehit(&sr) : |
393 |
< |
(*ofun[source[sn].so->otype].funp) |
338 |
< |
(source[sn].so, &sr) )) |
390 |
> |
#if SHADCACHE |
391 |
> |
/* check shadow cache */ |
392 |
> |
if (si.np == 1 && srcblocked(&sr)) { |
393 |
> |
cntord[sn].brt = 0.0; |
394 |
|
continue; |
395 |
< |
/* compute contribution */ |
396 |
< |
rayshade(&sr, sr.ro->omod); |
397 |
< |
multcolor(srccnt[sn].val, sr.rcol); |
398 |
< |
cntord[sn].brt = bright(srccnt[sn].val); |
395 |
> |
} |
396 |
> |
#endif |
397 |
> |
VCOPY(scp->dir, sr.rdir); |
398 |
> |
/* compute potential */ |
399 |
> |
sr.revf = srcvalue; |
400 |
> |
rayvalue(&sr); |
401 |
> |
copycolor(scp->val, sr.rcol); |
402 |
> |
multcolor(scp->val, scp->coef); |
403 |
> |
cntord[sn].brt = bright(scp->val); |
404 |
|
} |
405 |
|
/* sort contributions */ |
406 |
< |
qsort(cntord, nsources, sizeof(CNTPTR), cntcmp); |
406 |
> |
qsort(cntord, sn, sizeof(CNTPTR), cntcmp); |
407 |
|
{ /* find last */ |
408 |
|
register int l, m; |
409 |
|
|
410 |
< |
sn = 0; ncnts = l = nsources; |
410 |
> |
ncnts = l = sn; |
411 |
> |
sn = 0; |
412 |
|
while ((m = (sn + ncnts) >> 1) != l) { |
413 |
|
if (cntord[m].brt > 0.0) |
414 |
|
sn = m; |
417 |
|
l = m; |
418 |
|
} |
419 |
|
} |
420 |
+ |
if (ncnts == 0) |
421 |
+ |
return; /* no contributions! */ |
422 |
|
/* accumulate tail */ |
423 |
|
for (sn = ncnts-1; sn > 0; sn--) |
424 |
|
cntord[sn-1].brt += cntord[sn].brt; |
425 |
< |
/* start with prob=.5 */ |
426 |
< |
hit2 = 0.5; test2 = 1.0; |
425 |
> |
/* compute number to check */ |
426 |
> |
nshadcheck = pow((double)ncnts, shadcert) + .5; |
427 |
> |
/* modify threshold */ |
428 |
> |
ourthresh = shadthresh / r->rweight; |
429 |
|
/* test for shadows */ |
430 |
< |
for (sn = 0; sn < ncnts; sn++) { |
430 |
> |
for (nhits = 0, hwt = 0.0, sn = 0; sn < ncnts; |
431 |
> |
hwt += (double)source[scp->sno].nhits / |
432 |
> |
(double)source[scp->sno].ntests, |
433 |
> |
sn++) { |
434 |
|
/* check threshold */ |
435 |
|
if ((sn+nshadcheck>=ncnts ? cntord[sn].brt : |
436 |
< |
cntord[sn].brt-cntord[sn+nshadcheck].brt) < |
437 |
< |
ourthresh*bright(r->rcol)) |
436 |
> |
cntord[sn].brt-cntord[sn+nshadcheck].brt) |
437 |
> |
< ourthresh*bright(r->rcol)) |
438 |
|
break; |
439 |
< |
/* get statistics */ |
372 |
< |
hwt = (double)source[cntord[sn].sno].nhits / |
373 |
< |
(double)source[cntord[sn].sno].ntests; |
374 |
< |
test2 += hwt; |
375 |
< |
source[cntord[sn].sno].ntests++; |
439 |
> |
scp = srccnt + cntord[sn].sndx; |
440 |
|
/* test for hit */ |
441 |
|
rayorigin(&sr, r, SHADOW, 1.0); |
442 |
< |
VCOPY(sr.rdir, srccnt[cntord[sn].sno].dir); |
442 |
> |
VCOPY(sr.rdir, scp->dir); |
443 |
> |
sr.rsrc = scp->sno; |
444 |
> |
/* keep statistics */ |
445 |
> |
if (source[scp->sno].ntests++ > 0xfffffff0) { |
446 |
> |
source[scp->sno].ntests >>= 1; |
447 |
> |
source[scp->sno].nhits >>= 1; |
448 |
> |
} |
449 |
|
if (localhit(&sr, &thescene) && |
450 |
< |
sr.ro != source[cntord[sn].sno].so) { |
451 |
< |
/* check for transmission */ |
452 |
< |
if (sr.clipset != NULL && inset(sr.clipset, sr.ro->omod)) |
453 |
< |
raytrans(&sr); |
454 |
< |
else |
455 |
< |
rayshade(&sr, sr.ro->omod); |
456 |
< |
if (bright(sr.rcol) <= FTINY) |
450 |
> |
( sr.ro != source[scp->sno].so || |
451 |
> |
source[scp->sno].sflags & SFOLLOW )) { |
452 |
> |
/* follow entire path */ |
453 |
> |
raycont(&sr); |
454 |
> |
rayparticipate(&sr); |
455 |
> |
if (trace != NULL) |
456 |
> |
(*trace)(&sr); /* trace execution */ |
457 |
> |
if (bright(sr.rcol) <= FTINY) { |
458 |
> |
#if SHADCACHE |
459 |
> |
if ((scp <= srccnt || scp[-1].sno != scp->sno) |
460 |
> |
&& (scp >= srccnt+ncnts-1 || |
461 |
> |
scp[1].sno != scp->sno)) |
462 |
> |
srcblocker(&sr); |
463 |
> |
#endif |
464 |
|
continue; /* missed! */ |
465 |
< |
(*f)(srccnt[cntord[sn].sno].val, p, |
466 |
< |
srccnt[cntord[sn].sno].dir, |
467 |
< |
srccnt[cntord[sn].sno].dom); |
391 |
< |
multcolor(srccnt[cntord[sn].sno].val, sr.rcol); |
465 |
> |
} |
466 |
> |
copycolor(scp->val, sr.rcol); |
467 |
> |
multcolor(scp->val, scp->coef); |
468 |
|
} |
469 |
|
/* add contribution if hit */ |
470 |
< |
addcolor(r->rcol, srccnt[cntord[sn].sno].val); |
471 |
< |
hit2 += hwt; |
472 |
< |
source[cntord[sn].sno].nhits++; |
470 |
> |
addcolor(r->rcol, scp->val); |
471 |
> |
nhits++; |
472 |
> |
source[scp->sno].nhits++; |
473 |
|
} |
474 |
< |
/* weighted hit rate */ |
475 |
< |
hwt = hit2 / test2; |
476 |
< |
#ifdef notdef |
477 |
< |
sprintf(errmsg, "%d tested, %d untested, %f hit rate\n", |
474 |
> |
/* source hit rate */ |
475 |
> |
if (hwt > FTINY) |
476 |
> |
hwt = (double)nhits / hwt; |
477 |
> |
else |
478 |
> |
hwt = 0.5; |
479 |
> |
#ifdef DEBUG |
480 |
> |
sprintf(errmsg, "%d tested, %d untested, %f conditional hit rate\n", |
481 |
|
sn, ncnts-sn, hwt); |
482 |
|
eputs(errmsg); |
483 |
|
#endif |
484 |
|
/* add in untested sources */ |
485 |
|
for ( ; sn < ncnts; sn++) { |
486 |
< |
prob = hwt * (double)source[cntord[sn].sno].nhits / |
487 |
< |
(double)source[cntord[sn].sno].ntests; |
488 |
< |
scalecolor(srccnt[cntord[sn].sno].val, prob); |
489 |
< |
addcolor(r->rcol, srccnt[cntord[sn].sno].val); |
486 |
> |
scp = srccnt + cntord[sn].sndx; |
487 |
> |
prob = hwt * (double)source[scp->sno].nhits / |
488 |
> |
(double)source[scp->sno].ntests; |
489 |
> |
if (prob > 1.0) |
490 |
> |
prob = 1.0; |
491 |
> |
scalecolor(scp->val, prob); |
492 |
> |
addcolor(r->rcol, scp->val); |
493 |
|
} |
412 |
– |
|
413 |
– |
free(srccnt); |
414 |
– |
free(cntord); |
494 |
|
} |
495 |
|
|
496 |
|
|
497 |
< |
#define wrongsource(m, r) (m->otype!=MAT_ILLUM && \ |
498 |
< |
r->rsrc>=0 && \ |
499 |
< |
source[r->rsrc].so!=r->ro) |
497 |
> |
extern void |
498 |
> |
srcscatter( /* compute source scattering into ray */ |
499 |
> |
register RAY *r |
500 |
> |
) |
501 |
> |
{ |
502 |
> |
int oldsampndx; |
503 |
> |
int nsamps; |
504 |
> |
RAY sr; |
505 |
> |
SRCINDEX si; |
506 |
> |
double t, d; |
507 |
> |
double re, ge, be; |
508 |
> |
COLOR cvext; |
509 |
> |
int i, j; |
510 |
|
|
511 |
< |
#define badambient(m, r) ((r->crtype&(AMBIENT|SHADOW))==AMBIENT && \ |
512 |
< |
!(r->rtype&REFLECTED) && /* hack! */\ |
513 |
< |
!(m->otype==MAT_GLOW&&r->rot>m->oargs.farg[3])) |
511 |
> |
if (r->slights == NULL || r->slights[0] == 0 |
512 |
> |
|| r->gecc >= 1.-FTINY || r->rot >= FHUGE) |
513 |
> |
return; |
514 |
> |
if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1) |
515 |
> |
nsamps = 1; |
516 |
> |
#if MAXSSAMP |
517 |
> |
else if (nsamps > MAXSSAMP) |
518 |
> |
nsamps = MAXSSAMP; |
519 |
> |
#endif |
520 |
> |
oldsampndx = samplendx; |
521 |
> |
samplendx = random()&0x7fff; /* randomize */ |
522 |
> |
for (i = r->slights[0]; i > 0; i--) { /* for each source */ |
523 |
> |
for (j = 0; j < nsamps; j++) { /* for each sample position */ |
524 |
> |
samplendx++; |
525 |
> |
t = r->rot * (j+frandom())/nsamps; |
526 |
> |
/* extinction */ |
527 |
> |
re = t*colval(r->cext,RED); |
528 |
> |
ge = t*colval(r->cext,GRN); |
529 |
> |
be = t*colval(r->cext,BLU); |
530 |
> |
setcolor(cvext, re > 92. ? 0. : exp(-re), |
531 |
> |
ge > 92. ? 0. : exp(-ge), |
532 |
> |
be > 92. ? 0. : exp(-be)); |
533 |
> |
if (intens(cvext) <= FTINY) |
534 |
> |
break; /* too far away */ |
535 |
> |
sr.rorg[0] = r->rorg[0] + r->rdir[0]*t; |
536 |
> |
sr.rorg[1] = r->rorg[1] + r->rdir[1]*t; |
537 |
> |
sr.rorg[2] = r->rorg[2] + r->rdir[2]*t; |
538 |
> |
sr.rmax = 0.; |
539 |
> |
initsrcindex(&si); /* sample ray to this source */ |
540 |
> |
si.sn = r->slights[i]; |
541 |
> |
nopart(&si, &sr); |
542 |
> |
if (!srcray(&sr, NULL, &si) || |
543 |
> |
sr.rsrc != r->slights[i]) |
544 |
> |
continue; /* no path */ |
545 |
> |
#if SHADCACHE |
546 |
> |
if (srcblocked(&sr)) /* check shadow cache */ |
547 |
> |
continue; |
548 |
> |
#endif |
549 |
> |
copycolor(sr.cext, r->cext); |
550 |
> |
copycolor(sr.albedo, r->albedo); |
551 |
> |
sr.gecc = r->gecc; |
552 |
> |
sr.slights = r->slights; |
553 |
> |
rayvalue(&sr); /* eval. source ray */ |
554 |
> |
if (bright(sr.rcol) <= FTINY) { |
555 |
> |
#if SHADCACHE |
556 |
> |
srcblocker(&sr); /* add blocker to cache */ |
557 |
> |
#endif |
558 |
> |
continue; |
559 |
> |
} |
560 |
> |
if (r->gecc <= FTINY) /* compute P(theta) */ |
561 |
> |
d = 1.; |
562 |
> |
else { |
563 |
> |
d = DOT(r->rdir, sr.rdir); |
564 |
> |
d = 1. + r->gecc*r->gecc - 2.*r->gecc*d; |
565 |
> |
d = (1. - r->gecc*r->gecc) / (d*sqrt(d)); |
566 |
> |
} |
567 |
> |
/* other factors */ |
568 |
> |
d *= si.dom * r->rot / (4.*PI*nsamps); |
569 |
> |
multcolor(sr.rcol, r->cext); |
570 |
> |
multcolor(sr.rcol, r->albedo); |
571 |
> |
scalecolor(sr.rcol, d); |
572 |
> |
multcolor(sr.rcol, cvext); |
573 |
> |
addcolor(r->rcol, sr.rcol); /* add it in */ |
574 |
> |
} |
575 |
> |
} |
576 |
> |
samplendx = oldsampndx; |
577 |
> |
} |
578 |
|
|
579 |
+ |
|
580 |
+ |
/**************************************************************** |
581 |
+ |
* The following macros were separated from the m_light() routine |
582 |
+ |
* because they are very nasty and difficult to understand. |
583 |
+ |
*/ |
584 |
+ |
|
585 |
+ |
/* illumblock * |
586 |
+ |
* |
587 |
+ |
* We cannot allow an illum to pass to another illum, because that |
588 |
+ |
* would almost certainly constitute overcounting. |
589 |
+ |
* However, we do allow an illum to pass to another illum |
590 |
+ |
* that is actually going to relay to a virtual light source. |
591 |
+ |
* We also prevent an illum from passing to a glow; this provides a |
592 |
+ |
* convenient mechanism for defining detailed light source |
593 |
+ |
* geometry behind (or inside) an effective radiator. |
594 |
+ |
*/ |
595 |
+ |
|
596 |
+ |
static int |
597 |
+ |
weaksrcmat(OBJECT obj) /* identify material */ |
598 |
+ |
{ |
599 |
+ |
OBJREC *m = findmaterial(objptr(obj)); |
600 |
+ |
|
601 |
+ |
if (m == NULL) return(0); |
602 |
+ |
return((m->otype==MAT_ILLUM) | (m->otype==MAT_GLOW)); |
603 |
+ |
} |
604 |
+ |
|
605 |
+ |
#define illumblock(m, r) (!(source[r->rsrc].sflags&SVIRTUAL) && \ |
606 |
+ |
r->rod > 0.0 && \ |
607 |
+ |
weaksrcmat(source[r->rsrc].so->omod)) |
608 |
+ |
|
609 |
+ |
/* wrongsource * |
610 |
+ |
* |
611 |
+ |
* This source is the wrong source (ie. overcounted) if we are |
612 |
+ |
* aimed to a different source than the one we hit and the one |
613 |
+ |
* we hit is not an illum that should be passed. |
614 |
+ |
*/ |
615 |
+ |
|
616 |
+ |
#define wrongsource(m, r) (r->rsrc>=0 && source[r->rsrc].so!=r->ro && \ |
617 |
+ |
(m->otype!=MAT_ILLUM || illumblock(m,r))) |
618 |
+ |
|
619 |
+ |
/* distglow * |
620 |
+ |
* |
621 |
+ |
* A distant glow is an object that sometimes acts as a light source, |
622 |
+ |
* but is too far away from the test point to be one in this case. |
623 |
+ |
* (Glows with negative radii should NEVER participate in illumination.) |
624 |
+ |
*/ |
625 |
+ |
|
626 |
+ |
#define distglow(m, r, d) (m->otype==MAT_GLOW && \ |
627 |
+ |
m->oargs.farg[3] >= -FTINY && \ |
628 |
+ |
d > m->oargs.farg[3]) |
629 |
+ |
|
630 |
+ |
/* badcomponent * |
631 |
+ |
* |
632 |
+ |
* We must avoid counting light sources in the ambient calculation, |
633 |
+ |
* since the direct component is handled separately. Therefore, any |
634 |
+ |
* ambient ray which hits an active light source must be discarded. |
635 |
+ |
* The same is true for stray specular samples, since the specular |
636 |
+ |
* contribution from light sources is calculated separately. |
637 |
+ |
*/ |
638 |
+ |
|
639 |
+ |
#define badcomponent(m, r) (r->crtype&(AMBIENT|SPECULAR) && \ |
640 |
+ |
!(r->crtype&SHADOW || r->rod < 0.0 || \ |
641 |
+ |
/* not 100% correct */ distglow(m, r, r->rot))) |
642 |
+ |
|
643 |
+ |
/* passillum * |
644 |
+ |
* |
645 |
+ |
* An illum passes to another material type when we didn't hit it |
646 |
+ |
* on purpose (as part of a direct calculation), or it is relaying |
647 |
+ |
* a virtual light source. |
648 |
+ |
*/ |
649 |
+ |
|
650 |
|
#define passillum(m, r) (m->otype==MAT_ILLUM && \ |
651 |
< |
!(r->rsrc>=0&&source[r->rsrc].so==r->ro)) |
651 |
> |
(r->rsrc<0 || source[r->rsrc].so!=r->ro || \ |
652 |
> |
source[r->rsrc].sflags&SVIRTUAL)) |
653 |
|
|
654 |
+ |
/* srcignore * |
655 |
+ |
* |
656 |
+ |
* The -dv flag is normally on for sources to be visible. |
657 |
+ |
*/ |
658 |
|
|
659 |
< |
m_light(m, r) /* ray hit a light source */ |
660 |
< |
register OBJREC *m; |
661 |
< |
register RAY *r; |
659 |
> |
#define srcignore(m, r) !(directvis || r->crtype&SHADOW || \ |
660 |
> |
distglow(m, r, raydist(r,PRIMARY))) |
661 |
> |
|
662 |
> |
|
663 |
> |
extern int |
664 |
> |
m_light( /* ray hit a light source */ |
665 |
> |
register OBJREC *m, |
666 |
> |
register RAY *r |
667 |
> |
) |
668 |
|
{ |
669 |
|
/* check for over-counting */ |
670 |
< |
if (wrongsource(m, r) || badambient(m, r)) |
671 |
< |
return; |
670 |
> |
if (badcomponent(m, r)) |
671 |
> |
return(1); |
672 |
> |
if (wrongsource(m, r)) |
673 |
> |
return(1); |
674 |
|
/* check for passed illum */ |
675 |
|
if (passillum(m, r)) { |
676 |
< |
|
677 |
< |
if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID)) |
678 |
< |
raytrans(r); |
679 |
< |
else |
680 |
< |
rayshade(r, modifier(m->oargs.sarg[0])); |
681 |
< |
|
445 |
< |
/* otherwise treat as source */ |
446 |
< |
} else { |
676 |
> |
if (m->oargs.nsargs && strcmp(m->oargs.sarg[0], VOIDID)) |
677 |
> |
return(rayshade(r,lastmod(objndx(m),m->oargs.sarg[0]))); |
678 |
> |
raytrans(r); |
679 |
> |
return(1); |
680 |
> |
} |
681 |
> |
/* otherwise treat as source */ |
682 |
|
/* check for behind */ |
683 |
< |
if (r->rod < 0.0) |
684 |
< |
return; |
683 |
> |
if (r->rod < 0.0) |
684 |
> |
return(1); |
685 |
> |
/* check for invisibility */ |
686 |
> |
if (srcignore(m, r)) |
687 |
> |
return(1); |
688 |
> |
/* check for outside spot */ |
689 |
> |
if (m->otype==MAT_SPOT && spotout(r, makespot(m))) |
690 |
> |
return(1); |
691 |
|
/* get distribution pattern */ |
692 |
< |
raytexture(r, m->omod); |
692 |
> |
raytexture(r, m->omod); |
693 |
|
/* get source color */ |
694 |
< |
setcolor(r->rcol, m->oargs.farg[0], |
695 |
< |
m->oargs.farg[1], |
696 |
< |
m->oargs.farg[2]); |
694 |
> |
setcolor(r->rcol, m->oargs.farg[0], |
695 |
> |
m->oargs.farg[1], |
696 |
> |
m->oargs.farg[2]); |
697 |
|
/* modify value */ |
698 |
< |
multcolor(r->rcol, r->pcol); |
699 |
< |
} |
698 |
> |
multcolor(r->rcol, r->pcol); |
699 |
> |
return(1); |
700 |
|
} |
460 |
– |
|
461 |
– |
|
462 |
– |
o_source() {} /* intersection with a source is done elsewhere */ |