[Radiance-general] Utah sky model .cal file

Mark Stock mstock at umich.edu
Wed Aug 12 06:17:36 PDT 2009


All this talk of Radiance skies made me remember that I recently 
implemented part of Preetham, Shirley, Smits, "A Practical, 
Analytical Model for Daylight" for Radiance. It's rough around 
the edges, but produces good (if not totally accurate) results.

Specifically, I modeled the part that determines the sky color 
and brightness, not the part that determines the color shift for 
faraway objects due to atmospheric scattering (maybe I'll have 
that done by the Radiance User Conference this year).

To use it, first run gensky (as normal), but comment out the 
brightfunc description and add a new colorfunc entry. The real 
arguments are turbidity and sun direction (copy the last 3 
entries from the brightfunc line), like this example for a sky 
after sunset:

#void brightfunc skyfunc
#2 skybr skybright.cal
#0
#7 1 9.75e-01 4.02e-01 2.68e-01 -0.918161 0.378882 -0.115887

void colorfunc skyfunc
4 skyr skyg skyb utah.cal
0
4 2. -0.918161 0.378882 -0.115887

Like gensky, to use it attach it to a glow source:

skyfunc glow skydome
0 0 4  1. 1. 1. 0
skydome source sky
0 0 4  0 0 1  180
skydome source sky2
0 0 4  0 0 -1  180

So, for the sample scene file attached, run:

% oconv duskscene.rad > duskscene.oct
% rvu -vp 1 -5 2 -vd -1 5 -1.5 -vh 90 -vv 90 -ab 2 -ad 512 -ar 
512 -as 128 -aa 0.1 -pe -5 duskscene.oct

It isn't quite automatic yet, and it does emit some errors, 
though I hope to clean those up soon.

Would this be most useful as a command-line option to gensky? It 
would seem most applicable there. Plus, that would allow control 
over the sun color, which shifts subtly from white to orange-ish 
nearer the horizons.

Enjoy.

Mark
mstock at umich.edu
-------------- next part --------------
# gensky 08 18 19.5
# Local solar time: 19.30
# Solar altitude and azimuth: -6.7 112.4
# Ground ambient level: 2.0

#void brightfunc skyfunc
#2 skybr skybright.cal
#0
#7 1 9.75e-01 4.02e-01 2.68e-01 -0.918161 0.378882 -0.115887

void colorfunc skyfunc
4 skyr skyg skyb utah.cal
0
4 2. -0.918161 0.378882 -0.115887

skyfunc glow skydome
0 0 4  1. 1. 1. 0

skydome source sky
0 0 4  0 0 1  180
skydome source sky2
0 0 4  0 0 -1  180


void plastic groundc 0 0 5  0.5 0.4 0.24 0.0 0.0
groundc ring ground 0 0 8  0 0 0  0 0 1  0 20

void plastic grey 0 0 5  0.18 0.18 0.18 0 0
!genbox grey box 1 1 1 -r 0.02 | xform -t -0.5 -0.5 0
-------------- next part --------------
{
     preetham.cal - Sky color function for Radiance skies, meant
                    to work in place of skybright.cal

     From Preetham, Shirley, Smits, "A Practical, Analytical Model for Daylight"

     Converted to Radiance by Mark J. Stock, mstock at umich.edu

     A1			- Turbidity
     A2,A3,A4		- sun direction

     An example usage for a late afternoon sky follows:
     (run gensky 4 30 16.2 -a 42 +s to create the following text)

     # gensky 4 30 16.2 -a 42 +s
     # Local solar time: 16.11
     # Solar altitude and azimuth: 30.6 81.9
     # Ground ambient level: 15.4

     void light solar
     0
     0
     3 6.19e+06 6.19e+06 6.19e+06

     solar source sun
     0
     0
     4 -0.852270 -0.121498 0.508797 0.5

     #void brightfunc skyfunc
     #2 skybr skybright.cal
     #0
     #7 1 7.62e+00 1.51e+01 4.03e-01 -0.852270 -0.121498 0.508797
     # notice how I stole this line for skycolor below?

     void colorfunc skyfunc
     4 skyr skyg skyb utah.cal
     0
     4 2. -0.852270 -0.121498 0.508797

     skyfunc glow sky_glow
     0
     0
     4 1.0 1.0 1.0 0

     sky_glow source sky
     0
     0
     4 0 0 1 180

}

