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

Comparing ray/src/rt/normal.c (file contents):
Revision 2.27 by greg, Wed Jan 12 16:46:45 1994 UTC vs.
Revision 2.32 by greg, Wed Nov 22 09:27:55 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 23 | Line 23 | static char SCCSid[] = "$SunId$ LBL";
23   extern double  specthresh;              /* specular sampling threshold */
24   extern double  specjitter;              /* specular sampling jitter */
25  
26 + extern int  backvis;                    /* back faces visible? */
27 +
28   static  gaussamp();
29  
30   /*
# Line 154 | Line 156 | register RAY  *r;
156   {
157          NORMDAT  nd;
158          double  transtest, transdist;
159 +        double  mirtest, mirdist;
160 +        int     hastexture;
161 +        double  d;
162          COLOR  ctmp;
163          register int  i;
164                                                  /* easy shadow test */
# Line 162 | Line 167 | register RAY  *r;
167  
168          if (m->oargs.nfargs != (m->otype == MAT_TRANS ? 7 : 5))
169                  objerror(m, USER, "bad number of arguments");
170 +                                                /* check for back side */
171 +        if (r->rod < 0.0) {
172 +                if (!backvis && m->otype != MAT_TRANS) {
173 +                        raytrans(r);
174 +                        return(1);
175 +                }
176 +                flipsurface(r);                 /* reorient if backvis */
177 +        }
178          nd.mp = m;
179          nd.rp = r;
180                                                  /* get material color */
# Line 173 | Line 186 | register RAY  *r;
186          nd.alpha2 = m->oargs.farg[4];
187          if ((nd.alpha2 *= nd.alpha2) <= FTINY)
188                  nd.specfl |= SP_PURE;
189 <                                                /* reorient if necessary */
190 <        if (r->rod < 0.0)
178 <                flipsurface(r);
189 >        if (r->ro != NULL && isflat(r->ro->otype))
190 >                nd.specfl |= SP_FLAT;
191                                                  /* get modifiers */
192          raytexture(r, m->omod);
193 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
193 >        if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY)
194 >                nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
195 >        else {
196 >                VCOPY(nd.pnorm, r->ron);
197 >                nd.pdot = r->rod;
198 >        }
199          if (nd.pdot < .001)
200                  nd.pdot = .001;                 /* non-zero for dirnorm() */
201          multcolor(nd.mcolor, r->pcol);          /* modify material color */
202 <        transtest = 0;
203 <        transdist = r->rot;
204 <                                                /* get specular component */
188 <        if ((nd.rspec = m->oargs.farg[3]) > FTINY) {
189 <                nd.specfl |= SP_REFL;
190 <                                                /* compute specular color */
191 <                if (m->otype == MAT_METAL)
192 <                        copycolor(nd.scolor, nd.mcolor);
193 <                else
194 <                        setcolor(nd.scolor, 1.0, 1.0, 1.0);
195 <                scalecolor(nd.scolor, nd.rspec);
196 <                                                /* check threshold */
197 <                if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY)
198 <                        nd.specfl |= SP_RBLT;
199 <                                                /* compute reflected ray */
200 <                for (i = 0; i < 3; i++)
201 <                        nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
202 <                if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
203 <                        for (i = 0; i < 3; i++)         /* safety measure */
204 <                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
205 <
206 <                if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
207 <                        RAY  lr;
208 <                        if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
209 <                                VCOPY(lr.rdir, nd.vrefl);
210 <                                rayvalue(&lr);
211 <                                multcolor(lr.rcol, nd.scolor);
212 <                                addcolor(r->rcol, lr.rcol);
213 <                        }
214 <                }
215 <        }
202 >        mirtest = transtest = 0;
203 >        mirdist = transdist = r->rot;
204 >        nd.rspec = m->oargs.farg[3];
205                                                  /* compute transmission */
206          if (m->otype == MAT_TRANS) {
207                  nd.trans = m->oargs.farg[5]*(1.0 - nd.rspec);
# Line 224 | Line 213 | register RAY  *r;
213                          if (!(nd.specfl & SP_PURE) &&
214                                          specthresh >= nd.tspec-FTINY)
215                                  nd.specfl |= SP_TBLT;
216 <                        if (r->crtype & SHADOW ||
228 <                                        DOT(r->pert,r->pert) <= FTINY*FTINY) {
216 >                        if (!hastexture || r->crtype & SHADOW) {
217                                  VCOPY(nd.prdir, r->rdir);
218                                  transtest = 2;
219                          } else {
# Line 254 | Line 242 | register RAY  *r;
242          } else
243                  transtest = 0;
244  
245 <        if (r->crtype & SHADOW)                 /* the rest is shadow */
245 >        if (r->crtype & SHADOW) {               /* the rest is shadow */
246 >                r->rt = transdist;
247                  return(1);
248 +        }
249 +                                                /* get specular reflection */
250 +        if (nd.rspec > FTINY) {
251 +                nd.specfl |= SP_REFL;
252 +                                                /* compute specular color */
253 +                if (m->otype == MAT_METAL)
254 +                        copycolor(nd.scolor, nd.mcolor);
255 +                else
256 +                        setcolor(nd.scolor, 1.0, 1.0, 1.0);
257 +                scalecolor(nd.scolor, nd.rspec);
258 +                                                /* check threshold */
259 +                if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY)
260 +                        nd.specfl |= SP_RBLT;
261 +                                                /* compute reflected ray */
262 +                for (i = 0; i < 3; i++)
263 +                        nd.vrefl[i] = r->rdir[i] + 2.*nd.pdot*nd.pnorm[i];
264 +                                                /* penetration? */
265 +                if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY)
266 +                        for (i = 0; i < 3; i++)         /* safety measure */
267 +                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
268 +
269 +                if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
270 +                        RAY  lr;
271 +                        if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
272 +                                VCOPY(lr.rdir, nd.vrefl);
273 +                                rayvalue(&lr);
274 +                                multcolor(lr.rcol, nd.scolor);
275 +                                addcolor(r->rcol, lr.rcol);
276 +                                if (!hastexture && nd.specfl & SP_FLAT) {
277 +                                        mirtest = 2.*bright(lr.rcol);
278 +                                        mirdist = r->rot + lr.rt;
279 +                                }
280 +                        }
281 +                }
282 +        }
283                                                  /* diffuse reflection */
284          nd.rdiff = 1.0 - nd.trans - nd.rspec;
285  
286          if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY)
287                  return(1);                      /* 100% pure specular */
288  
265        if (r->ro != NULL && (r->ro->otype == OBJ_FACE ||
266                        r->ro->otype == OBJ_RING))
267                nd.specfl |= SP_FLAT;
268
289          if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_PURE))
290                  gaussamp(r, &nd);
291  
292          if (nd.rdiff > FTINY) {         /* ambient from this side */
293 <                ambient(ctmp, r);
293 >                ambient(ctmp, r, hastexture?nd.pnorm:r->ron);
294                  if (nd.specfl & SP_RBLT)
295                          scalecolor(ctmp, 1.0-nd.trans);
296                  else
# Line 280 | Line 300 | register RAY  *r;
300          }
301          if (nd.tdiff > FTINY) {         /* ambient from other side */
302                  flipsurface(r);
303 <                ambient(ctmp, r);
303 >                if (hastexture) {
304 >                        FVECT  bnorm;
305 >                        bnorm[0] = -nd.pnorm[0];
306 >                        bnorm[1] = -nd.pnorm[1];
307 >                        bnorm[2] = -nd.pnorm[2];
308 >                        ambient(ctmp, r, bnorm);
309 >                } else
310 >                        ambient(ctmp, r, r->ron);
311                  if (nd.specfl & SP_TBLT)
312                          scalecolor(ctmp, nd.trans);
313                  else
# Line 292 | Line 319 | register RAY  *r;
319                                          /* add direct component */
320          direct(r, dirnorm, &nd);
321                                          /* check distance */
322 <        if (transtest > bright(r->rcol))
322 >        d = bright(r->rcol);
323 >        if (transtest > d)
324                  r->rt = transdist;
325 +        else if (mirtest > d)
326 +                r->rt = mirdist;
327  
328          return(1);
329   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines