How lighting works in Voxel Play

Modified on Thu, 16 Jan at 1:58 PM

Voxel Play handles two kind of lighting systems:


- Voxel lighting

- Unity lighting


Voxel lighting is baked in runtime into the chunk structure per voxel. This voxel lighting represent the Sun light and also any emissive voxels or torches.


On the other hand, Unity lighting refers to the usual directional, point and spot lights.


Voxel Lighting


Voxel light propagation is handled in two distinct passes: one for Sun lighting and another for emissive lighting, such as that from torches. If no emissive sources (like torches) are present, no emissive lighting propagation occurs.


Lighting values are stored per voxel using a single byte. The upper four bits represent the emissive lighting intensity, while the lower four bits represent the Sun lighting intensity. Both intensities range from 0 to 15, where 0 indicates no lighting, and 15 indicates full lighting.


The Sun lighting value represents the maximum intensity of sunlight a voxel receives. This value is combined with the Sun's altitude in the sky—where 1 corresponds to the Sun directly overhead, and 0 corresponds to the Sun at the horizon or below—to determine the final light intensity applied to the voxel's color.


Sun lighting propagates using a breadth-first search (BFS) algorithm, spreading light from one voxel to its neighbors. For chunks below the terrain surface, the sunlight intensity decreases by 1 (or by an amount specified in the world settings) with each step. This models the concept that sunlight above the terrain is "infinite," while its intensity diminishes underground.


Emissive lighting propagates in a similar manner but always decreases by 1 per step, regardless of the chunk's altitude. This reflects the finite nature of emissive lighting sources, such as torches.


When a chunk is modified (ie. a voxel is destroyed), the lighting for the affected chunks is recalculated. Otherwise, the lighting data doesn't change, even if the Sun rotates since the altitude of the Sun in the sky is used to calculate the final lighting in the shader itself.


The Ambient Occlusion option in Voxel Play is computed and combined with the stored voxel light data.


Unity Lighting

Check this other article to learn more about how Voxel Play handles normal Unity lights, such as point lights.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article