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.29 by greg, Fri Sep 15 15:47:30 1995 UTC

# 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;
202 >        mirtest = transtest = 0;
203 >        mirdist = transdist = r->rot;
204                                                  /* get specular component */
205          if ((nd.rspec = m->oargs.farg[3]) > FTINY) {
206                  nd.specfl |= SP_REFL;
# Line 205 | Line 215 | register RAY  *r;
215                          nd.specfl |= SP_RBLT;
216                                                  /* compute reflected ray */
217                  for (i = 0; i < 3; i++)
218 <                        nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
219 <                if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
218 >                        nd.vrefl[i] = r->rdir[i] + 2.*nd.pdot*nd.pnorm[i];
219 >                                                /* penetration? */
220 >                if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY)
221                          for (i = 0; i < 3; i++)         /* safety measure */
222                                  nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
223  
# Line 217 | Line 228 | register RAY  *r;
228                                  rayvalue(&lr);
229                                  multcolor(lr.rcol, nd.scolor);
230                                  addcolor(r->rcol, lr.rcol);
231 +                                if (!hastexture && nd.specfl & SP_FLAT) {
232 +                                        mirtest = 2.*bright(lr.rcol);
233 +                                        mirdist = r->rot + lr.rt;
234 +                                }
235                          }
236                  }
237          }
# Line 231 | Line 246 | register RAY  *r;
246                          if (!(nd.specfl & SP_PURE) &&
247                                          specthresh >= nd.tspec-FTINY)
248                                  nd.specfl |= SP_TBLT;
249 <                        if (r->crtype & SHADOW ||
235 <                                        DOT(r->pert,r->pert) <= FTINY*FTINY) {
249 >                        if (!hastexture || r->crtype & SHADOW) {
250                                  VCOPY(nd.prdir, r->rdir);
251                                  transtest = 2;
252                          } else {
# Line 261 | Line 275 | register RAY  *r;
275          } else
276                  transtest = 0;
277  
278 <        if (r->crtype & SHADOW)                 /* the rest is shadow */
278 >        if (r->crtype & SHADOW) {               /* the rest is shadow */
279 >                r->rt = transdist;
280                  return(1);
281 +        }
282                                                  /* diffuse reflection */
283          nd.rdiff = 1.0 - nd.trans - nd.rspec;
284  
285          if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY)
286                  return(1);                      /* 100% pure specular */
287  
272        if (r->ro != NULL && (r->ro->otype == OBJ_FACE ||
273                        r->ro->otype == OBJ_RING))
274                nd.specfl |= SP_FLAT;
275
288          if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_PURE))
289                  gaussamp(r, &nd);
290  
# Line 299 | Line 311 | register RAY  *r;
311                                          /* add direct component */
312          direct(r, dirnorm, &nd);
313                                          /* check distance */
314 <        if (transtest > bright(r->rcol))
314 >        d = bright(r->rcol);
315 >        if (transtest > d)
316                  r->rt = transdist;
317 +        else if (mirtest > d)
318 +                r->rt = mirdist;
319  
320          return(1);
321   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines