1 |
– |
/* Copyright (c) 1996 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 "ambient.h" |
13 |
+ |
|
14 |
|
#include "otypes.h" |
15 |
|
|
16 |
|
#include "func.h" |
17 |
|
|
18 |
|
#include "random.h" |
19 |
|
|
19 |
– |
extern double specthresh; /* specular sampling threshold */ |
20 |
– |
extern double specjitter; /* specular sampling jitter */ |
21 |
– |
|
22 |
– |
extern int backvis; /* back faces visible? */ |
23 |
– |
|
20 |
|
#ifndef MAXITER |
21 |
|
#define MAXITER 10 /* maximum # specular ray attempts */ |
22 |
|
#endif |
23 |
|
|
28 |
– |
static agaussamp(), getacoords(); |
29 |
– |
|
24 |
|
/* |
25 |
|
* This routine implements the anisotropic Gaussian |
26 |
|
* model described by Ward in Siggraph `92 article. |
62 |
|
double pdot; /* perturbed dot product */ |
63 |
|
} ANISODAT; /* anisotropic material data */ |
64 |
|
|
65 |
+ |
static void getacoords(); |
66 |
+ |
static void agaussamp(); |
67 |
|
|
68 |
+ |
|
69 |
+ |
static void |
70 |
|
diraniso(cval, np, ldir, omega) /* compute source contribution */ |
71 |
|
COLOR cval; /* returned coefficient */ |
72 |
|
register ANISODAT *np; /* material data */ |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
+ |
int |
184 |
|
m_aniso(m, r) /* shade ray that hit something anisotropic */ |
185 |
|
register OBJREC *m; |
186 |
|
register RAY *r; |
194 |
|
|
195 |
|
if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6)) |
196 |
|
objerror(m, USER, "bad number of real arguments"); |
197 |
+ |
/* check for back side */ |
198 |
+ |
if (r->rod < 0.0) { |
199 |
+ |
if (!backvis && m->otype != MAT_TRANS2) { |
200 |
+ |
raytrans(r); |
201 |
+ |
return(1); |
202 |
+ |
} |
203 |
+ |
raytexture(r, m->omod); |
204 |
+ |
flipsurface(r); /* reorient if backvis */ |
205 |
+ |
} else |
206 |
+ |
raytexture(r, m->omod); |
207 |
+ |
/* get material color */ |
208 |
|
nd.mp = m; |
209 |
|
nd.rp = r; |
200 |
– |
/* get material color */ |
210 |
|
setcolor(nd.mcolor, m->oargs.farg[0], |
211 |
|
m->oargs.farg[1], |
212 |
|
m->oargs.farg[2]); |
216 |
|
nd.v_alpha = m->oargs.farg[5]; |
217 |
|
if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY) |
218 |
|
objerror(m, USER, "roughness too small"); |
219 |
< |
/* check for back side */ |
211 |
< |
if (r->rod < 0.0) { |
212 |
< |
if (!backvis && m->otype != MAT_TRANS2) { |
213 |
< |
raytrans(r); |
214 |
< |
return(1); |
215 |
< |
} |
216 |
< |
flipsurface(r); /* reorient if backvis */ |
217 |
< |
} |
218 |
< |
/* get modifiers */ |
219 |
< |
raytexture(r, m->omod); |
219 |
> |
|
220 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
221 |
|
if (nd.pdot < .001) |
222 |
|
nd.pdot = .001; /* non-zero for diraniso() */ |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
< |
static |
310 |
> |
static void |
311 |
|
getacoords(r, np) /* set up coordinate system */ |
312 |
|
RAY *r; |
313 |
|
register ANISODAT *np; |
320 |
|
errno = 0; |
321 |
|
for (i = 0; i < 3; i++) |
322 |
|
np->u[i] = evalue(mf->ep[i]); |
323 |
< |
if (errno) { |
323 |
> |
if (errno == EDOM || errno == ERANGE) { |
324 |
|
objerror(np->mp, WARNING, "compute error"); |
325 |
|
np->specfl |= SP_BADU; |
326 |
|
return; |
337 |
|
} |
338 |
|
|
339 |
|
|
340 |
< |
static |
340 |
> |
static void |
341 |
|
agaussamp(r, np) /* sample anisotropic gaussian specular */ |
342 |
|
RAY *r; |
343 |
|
register ANISODAT *np; |
359 |
|
d = urand(ilhash(dimlist,ndims)+samplendx); |
360 |
|
multisamp(rv, 2, d); |
361 |
|
d = 2.0*PI * rv[0]; |
362 |
< |
cosp = cos(d) * np->u_alpha; |
363 |
< |
sinp = sin(d) * np->v_alpha; |
362 |
> |
cosp = tcos(d) * np->u_alpha; |
363 |
> |
sinp = tsin(d) * np->v_alpha; |
364 |
|
d = sqrt(cosp*cosp + sinp*sinp); |
365 |
|
cosp /= d; |
366 |
|
sinp /= d; |
397 |
|
d = urand(ilhash(dimlist,ndims)+1823+samplendx); |
398 |
|
multisamp(rv, 2, d); |
399 |
|
d = 2.0*PI * rv[0]; |
400 |
< |
cosp = cos(d) * np->u_alpha; |
401 |
< |
sinp = sin(d) * np->v_alpha; |
400 |
> |
cosp = tcos(d) * np->u_alpha; |
401 |
> |
sinp = tsin(d) * np->v_alpha; |
402 |
|
d = sqrt(cosp*cosp + sinp*sinp); |
403 |
|
cosp /= d; |
404 |
|
sinp /= d; |
408 |
|
else |
409 |
|
d = sqrt(-log(rv[1]) / |
410 |
|
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
411 |
< |
sinp*sinp/(np->v_alpha*np->u_alpha))); |
411 |
> |
sinp*sinp/(np->v_alpha*np->v_alpha))); |
412 |
|
for (i = 0; i < 3; i++) |
413 |
|
sr.rdir[i] = np->prdir[i] + |
414 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |