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.28 by greg, Wed Dec 21 09:51:49 1994 UTC vs.
Revision 2.30 by greg, Tue Sep 26 15:05:32 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 156 | 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 164 | 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 175 | 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 <                                                /* check for back side */
190 <        if (r->rod < 0.0) {
180 <                if (!backvis && m->otype != MAT_TRANS) {
181 <                        raytrans(r);
182 <                        return(1);
183 <                }
184 <                flipsurface(r);                 /* reorient if backvis */
185 <        }
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 */
195 <        if ((nd.rspec = m->oargs.farg[3]) > FTINY) {
196 <                nd.specfl |= SP_REFL;
197 <                                                /* compute specular color */
198 <                if (m->otype == MAT_METAL)
199 <                        copycolor(nd.scolor, nd.mcolor);
200 <                else
201 <                        setcolor(nd.scolor, 1.0, 1.0, 1.0);
202 <                scalecolor(nd.scolor, nd.rspec);
203 <                                                /* check threshold */
204 <                if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY)
205 <                        nd.specfl |= SP_RBLT;
206 <                                                /* compute reflected ray */
207 <                for (i = 0; i < 3; i++)
208 <                        nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
209 <                if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
210 <                        for (i = 0; i < 3; i++)         /* safety measure */
211 <                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
212 <
213 <                if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
214 <                        RAY  lr;
215 <                        if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
216 <                                VCOPY(lr.rdir, nd.vrefl);
217 <                                rayvalue(&lr);
218 <                                multcolor(lr.rcol, nd.scolor);
219 <                                addcolor(r->rcol, lr.rcol);
220 <                        }
221 <                }
222 <        }
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 231 | 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 ||
235 <                                        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 261 | 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  
272        if (r->ro != NULL && (r->ro->otype == OBJ_FACE ||
273                        r->ro->otype == OBJ_RING))
274                nd.specfl |= SP_FLAT;
275
289          if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_PURE))
290                  gaussamp(r, &nd);
291  
# Line 299 | Line 312 | register RAY  *r;
312                                          /* add direct component */
313          direct(r, dirnorm, &nd);
314                                          /* check distance */
315 <        if (transtest > bright(r->rcol))
315 >        d = bright(r->rcol);
316 >        if (transtest > d)
317                  r->rt = transdist;
318 +        else if (mirtest > d)
319 +                r->rt = mirdist;
320  
321          return(1);
322   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines