--- ray/src/rt/aniso.c 2003/02/22 02:07:28 2.34 +++ ray/src/rt/aniso.c 2004/03/30 16:13:00 2.41 @@ -1,73 +1,18 @@ #ifndef lint -static const char RCSid[] = "$Id: aniso.c,v 2.34 2003/02/22 02:07:28 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. */ -/* ==================================================================== - * The Radiance Software License, Version 1.0 - * - * Copyright (c) 1990 - 2002 The Regents of the University of California, - * through Lawrence Berkeley National Laboratory. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes Radiance software - * (http://radsite.lbl.gov/) - * developed by the Lawrence Berkeley National Laboratory - * (http://www.lbl.gov/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Radiance," "Lawrence Berkeley National Laboratory" - * and "The Regents of the University of California" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact radiance@radsite.lbl.gov. - * - * 5. Products derived from this software may not be called "Radiance", - * nor may "Radiance" appear in their name, without prior written - * permission of Lawrence Berkeley National Laboratory. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of Lawrence Berkeley National Laboratory. For more - * information on Lawrence Berkeley National Laboratory, please see - * . - */ +#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 @@ -115,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; @@ -233,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; @@ -247,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]); @@ -259,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() */ @@ -360,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; @@ -372,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; @@ -390,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;