--- ray/src/gen/gensky.c 1992/03/20 15:29:10 2.5 +++ ray/src/gen/gensky.c 1993/06/04 14:30:24 2.10 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -19,9 +19,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" -#ifndef atof -extern double atof(); -#endif extern char *strcpy(), *strcat(), *malloc(); extern double stadj(), sdec(), sazi(), salt(); @@ -49,7 +46,7 @@ double gprefl = 0.2; double sundir[3]; double groundbr; double F2; -double solarbr; +double solarbr = -1.0; char *progname; char errmsg[128]; @@ -59,7 +56,6 @@ main(argc, argv) int argc; char *argv[]; { - extern double fabs(); int i; progname = argv[0]; @@ -75,8 +71,14 @@ char *argv[]; month = 0; } else { month = atoi(argv[1]); + if (month < 1 || month > 12) + userror("bad month"); day = atoi(argv[2]); + if (day < 1 || day > 31) + userror("bad day"); hour = atof(argv[3]); + if (hour < 0 || hour >= 24) + userror("bad hour"); tsolar = argv[3][0] == '+'; } for (i = 4; i < argc; i++) @@ -86,6 +88,9 @@ char *argv[]; cloudy = 0; dosun = argv[i][0] == '+'; break; + case 'r': + solarbr = atof(argv[++i]); + break; case 'c': cloudy = argv[i][0] == '+' ? 2 : 1; dosun = 0; @@ -143,6 +148,14 @@ computesky() /* compute sky parameters */ altitude = salt(sd, st); azimuth = sazi(sd, st); } + if (!cloudy && altitude > 87.*PI/180.) { + fprintf(stderr, +"%s: warning - sun too close to zenith, reducing altitude to 87 degrees\n", + progname); + printf( +"# warning - sun too close to zenith, reducing altitude to 87 degrees\n"); + altitude = 87.*PI/180.; + } sundir[0] = -sin(azimuth)*cos(altitude); sundir[1] = -cos(azimuth)*cos(altitude); sundir[2] = sin(altitude); @@ -151,7 +164,7 @@ computesky() /* compute sky parameters */ if (zenithbr <= 0.0) if (cloudy) { zenithbr = 8.6*sundir[2] + .123; - zenithbr *= 1000.0/SKYEFFICACY; + zenithbr *= 1000.0/WHTEFFICACY; } else { zenithbr = (1.376*turbidity-1.81)*tan(altitude)+0.38; zenithbr *= 1000.0/SKYEFFICACY; @@ -168,14 +181,12 @@ computesky() /* compute sky parameters */ } else { F2 = 0.274*(0.91 + 10.0*exp(-3.0*(PI/2.0-altitude)) + 0.45*sundir[2]*sundir[2]); - groundbr = zenithbr*normsc(PI/2.0-altitude)/F2/PI; + groundbr = zenithbr*normsc(altitude)/F2/PI; printf("# Ground ambient level: %f\n", groundbr); - if (sundir[2] > 0.0) { - if (sundir[2] > .16) - solarbr = (1.5e9/SUNEFFICACY) * - (1.147 - .147/sundir[2]); - else - solarbr = 1.5e9/SUNEFFICACY*(1.147-.147/.16); + if (sundir[2] > 0.0 && solarbr != 0.0) { + if (solarbr < 0.0) + solarbr = 1.5e9/SUNEFFICACY * + (1.147 - .147/(sundir[2]>.16?sundir[2]:.16)); groundbr += solarbr*6e-5*sundir[2]/PI; } else dosun = 0;