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

Comparing ray/src/gen/gendaymtx.c (file contents):
Revision 2.2 by greg, Fri Jan 18 19:56:03 2013 UTC vs.
Revision 2.4 by greg, Sun Jan 20 01:16:15 2013 UTC

# Line 246 | Line 246 | static const ModelCoeff DirectLumEff[8] =
246          { 101.18,  1.58, -1.10,  -8.29 }
247   };
248  
249 + #ifndef NSUNPATCH
250 + #define NSUNPATCH       4               /* # patches to spread sun into */
251 + #endif
252 +
253   extern int jdate(int month, int day);
254   extern double stadj(int  jd);
255   extern double sdec(int  jd);
# Line 256 | Line 260 | extern double  s_latitude;
260   extern double  s_longitude;
261   extern double  s_meridian;
262  
259 double          grefl = 0.2;            /* diffuse ground reflectance */
260
263   int             verbose = 0;            /* progress reports to stderr? */
264  
265   int             outfmt = 'a';           /* output format */
266  
267   int             rhsubdiv = 1;           /* Reinhart sky subdivisions */
268  
269 < float           skycolor[3] = {.96, 1.004, 1.118};      /* sky coloration */
269 > COLOR           skycolor = {.96, 1.004, 1.118}; /* sky coloration */
270 > COLOR           suncolor = {1., 1., 1.};        /* sun color */
271 > COLOR           grefl = {.2, .2, .2};           /* ground reflectance */
272  
269 int             do_sun = 1;             /* output direct solar contribution? */
270
273   int             nskypatch;              /* number of Reinhart patches */
274   float           *rh_palt;               /* sky patch altitudes (radians) */
275   float           *rh_pazi;               /* sky patch azimuths (radians) */
# Line 305 | Line 307 | main(int argc, char *argv[])
307                                          /* get options */
308          for (i = 1; i < argc && argv[i][0] == '-'; i++)
309                  switch (argv[i][1]) {
310 <                case 'g':
311 <                        grefl = atof(argv[++i]);
310 >                case 'g':                       /* ground reflectance */
311 >                        grefl[0] = atof(argv[++i]);
312 >                        grefl[1] = atof(argv[++i]);
313 >                        grefl[2] = atof(argv[++i]);
314                          break;
315 <                case 'v':
315 >                case 'v':                       /* verbose progress reports */
316                          verbose++;
317                          break;
318 <                case 'o':
318 >                case 'o':                       /* output format */
319                          switch (argv[i][2]) {
320                          case 'f':
321                          case 'd':
# Line 322 | Line 326 | main(int argc, char *argv[])
326                                  goto userr;
327                          }
328                          break;
329 <                case 'm':
329 >                case 'm':                       /* Reinhart subdivisions */
330                          rhsubdiv = atoi(argv[++i]);
331                          break;
332 <                case 'c':
332 >                case 'c':                       /* sky color */
333                          skycolor[0] = atof(argv[++i]);
334                          skycolor[1] = atof(argv[++i]);
335                          skycolor[2] = atof(argv[++i]);
336                          break;
337 <                case 'd':
334 <                        do_sun = 1;
337 >                case 'd':                       /* solar (direct) only */
338                          skycolor[0] = skycolor[1] = skycolor[2] = 0;
339 +                        if (suncolor[1] <= 1e-4)
340 +                                suncolor[0] = suncolor[1] = suncolor[2] = 1;
341                          break;
342 <                case 's':
343 <                        do_sun = 0;
342 >                case 's':                       /* sky only (no direct) */
343 >                        suncolor[0] = suncolor[1] = suncolor[2] = 0;
344                          if (skycolor[1] <= 1e-4)
345                                  skycolor[0] = skycolor[1] = skycolor[2] = 1;
346                          break;
# Line 429 | Line 434 | main(int argc, char *argv[])
434                  }
435                                          /* compute sky patch values */
436                  ComputeSky(mtx_data+mtx_offset);
437 <                if (do_sun)
433 <                        AddDirect(mtx_data+mtx_offset);
437 >                AddDirect(mtx_data+mtx_offset);
438          }
439                                          /* check for junk at end */
440          while ((i = fgetc(stdin)) != EOF)
# Line 455 | Line 459 | main(int argc, char *argv[])
459                  switch (outfmt) {
460                  case 'a':
461                          for (j = 0; j < ntsteps; j++) {
462 <                                printf("%.3e %.3e %.3e\n", mtx_data[mtx_offset],
462 >                                printf("%.3g %.3g %.3g\n", mtx_data[mtx_offset],
463                                                  mtx_data[mtx_offset+1],
464                                                  mtx_data[mtx_offset+2]);
465                                  mtx_offset += 3*nskypatch;
# Line 558 | Line 562 | ComputeSky(float *parr)
562                  return;
563          }
564          /* Compute ground radiance (include solar contribution if any) */
565 <        parr[0] = diff_illum * (1./PI/WHTEFFICACY);
565 >        parr[0] = diff_illum;
566          if (altitude > 0)
567 <                parr[0] += dir_illum * sin(altitude) * (1./PI/WHTEFFICACY);
568 <        parr[2] = parr[1] = parr[0];
567 >                parr[0] += dir_illum * sin(altitude);
568 >        parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
569 >        multcolor(parr, grefl);
570  
571          /* Calculate Perez sky model parameters */
572          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
# Line 593 | Line 598 | void
598   AddDirect(float *parr)
599   {
600          FVECT   svec;
601 <        double  near_dprod[4];
602 <        int     near_patch[4];
603 <        double  wta[4], wtot;
601 >        double  near_dprod[NSUNPATCH];
602 >        int     near_patch[NSUNPATCH];
603 >        double  wta[NSUNPATCH], wtot;
604          int     i, j, p;
605  
606 <        if (!do_sun || dir_illum < 1e-4)
606 >        if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
607                  return;
608 <                                        /* identify 4 closest patches */
609 <        for (i = 4; i--; )
608 >                                        /* identify NSUNPATCH closest patches */
609 >        for (i = NSUNPATCH; i--; )
610                  near_dprod[i] = -1.;
611          vector(svec, altitude, azimuth);
612          for (p = 1; p < nskypatch; p++) {
# Line 609 | Line 614 | AddDirect(float *parr)
614                  double  dprod;
615                  rh_vector(pvec, p);
616                  dprod = DOT(pvec, svec);
617 <                for (i = 0; i < 4; i++)
617 >                for (i = 0; i < NSUNPATCH; i++)
618                          if (dprod > near_dprod[i]) {
619 <                                for (j = 4; --j > i; ) {
619 >                                for (j = NSUNPATCH; --j > i; ) {
620                                          near_dprod[j] = near_dprod[j-1];
621                                          near_patch[j] = near_patch[j-1];
622                                  }
# Line 621 | Line 626 | AddDirect(float *parr)
626                          }
627          }
628          wtot = 0;                       /* weight by proximity */
629 <        for (i = 4; i--; )
629 >        for (i = NSUNPATCH; i--; )
630                  wtot += wta[i] = 1./(1.002 - near_dprod[i]);
631                                          /* add to nearest patch radiances */
632 <        for (i = 4; i--; ) {
632 >        for (i = NSUNPATCH; i--; ) {
633                  float   *pdest = parr + 3*near_patch[i];
634                  float   val_add = wta[i] * dir_illum /
635                                  (WHTEFFICACY * wtot * rh_dom[near_patch[i]]);
636 <                *pdest++ += val_add;
637 <                *pdest++ += val_add;
638 <                *pdest++ += val_add;
636 >                *pdest++ += val_add*suncolor[0];
637 >                *pdest++ += val_add*suncolor[1];
638 >                *pdest++ += val_add*suncolor[2];
639          }
640   }
641  
# Line 665 | Line 670 | rh_init(void)
670          for (i = 0; i < NROW*rhsubdiv; i++) {
671                  const float     ralt = alpha*(i + .5);
672                  const int       ninrow = tnaz[i/rhsubdiv]*rhsubdiv;
673 <                const float     dom = (sin(alpha*(i+1)) - sin(alpha*i))/ninrow;
673 >                const float     dom = 2.*PI*(sin(alpha*(i+1)) - sin(alpha*i)) /
674 >                                                (double)ninrow;
675                  for (j = 0; j < ninrow; j++) {
676                          rh_palt[p] = ralt;
677                          rh_pazi[p] = 2.*PI * j / (double)ninrow;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines