feather icon indicating copy to clipboard operation
feather copied to clipboard

Lighting support

Open caelunshun opened this issue 6 years ago • 8 comments

Lighting will need to be calculated each time a block is updated.

For reference:

  • https://minecraft.gamepedia.com/Light
  • https://en.wikipedia.org/wiki/Flood_fill

Ideally, this would be done multithreaded on a per-chunk basis.

I'm not sure how to correctly handle block updates. We could recalculate the light for the entire chunk, but this is incredibly inefficient.

caelunshun avatar Aug 16 '19 05:08 caelunshun

Just stumbled over this project, looks awesome! I thought i'd try to play around with this a bit to learn about spec.

What about a System which goes through all BlockUpdateEvents and recalculates lighting in every chunk which has been updated?

NyxCode avatar Sep 05 '19 11:09 NyxCode

Just stumbled over this project, looks awesome! I thought i'd try to play around with this a bit to learn about spec.

What about a System which goes through all BlockUpdateEvents and recalculates lighting in every chunk which has been updated?

Lighting would be stored in the Chunk, as it is in vanilla, in two compact arrays. See https://wiki.vg/index.php?title=Chunk_Format&diff=14678&oldid=14646#Chunk_Section_structure.

As a starting point, going through BlockUpdateEvents and recalculating the entire chunk would be fine. We would want to optimize the algorithm so that only blocks affected by light updates are recalculated, and not the entire chunk.

caelunshun avatar Sep 05 '19 12:09 caelunshun

that sounds reasonable. I think a good approach would be to store all light sources in each chunk. When a light source is placed/destroyed, we just increase/decrease the light-level of surrounding blocks. When a normal block is placed/broken though, we'll have to go through all light sources (which are close) and recalculate their light. What do you think? For this it'd be nice to create a struct similar to ChunkMap which just stores the light sources, soemthing like HashMap<ChunkPosition, Vec<(BlockPosition, LightLevel)>>.

NyxCode avatar Sep 05 '19 15:09 NyxCode

@NyxCode Yes, that will work. To start, we should probably resolve #103 so that existing lighting data is loaded. This will also involve adding the light storage in Chunk.

Glad to see some interest in this project!

caelunshun avatar Sep 05 '19 19:09 caelunshun

yeah, i'll look at that first! I don't have a lot of time, but this project looks great! Is there a place for discussions/questions except github issues? maybe a discord server?

NyxCode avatar Sep 05 '19 21:09 NyxCode

Is there a place for discussions/questions except github issues? maybe a discord server?

Well, the project didn't have any publicity until it ballooned yesterday, so we don't really have a community or discussion place. I could make a Discord server, but given the early state of the project, I'm not sure if there's a need yet.

caelunshun avatar Sep 05 '19 22:09 caelunshun

:D the post on the rust subreddit, huh? I mean, it's your call, but I could imagine that a place for discussion on the development would be usefull.

NyxCode avatar Sep 05 '19 23:09 NyxCode

I mean, it's your call, but I could imagine that a place for discussion on the development would be usefull.

I guess I agree; here's the Discord server. https://discord.gg/4eYmK69

caelunshun avatar Sep 05 '19 23:09 caelunshun