Chunk Wide Lighting

Jul 12, 2011 at 2:52 AM

I'm curious...in techcraft, what happens when you generate a chunk?

On my voxel engine, when chunks get generated, they have dark borders around them.  They go away, of course, when the chunk gets rebuilt.

I've tried simple rebuilding all the surrounding chunks when a chunk gets generated, but it takes too much time.  How did you guys fix this issue?

Jul 13, 2011 at 11:23 AM

Hi Tony...

This issue is a complete pain - the solution is to make generating and lighting your chunks into separate stages. You should never light a chunk unless all it's surrounding chunks have been generated. Exactly how you do this is very dependant on how you deal with player movement and chunk generation. I've tried numerous way and still don't have a method that i'm entirely happy with.

At the simplest you need to something along these lines....

Say your draw distance is 10 chunks, you generate chunks when they are 10 away from the player. You only light the chunks when they're 9 away. This will ensure that when you come to do the lighting the surrounding chunks have been generated.

Jul 13, 2011 at 10:39 PM

That's brilliant!
I saw that in the code, and I didn't understand what it was supposed to do at all, but now I understand!

Thanks for your help! 

Jul 18, 2011 at 9:39 PM

I have a better idea.

How about add a boolean Ready variable, that's something like this:

public bool Ready
        {
            get
            {
                return (XIncreasing != null && XIncreasing.DoneGenerated) &&
                (XDecreasing != null && XDecreasing.DoneGenerated) &&
                (ZIncreasing != null && ZIncreasing.DoneGenerated) &&
                (ZDecreasing != null && ZDecreasing.DoneGenerated);
            }
        }

After the ChunkGenerator finishes generating a chunk, it sets the DoneGenerated variable in the chunk to true.  Therefore, a chunk won't build (and therefore light) unless its neighbor chunks are generated.