I've now added skylight and sunlight to the ray tracer based on the approach in "A Practical Analytic Model for Daylight". I currently treat the sun as a point light source though, which is not physically correct. Without bilinear path tracing or metropolis light transport though, having such a small and intense light source would lead to large amount of noise in the rendering, so it'll have to do for now. The image below shows an example scene with skylight and sunlight. It's a more detailed version of the terrain used before. I added support for 16-bit greyscale PNGs recently, meaning I could finally load the 16385 x 16385 Puget Sound height map. It's not terribly slow compared to the 4097 x 4097 version, though due to the memory requirements I have to cut off the kd-tree before it reaches the maximum depth, causing each leaf node to have 32 triangles. The code currently intersects the ray against all the triangles in the leaf node, which is a bit inefficient, so I should probably optimize it at some point. At this size the height map consumes 512 MB and the kd tree consumes 384 MB of memory. I'm still using the 4096 x 4096 texture, since the highest resolution would consume 1 GB of memory.
A Practical Analytic Model for Daylight