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 2.3 by greg, Tue Mar 10 11:12:06 1992 UTC vs.
Revision 2.12 by greg, Mon Jun 14 13:54:26 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #include  "color.h"
21  
22 #ifndef atof
23 extern double  atof();
24 #endif
22   extern char  *strcpy(), *strcat(), *malloc();
23   extern double  stadj(), sdec(), sazi(), salt();
24  
# Line 36 | Line 33 | extern double  s_longitude;
33   extern double  s_meridian;
34                                          /* required values */
35   int  month, day;                                /* date */
36 < double  hour;                                   /* standard time */
36 > double  hour;                                   /* time */
37 > int  tsolar;                                    /* 0=standard, 1=solar */
38   double  altitude, azimuth;                      /* or solar angles */
39                                          /* default values */
40 < int  cloudy = 0;
40 > int  cloudy = 0;                                /* 1=standard, 2=uniform */
41   int  dosun = 1;
42 < double  zenithbr = -1.0;
42 > double  zenithbr = 0.0;
43 > int     u_zenith = 0;                           /* -1=irradiance, 1=radiance */
44   double  turbidity = 2.75;
45   double  gprefl = 0.2;
46                                          /* computed values */
47   double  sundir[3];
48   double  groundbr;
49   double  F2;
50 < double  solarbr;
50 > double  solarbr = 0.0;
51 > int     u_solar = 0;                            /* -1=irradiance, 1=radiance */
52  
53   char  *progname;
54   char  errmsg[128];
# Line 58 | Line 58 | main(argc, argv)
58   int  argc;
59   char  *argv[];
60   {
61        extern double  fabs();
61          int  i;
62  
63          progname = argv[0];
# Line 74 | Line 73 | char  *argv[];
73                  month = 0;
74          } else {
75                  month = atoi(argv[1]);
76 +                if (month < 1 || month > 12)
77 +                        userror("bad month");
78                  day = atoi(argv[2]);
79 +                if (day < 1 || day > 31)
80 +                        userror("bad day");
81                  hour = atof(argv[3]);
82 +                if (hour < 0 || hour >= 24)
83 +                        userror("bad hour");
84 +                tsolar = argv[3][0] == '+';
85          }
86          for (i = 4; i < argc; i++)
87                  if (argv[i][0] == '-' || argv[i][0] == '+')
# Line 84 | Line 90 | char  *argv[];
90                                  cloudy = 0;
91                                  dosun = argv[i][0] == '+';
92                                  break;
93 +                        case 'r':
94 +                        case 'R':
95 +                                u_solar = argv[i][1]=='R' ? -1 : 1;
96 +                                solarbr = atof(argv[++i]);
97 +                                break;
98                          case 'c':
99 <                                cloudy = 1;
99 >                                cloudy = argv[i][0] == '+' ? 2 : 1;
100                                  dosun = 0;
101                                  break;
102                          case 't':
103                                  turbidity = atof(argv[++i]);
104                                  break;
105                          case 'b':
106 +                        case 'B':
107 +                                u_zenith = argv[i][1]=='B' ? -1 : 1;
108                                  zenithbr = atof(argv[++i]);
109                                  break;
110                          case 'g':
# Line 127 | Line 140 | char  *argv[];
140  
141   computesky()                    /* compute sky parameters */
142   {
143 +        double  normfactor;
144                                          /* compute solar direction */
145          if (month) {                    /* from date and time */
146                  int  jd;
# Line 134 | Line 148 | computesky()                   /* compute sky parameters */
148  
149                  jd = jdate(month, day);         /* Julian date */
150                  sd = sdec(jd);                  /* solar declination */
151 <                st = hour + stadj(jd);          /* solar time */
151 >                if (tsolar)                     /* solar time */
152 >                        st = hour;
153 >                else
154 >                        st = hour + stadj(jd);
155                  altitude = salt(sd, st);
156                  azimuth = sazi(sd, st);
157 +                printf("# Solar altitude and azimuth: %f %f\n",
158 +                                180./PI*altitude, 180./PI*azimuth);
159          }
160 +        if (!cloudy && altitude > 87.*PI/180.) {
161 +                fprintf(stderr,
162 + "%s: warning - sun too close to zenith, reducing altitude to 87 degrees\n",
163 +                                progname);
164 +                printf(
165 + "# warning - sun too close to zenith, reducing altitude to 87 degrees\n");
166 +                altitude = 87.*PI/180.;
167 +        }
168          sundir[0] = -sin(azimuth)*cos(altitude);
169          sundir[1] = -cos(azimuth)*cos(altitude);
170          sundir[2] = sin(altitude);
171  
172 +                                        /* Compute normalization factor */
173 +        if (cloudy == 2)
174 +                normfactor = 1.0;
175 +        else if (cloudy == 1)
176 +                normfactor = 0.777778;
177 +        else {
178 +                F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) +
179 +                                0.45*sundir[2]*sundir[2]);
180 +                normfactor = normsc(altitude)/F2/PI;
181 +        }
182                                          /* Compute zenith brightness */
183 <        if (zenithbr <= 0.0)
184 <                if (cloudy) {
183 >        if (u_zenith == -1)
184 >                zenithbr /= normfactor*PI;
185 >        else if (u_zenith == 0) {
186 >                if (cloudy)
187                          zenithbr = 8.6*sundir[2] + .123;
188 <                        zenithbr *= 1000.0/SKYEFFICACY;
150 <                } else {
188 >                else
189                          zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38;
190 +                if (zenithbr < 0.0)
191 +                        zenithbr = 0.0;
192 +                else
193                          zenithbr *= 1000.0/SKYEFFICACY;
153                }
154        if (zenithbr < 0.0)
155                zenithbr = 0.0;
156                                        /* Compute horizontal radiance */
157        if (cloudy) {
158                groundbr = zenithbr*0.777778;
159                printf("# Ground ambient level: %f\n", groundbr);
160        } else {
161                F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) +
162                                0.45*sundir[2]*sundir[2]);
163                groundbr = zenithbr*normsc(PI/2.0-altitude)/F2/PI;
164                printf("# Ground ambient level: %f\n", groundbr);
165                if (sundir[2] > 0.0) {
166                        if (sundir[2] > .16)
167                                solarbr = (1.5e9/SUNEFFICACY) *
168                                        (1.147 - .147/sundir[2]);
169                        else
170                                solarbr = 1.5e9/SUNEFFICACY*(1.147-.147/.16);
171                        groundbr += solarbr*6e-5*sundir[2]/PI;
172                } else
173                        dosun = 0;
194          }
195 +                                        /* Compute horizontal radiance */
196 +        groundbr = zenithbr*normfactor;
197 +        printf("# Ground ambient level: %f\n", groundbr);
198 +        if (sundir[2] > 0.0 && (!u_solar || solarbr > 0.0)) {
199 +                if (u_solar == -1)
200 +                        solarbr /= 6e-5*sundir[2];
201 +                else if (u_solar == 0)
202 +                        solarbr = 1.5e9/SUNEFFICACY *
203 +                        (1.147 - .147/(sundir[2]>.16?sundir[2]:.16));
204 +                groundbr += 6e-5/PI*solarbr*sundir[2];
205 +        } else
206 +                dosun = 0;
207          groundbr *= gprefl;
208   }
209  
# Line 191 | Line 223 | printsky()                     /* print out sky */
223          printf("2 skybright skybright.cal\n");
224          printf("0\n");
225          if (cloudy)
226 <                printf("3 1 %.2e %.2e\n", zenithbr, groundbr);
226 >                printf("3 %d %.2e %.2e\n", cloudy, zenithbr, groundbr);
227          else
228                  printf("7 -1 %.2e %.2e %.2e %f %f %f\n", zenithbr, groundbr,
229                                  F2, sundir[0], sundir[1], sundir[2]);
# Line 200 | Line 232 | printsky()                     /* print out sky */
232  
233   printdefaults()                 /* print default values */
234   {
235 <        if (cloudy)
235 >        if (cloudy == 1)
236                  printf("-c\t\t\t\t# Cloudy sky\n");
237 +        else if (cloudy == 2)
238 +                printf("+c\t\t\t\t# Uniform cloudy sky\n");
239          else if (dosun)
240                  printf("+s\t\t\t\t# Sunny sky with sun\n");
241          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines