I have implemented Preetham, Shirley, and Smits’s daylight model using Aubrey Jaffer’s Scheme implementation as a reference and confirmed that my implementation produces the same results in the xyY coordinate space for the same input on all my test cases as Jaffer’s.
However, when I try to convert this output to sRGB using the standard formulae, almost all inputs except for those around sunrise and sunset map to colours ‘darker than black’ (all coordinates less than 0) at night, or ‘lighter than white’ (all coordinates greater than 1.0/255) during the day.
An example: for solar day 38 (declination -15.7117) at solar hour 14 at latitude 52.52 (θs = 72.9996°, φs = 44.0935°) with turbidity 6, Jaffer’s implementation and mine both give xyY values for θ = 30, φ = 0: (0.3576953919457298, 0.3065955987210767, 5.907977352059564). This is the procedure
clear-sky-color-xyY in Jaffer’s Scheme implementation. However, using Jaffer’s
CIEXYZ->sRGB procedures (which likewise apply the same formulae as my code) on this result yields sRGB octets 255, 255, and 255.
For solar hours around 7 and 17 (sunset and sunrise), the results appear somewhat reasonable, but broad daylight and dark night are both too light and too dark.
What corrections are necessary to make the model practical for rendering in sRGB and similar colour spaces?