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

Comparing ray/src/rt/ashikhmin.c (file contents):
Revision 2.6 by greg, Wed Sep 2 18:59:01 2015 UTC vs.
Revision 2.7 by greg, Wed Nov 15 18:02:52 2023 UTC

# Line 38 | Line 38 | typedef struct {
38          OBJREC  *mp;            /* material pointer */
39          RAY  *rp;               /* ray pointer */
40          short  specfl;          /* specularity flags, defined above */
41 <        COLOR  mcolor;          /* color of this material */
42 <        COLOR  scolor;          /* color of specular component */
41 >        SCOLOR  mcolor;         /* color of this material */
42 >        SCOLOR  scolor;         /* color of specular component */
43          FVECT  u, v;            /* u and v vectors orienting anisotropy */
44          double  u_power;        /* u power */
45          double  v_power;        /* v power */
# Line 65 | Line 65 | schlick_fres(double dprod)
65  
66   static void
67   dirashik(               /* compute source contribution */
68 <        COLOR  cval,            /* returned coefficient */
68 >        SCOLOR  scval,          /* returned coefficient */
69          void  *nnp,             /* material data */
70          FVECT  ldir,            /* light source direction */
71          double  omega           /* light source size */
# Line 75 | Line 75 | dirashik(              /* compute source contribution */
75          double  ldot;
76          double  dtmp, dtmp1, dtmp2;
77          FVECT  h;
78 <        COLOR  ctmp;
78 >        SCOLOR  sctmp;
79  
80 <        setcolor(cval, 0.0, 0.0, 0.0);
80 >        scolorblack(scval);
81  
82          ldot = DOT(np->pnorm, ldir);
83  
84 <        if (ldot < 0.0)
84 >        if (ldot <= FTINY)
85                  return;         /* wrong side */
86  
87          /*
88           *  Compute and add diffuse reflected component to returned
89           *  color.
90           */
91 <        copycolor(ctmp, np->mcolor);
91 >        copyscolor(sctmp, np->mcolor);
92          dtmp = ldot * omega * (1.0/PI) * (1. - schlick_fres(ldot));
93 <        scalecolor(ctmp, dtmp);        
94 <        addcolor(cval, ctmp);
93 >        scalescolor(sctmp, dtmp);
94 >        saddscolor(scval, sctmp);
95  
96          if (!(np->specfl & SPA_REFL) || ambRayInPmap(np->rp))
97                  return;
# Line 113 | Line 113 | dirashik(              /* compute source contribution */
113          dtmp /= 8.*PI * DOT(ldir,h) * MAX(ldot,np->pdot);
114                                          /* worth using? */
115          if (dtmp > FTINY) {
116 <                copycolor(ctmp, np->scolor);
116 >                copyscolor(sctmp, np->scolor);
117                  dtmp *= ldot * omega;
118 <                scalecolor(ctmp, dtmp);
119 <                addcolor(cval, ctmp);
118 >                scalescolor(sctmp, dtmp);
119 >                saddscolor(scval, sctmp);
120          }
121   }
122  
# Line 128 | Line 128 | m_ashikhmin(                   /* shade ray that hit something anisotr
128   )
129   {
130          ASHIKDAT  nd;
131 <        COLOR  ctmp;
131 >        SCOLOR  sctmp;
132          double  fres;
133          int  i;
134                                                  /* easy shadow test */
# Line 150 | Line 150 | m_ashikhmin(                   /* shade ray that hit something anisotr
150                                                  /* get material color */
151          nd.mp = m;
152          nd.rp = r;
153 <        setcolor(nd.mcolor, m->oargs.farg[0],
153 >        setscolor(nd.mcolor, m->oargs.farg[0],
154                             m->oargs.farg[1],
155                             m->oargs.farg[2]);
156 <        setcolor(nd.scolor, m->oargs.farg[3],
156 >        setscolor(nd.scolor, m->oargs.farg[3],
157                             m->oargs.farg[4],
158                             m->oargs.farg[5]);
159                                                  /* get specular power */
# Line 164 | Line 164 | m_ashikhmin(                   /* shade ray that hit something anisotr
164          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
165          if (nd.pdot < .001)
166                  nd.pdot = .001;                 /* non-zero for dirashik() */
167 <        multcolor(nd.mcolor, r->pcol);          /* modify diffuse color */
167 >        smultscolor(nd.mcolor, r->pcol);        /* modify diffuse color */
168  
169 <        if (bright(nd.scolor) > FTINY) {        /* adjust specular color */
169 >        if (sintens(nd.scolor) > FTINY) {       /* adjust specular color */
170                  nd.specfl |= SPA_REFL;
171                                                  /* check threshold */
172 <                if (specthresh >= bright(nd.scolor)-FTINY)
172 >                if (specthresh >= pbright(nd.scolor)-FTINY)
173                          nd.specfl |= SPA_RBLT;
174                  fres = schlick_fres(nd.pdot);   /* Schick's Fresnel approx */
175 <                for (i = 0; i < 3; i++)
176 <                        colval(nd.scolor,i) += (1.-colval(nd.scolor,i))*fres;
175 >                for (i = NCSAMP; i--; )
176 >                        nd.scolor[i] += (1.-nd.scolor[i])*fres;
177          }
178          if (r->ro != NULL && isflat(r->ro->otype))
179                  nd.specfl |= SPA_FLAT;
# Line 183 | Line 183 | m_ashikhmin(                   /* shade ray that hit something anisotr
183          if ((nd.specfl & (SPA_REFL|SPA_RBLT)) == SPA_REFL)
184                  ashiksamp(&nd);
185                                                  /* diffuse interreflection */
186 <        if (bright(nd.mcolor) > FTINY) {
187 <                copycolor(ctmp, nd.mcolor);     /* modified by material color */                
186 >        if (sintens(nd.mcolor) > FTINY) {
187 >                copyscolor(sctmp, nd.mcolor);   /* modified by material color */
188                  if (nd.specfl & SPA_RBLT)       /* add in specular as well? */
189 <                        addcolor(ctmp, nd.scolor);
190 <                multambient(ctmp, r, nd.pnorm);
191 <                addcolor(r->rcol, ctmp);        /* add to returned color */
189 >                        saddscolor(sctmp, nd.scolor);
190 >                multambient(sctmp, r, nd.pnorm);
191 >                saddscolor(r->rcol, sctmp);     /* add to returned color */
192          }
193          direct(r, dirashik, &nd);               /* add direct component */
194  
# Line 248 | Line 248 | ashiksamp(             /* sample anisotropic Ashikhmin-Shirley sp
248                          nstarget = sr.rweight/minweight;
249                  if (nstarget > 1) {
250                          dtmp = 1./nstarget;
251 <                        scalecolor(sr.rcoef, dtmp);
251 >                        scalescolor(sr.rcoef, dtmp);
252                          sr.rweight *= dtmp;
253                  } else
254                          nstarget = 1;
# Line 284 | Line 284 | ashiksamp(             /* sample anisotropic Ashikhmin-Shirley sp
284                          continue;
285                  checknorm(sr.rdir);
286                  rayvalue(&sr);
287 <                multcolor(sr.rcol, sr.rcoef);
288 <                addcolor(np->rp->rcol, sr.rcol);
287 >                smultscolor(sr.rcol, sr.rcoef);
288 >                saddscolor(np->rp->rcol, sr.rcol);
289                  ++nstaken;
290          }
291          ndims--;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines