I don't think there's any particular magic number to the number of blocks held in a chunk. The considerations are the minimum required for sane light propagation (16 for any given dimension), and a memory saved vs mesh generation time - the larger the chunk the memory is saved through the use of congruent primitives in a simple array, at the cost of how long it takes to generate the chunk.When we reach the terrain generation stage we are dealing with chunks that now are something like 16x16x16 or 32x32x32 or so. I figure there's some benefit to them being cubic, and 32^3 = 32,768 so an array of shorts would take 65,536 bytes, useful?
Keep in mind that the only requirement is to be able obtain a general height value for a given block/chunk. It need not be overly accurate, nor necessarily stored if it can be derived from the same seed condition reasonably quickly. If you are doing erosion and tectonic plate simulations that is unlikely, but you can still have a relatively sparse heightmap and interpolate.To save space on height we could make the value stored in the heightmap be a byte (256 values) but be multiplied by a static value to get the actual in-world average height of the surface in that chunk column. I'm not sure how useful that is, but using an exact height from 0-256 isn't enough. Maybe multiply by 16 or 32 to get the real height in the world?
I don't agree regarding the handling of sunlight high up. It would mess up any sort of enclosed space, such as cave systems in large floating islands or even just houses. What we need is for shadows cast high up to decay at some distance from the shadow caster,Around the average surface height we care about sunlight calculations in a set vertical band, like 256 blocks. Anything below that is considered devoid of sunlight (and that value could be used for something else) and anything above is always the max possible light value as per time of day (so again we can use the value for something else)
The difficulty comes in a few ways:
- Player modifies the terrain drastically so the average height value changes - the world map storage for height values must be able to change after initial generation
- Player outright does something obnoxious, like fill one side of a chunk column with blocks and clear the other side Where does the sunlight go, as simply averaging a chunk column could leave the average value hundreds below the top solid block?
For sunlight affected areas, what I would suggest is having 16x128x16 chunks (or even larger vertical), and setting up sunlight propagation so that it goes from total shadow back to full sunlight over a distance of ~128 blocks, given no further shadow casting blocks. That is, we have shadow attenuation rather than light attenuation. This ensures that you only ever need one chunk above (and one chunk below) in order to do lighting recalculations. Obviously large enclosed spaces would be lit wrong (like huge caverns in floating islands), but it should suit the majority of cases.