Voxel Engine Lighting

Hey guys,

I’ve been working on a voxel engine for some time now. And I have all kinds of functionality in it - terrain generation, all kinds of block types, block functionality, and a bunch of unique things.

But one thing I absolutely can’t seem to get my mind wrapped around is lighting. And by that I mean I can’t even figure it out at the most basic level.

I think I’m stuck with the wrong perspective on this. I don’t see how I’d even begin going about lighting. I hear about using vertices, shaders, etc. But how do you actually use vertices and shaders to make a block light up, so that you can begin a flood-fill type system (with the byte representing light, checking neighbors, etc.)?

So basically, I’m not sure where you even start. I’m pretty new with this kind of thing.

I’ve done a lot of research about this, but I can’t get seem to find anything that helps me get going in the right direction on this. I think people assume that people making these engines know a lot about shaders, procedural mesh building, etc. And maybe that’s true… but I sure don’t! I’m trying to learn about all of that through making this game.

Thanks in advance if you can point me in the right direction.

PS: I’m not looking for detailed code giving an implementation, exactly. I’m just looking for some information on what I can do. I mean, am I suppose to use vertices to do this, and if so, how?

Am I supposed to use a shader? Say I have a shader, how do I apply it to blocks in a voxel engine in a way to make this work?

Am I supposed to have materials? Then I can use shaders. But how do I use materials? Do I apply one to each face of the cube? And still, how would lighting be done with this system?

As you can see, I’m rather confused.

If you don’t care about shadows, you can use the regular built in Unity lights, either vertex or pixel based. If you do care about shadows, then you either need to do raycasting or a lot of shader fanciness. Raycasting is almost certainly easier. The basic idea is when a light changes (is placed, moves, etc) then cast a ray to each voxel and see if it hits anything. If it doesn’t then compute the brightness based on distance attenuation from the light. If it hits something, then it’s in shadow. Keep track of all voxels affected by a light so that you can undo the light effect when it moves or is deleted. This approach works for the global sunlight, too, just cast from the voxel center in the direction of the sun for a certain “long enough” distance. If it hits anything, it’s shadowed.