ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/glass.c
(Generate patch)

Comparing ray/src/rt/glass.c (file contents):
Revision 2.10 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.28 by greg, Fri Apr 19 19:01:32 2019 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  glass.c - simpler shading function for thin glass surfaces.
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10   #include  "ray.h"
66
11   #include  "otypes.h"
12 + #include  "rtotypes.h"
13 + #include  "pmapmat.h"
14  
15   /*
16   *  This definition of glass provides for a quick calculation
# Line 96 | Line 42 | static const char      RCSid[] = "$Id$";
42   #define  RINDEX         1.52            /* refractive index of glass */
43  
44  
45 < m_glass(m, r)           /* color a ray which hit a thin glass surface */
46 < OBJREC  *m;
47 < register RAY  *r;
45 > int
46 > m_glass(                /* color a ray which hit a thin glass surface */
47 >        OBJREC  *m,
48 >        RAY  *r
49 > )
50   {
51          COLOR  mcolor;
52          double  pdot;
53          FVECT  pnorm;
54 <        double  rindex, cos2;
54 >        double  rindex=0, cos2;
55          COLOR  trans, refl;
56 <        int  hastexture;
56 >        int  hastexture, hastrans;
57          double  d, r1e, r1m;
110        double  transtest, transdist;
111        double  mirtest, mirdist;
58          RAY  p;
59 <        register int  i;
59 >        int  i;
60 >
61 >        /* PMAP: skip refracted shadow or ambient ray if accounted for in
62 >           photon map */
63 >        if (shadowRayInPmap(r) || ambRayInPmap(r))
64 >                return(1);
65                                                  /* check arguments */
66          if (m->oargs.nfargs == 3)
67                  rindex = RINDEX;                /* default value of n */
# Line 118 | Line 69 | register RAY  *r;
69                  rindex = m->oargs.farg[3];      /* use their value */
70          else
71                  objerror(m, USER, "bad arguments");
72 <
72 >                                                /* check back face visibility */
73 >        if (!backvis && r->rod <= 0.0) {
74 >                raytrans(r);
75 >                return(1);
76 >        }
77 >                                                /* check transmission */
78          setcolor(mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]);
79 <
80 <        if (r->rod < 0.0)                       /* reorient if necessary */
81 <                flipsurface(r);
82 <        mirtest = transtest = 0;
83 <        mirdist = transdist = r->rot;
79 >        if ((hastrans = (intens(mcolor) > 1e-15))) {
80 >                for (i = 0; i < 3; i++)
81 >                        if (colval(mcolor,i) < 1e-15)
82 >                                colval(mcolor,i) = 1e-15;
83 >        } else if (r->crtype & SHADOW)
84 >                return(1);
85                                                  /* get modifiers */
86          raytexture(r, m->omod);
87 <        if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY)
87 >        if (r->rod < 0.0)                       /* reorient if necessary */
88 >                flipsurface(r);
89 >                                                /* perturb normal */
90 >        if ( (hastexture = (DOT(r->pert,r->pert) > FTINY*FTINY)) ) {
91                  pdot = raynormal(pnorm, r);
92 <        else {
92 >        } else {
93                  VCOPY(pnorm, r->ron);
94                  pdot = r->rod;
95          }
96                                                  /* angular transmission */
97          cos2 = sqrt( (1.0-1.0/(rindex*rindex)) +
98                       pdot*pdot/(rindex*rindex) );
99 <        setcolor(mcolor, pow(colval(mcolor,RED), 1.0/cos2),
100 <                         pow(colval(mcolor,GRN), 1.0/cos2),
101 <                         pow(colval(mcolor,BLU), 1.0/cos2));
99 >        if (hastrans)
100 >                setcolor(mcolor, pow(colval(mcolor,RED), 1.0/cos2),
101 >                                 pow(colval(mcolor,GRN), 1.0/cos2),
102 >                                 pow(colval(mcolor,BLU), 1.0/cos2));
103  
104                                                  /* compute reflection */
105          r1e = (pdot - rindex*cos2) / (pdot + rindex*cos2);
106          r1e *= r1e;
107          r1m = (1.0/pdot - rindex/cos2) / (1.0/pdot + rindex/cos2);
108          r1m *= r1m;
109 <                                                /* compute transmittance */
110 <        for (i = 0; i < 3; i++) {
111 <                d = colval(mcolor, i);
112 <                colval(trans,i) = .5*(1.0-r1e)*(1.0-r1e)*d/(1.0-r1e*r1e*d*d);
113 <                colval(trans,i) += .5*(1.0-r1m)*(1.0-r1m)*d/(1.0-r1m*r1m*d*d);
114 <        }
109 >                                                /* compute transmission */
110 >        if (hastrans) {
111 >                for (i = 0; i < 3; i++) {
112 >                        d = colval(mcolor, i);
113 >                        colval(trans,i) = .5*(1.0-r1e)*(1.0-r1e)*d /
114 >                                                        (1.0-r1e*r1e*d*d);
115 >                        colval(trans,i) += .5*(1.0-r1m)*(1.0-r1m)*d /
116 >                                                        (1.0-r1m*r1m*d*d);
117 >                }
118 >                multcolor(trans, r->pcol);      /* modify by pattern */
119                                                  /* transmitted ray */
120 <        if (rayorigin(&p, r, TRANS, bright(trans)) == 0) {
121 <                if (!(r->crtype & SHADOW) && hastexture) {
122 <                        for (i = 0; i < 3; i++)         /* perturb direction */
123 <                                p.rdir[i] = r->rdir[i] +
124 <                                                2.*(1.-rindex)*r->pert[i];
125 <                        if (normalize(p.rdir) == 0.0) {
126 <                                objerror(m, WARNING, "bad perturbation");
120 >                if (rayorigin(&p, TRANS, r, trans) == 0) {
121 >                        if (!(r->crtype & (SHADOW|AMBIENT)) && hastexture) {
122 >                                VSUM(p.rdir, r->rdir, r->pert, 2.*(1.-rindex));
123 >                                if (normalize(p.rdir) == 0.0) {
124 >                                        objerror(m, WARNING, "bad perturbation");
125 >                                        VCOPY(p.rdir, r->rdir);
126 >                                }
127 >                        } else {
128                                  VCOPY(p.rdir, r->rdir);
129                          }
130 <                } else {
131 <                        VCOPY(p.rdir, r->rdir);
132 <                        transtest = 2;
130 >                        rayvalue(&p);
131 >                        multcolor(p.rcol, p.rcoef);
132 >                        addcolor(r->rcol, p.rcol);
133 >                        if (!hastexture || r->crtype & (SHADOW|AMBIENT))
134 >                                r->rxt = r->rot + raydistance(&p);
135                  }
168                rayvalue(&p);
169                multcolor(p.rcol, r->pcol);     /* modify */
170                multcolor(p.rcol, trans);
171                addcolor(r->rcol, p.rcol);
172                transtest *= bright(p.rcol);
173                transdist = r->rot + p.rt;
136          }
137 <
176 <        if (r->crtype & SHADOW) {               /* skip reflected ray */
177 <                r->rt = transdist;
137 >        if (r->crtype & SHADOW)                 /* skip reflected ray */
138                  return(1);
179        }
139                                                  /* compute reflectance */
140          for (i = 0; i < 3; i++) {
141                  d = colval(mcolor, i);
# Line 185 | Line 144 | register RAY  *r;
144                  colval(refl,i) += .5*r1m*(1.0+(1.0-2.0*r1m)*d)/(1.0-r1m*r1m*d);
145          }
146                                                  /* reflected ray */
147 <        if (rayorigin(&p, r, REFLECTED, bright(refl)) == 0) {
148 <                for (i = 0; i < 3; i++)
149 <                        p.rdir[i] = r->rdir[i] + 2.0*pdot*pnorm[i];
147 >        if (rayorigin(&p, REFLECTED, r, refl) == 0) {
148 >                VSUM(p.rdir, r->rdir, pnorm, 2.*pdot);
149 >                checknorm(p.rdir);
150                  rayvalue(&p);
151 <                multcolor(p.rcol, refl);
151 >                multcolor(p.rcol, p.rcoef);
152 >                copycolor(r->mcol, p.rcol);
153                  addcolor(r->rcol, p.rcol);
154 <                if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) {
155 <                        mirtest = 2.0*bright(p.rcol);
156 <                        mirdist = r->rot + p.rt;
157 <                }
154 >                r->rmt = r->rot;
155 >                if (r->ro != NULL && isflat(r->ro->otype) &&
156 >                                !hastexture | (r->crtype & AMBIENT))
157 >                        r->rmt += raydistance(&p);
158          }
199                                        /* check distance */
200        d = bright(r->rcol);
201        if (transtest > d)
202                r->rt = transdist;
203        else if (mirtest > d)
204                r->rt = mirdist;
159          return(1);
160   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines