Sunday, March 27, 2016

opengl - Lighting in a Minecraftian World


Minecraft is a game that is largely based on a heightmap and uses that heigtmap information to flood the world with light. From my understanding the highest point in the heightmap is the end of the sunlight influenced area. Everything above that is lit by sunlight, everything below that just is influenced by light nearby in a radius of 8 blocks.


Thus if you have a floating island on the top of your world everything below that will be seen essentially as a cave. When two lights influence the same point the brighter light wins (unsure about that).



Either way there are a couple of problems with minecrafts lighting model: first of all, if your world does not have a heightmap it becomes trickier to figure out what exactly is supposed to emit sunlight and what not. A simple way would be to assume that the world is (in my case) a floating rock and then traverse each axis from both directions and figure out where the rock starts and ends. But this does not fully eliminate the problem as dents in the rock are not supposed to be in darkness.


Minecraft itself will cache the light information in its chunks together with the information about the material of a block. Thus only if the world is modified the lighting has to update. Unfortunately that process is still pretty slow on updates and on quick light changes one can see the lighting lag behind. That's especially true if a lot of blocks change (TNT, sunset etc.) and you're not running the fastest computer (Or Java on Mac).


From my still limited understanding of 3D graphics lighting a world like minecraft shouldn't be the biggest issue. How would you tackle the problem?


I think the basic requirements for lighting in a voxel world would be



  1. update fast enough that it could happen in a single frame. One might be able to do the lighting in the graphics device and download the changed light information to the main RAM.

  2. light information must be quickly available for the main game logic so not entirely based on the graphics device: reasoning: light affects the growth of grass, spawning of monsters etc.

  3. light updates would have to be local to a chunk or have some other limit so that one does not have to relight the whole world which might be very large in size.


The main idea would be to make the light updates fast, not necessarily more beautiful. For general light rendering performance improvements one could easily add SSAO on top of that which should result in much nicer worlds.





No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...