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 |
|
* Routines to do the actual calculation for mkillum |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include "mkillum.h" |
8 |
> |
#include <string.h> |
9 |
|
|
10 |
+ |
#include "mkillum.h" |
11 |
|
#include "face.h" |
14 |
– |
|
12 |
|
#include "cone.h" |
16 |
– |
|
13 |
|
#include "random.h" |
14 |
|
|
15 |
|
|
16 |
< |
o_default(ob, il, rt, nm) /* default illum action */ |
17 |
< |
OBJREC *ob; |
18 |
< |
struct illum_args *il; |
19 |
< |
struct rtproc *rt; |
20 |
< |
char *nm; |
16 |
> |
COLORV * distarr = NULL; /* distribution array */ |
17 |
> |
int distsiz = 0; |
18 |
> |
|
19 |
> |
|
20 |
> |
void |
21 |
> |
newdist( /* allocate & clear distribution array */ |
22 |
> |
int siz |
23 |
> |
) |
24 |
|
{ |
25 |
+ |
if (siz == 0) { |
26 |
+ |
if (distsiz > 0) |
27 |
+ |
free((void *)distarr); |
28 |
+ |
distarr = NULL; |
29 |
+ |
distsiz = 0; |
30 |
+ |
return; |
31 |
+ |
} |
32 |
+ |
if (distsiz < siz) { |
33 |
+ |
if (distsiz > 0) |
34 |
+ |
free((void *)distarr); |
35 |
+ |
distarr = (COLORV *)malloc(sizeof(COLOR)*siz); |
36 |
+ |
if (distarr == NULL) |
37 |
+ |
error(SYSTEM, "out of memory in newdist"); |
38 |
+ |
distsiz = siz; |
39 |
+ |
} |
40 |
+ |
memset(distarr, '\0', sizeof(COLOR)*siz); |
41 |
+ |
} |
42 |
+ |
|
43 |
+ |
|
44 |
+ |
int |
45 |
+ |
process_ray(RAY *r, int rv) |
46 |
+ |
{ |
47 |
+ |
COLORV *colp; |
48 |
+ |
|
49 |
+ |
if (rv == 0) |
50 |
+ |
return(0); |
51 |
+ |
if (rv < 0) |
52 |
+ |
error(USER, "ray tracing process died"); |
53 |
+ |
if (r->rno >= distsiz) |
54 |
+ |
error(INTERNAL, "bad returned index in process_ray"); |
55 |
+ |
colp = &distarr[r->rno * 3]; |
56 |
+ |
addcolor(colp, r->rcol); |
57 |
+ |
return(1); |
58 |
+ |
} |
59 |
+ |
|
60 |
+ |
|
61 |
+ |
void |
62 |
+ |
raysamp( /* queue a ray sample */ |
63 |
+ |
int ndx, |
64 |
+ |
FVECT org, |
65 |
+ |
FVECT dir |
66 |
+ |
) |
67 |
+ |
{ |
68 |
+ |
RAY myRay; |
69 |
+ |
int rv; |
70 |
+ |
|
71 |
+ |
if ((ndx < 0) | (ndx >= distsiz)) |
72 |
+ |
error(INTERNAL, "bad index in raysamp"); |
73 |
+ |
VCOPY(myRay.rorg, org); |
74 |
+ |
VCOPY(myRay.rdir, dir); |
75 |
+ |
myRay.rmax = .0; |
76 |
+ |
rayorigin(&myRay, PRIMARY, NULL, NULL); |
77 |
+ |
myRay.rno = ndx; |
78 |
+ |
/* queue ray, check result */ |
79 |
+ |
process_ray(&myRay, ray_pqueue(&myRay)); |
80 |
+ |
} |
81 |
+ |
|
82 |
+ |
|
83 |
+ |
void |
84 |
+ |
rayclean() /* finish all pending rays */ |
85 |
+ |
{ |
86 |
+ |
RAY myRay; |
87 |
+ |
|
88 |
+ |
while (process_ray(&myRay, ray_presult(&myRay, 0))) |
89 |
+ |
; |
90 |
+ |
} |
91 |
+ |
|
92 |
+ |
|
93 |
+ |
static void |
94 |
+ |
mkaxes( /* compute u and v to go with n */ |
95 |
+ |
FVECT u, |
96 |
+ |
FVECT v, |
97 |
+ |
FVECT n |
98 |
+ |
) |
99 |
+ |
{ |
100 |
+ |
register int i; |
101 |
+ |
|
102 |
+ |
v[0] = v[1] = v[2] = 0.0; |
103 |
+ |
for (i = 0; i < 3; i++) |
104 |
+ |
if (n[i] < 0.6 && n[i] > -0.6) |
105 |
+ |
break; |
106 |
+ |
v[i] = 1.0; |
107 |
+ |
fcross(u, v, n); |
108 |
+ |
normalize(u); |
109 |
+ |
fcross(v, n, u); |
110 |
+ |
} |
111 |
+ |
|
112 |
+ |
|
113 |
+ |
static void |
114 |
+ |
rounddir( /* compute uniform spherical direction */ |
115 |
+ |
register FVECT dv, |
116 |
+ |
double alt, |
117 |
+ |
double azi |
118 |
+ |
) |
119 |
+ |
{ |
120 |
+ |
double d1, d2; |
121 |
+ |
|
122 |
+ |
dv[2] = 1. - 2.*alt; |
123 |
+ |
d1 = sqrt(1. - dv[2]*dv[2]); |
124 |
+ |
d2 = 2.*PI * azi; |
125 |
+ |
dv[0] = d1*cos(d2); |
126 |
+ |
dv[1] = d1*sin(d2); |
127 |
+ |
} |
128 |
+ |
|
129 |
+ |
|
130 |
+ |
static void |
131 |
+ |
flatdir( /* compute uniform hemispherical direction */ |
132 |
+ |
register FVECT dv, |
133 |
+ |
double alt, |
134 |
+ |
double azi |
135 |
+ |
) |
136 |
+ |
{ |
137 |
+ |
double d1, d2; |
138 |
+ |
|
139 |
+ |
d1 = sqrt(alt); |
140 |
+ |
d2 = 2.*PI * azi; |
141 |
+ |
dv[0] = d1*cos(d2); |
142 |
+ |
dv[1] = d1*sin(d2); |
143 |
+ |
dv[2] = sqrt(1. - alt); |
144 |
+ |
} |
145 |
+ |
|
146 |
+ |
|
147 |
+ |
int |
148 |
+ |
my_default( /* default illum action */ |
149 |
+ |
OBJREC *ob, |
150 |
+ |
struct illum_args *il, |
151 |
+ |
char *nm |
152 |
+ |
) |
153 |
+ |
{ |
154 |
|
sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", |
155 |
|
nm, ofun[ob->otype].funame, ob->oname); |
156 |
|
error(WARNING, errmsg); |
157 |
< |
if (!(il->flags & IL_LIGHT)) |
158 |
< |
printobj(il->altmat, ob); |
157 |
> |
printobj(il->altmat, ob); |
158 |
> |
return(1); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
< |
o_face(ob, il, rt, nm) /* make an illum face */ |
163 |
< |
OBJREC *ob; |
164 |
< |
struct illum_args *il; |
165 |
< |
struct rtproc *rt; |
166 |
< |
char *nm; |
162 |
> |
int |
163 |
> |
my_face( /* make an illum face */ |
164 |
> |
OBJREC *ob, |
165 |
> |
struct illum_args *il, |
166 |
> |
char *nm |
167 |
> |
) |
168 |
|
{ |
169 |
|
#define MAXMISS (5*n*il->nsamps) |
170 |
< |
int dim[3]; |
171 |
< |
int n, nalt, nazi, h; |
43 |
< |
float *distarr; |
170 |
> |
int dim[2]; |
171 |
> |
int n, nalt, nazi, h, alti; |
172 |
|
double sp[2], r1, r2; |
173 |
|
FVECT dn, org, dir; |
174 |
|
FVECT u, v; |
175 |
|
double ur[2], vr[2]; |
176 |
+ |
MAT4 xfm; |
177 |
|
int nmisses; |
178 |
< |
register FACE *fa; |
178 |
> |
FACE *fa; |
179 |
|
register int i, j; |
180 |
|
/* get/check arguments */ |
181 |
|
fa = getface(ob); |
182 |
|
if (fa->area == 0.0) { |
183 |
|
freeface(ob); |
184 |
< |
o_default(ob, il, rt, nm); |
56 |
< |
return; |
184 |
> |
return(my_default(ob, il, nm)); |
185 |
|
} |
186 |
|
/* set up sampling */ |
187 |
< |
if (il->sampdens <= 0) |
188 |
< |
nalt = nazi = 1; |
189 |
< |
else { |
190 |
< |
n = PI * il->sampdens; |
191 |
< |
nalt = sqrt(n/PI) + .5; |
192 |
< |
nazi = PI*nalt + .5; |
187 |
> |
if (il->sd != NULL) { |
188 |
> |
if (!getBSDF_xfm(xfm, fa->norm, il->udir)) { |
189 |
> |
objerror(ob, WARNING, "illegal up direction"); |
190 |
> |
freeface(ob); |
191 |
> |
return(my_default(ob, il, nm)); |
192 |
> |
} |
193 |
> |
n = il->sd->ninc; |
194 |
> |
} else { |
195 |
> |
if (il->sampdens <= 0) { |
196 |
> |
nalt = nazi = 1; /* diffuse assumption */ |
197 |
> |
} else { |
198 |
> |
n = PI * il->sampdens; |
199 |
> |
nalt = sqrt(n/PI) + .5; |
200 |
> |
nazi = PI*nalt + .5; |
201 |
> |
} |
202 |
> |
n = nazi*nalt; |
203 |
|
} |
204 |
< |
n = nalt*nazi; |
205 |
< |
distarr = (float *)calloc(n, 3*sizeof(float)); |
206 |
< |
if (distarr == NULL) |
207 |
< |
error(SYSTEM, "out of memory in o_face"); |
208 |
< |
mkaxes(u, v, fa->norm); |
204 |
> |
newdist(n); |
205 |
> |
/* take first edge >= sqrt(area) */ |
206 |
> |
for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) { |
207 |
> |
u[0] = VERTEX(fa,i)[0] - VERTEX(fa,j)[0]; |
208 |
> |
u[1] = VERTEX(fa,i)[1] - VERTEX(fa,j)[1]; |
209 |
> |
u[2] = VERTEX(fa,i)[2] - VERTEX(fa,j)[2]; |
210 |
> |
if ((r1 = DOT(u,u)) >= fa->area-FTINY) |
211 |
> |
break; |
212 |
> |
} |
213 |
> |
if (i < fa->nv) { /* got one! -- let's align our axes */ |
214 |
> |
r2 = 1.0/sqrt(r1); |
215 |
> |
u[0] *= r2; u[1] *= r2; u[2] *= r2; |
216 |
> |
fcross(v, fa->norm, u); |
217 |
> |
} else /* oh well, we'll just have to wing it */ |
218 |
> |
mkaxes(u, v, fa->norm); |
219 |
> |
/* now, find limits in (u,v) coordinates */ |
220 |
|
ur[0] = vr[0] = FHUGE; |
221 |
|
ur[1] = vr[1] = -FHUGE; |
222 |
|
for (i = 0; i < fa->nv; i++) { |
230 |
|
dim[0] = random(); |
231 |
|
/* sample polygon */ |
232 |
|
nmisses = 0; |
233 |
< |
for (dim[1] = 0; dim[1] < nalt; dim[1]++) |
85 |
< |
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
233 |
> |
for (dim[1] = 0; dim[1] < n; dim[1]++) |
234 |
|
for (i = 0; i < il->nsamps; i++) { |
235 |
|
/* random direction */ |
236 |
< |
h = ilhash(dim, 3) + i; |
237 |
< |
multisamp(sp, 2, urand(h)); |
238 |
< |
r1 = (dim[1] + sp[0])/nalt; |
239 |
< |
r2 = (dim[2] + sp[1] - .5)/nazi; |
240 |
< |
flatdir(dn, r1, r2); |
241 |
< |
for (j = 0; j < 3; j++) |
242 |
< |
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j]; |
236 |
> |
h = ilhash(dim, 2) + i; |
237 |
> |
if (il->sd != NULL) { |
238 |
> |
r_BSDF_incvec(dir, il->sd, dim[1], urand(h), xfm); |
239 |
> |
} else { |
240 |
> |
multisamp(sp, 2, urand(h)); |
241 |
> |
alti = dim[1]/nazi; |
242 |
> |
r1 = (alti + sp[0])/nalt; |
243 |
> |
r2 = (dim[1] - alti*nazi + sp[1] - .5)/nazi; |
244 |
> |
flatdir(dn, r1, r2); |
245 |
> |
for (j = 0; j < 3; j++) |
246 |
> |
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - |
247 |
> |
dn[2]*fa->norm[j]; |
248 |
> |
} |
249 |
|
/* random location */ |
250 |
|
do { |
251 |
|
multisamp(sp, 2, urand(h+4862+nmisses)); |
257 |
|
} while (!inface(org, fa) && nmisses++ < MAXMISS); |
258 |
|
if (nmisses > MAXMISS) { |
259 |
|
objerror(ob, WARNING, "bad aspect"); |
260 |
< |
rt->nrays = 0; |
260 |
> |
rayclean(); |
261 |
|
freeface(ob); |
262 |
< |
free((char *)distarr); |
109 |
< |
o_default(ob, il, rt, nm); |
110 |
< |
return; |
262 |
> |
return(my_default(ob, il, nm)); |
263 |
|
} |
264 |
+ |
if (il->sd != NULL && DOT(dir, fa->norm) < -FTINY) |
265 |
+ |
r1 = -1.0001*il->thick - .0001; |
266 |
+ |
else |
267 |
+ |
r1 = .0001; |
268 |
|
for (j = 0; j < 3; j++) |
269 |
< |
org[j] += .001*fa->norm[j]; |
269 |
> |
org[j] += r1*fa->norm[j]; |
270 |
|
/* send sample */ |
271 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
271 |
> |
raysamp(dim[1], org, dir); |
272 |
|
} |
273 |
< |
rayflush(rt); |
273 |
> |
rayclean(); |
274 |
> |
if (il->sd != NULL) { /* run distribution through BSDF */ |
275 |
> |
nalt = sqrt(il->sd->nout/PI) + .5; |
276 |
> |
nazi = PI*nalt + .5; |
277 |
> |
redistribute(il->sd, nalt, nazi, u, v, fa->norm, xfm); |
278 |
> |
} |
279 |
|
/* write out the face and its distribution */ |
280 |
< |
if (average(il, distarr, nalt*nazi)) { |
280 |
> |
if (average(il, distarr, n)) { |
281 |
|
if (il->sampdens > 0) |
282 |
|
flatout(il, distarr, nalt, nazi, u, v, fa->norm); |
283 |
|
illumout(il, ob); |
284 |
< |
} else if (!(il->flags & IL_LIGHT)) |
284 |
> |
} else |
285 |
|
printobj(il->altmat, ob); |
286 |
|
/* clean up */ |
287 |
|
freeface(ob); |
288 |
< |
free((char *)distarr); |
288 |
> |
return(0); |
289 |
|
#undef MAXMISS |
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
< |
o_sphere(ob, il, rt, nm) /* make an illum sphere */ |
294 |
< |
register OBJREC *ob; |
295 |
< |
struct illum_args *il; |
296 |
< |
struct rtproc *rt; |
297 |
< |
char *nm; |
293 |
> |
int |
294 |
> |
my_sphere( /* make an illum sphere */ |
295 |
> |
register OBJREC *ob, |
296 |
> |
struct illum_args *il, |
297 |
> |
char *nm |
298 |
> |
) |
299 |
|
{ |
300 |
|
int dim[3]; |
301 |
|
int n, nalt, nazi; |
140 |
– |
float *distarr; |
302 |
|
double sp[4], r1, r2, r3; |
303 |
|
FVECT org, dir; |
304 |
|
FVECT u, v; |
311 |
|
nalt = nazi = 1; |
312 |
|
else { |
313 |
|
n = 4.*PI * il->sampdens; |
314 |
< |
nalt = sqrt(n/PI) + .5; |
315 |
< |
nazi = PI*nalt + .5; |
314 |
> |
nalt = sqrt(2./PI*n) + .5; |
315 |
> |
nazi = PI/2.*nalt + .5; |
316 |
|
} |
317 |
+ |
if (il->sd != NULL) |
318 |
+ |
objerror(ob, WARNING, "BSDF ignored"); |
319 |
|
n = nalt*nazi; |
320 |
< |
distarr = (float *)calloc(n, 3*sizeof(float)); |
158 |
< |
if (distarr == NULL) |
159 |
< |
error(SYSTEM, "out of memory in o_sphere"); |
320 |
> |
newdist(n); |
321 |
|
dim[0] = random(); |
322 |
|
/* sample sphere */ |
323 |
|
for (dim[1] = 0; dim[1] < nalt; dim[1]++) |
342 |
|
dir[j] = -dir[j]; |
343 |
|
} |
344 |
|
/* send sample */ |
345 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
345 |
> |
raysamp(dim[1]*nazi+dim[2], org, dir); |
346 |
|
} |
347 |
< |
rayflush(rt); |
347 |
> |
rayclean(); |
348 |
|
/* write out the sphere and its distribution */ |
349 |
< |
if (average(il, distarr, nalt*nazi)) { |
349 |
> |
if (average(il, distarr, n)) { |
350 |
|
if (il->sampdens > 0) |
351 |
|
roundout(il, distarr, nalt, nazi); |
352 |
|
else |
353 |
|
objerror(ob, WARNING, "diffuse distribution"); |
354 |
|
illumout(il, ob); |
355 |
< |
} else if (!(il->flags & IL_LIGHT)) |
355 |
> |
} else |
356 |
|
printobj(il->altmat, ob); |
357 |
|
/* clean up */ |
358 |
< |
free((char *)distarr); |
358 |
> |
return(1); |
359 |
|
} |
360 |
|
|
361 |
|
|
362 |
< |
o_ring(ob, il, rt, nm) /* make an illum ring */ |
363 |
< |
OBJREC *ob; |
364 |
< |
struct illum_args *il; |
365 |
< |
struct rtproc *rt; |
366 |
< |
char *nm; |
362 |
> |
int |
363 |
> |
my_ring( /* make an illum ring */ |
364 |
> |
OBJREC *ob, |
365 |
> |
struct illum_args *il, |
366 |
> |
char *nm |
367 |
> |
) |
368 |
|
{ |
369 |
< |
int dim[3]; |
370 |
< |
int n, nalt, nazi; |
371 |
< |
float *distarr; |
372 |
< |
double sp[4], r1, r2, r3; |
369 |
> |
int dim[2]; |
370 |
> |
int n, nalt, nazi, alti; |
371 |
> |
double sp[2], r1, r2, r3; |
372 |
> |
int h; |
373 |
|
FVECT dn, org, dir; |
374 |
|
FVECT u, v; |
375 |
< |
register CONE *co; |
375 |
> |
MAT4 xfm; |
376 |
> |
CONE *co; |
377 |
|
register int i, j; |
378 |
|
/* get/check arguments */ |
379 |
|
co = getcone(ob, 0); |
380 |
|
/* set up sampling */ |
381 |
< |
if (il->sampdens <= 0) |
382 |
< |
nalt = nazi = 1; |
383 |
< |
else { |
384 |
< |
n = PI * il->sampdens; |
385 |
< |
nalt = sqrt(n/PI) + .5; |
386 |
< |
nazi = PI*nalt + .5; |
381 |
> |
if (il->sd != NULL) { |
382 |
> |
if (!getBSDF_xfm(xfm, co->ad, il->udir)) { |
383 |
> |
objerror(ob, WARNING, "illegal up direction"); |
384 |
> |
freecone(ob); |
385 |
> |
return(my_default(ob, il, nm)); |
386 |
> |
} |
387 |
> |
n = il->sd->ninc; |
388 |
> |
} else { |
389 |
> |
if (il->sampdens <= 0) { |
390 |
> |
nalt = nazi = 1; /* diffuse assumption */ |
391 |
> |
} else { |
392 |
> |
n = PI * il->sampdens; |
393 |
> |
nalt = sqrt(n/PI) + .5; |
394 |
> |
nazi = PI*nalt + .5; |
395 |
> |
} |
396 |
> |
n = nazi*nalt; |
397 |
|
} |
398 |
< |
n = nalt*nazi; |
226 |
< |
distarr = (float *)calloc(n, 3*sizeof(float)); |
227 |
< |
if (distarr == NULL) |
228 |
< |
error(SYSTEM, "out of memory in o_ring"); |
398 |
> |
newdist(n); |
399 |
|
mkaxes(u, v, co->ad); |
400 |
|
dim[0] = random(); |
401 |
|
/* sample disk */ |
402 |
< |
for (dim[1] = 0; dim[1] < nalt; dim[1]++) |
233 |
< |
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
402 |
> |
for (dim[1] = 0; dim[1] < n; dim[1]++) |
403 |
|
for (i = 0; i < il->nsamps; i++) { |
404 |
|
/* next sample point */ |
405 |
< |
multisamp(sp, 4, urand(ilhash(dim,3)+i)); |
405 |
> |
h = ilhash(dim,2) + i; |
406 |
|
/* random direction */ |
407 |
< |
r1 = (dim[1] + sp[0])/nalt; |
408 |
< |
r2 = (dim[2] + sp[1] - .5)/nazi; |
409 |
< |
flatdir(dn, r1, r2); |
410 |
< |
for (j = 0; j < 3; j++) |
407 |
> |
if (il->sd != NULL) { |
408 |
> |
r_BSDF_incvec(dir, il->sd, dim[1], urand(h), xfm); |
409 |
> |
} else { |
410 |
> |
multisamp(sp, 2, urand(h)); |
411 |
> |
alti = dim[1]/nazi; |
412 |
> |
r1 = (alti + sp[0])/nalt; |
413 |
> |
r2 = (dim[1] - alti*nazi + sp[1] - .5)/nazi; |
414 |
> |
flatdir(dn, r1, r2); |
415 |
> |
for (j = 0; j < 3; j++) |
416 |
|
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; |
417 |
+ |
} |
418 |
|
/* random location */ |
419 |
+ |
multisamp(sp, 2, urand(h+8371)); |
420 |
|
r3 = sqrt(CO_R0(co)*CO_R0(co) + |
421 |
< |
sp[2]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); |
422 |
< |
r2 = 2.*PI*sp[3]; |
421 |
> |
sp[0]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); |
422 |
> |
r2 = 2.*PI*sp[1]; |
423 |
|
r1 = r3*cos(r2); |
424 |
|
r2 = r3*sin(r2); |
425 |
+ |
if (il->sd != NULL && DOT(dir, co->ad) < -FTINY) |
426 |
+ |
r3 = -1.0001*il->thick - .0001; |
427 |
+ |
else |
428 |
+ |
r3 = .0001; |
429 |
|
for (j = 0; j < 3; j++) |
430 |
< |
org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] + |
431 |
< |
.001*co->ad[j]; |
252 |
< |
|
430 |
> |
org[j] = CO_P0(co)[j] + r1*u[j] + r2*v[j] + |
431 |
> |
r3*co->ad[j]; |
432 |
|
/* send sample */ |
433 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
433 |
> |
raysamp(dim[1], org, dir); |
434 |
|
} |
435 |
< |
rayflush(rt); |
435 |
> |
rayclean(); |
436 |
> |
if (il->sd != NULL) { /* run distribution through BSDF */ |
437 |
> |
nalt = sqrt(il->sd->nout/PI) + .5; |
438 |
> |
nazi = PI*nalt + .5; |
439 |
> |
redistribute(il->sd, nalt, nazi, u, v, co->ad, xfm); |
440 |
> |
} |
441 |
|
/* write out the ring and its distribution */ |
442 |
< |
if (average(il, distarr, nalt*nazi)) { |
442 |
> |
if (average(il, distarr, n)) { |
443 |
|
if (il->sampdens > 0) |
444 |
|
flatout(il, distarr, nalt, nazi, u, v, co->ad); |
445 |
|
illumout(il, ob); |
446 |
< |
} else if (!(il->flags & IL_LIGHT)) |
446 |
> |
} else |
447 |
|
printobj(il->altmat, ob); |
448 |
|
/* clean up */ |
449 |
|
freecone(ob); |
450 |
< |
free((char *)distarr); |
267 |
< |
} |
268 |
< |
|
269 |
< |
|
270 |
< |
raysamp(res, org, dir, rt) /* compute a ray sample */ |
271 |
< |
float res[3]; |
272 |
< |
FVECT org, dir; |
273 |
< |
register struct rtproc *rt; |
274 |
< |
{ |
275 |
< |
register float *fp; |
276 |
< |
|
277 |
< |
if (rt->nrays == rt->bsiz) |
278 |
< |
rayflush(rt); |
279 |
< |
rt->dest[rt->nrays] = res; |
280 |
< |
fp = rt->buf + 6*rt->nrays++; |
281 |
< |
*fp++ = org[0]; *fp++ = org[1]; *fp++ = org[2]; |
282 |
< |
*fp++ = dir[0]; *fp++ = dir[1]; *fp = dir[2]; |
283 |
< |
} |
284 |
< |
|
285 |
< |
|
286 |
< |
rayflush(rt) /* flush buffered rays */ |
287 |
< |
register struct rtproc *rt; |
288 |
< |
{ |
289 |
< |
register int i; |
290 |
< |
|
291 |
< |
if (rt->nrays <= 0) |
292 |
< |
return; |
293 |
< |
bzero(rt->buf+6*rt->nrays, 6*sizeof(float)); |
294 |
< |
errno = 0; |
295 |
< |
if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf, |
296 |
< |
3*sizeof(float)*rt->nrays, |
297 |
< |
6*sizeof(float)*(rt->nrays+1)) < |
298 |
< |
3*sizeof(float)*rt->nrays ) |
299 |
< |
error(SYSTEM, "error reading from rtrace process"); |
300 |
< |
i = rt->nrays; |
301 |
< |
while (i--) { |
302 |
< |
rt->dest[i][0] += rt->buf[3*i]; |
303 |
< |
rt->dest[i][1] += rt->buf[3*i+1]; |
304 |
< |
rt->dest[i][2] += rt->buf[3*i+2]; |
305 |
< |
} |
306 |
< |
rt->nrays = 0; |
307 |
< |
} |
308 |
< |
|
309 |
< |
|
310 |
< |
mkaxes(u, v, n) /* compute u and v to go with n */ |
311 |
< |
FVECT u, v, n; |
312 |
< |
{ |
313 |
< |
register int i; |
314 |
< |
|
315 |
< |
v[0] = v[1] = v[2] = 0.0; |
316 |
< |
for (i = 0; i < 3; i++) |
317 |
< |
if (n[i] < 0.6 && n[i] > -0.6) |
318 |
< |
break; |
319 |
< |
v[i] = 1.0; |
320 |
< |
fcross(u, v, n); |
321 |
< |
normalize(u); |
322 |
< |
fcross(v, n, u); |
323 |
< |
} |
324 |
< |
|
325 |
< |
|
326 |
< |
rounddir(dv, alt, azi) /* compute uniform spherical direction */ |
327 |
< |
register FVECT dv; |
328 |
< |
double alt, azi; |
329 |
< |
{ |
330 |
< |
double d1, d2; |
331 |
< |
|
332 |
< |
dv[2] = 1. - 2.*alt; |
333 |
< |
d1 = sqrt(1. - dv[2]*dv[2]); |
334 |
< |
d2 = 2.*PI * azi; |
335 |
< |
dv[0] = d1*cos(d2); |
336 |
< |
dv[1] = d1*sin(d2); |
337 |
< |
} |
338 |
< |
|
339 |
< |
|
340 |
< |
flatdir(dv, alt, azi) /* compute uniform hemispherical direction */ |
341 |
< |
register FVECT dv; |
342 |
< |
double alt, azi; |
343 |
< |
{ |
344 |
< |
double d1, d2; |
345 |
< |
|
346 |
< |
d1 = sqrt(alt); |
347 |
< |
d2 = 2.*PI * azi; |
348 |
< |
dv[0] = d1*cos(d2); |
349 |
< |
dv[1] = d1*sin(d2); |
350 |
< |
dv[2] = sqrt(1. - alt); |
450 |
> |
return(1); |
451 |
|
} |