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.3 by greg, Sat Jan 19 20:38:36 2013 UTC vs.
Revision 2.7 by greg, Sat Jan 26 00:59:08 2013 UTC

# Line 260 | Line 260 | extern double  s_latitude;
260   extern double  s_longitude;
261   extern double  s_meridian;
262  
263 double          grefl = 0.2;            /* diffuse ground reflectance */
264
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  
273 int             do_sun = 1;             /* output direct solar contribution? */
274
273   int             nskypatch;              /* number of Reinhart patches */
274   float           *rh_palt;               /* sky patch altitudes (radians) */
275   float           *rh_pazi;               /* sky patch azimuths (radians) */
# Line 309 | 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 326 | 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':
338 <                        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 433 | Line 434 | main(int argc, char *argv[])
434                  }
435                                          /* compute sky patch values */
436                  ComputeSky(mtx_data+mtx_offset);
437 <                if (do_sun)
437 <                        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 494 | Line 494 | main(int argc, char *argv[])
494                  fprintf(stderr, "%s: done.\n", progname);
495          exit(0);
496   userr:
497 <        fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g refl][-c r g b][-o{f|d}] [tape.wea]\n",
497 >        fprintf(stderr, "Usage: %s [-v][-d|-s][-m N][-g r g b][-c r g b][-o{f|d}] [tape.wea]\n",
498                          progname);
499          exit(1);
500   fmterr:
# Line 515 | Line 515 | ComputeSky(float *parr)
515   {
516          int index;                      /* Category index */
517          double norm_diff_illum;         /* Normalized diffuse illuimnance */
518        double zlumin;                  /* Zenith luminance */
518          int i;
519          
520          /* Calculate atmospheric precipitable water content */
521          apwc = CalcPrecipWater(dew_point);
522  
523 <        /* Limit solar altitude to keep circumsolar off zenith */
524 <        if (altitude > DegToRad(87.0))
525 <                altitude = DegToRad(87.0);
523 >        /* Calculate sun zenith angle (don't let it dip below horizon) */
524 >        /* Also limit minimum angle to keep circumsolar off zenith */
525 >        if (altitude <= 0.0)
526 >                sun_zenith = DegToRad(90.0);
527 >        else if (altitude >= DegToRad(87.0))
528 >                sun_zenith = DegToRad(3.0);
529 >        else
530 >                sun_zenith = DegToRad(90.0) - altitude;
531  
528        /* Calculate sun zenith angle */
529        sun_zenith = DegToRad(90.0) - altitude;
530
532          /* Compute the inputs for the calculation of the sky distribution */
533          
534          if (input == 0)                                 /* XXX never used */
# Line 565 | Line 566 | ComputeSky(float *parr)
566          parr[0] = diff_illum;
567          if (altitude > 0)
568                  parr[0] += dir_illum * sin(altitude);
569 <        parr[2] = parr[1] = parr[0] *= grefl*(1./PI/WHTEFFICACY);
569 >        parr[2] = parr[1] = parr[0] *= (1./PI/WHTEFFICACY);
570 >        multcolor(parr, grefl);
571  
572          /* Calculate Perez sky model parameters */
573          CalcPerezParam(sun_zenith, sky_clearness, sky_brightness, index);
# Line 579 | Line 581 | ComputeSky(float *parr)
581          /* Normalization coefficient */
582          norm_diff_illum = diff_illum / norm_diff_illum;
583  
582        /* Calculate relative zenith luminance */
583        zlumin = CalcRelLuminance(sun_zenith, 0.0);
584
585        /* Calculate absolute zenith illuminance */
586        zlumin *= norm_diff_illum;
587
584          /* Apply to sky patches to get absolute radiance values */
585          for (i = 1; i < nskypatch; i++) {
586 <                scalecolor(parr+3*i, zlumin*(1./WHTEFFICACY));
586 >                scalecolor(parr+3*i, norm_diff_illum*(1./WHTEFFICACY));
587                  multcolor(parr+3*i, skycolor);
588          }
589   }
# Line 602 | Line 598 | AddDirect(float *parr)
598          double  wta[NSUNPATCH], wtot;
599          int     i, j, p;
600  
601 <        if (!do_sun || dir_illum < 1e-4)
601 >        if (dir_illum <= 1e-4 || bright(suncolor) <= 1e-4)
602                  return;
603                                          /* identify NSUNPATCH closest patches */
604          for (i = NSUNPATCH; i--; )
# Line 632 | Line 628 | AddDirect(float *parr)
628                  float   *pdest = parr + 3*near_patch[i];
629                  float   val_add = wta[i] * dir_illum /
630                                  (WHTEFFICACY * wtot * rh_dom[near_patch[i]]);
631 <                *pdest++ += val_add;
632 <                *pdest++ += val_add;
633 <                *pdest++ += val_add;
631 >                *pdest++ += val_add*suncolor[0];
632 >                *pdest++ += val_add*suncolor[1];
633 >                *pdest++ += val_add*suncolor[2];
634          }
635   }
636  
# Line 942 | Line 938 | double CalcRelHorzIllum( float *parr )
938          double rh_illum = 0.0;  /* Relative horizontal illuminance */
939  
940          for (i = 1; i < nskypatch; i++)
941 <                rh_illum += parr[3*i+1] * rh_cos(i);
941 >                rh_illum += parr[3*i+1] * rh_cos(i) * rh_dom[i];
942  
943 <        return rh_illum * (2.0 * PI / (nskypatch-1));
943 >        return rh_illum;
944   }
945  
946   /* Calculate earth orbit eccentricity correction factor */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines