Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lighting #61

Closed
IntegratedQuantum opened this issue Sep 17, 2023 · 0 comments
Closed

Lighting #61

IntegratedQuantum opened this issue Sep 17, 2023 · 0 comments
Labels
engine enhancement a new feature or improvement experimental a feature or idea that will require lots of experimentation graphics

Comments

@IntegratedQuantum
Copy link
Member

IntegratedQuantum commented Sep 17, 2023

The game should have some flood-fill based ambient lighting.

Difficulties

Minecraft's lighting algorithm is fairly simple, however it is also fairly limited due to only having 16 different light values and 2 light channels. This means that the light is not colored and a torch can at most light 16 blocks in one direction.

In Cubyz I would like to have colored lighting (e.g. colored light sources and colored light absorption through glass).

Additionally I would like to have long range interactions. Especially for larger caves minecraft's lighting model looks wrong because torch light cannot reach the opposite wall.

Now bother of these come at a heavy performance cost. 3 more color channels would increase the cost by 3×
Increasing the light range by 2× would increase the cost by 2³ = 8×

Solution Idea 1

Rather than doing lighting on a per-block level, it should be done at a larger scale.

This can be done with a coarse graph structure of the transparent volumes, and traversing that graph on light updates.

Problems with that approach

  • how should the terrain be coarsened?
  • which nodes should a given block sample to achieve proper smooth lighting?
  • What happens at boundaries between different media, like colored glass and air? We wouldn't want white light to bleed through a colored glass pane.

Solution Idea 2

Store column-wise runlength-encoding data.
For each run we only need to store one light value, remaining values are inferred from the block properties and the distance to that light source.
When there is multiple lights that hit the run in different places, then the run should be split into 2 smaller runs.

Problems

  • The number of runs will change often during the propagation. This means that a lot of memory should be preallocated, leading to wasted memory. One idea would be to store each run in a different array of 32² elements. As soon as one column exceeds the number of arrays, a new array would be allocated. This wastes a bit of memory, but should use less cache-memory than fragmented allocations.
@IntegratedQuantum IntegratedQuantum added enhancement a new feature or improvement experimental a feature or idea that will require lots of experimentation graphics engine labels Sep 17, 2023
IntegratedQuantum added a commit that referenced this issue Oct 28, 2023
Now there is only one mutex left inside the process for updating and rendering chunks on the client-side.
This is a bit of a step back here. A lot of processes are now locked to the render thread.
Once I implemented lighing #61 I will need to look for better options.
IntegratedQuantum added a commit that referenced this issue Nov 5, 2023
…trating just ambient occlusion.

Starts work on #61
IntegratedQuantum added a commit that referenced this issue Nov 27, 2023
…ead.

While pretty insignificant on its own, this is an important step towards #168 and #61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine enhancement a new feature or improvement experimental a feature or idea that will require lots of experimentation graphics
Projects
None yet
Development

No branches or pull requests

1 participant