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

Comparing ray/src/gen/gensky.c (file contents):
Revision 1.1 by greg, Thu Feb 2 11:16:29 1989 UTC vs.
Revision 2.6 by greg, Tue Apr 14 10:29:24 1992 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17  
18   #include  <math.h>
19  
20 + #include  "color.h"
21  
22 + #ifndef atof
23 + extern double  atof();
24 + #endif
25   extern char  *strcpy(), *strcat(), *malloc();
26   extern double  stadj(), sdec(), sazi(), salt();
27  
# Line 31 | Line 35 | extern double  s_latitude;
35   extern double  s_longitude;
36   extern double  s_meridian;
37                                          /* required values */
38 < int  month, day;
39 < double  hour;
38 > int  month, day;                                /* date */
39 > double  hour;                                   /* time */
40 > int  tsolar;                                    /* 0=standard, 1=solar */
41 > double  altitude, azimuth;                      /* or solar angles */
42                                          /* default values */
43 < int  cloudy = 0;
43 > int  cloudy = 0;                                /* 1=standard, 2=uniform */
44   int  dosun = 1;
45   double  zenithbr = -1.0;
46   double  turbidity = 2.75;
# Line 53 | Line 59 | main(argc, argv)
59   int  argc;
60   char  *argv[];
61   {
62 <        extern double  atof();
62 >        extern double  fabs();
63          int  i;
64  
65          progname = argv[0];
# Line 63 | Line 69 | char  *argv[];
69          }
70          if (argc < 4)
71                  userror("arg count");
72 <        month = atoi(argv[1]);
73 <        day = atoi(argv[2]);
74 <        hour = atof(argv[3]);
72 >        if (!strcmp(argv[1], "-ang")) {
73 >                altitude = atof(argv[2]) * (PI/180);
74 >                azimuth = atof(argv[3]) * (PI/180);
75 >                month = 0;
76 >        } else {
77 >                month = atoi(argv[1]);
78 >                if (month < 1 || month > 12)
79 >                        userror("bad month");
80 >                day = atoi(argv[2]);
81 >                if (day < 1 || day > 31)
82 >                        userror("bad day");
83 >                hour = atof(argv[3]);
84 >                if (hour < 0 || hour >= 24)
85 >                        userror("bad hour");
86 >                tsolar = argv[3][0] == '+';
87 >        }
88          for (i = 4; i < argc; i++)
89                  if (argv[i][0] == '-' || argv[i][0] == '+')
90                          switch (argv[i][1]) {
# Line 74 | Line 93 | char  *argv[];
93                                  dosun = argv[i][0] == '+';
94                                  break;
95                          case 'c':
96 <                                cloudy = 1;
96 >                                cloudy = argv[i][0] == '+' ? 2 : 1;
97                                  dosun = 0;
98                                  break;
99                          case 't':
# Line 102 | Line 121 | char  *argv[];
121                  else
122                          userror("bad option");
123  
124 +        if (fabs(s_meridian-s_longitude) > 30*PI/180)
125 +                fprintf(stderr,
126 +        "%s: warning: %.1f hours btwn. standard meridian and longitude\n",
127 +                        progname, (s_longitude-s_meridian)*12/PI);
128 +
129          printhead(argc, argv);
130  
131          computesky();
# Line 111 | Line 135 | char  *argv[];
135  
136   computesky()                    /* compute sky parameters */
137   {
114        int  jd;
115        double  sd, st;
116        double  altitude, azimuth;
138                                          /* compute solar direction */
139 <        jd = jdate(month, day);                 /* Julian date */
140 <        sd = sdec(jd);                          /* solar declination */
141 <        st = hour + stadj(jd);                  /* solar time */
142 <        altitude = salt(sd, st);
143 <        azimuth = sazi(sd, st);
139 >        if (month) {                    /* from date and time */
140 >                int  jd;
141 >                double  sd, st;
142 >
143 >                jd = jdate(month, day);         /* Julian date */
144 >                sd = sdec(jd);                  /* solar declination */
145 >                if (tsolar)                     /* solar time */
146 >                        st = hour;
147 >                else
148 >                        st = hour + stadj(jd);
149 >                altitude = salt(sd, st);
150 >                azimuth = sazi(sd, st);
151 >        }
152          sundir[0] = -sin(azimuth)*cos(altitude);
153          sundir[1] = -cos(azimuth)*cos(altitude);
154          sundir[2] = sin(altitude);
# Line 128 | Line 157 | computesky()                   /* compute sky parameters */
157          if (zenithbr <= 0.0)
158                  if (cloudy) {
159                          zenithbr = 8.6*sundir[2] + .123;
160 <                        zenithbr *= 1000.0/683.0;
160 >                        zenithbr *= 1000.0/WHTEFFICACY;
161                  } else {
162                          zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38;
163 <                        zenithbr *= 1000.0/683.0;
163 >                        zenithbr *= 1000.0/SKYEFFICACY;
164                  }
165 +        if (zenithbr < 0.0)
166 +                zenithbr = 0.0;
167                                          /* Compute horizontal radiance */
168          if (cloudy) {
169 <                groundbr = zenithbr*0.777778;
169 >                if (cloudy == 2)
170 >                        groundbr = zenithbr;
171 >                else
172 >                        groundbr = zenithbr*0.777778;
173                  printf("# Ground ambient level: %f\n", groundbr);
174          } else {
175                  F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) +
176                                  0.45*sundir[2]*sundir[2]);
177 <                groundbr = zenithbr*normsc(PI/2.0-altitude)/F2/PI;
177 >                groundbr = zenithbr*normsc(altitude)/F2/PI;
178                  printf("# Ground ambient level: %f\n", groundbr);
179                  if (sundir[2] > 0.0) {
180                          if (sundir[2] > .16)
181 <                                solarbr = 2.47e6 - 3.15e5/sundir[2];
181 >                                solarbr = (1.5e9/SUNEFFICACY) *
182 >                                        (1.147 - .147/sundir[2]);
183                          else
184 <                                solarbr = 5e5;
184 >                                solarbr = 1.5e9/SUNEFFICACY*(1.147-.147/.16);
185                          groundbr += solarbr*6e-5*sundir[2]/PI;
186                  } else
187                          dosun = 0;
# Line 157 | Line 192 | computesky()                   /* compute sky parameters */
192  
193   printsky()                      /* print out sky */
194   {
160        register int  i;
161
195          if (dosun) {
196                  printf("\nvoid light solar\n");
197                  printf("0\n0\n");
198 <                printf("3 %f %f %f\n", solarbr, solarbr, solarbr);
198 >                printf("3 %.2e %.2e %.2e\n", solarbr, solarbr, solarbr);
199                  printf("\nsolar source sun\n");
200                  printf("0\n0\n");
201                  printf("4 %f %f %f 0.5\n", sundir[0], sundir[1], sundir[2]);
# Line 172 | Line 205 | printsky()                     /* print out sky */
205          printf("2 skybright skybright.cal\n");
206          printf("0\n");
207          if (cloudy)
208 <                printf("3 1 %f %f\n", zenithbr, groundbr);
208 >                printf("3 %d %.2e %.2e\n", cloudy, zenithbr, groundbr);
209          else
210 <                printf("7 -1 %f %f %f %f %f %f\n", zenithbr, groundbr, F2,
211 <                                sundir[0], sundir[1], sundir[2]);
210 >                printf("7 -1 %.2e %.2e %.2e %f %f %f\n", zenithbr, groundbr,
211 >                                F2, sundir[0], sundir[1], sundir[2]);
212   }
213  
214  
215   printdefaults()                 /* print default values */
216   {
217 <        if (cloudy)
217 >        if (cloudy == 1)
218                  printf("-c\t\t\t\t# Cloudy sky\n");
219 +        else if (cloudy == 2)
220 +                printf("+c\t\t\t\t# Uniform cloudy sky\n");
221          else if (dosun)
222                  printf("+s\t\t\t\t# Sunny sky with sun\n");
223          else
# Line 204 | Line 239 | char  *msg;
239          if (msg != NULL)
240                  fprintf(stderr, "%s: Use error - %s\n", progname, msg);
241          fprintf(stderr, "Usage: %s month day hour [options]\n", progname);
242 +        fprintf(stderr, "   Or: %s -ang altitude azimuth [options]\n", progname);
243          fprintf(stderr, "   Or: %s -defaults\n", progname);
244          exit(1);
245   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines