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

Comparing ray/src/cv/bsdf2ttree.c (file contents):
Revision 2.15 by greg, Wed May 15 03:22:31 2013 UTC vs.
Revision 2.18 by greg, Thu Sep 26 17:05:00 2013 UTC

# Line 24 | Line 24 | int                    samp_order = 6;
24   const double            ssamp_thresh = 0.35;
25                                  /* number of super-samples */
26   const int               nssamp = 100;
27 +                                /* limit on number of RBF lobes */
28 + static int              lobe_lim = 15000;
29  
30   /* Output XML prologue to stdout */
31   static void
# Line 112 | Line 114 | eval_isotropic(char *funame)
114   {
115          const int       sqres = 1<<samp_order;
116          FILE            *ofp = NULL;
117 +        int             assignD = 0;
118          char            cmd[128];
119          int             ix, ox, oy;
120          double          iovec[6];
# Line 131 | Line 134 | eval_isotropic(char *funame)
134                  SET_FILE_BINARY(ofp);
135          } else
136                  fputs("{\n", stdout);
137 +                                                /* need to assign Dx, Dy, Dz? */
138 +        if (funame != NULL)
139 +                assignD = (fundefined(funame) < 6);
140                                                  /* run through directions */
141          for (ix = 0; ix < sqres/2; ix++) {
142                  RBFNODE *rbf = NULL;
# Line 138 | Line 144 | eval_isotropic(char *funame)
144                  iovec[1] = .0;
145                  iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]);
146                  if (funame == NULL)
147 <                        rbf = advect_rbf(iovec);
147 >                        rbf = advect_rbf(iovec, lobe_lim);
148                  for (ox = 0; ox < sqres; ox++) {
149                      float       last_bsdf = -1;
150                      for (oy = 0; oy < sqres; oy++) {
# Line 149 | Line 155 | eval_isotropic(char *funame)
155                              bsdf = eval_rbfrep(rbf, iovec+3) *
156                                                  output_orient/iovec[5];
157                          else {
158 <                            double      ssa[3], ssvec[6];
158 >                            double      ssa[3], ssvec[6], sum;
159                              int         ssi;
160 +                            if (assignD) {
161 +                                varset("Dx", '=', -iovec[3]);
162 +                                varset("Dy", '=', -iovec[4]);
163 +                                varset("Dz", '=', -iovec[5]);
164 +                                ++eclock;
165 +                            }
166                              bsdf = funvalue(funame, 6, iovec);
167                              if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
168 <                                bsdf = 0;       /* super-sample voxel */
168 >                                sum = 0;        /* super-sample voxel */
169                                  for (ssi = nssamp; ssi--; ) {
170                                      SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp);
171                                      ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.;
# Line 165 | Line 177 | eval_isotropic(char *funame)
177                                      ssvec[5] = output_orient *
178                                                  sqrt(1. - ssvec[3]*ssvec[3] -
179                                                          ssvec[4]*ssvec[4]);
180 <                                    bsdf += funvalue(funame, 6, ssvec);
180 >                                    if (assignD) {
181 >                                        varset("Dx", '=', -iovec[3]);
182 >                                        varset("Dy", '=', -iovec[4]);
183 >                                        varset("Dz", '=', -iovec[5]);
184 >                                        ++eclock;
185 >                                    }
186 >                                    sum += funvalue(funame, 6, ssvec);
187                                  }
188 <                                bsdf /= (float)nssamp;
188 >                                bsdf = sum/nssamp;
189                              }
190                          }
191                          if (pctcull >= 0)
# Line 200 | Line 218 | eval_anisotropic(char *funame)
218   {
219          const int       sqres = 1<<samp_order;
220          FILE            *ofp = NULL;
221 +        int             assignD = 0;
222          char            cmd[128];
223          int             ix, iy, ox, oy;
224          double          iovec[6];
# Line 218 | Line 237 | eval_anisotropic(char *funame)
237                  }
238          } else
239                  fputs("{\n", stdout);
240 +                                                /* need to assign Dx, Dy, Dz? */
241 +        if (funame != NULL)
242 +                assignD = (fundefined(funame) < 6);
243                                                  /* run through directions */
244          for (ix = 0; ix < sqres; ix++)
245              for (iy = 0; iy < sqres; iy++) {
# Line 226 | Line 248 | eval_anisotropic(char *funame)
248                  iovec[2] = input_orient *
249                                  sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]);
250                  if (funame == NULL)
251 <                        rbf = advect_rbf(iovec);
251 >                        rbf = advect_rbf(iovec, lobe_lim);
252                  for (ox = 0; ox < sqres; ox++) {
253                      float       last_bsdf = -1;
254                      for (oy = 0; oy < sqres; oy++) {
# Line 237 | Line 259 | eval_anisotropic(char *funame)
259                              bsdf = eval_rbfrep(rbf, iovec+3) *
260                                                  output_orient/iovec[5];
261                          else {
262 <                            double      ssa[4], ssvec[6];
262 >                            double      ssa[4], ssvec[6], sum;
263                              int         ssi;
264 +                            if (assignD) {
265 +                                varset("Dx", '=', -iovec[3]);
266 +                                varset("Dy", '=', -iovec[4]);
267 +                                varset("Dz", '=', -iovec[5]);
268 +                                ++eclock;
269 +                            }
270                              bsdf = funvalue(funame, 6, iovec);
271                              if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
272 <                                bsdf = 0;       /* super-sample voxel */
272 >                                sum = 0;        /* super-sample voxel */
273                                  for (ssi = nssamp; ssi--; ) {
274                                      SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp);
275                                      SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres,
# Line 254 | Line 282 | eval_anisotropic(char *funame)
282                                      ssvec[5] = output_orient *
283                                                  sqrt(1. - ssvec[3]*ssvec[3] -
284                                                          ssvec[4]*ssvec[4]);
285 <                                    bsdf += funvalue(funame, 6, ssvec);
285 >                                    if (assignD) {
286 >                                        varset("Dx", '=', -iovec[3]);
287 >                                        varset("Dy", '=', -iovec[4]);
288 >                                        varset("Dz", '=', -iovec[5]);
289 >                                        ++eclock;
290 >                                    }
291 >                                    sum += funvalue(funame, 6, ssvec);
292                                  }
293 <                                bsdf /= (float)nssamp;
293 >                                bsdf = sum/nssamp;
294                              }
295                          }
296                          if (pctcull >= 0)
# Line 324 | Line 358 | main(int argc, char *argv[])
358                  case 'g':
359                          samp_order = atoi(argv[++i]);
360                          break;
361 +                case 'l':
362 +                        lobe_lim = atoi(argv[++i]);
363 +                        break;
364                  default:
365                          goto userr;
366                  }
367          if (single_plane_incident >= 0) {       /* function-based BSDF? */
368                  void    (*evf)(char *s) = single_plane_incident ?
369                                  &eval_isotropic : &eval_anisotropic;
370 <                if (i != argc-1 || fundefined(argv[i]) != 6) {
370 >                if (i != argc-1 || fundefined(argv[i]) < 3) {
371                          fprintf(stderr,
372          "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n",
373                                          progname);
374 +                        fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n",
375 +                                        progname);
376                          goto userr;
377                  }
378 +                ++eclock;
379                  xml_prologue(argc, argv);       /* start XML output */
380                  if (dofwd) {
381                          input_orient = -1;
# Line 388 | Line 428 | main(int argc, char *argv[])
428          return(0);
429   userr:
430          fprintf(stderr,
431 <        "Usage: %s [-g Nlog2][-t pctcull] [bsdf.sir ..] > bsdf.xml\n",
431 >        "Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
432                                  progname);
433          fprintf(stderr,
434          "   or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines