1 |
– |
/* Copyright (c) 1992 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 |
|
* Shading functions for anisotropic materials. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
|
#include "otypes.h" |
15 |
|
|
16 |
|
#include "random.h" |
17 |
|
|
18 |
< |
extern double specthresh; /* specular sampling threshold */ |
19 |
< |
extern double specjitter; /* specular sampling jitter */ |
18 |
> |
#ifndef MAXITER |
19 |
> |
#define MAXITER 10 /* maximum # specular ray attempts */ |
20 |
> |
#endif |
21 |
|
|
22 |
|
/* |
23 |
< |
* This anisotropic reflection model uses a variant on the |
24 |
< |
* exponential Gaussian used in normal.c. |
23 |
> |
* This routine implements the anisotropic Gaussian |
24 |
> |
* model described by Ward in Siggraph `92 article. |
25 |
|
* We orient the surface towards the incoming ray, so a single |
26 |
|
* surface can be used to represent an infinitely thin object. |
27 |
|
* |
34 |
|
* 8 red grn blu rspec u-rough v-rough trans tspec |
35 |
|
*/ |
36 |
|
|
37 |
– |
#define BSPEC(m) (6.0) /* specularity parameter b */ |
38 |
– |
|
37 |
|
/* specularity flags */ |
38 |
|
#define SP_REFL 01 /* has reflected specular component */ |
39 |
|
#define SP_TRAN 02 /* has transmitted specular */ |
40 |
< |
#define SP_PURE 010 /* purely specular (zero roughness) */ |
41 |
< |
#define SP_FLAT 020 /* reflecting surface is flat */ |
42 |
< |
#define SP_RBLT 040 /* reflection below sample threshold */ |
43 |
< |
#define SP_TBLT 0100 /* transmission below threshold */ |
46 |
< |
#define SP_BADU 0200 /* bad u direction calculation */ |
40 |
> |
#define SP_FLAT 04 /* reflecting surface is flat */ |
41 |
> |
#define SP_RBLT 010 /* reflection below sample threshold */ |
42 |
> |
#define SP_TBLT 020 /* transmission below threshold */ |
43 |
> |
#define SP_BADU 040 /* bad u direction calculation */ |
44 |
|
|
45 |
|
typedef struct { |
46 |
|
OBJREC *mp; /* material pointer */ |
60 |
|
double pdot; /* perturbed dot product */ |
61 |
|
} ANISODAT; /* anisotropic material data */ |
62 |
|
|
63 |
+ |
static void getacoords(); |
64 |
+ |
static void agaussamp(); |
65 |
|
|
66 |
+ |
|
67 |
+ |
static void |
68 |
|
diraniso(cval, np, ldir, omega) /* compute source contribution */ |
69 |
|
COLOR cval; /* returned coefficient */ |
70 |
|
register ANISODAT *np; /* material data */ |
72 |
|
double omega; /* light source size */ |
73 |
|
{ |
74 |
|
double ldot; |
75 |
< |
double dtmp, dtmp2; |
75 |
> |
double dtmp, dtmp1, dtmp2; |
76 |
|
FVECT h; |
77 |
|
double au2, av2; |
78 |
|
COLOR ctmp; |
95 |
|
scalecolor(ctmp, dtmp); |
96 |
|
addcolor(cval, ctmp); |
97 |
|
} |
98 |
< |
if (ldot > FTINY && (np->specfl&(SP_REFL|SP_PURE|SP_BADU)) == SP_REFL) { |
98 |
> |
if (ldot > FTINY && (np->specfl&(SP_REFL|SP_BADU)) == SP_REFL) { |
99 |
|
/* |
100 |
|
* Compute specular reflection coefficient using |
101 |
|
* anisotropic gaussian distribution model. |
105 |
|
au2 = av2 = omega/(4.0*PI); |
106 |
|
else |
107 |
|
au2 = av2 = 0.0; |
108 |
< |
au2 += np->u_alpha * np->u_alpha; |
109 |
< |
av2 += np->v_alpha * np->v_alpha; |
108 |
> |
au2 += np->u_alpha*np->u_alpha; |
109 |
> |
av2 += np->v_alpha*np->v_alpha; |
110 |
|
/* half vector */ |
111 |
|
h[0] = ldir[0] - np->rp->rdir[0]; |
112 |
|
h[1] = ldir[1] - np->rp->rdir[1]; |
113 |
|
h[2] = ldir[2] - np->rp->rdir[2]; |
113 |
– |
normalize(h); |
114 |
|
/* ellipse */ |
115 |
< |
dtmp = DOT(np->u, h); |
116 |
< |
dtmp *= dtmp / au2; |
115 |
> |
dtmp1 = DOT(np->u, h); |
116 |
> |
dtmp1 *= dtmp1 / au2; |
117 |
|
dtmp2 = DOT(np->v, h); |
118 |
|
dtmp2 *= dtmp2 / av2; |
119 |
|
/* gaussian */ |
120 |
< |
dtmp = (dtmp + dtmp2) / (1.0 + DOT(np->pnorm, h)); |
121 |
< |
dtmp = exp(-2.0*dtmp) / (4.0*PI * sqrt(au2*av2)); |
120 |
> |
dtmp = DOT(np->pnorm, h); |
121 |
> |
dtmp = (dtmp1 + dtmp2) / (dtmp*dtmp); |
122 |
> |
dtmp = exp(-dtmp) * (0.25/PI) |
123 |
> |
* sqrt(ldot/(np->pdot*au2*av2)); |
124 |
|
/* worth using? */ |
125 |
|
if (dtmp > FTINY) { |
126 |
|
copycolor(ctmp, np->scolor); |
127 |
< |
dtmp *= omega / np->pdot; |
127 |
> |
dtmp *= omega; |
128 |
|
scalecolor(ctmp, dtmp); |
129 |
|
addcolor(cval, ctmp); |
130 |
|
} |
138 |
|
scalecolor(ctmp, dtmp); |
139 |
|
addcolor(cval, ctmp); |
140 |
|
} |
141 |
< |
if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_PURE|SP_BADU)) == SP_TRAN) { |
141 |
> |
if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_BADU)) == SP_TRAN) { |
142 |
|
/* |
143 |
|
* Compute specular transmission. Specular transmission |
144 |
|
* is always modified by material color. |
145 |
|
*/ |
146 |
|
/* roughness + source */ |
147 |
+ |
au2 = av2 = omega / PI; |
148 |
+ |
au2 += np->u_alpha*np->u_alpha; |
149 |
+ |
av2 += np->v_alpha*np->v_alpha; |
150 |
+ |
/* "half vector" */ |
151 |
+ |
h[0] = ldir[0] - np->prdir[0]; |
152 |
+ |
h[1] = ldir[1] - np->prdir[1]; |
153 |
+ |
h[2] = ldir[2] - np->prdir[2]; |
154 |
+ |
dtmp = DOT(h,h); |
155 |
+ |
if (dtmp > FTINY*FTINY) { |
156 |
+ |
dtmp1 = DOT(h,np->pnorm); |
157 |
+ |
dtmp = 1.0 - dtmp1*dtmp1/dtmp; |
158 |
+ |
if (dtmp > FTINY*FTINY) { |
159 |
+ |
dtmp1 = DOT(h,np->u); |
160 |
+ |
dtmp1 *= dtmp1 / au2; |
161 |
+ |
dtmp2 = DOT(h,np->v); |
162 |
+ |
dtmp2 *= dtmp2 / av2; |
163 |
+ |
dtmp = (dtmp1 + dtmp2) / dtmp; |
164 |
+ |
} |
165 |
+ |
} else |
166 |
+ |
dtmp = 0.0; |
167 |
|
/* gaussian */ |
168 |
< |
dtmp = 0.0; |
168 |
> |
dtmp = exp(-dtmp) * (1.0/PI) |
169 |
> |
* sqrt(-ldot/(np->pdot*au2*av2)); |
170 |
|
/* worth using? */ |
171 |
|
if (dtmp > FTINY) { |
172 |
|
copycolor(ctmp, np->mcolor); |
173 |
< |
dtmp *= np->tspec * omega / np->pdot; |
173 |
> |
dtmp *= np->tspec * omega; |
174 |
|
scalecolor(ctmp, dtmp); |
175 |
|
addcolor(cval, ctmp); |
176 |
|
} |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
+ |
int |
182 |
|
m_aniso(m, r) /* shade ray that hit something anisotropic */ |
183 |
|
register OBJREC *m; |
184 |
|
register RAY *r; |
185 |
|
{ |
186 |
|
ANISODAT nd; |
163 |
– |
double transtest, transdist; |
164 |
– |
double dtmp; |
187 |
|
COLOR ctmp; |
188 |
|
register int i; |
189 |
|
/* easy shadow test */ |
190 |
< |
if (r->crtype & SHADOW && m->otype != MAT_TRANS2) |
191 |
< |
return; |
190 |
> |
if (r->crtype & SHADOW) |
191 |
> |
return(1); |
192 |
|
|
193 |
|
if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6)) |
194 |
|
objerror(m, USER, "bad number of real arguments"); |
195 |
+ |
/* check for back side */ |
196 |
+ |
if (r->rod < 0.0) { |
197 |
+ |
if (!backvis && m->otype != MAT_TRANS2) { |
198 |
+ |
raytrans(r); |
199 |
+ |
return(1); |
200 |
+ |
} |
201 |
+ |
raytexture(r, m->omod); |
202 |
+ |
flipsurface(r); /* reorient if backvis */ |
203 |
+ |
} else |
204 |
+ |
raytexture(r, m->omod); |
205 |
+ |
/* get material color */ |
206 |
|
nd.mp = m; |
207 |
|
nd.rp = r; |
175 |
– |
/* get material color */ |
208 |
|
setcolor(nd.mcolor, m->oargs.farg[0], |
209 |
|
m->oargs.farg[1], |
210 |
|
m->oargs.farg[2]); |
212 |
|
nd.specfl = 0; |
213 |
|
nd.u_alpha = m->oargs.farg[4]; |
214 |
|
nd.v_alpha = m->oargs.farg[5]; |
215 |
< |
if (nd.u_alpha <= FTINY || nd.v_alpha <= FTINY) |
216 |
< |
nd.specfl |= SP_PURE; |
217 |
< |
/* reorient if necessary */ |
186 |
< |
if (r->rod < 0.0) |
187 |
< |
flipsurface(r); |
188 |
< |
/* get modifiers */ |
189 |
< |
raytexture(r, m->omod); |
215 |
> |
if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY) |
216 |
> |
objerror(m, USER, "roughness too small"); |
217 |
> |
|
218 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
219 |
|
if (nd.pdot < .001) |
220 |
|
nd.pdot = .001; /* non-zero for diraniso() */ |
221 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
194 |
– |
transtest = 0; |
222 |
|
/* get specular component */ |
223 |
|
if ((nd.rspec = m->oargs.farg[3]) > FTINY) { |
224 |
|
nd.specfl |= SP_REFL; |
228 |
|
else |
229 |
|
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
230 |
|
scalecolor(nd.scolor, nd.rspec); |
204 |
– |
/* improved model */ |
205 |
– |
dtmp = exp(-BSPEC(m)*nd.pdot); |
206 |
– |
for (i = 0; i < 3; i++) |
207 |
– |
colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp; |
208 |
– |
nd.rspec += (1.0-nd.rspec)*dtmp; |
231 |
|
/* check threshold */ |
232 |
< |
if (specthresh > FTINY && |
211 |
< |
((specthresh >= 1.-FTINY || |
212 |
< |
specthresh + (.05 - .1*frandom()) > nd.rspec))) |
232 |
> |
if (specthresh >= nd.rspec-FTINY) |
233 |
|
nd.specfl |= SP_RBLT; |
234 |
|
/* compute refl. direction */ |
235 |
|
for (i = 0; i < 3; i++) |
237 |
|
if (DOT(nd.vrefl, r->ron) <= FTINY) /* penetration? */ |
238 |
|
for (i = 0; i < 3; i++) /* safety measure */ |
239 |
|
nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; |
220 |
– |
|
221 |
– |
if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) { |
222 |
– |
RAY lr; |
223 |
– |
if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) { |
224 |
– |
VCOPY(lr.rdir, nd.vrefl); |
225 |
– |
rayvalue(&lr); |
226 |
– |
multcolor(lr.rcol, nd.scolor); |
227 |
– |
addcolor(r->rcol, lr.rcol); |
228 |
– |
} |
229 |
– |
} |
240 |
|
} |
241 |
|
/* compute transmission */ |
242 |
< |
if (m->otype == MAT_TRANS) { |
242 |
> |
if (m->otype == MAT_TRANS2) { |
243 |
|
nd.trans = m->oargs.farg[6]*(1.0 - nd.rspec); |
244 |
|
nd.tspec = nd.trans * m->oargs.farg[7]; |
245 |
|
nd.tdiff = nd.trans - nd.tspec; |
246 |
|
if (nd.tspec > FTINY) { |
247 |
|
nd.specfl |= SP_TRAN; |
248 |
|
/* check threshold */ |
249 |
< |
if (specthresh > FTINY && |
240 |
< |
((specthresh >= 1.-FTINY || |
241 |
< |
specthresh + |
242 |
< |
(.05 - .1*frandom()) > nd.tspec))) |
249 |
> |
if (specthresh >= nd.tspec-FTINY) |
250 |
|
nd.specfl |= SP_TBLT; |
251 |
< |
if (r->crtype & SHADOW || |
245 |
< |
DOT(r->pert,r->pert) <= FTINY*FTINY) { |
251 |
> |
if (DOT(r->pert,r->pert) <= FTINY*FTINY) { |
252 |
|
VCOPY(nd.prdir, r->rdir); |
247 |
– |
transtest = 2; |
253 |
|
} else { |
254 |
|
for (i = 0; i < 3; i++) /* perturb */ |
255 |
< |
nd.prdir[i] = r->rdir[i] - |
251 |
< |
0.5*r->pert[i]; |
255 |
> |
nd.prdir[i] = r->rdir[i] - r->pert[i]; |
256 |
|
if (DOT(nd.prdir, r->ron) < -FTINY) |
257 |
|
normalize(nd.prdir); /* OK */ |
258 |
|
else |
261 |
|
} |
262 |
|
} else |
263 |
|
nd.tdiff = nd.tspec = nd.trans = 0.0; |
260 |
– |
/* transmitted ray */ |
261 |
– |
if ((nd.specfl&(SP_TRAN|SP_PURE)) == (SP_TRAN|SP_PURE)) { |
262 |
– |
RAY lr; |
263 |
– |
if (rayorigin(&lr, r, TRANS, nd.tspec) == 0) { |
264 |
– |
VCOPY(lr.rdir, nd.prdir); |
265 |
– |
rayvalue(&lr); |
266 |
– |
scalecolor(lr.rcol, nd.tspec); |
267 |
– |
multcolor(lr.rcol, nd.mcolor); /* modified by color */ |
268 |
– |
addcolor(r->rcol, lr.rcol); |
269 |
– |
transtest *= bright(lr.rcol); |
270 |
– |
transdist = r->rot + lr.rt; |
271 |
– |
} |
272 |
– |
} |
264 |
|
|
274 |
– |
if (r->crtype & SHADOW) /* the rest is shadow */ |
275 |
– |
return; |
265 |
|
/* diffuse reflection */ |
266 |
|
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
267 |
|
|
268 |
< |
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
269 |
< |
return; /* 100% pure specular */ |
281 |
< |
|
282 |
< |
if (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING) |
268 |
> |
if (r->ro != NULL && isflat(r->ro->otype) && |
269 |
> |
DOT(r->pert,r->pert) <= FTINY*FTINY) |
270 |
|
nd.specfl |= SP_FLAT; |
271 |
|
|
272 |
|
getacoords(r, &nd); /* set up coordinates */ |
273 |
|
|
274 |
< |
if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & (SP_PURE|SP_BADU))) |
274 |
> |
if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_BADU)) |
275 |
|
agaussamp(r, &nd); |
276 |
|
|
277 |
|
if (nd.rdiff > FTINY) { /* ambient from this side */ |
278 |
< |
ambient(ctmp, r); |
278 |
> |
ambient(ctmp, r, nd.pnorm); |
279 |
|
if (nd.specfl & SP_RBLT) |
280 |
|
scalecolor(ctmp, 1.0-nd.trans); |
281 |
|
else |
284 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
285 |
|
} |
286 |
|
if (nd.tdiff > FTINY) { /* ambient from other side */ |
287 |
+ |
FVECT bnorm; |
288 |
+ |
|
289 |
|
flipsurface(r); |
290 |
< |
ambient(ctmp, r); |
290 |
> |
bnorm[0] = -nd.pnorm[0]; |
291 |
> |
bnorm[1] = -nd.pnorm[1]; |
292 |
> |
bnorm[2] = -nd.pnorm[2]; |
293 |
> |
ambient(ctmp, r, bnorm); |
294 |
|
if (nd.specfl & SP_TBLT) |
295 |
|
scalecolor(ctmp, nd.trans); |
296 |
|
else |
301 |
|
} |
302 |
|
/* add direct component */ |
303 |
|
direct(r, diraniso, &nd); |
304 |
< |
/* check distance */ |
305 |
< |
if (transtest > bright(r->rcol)) |
314 |
< |
r->rt = transdist; |
304 |
> |
|
305 |
> |
return(1); |
306 |
|
} |
307 |
|
|
308 |
|
|
309 |
< |
static |
309 |
> |
static void |
310 |
|
getacoords(r, np) /* set up coordinate system */ |
311 |
|
RAY *r; |
312 |
|
register ANISODAT *np; |
319 |
|
errno = 0; |
320 |
|
for (i = 0; i < 3; i++) |
321 |
|
np->u[i] = evalue(mf->ep[i]); |
322 |
< |
if (errno) { |
322 |
> |
if (errno == EDOM || errno == ERANGE) { |
323 |
|
objerror(np->mp, WARNING, "compute error"); |
324 |
|
np->specfl |= SP_BADU; |
325 |
|
return; |
326 |
|
} |
327 |
< |
multv3(np->u, np->u, mf->f->xfm); |
327 |
> |
if (mf->f != &unitxf) |
328 |
> |
multv3(np->u, np->u, mf->f->xfm); |
329 |
|
fcross(np->v, np->pnorm, np->u); |
330 |
|
if (normalize(np->v) == 0.0) { |
331 |
|
objerror(np->mp, WARNING, "illegal orientation vector"); |
336 |
|
} |
337 |
|
|
338 |
|
|
339 |
< |
static |
339 |
> |
static void |
340 |
|
agaussamp(r, np) /* sample anisotropic gaussian specular */ |
341 |
|
RAY *r; |
342 |
|
register ANISODAT *np; |
345 |
|
FVECT h; |
346 |
|
double rv[2]; |
347 |
|
double d, sinp, cosp; |
348 |
+ |
int niter; |
349 |
|
register int i; |
350 |
|
/* compute reflection */ |
351 |
|
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
352 |
|
rayorigin(&sr, r, SPECULAR, np->rspec) == 0) { |
353 |
|
dimlist[ndims++] = (int)np->mp; |
354 |
< |
d = urand(ilhash(dimlist,ndims)+samplendx); |
355 |
< |
multisamp(rv, 2, d); |
356 |
< |
d = 2.0*PI * rv[0]; |
357 |
< |
cosp = np->u_alpha * cos(d); |
358 |
< |
sinp = np->v_alpha * sin(d); |
359 |
< |
d = sqrt(cosp*cosp + sinp*sinp); |
360 |
< |
cosp /= d; |
361 |
< |
sinp /= d; |
362 |
< |
rv[1] = 1.0 - specjitter*rv[1]; |
363 |
< |
if (rv[1] <= FTINY) |
364 |
< |
d = 1.0; |
365 |
< |
else |
366 |
< |
d = sqrt(-log(rv[1]) / |
367 |
< |
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
368 |
< |
sinp*sinp/(np->v_alpha*np->v_alpha))); |
369 |
< |
for (i = 0; i < 3; i++) |
370 |
< |
h[i] = np->pnorm[i] + |
371 |
< |
d*(cosp*np->u[i] + sinp*np->v[i]); |
372 |
< |
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
373 |
< |
for (i = 0; i < 3; i++) |
374 |
< |
sr.rdir[i] = r->rdir[i] + d*h[i]; |
375 |
< |
if (DOT(sr.rdir, r->ron) <= FTINY) /* penetration? */ |
376 |
< |
VCOPY(sr.rdir, np->vrefl); /* jitter no good */ |
377 |
< |
rayvalue(&sr); |
378 |
< |
multcolor(sr.rcol, np->scolor); |
379 |
< |
addcolor(r->rcol, sr.rcol); |
354 |
> |
for (niter = 0; niter < MAXITER; niter++) { |
355 |
> |
if (niter) |
356 |
> |
d = frandom(); |
357 |
> |
else |
358 |
> |
d = urand(ilhash(dimlist,ndims)+samplendx); |
359 |
> |
multisamp(rv, 2, d); |
360 |
> |
d = 2.0*PI * rv[0]; |
361 |
> |
cosp = tcos(d) * np->u_alpha; |
362 |
> |
sinp = tsin(d) * np->v_alpha; |
363 |
> |
d = sqrt(cosp*cosp + sinp*sinp); |
364 |
> |
cosp /= d; |
365 |
> |
sinp /= d; |
366 |
> |
rv[1] = 1.0 - specjitter*rv[1]; |
367 |
> |
if (rv[1] <= FTINY) |
368 |
> |
d = 1.0; |
369 |
> |
else |
370 |
> |
d = sqrt(-log(rv[1]) / |
371 |
> |
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
372 |
> |
sinp*sinp/(np->v_alpha*np->v_alpha))); |
373 |
> |
for (i = 0; i < 3; i++) |
374 |
> |
h[i] = np->pnorm[i] + |
375 |
> |
d*(cosp*np->u[i] + sinp*np->v[i]); |
376 |
> |
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
377 |
> |
for (i = 0; i < 3; i++) |
378 |
> |
sr.rdir[i] = r->rdir[i] + d*h[i]; |
379 |
> |
if (DOT(sr.rdir, r->ron) > FTINY) { |
380 |
> |
rayvalue(&sr); |
381 |
> |
multcolor(sr.rcol, np->scolor); |
382 |
> |
addcolor(r->rcol, sr.rcol); |
383 |
> |
break; |
384 |
> |
} |
385 |
> |
} |
386 |
|
ndims--; |
387 |
|
} |
388 |
|
/* compute transmission */ |
389 |
|
if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && |
390 |
|
rayorigin(&sr, r, SPECULAR, np->tspec) == 0) { |
391 |
|
dimlist[ndims++] = (int)np->mp; |
392 |
< |
d = urand(ilhash(dimlist,ndims)+1823+samplendx); |
393 |
< |
multisamp(rv, 2, d); |
394 |
< |
d = 2.0*PI * rv[0]; |
395 |
< |
cosp = cos(d); |
396 |
< |
sinp = sin(d); |
397 |
< |
rv[1] = 1.0 - specjitter*rv[1]; |
398 |
< |
if (rv[1] <= FTINY) |
399 |
< |
d = 1.0; |
400 |
< |
else |
401 |
< |
d = sqrt(-log(rv[1]) / |
402 |
< |
(cosp*cosp*4./(np->u_alpha*np->u_alpha) + |
403 |
< |
sinp*sinp*4./(np->v_alpha*np->v_alpha))); |
404 |
< |
for (i = 0; i < 3; i++) |
405 |
< |
sr.rdir[i] = np->prdir[i] + |
406 |
< |
d*(cosp*np->u[i] + sinp*np->v[i]); |
407 |
< |
if (DOT(sr.rdir, r->ron) < -FTINY) |
408 |
< |
normalize(sr.rdir); /* OK, normalize */ |
409 |
< |
else |
410 |
< |
VCOPY(sr.rdir, np->prdir); /* else no jitter */ |
411 |
< |
rayvalue(&sr); |
412 |
< |
multcolor(sr.rcol, np->scolor); |
413 |
< |
addcolor(r->rcol, sr.rcol); |
392 |
> |
for (niter = 0; niter < MAXITER; niter++) { |
393 |
> |
if (niter) |
394 |
> |
d = frandom(); |
395 |
> |
else |
396 |
> |
d = urand(ilhash(dimlist,ndims)+1823+samplendx); |
397 |
> |
multisamp(rv, 2, d); |
398 |
> |
d = 2.0*PI * rv[0]; |
399 |
> |
cosp = tcos(d) * np->u_alpha; |
400 |
> |
sinp = tsin(d) * np->v_alpha; |
401 |
> |
d = sqrt(cosp*cosp + sinp*sinp); |
402 |
> |
cosp /= d; |
403 |
> |
sinp /= d; |
404 |
> |
rv[1] = 1.0 - specjitter*rv[1]; |
405 |
> |
if (rv[1] <= FTINY) |
406 |
> |
d = 1.0; |
407 |
> |
else |
408 |
> |
d = sqrt(-log(rv[1]) / |
409 |
> |
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
410 |
> |
sinp*sinp/(np->v_alpha*np->v_alpha))); |
411 |
> |
for (i = 0; i < 3; i++) |
412 |
> |
sr.rdir[i] = np->prdir[i] + |
413 |
> |
d*(cosp*np->u[i] + sinp*np->v[i]); |
414 |
> |
if (DOT(sr.rdir, r->ron) < -FTINY) { |
415 |
> |
normalize(sr.rdir); /* OK, normalize */ |
416 |
> |
rayvalue(&sr); |
417 |
> |
scalecolor(sr.rcol, np->tspec); |
418 |
> |
multcolor(sr.rcol, np->mcolor); /* modify */ |
419 |
> |
addcolor(r->rcol, sr.rcol); |
420 |
> |
break; |
421 |
> |
} |
422 |
> |
} |
423 |
|
ndims--; |
424 |
|
} |
425 |
|
} |