{ perez(theta, gamma, a, b, c, d, e) = (1.+a*exp(b/cos(theta))) * (1+c*exp(d*gamma)+e*cos(gamma)*cos(gamma)); }
perez(t, g, a, b, c, d, e) = (1.+a*exp(b/(0.0001+abs(cos(t))))) * (1+c*exp(d*g)+e*cos(g)*cos(g));

cosgamma = Dx*A2 + Dy*A3 + Dz*A4;
gamma = Acos(cosgamma);		{ angle from sun to this point in sky }
theta = Acos(Dz);		{ angle from zenith to this point in sky }
thetas = Acos(A4);		{ angle from zenith to sun }

{ zenith brightness, chromaticity }
yyz = (4.0453*A1 - 4.971)*tan((0.4444-A1/120.)*(3.1415927-2*thetas)) - 0.2155*A1 + 2.4192;
xz = 0.25886 + 0.00394*A1 + thetas*(0.06052 - 0.03202*A1*(1.-0.065272*A1) + thetas*(-0.21196 + 0.06377*A1*(1.-0.058805*A1) + thetas*(0.11693 - 0.02903*A1*(1.-0.057182*A1))));
yz = 0.26688 + 0.00516*A1 + thetas*(0.0667 - 0.04153*A1*(1.-0.07633*A1) + thetas*(-0.26756 + 0.0897*A1*(1.-0.068004*A1) + thetas*(0.15346 - 0.04214*A1*(1.-0.065259*A1))));

{ distribution coefficients for luminance, chromaticity; functions of turbidity }
ayy = 0.1787*A1 - 1.463;
byy = -0.3554*A1 + 0.4275;
cyy = -0.0227*A1 + 5.3251;
dyy = 0.1206*A1 - 2.5771;
eyy = -0.067*A1 + 0.3703;

ax = -0.0193*A1 - 0.2593;
bx = -0.0665*A1 + 0.0008;
cx = -0.0004*A1 + 0.2125;
dx = -0.0641*A1 - 0.8989;
ex = -0.0033*A1 + 0.0452;

ay = -0.0167*A1 - 0.2608;
by = -0.095*A1 + 0.0092;
cy = -0.0079*A1 + 0.2102;
dy = -0.0441*A1 - 1.6537;
ey = -0.0109*A1 + 0.0529;

{ point values for luminance, chromaticity }
yyp = yyz * perez(theta, gamma, ayy, byy, cyy, dyy, eyy) / perez(0., thetas, ayy, byy, cyy, dyy, eyy);
xp = xz * perez(theta, gamma, ax, bx, cx, dx, ex) / perez(0., thetas, ax, bx, cx, dx, ex);
yp = yz * perez(theta, gamma, ay, by, cy, dy, ey) / perez(0., thetas, ay, by, cy, dy, ey);

{ output brightness }
skybr = yyp;

{ output radiance }

{ first, tristimulus values }
x = yyp*xp/yp;
y = yyp;
{z = yyp*(1.-xp-yp)/yp;}
z = yyp*if(1.-xp-yp, 1-xp-yp, 0.)/yp;

{ convert using CIE M^-1 matrix from http://www.brucelindbloom.com/Eqn_RGB_XYZ_Matrix.html }
{ do not apply gamma, as we are in linear units }
skyr = 2.3706743*x - 0.9000405*y - 0.4706338*z;
skyg = -0.513885*x + 1.4253036*y + 0.0885814*z;
skyb = 0.0052982*x - 0.0146949*y + 1.0093968*z;
{r = 2.3706743*x - 0.9000405*y - 0.4706338*z;
g = -0.513885*x + 1.4253036*y + 0.0885814*z;
b = 0.0052982*x - 0.0146949*y + 1.0093968*z;

skyr = if(r, r, 0.);
skyg = if(g, g, 0.);
skyb = if(b, b, 0.);}


More information about the Radiance-general mailing list