--- ray/src/rt/aniso.c 2003/02/25 02:47:22 2.35 +++ ray/src/rt/aniso.c 2004/03/30 16:13:00 2.41 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: aniso.c,v 2.35 2003/02/25 02:47:22 greg Exp $"; +static const char RCSid[] = "$Id: aniso.c,v 2.41 2004/03/30 16:13:00 schorsch Exp $"; #endif /* * Shading functions for anisotropic materials. @@ -8,11 +8,11 @@ static const char RCSid[] = "$Id: aniso.c,v 2.35 2003/ #include "copyright.h" #include "ray.h" - +#include "ambient.h" #include "otypes.h" - +#include "rtotypes.h" +#include "source.h" #include "func.h" - #include "random.h" #ifndef MAXITER @@ -60,17 +60,20 @@ typedef struct { double pdot; /* perturbed dot product */ } ANISODAT; /* anisotropic material data */ -static void getacoords(); -static void agaussamp(); +static srcdirf_t diraniso; +static void getacoords(RAY *r, ANISODAT *np); +static void agaussamp(RAY *r, ANISODAT *np); static void -diraniso(cval, np, ldir, omega) /* compute source contribution */ -COLOR cval; /* returned coefficient */ -register ANISODAT *np; /* material data */ -FVECT ldir; /* light source direction */ -double omega; /* light source size */ +diraniso( /* compute source contribution */ + COLOR cval, /* returned coefficient */ + void *nnp, /* material data */ + FVECT ldir, /* light source direction */ + double omega /* light source size */ +) { + register ANISODAT *np = nnp; double ldot; double dtmp, dtmp1, dtmp2; FVECT h; @@ -178,10 +181,11 @@ double omega; /* light source size */ } -int -m_aniso(m, r) /* shade ray that hit something anisotropic */ -register OBJREC *m; -register RAY *r; +extern int +m_aniso( /* shade ray that hit something anisotropic */ + register OBJREC *m, + register RAY *r +) { ANISODAT nd; COLOR ctmp; @@ -192,9 +196,19 @@ register RAY *r; if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6)) objerror(m, USER, "bad number of real arguments"); + /* check for back side */ + if (r->rod < 0.0) { + if (!backvis && m->otype != MAT_TRANS2) { + raytrans(r); + return(1); + } + raytexture(r, m->omod); + flipsurface(r); /* reorient if backvis */ + } else + raytexture(r, m->omod); + /* get material color */ nd.mp = m; nd.rp = r; - /* get material color */ setcolor(nd.mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); @@ -204,16 +218,7 @@ register RAY *r; nd.v_alpha = m->oargs.farg[5]; if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY) objerror(m, USER, "roughness too small"); - /* check for back side */ - if (r->rod < 0.0) { - if (!backvis && m->otype != MAT_TRANS2) { - raytrans(r); - return(1); - } - flipsurface(r); /* reorient if backvis */ - } - /* get modifiers */ - raytexture(r, m->omod); + nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ if (nd.pdot < .001) nd.pdot = .001; /* non-zero for diraniso() */ @@ -305,9 +310,10 @@ register RAY *r; static void -getacoords(r, np) /* set up coordinate system */ -RAY *r; -register ANISODAT *np; +getacoords( /* set up coordinate system */ + RAY *r, + register ANISODAT *np +) { register MFUNC *mf; register int i; @@ -317,7 +323,7 @@ register ANISODAT *np; errno = 0; for (i = 0; i < 3; i++) np->u[i] = evalue(mf->ep[i]); - if (errno) { + if (errno == EDOM || errno == ERANGE) { objerror(np->mp, WARNING, "compute error"); np->specfl |= SP_BADU; return; @@ -335,9 +341,10 @@ register ANISODAT *np; static void -agaussamp(r, np) /* sample anisotropic gaussian specular */ -RAY *r; -register ANISODAT *np; +agaussamp( /* sample anisotropic gaussian specular */ + RAY *r, + register ANISODAT *np +) { RAY sr; FVECT h;