2
\$\begingroup\$

I'm working on a Voxel project in Unity3D for fun and learning. I've been reading up on how this is done and have implemented a simple Voxel map in my project. My question is about the lighting. I've read several articles on how Minecraft implemented lighting. It doesn't seem too complicated but I'm wondering if it's necessary in Unity (and also I'm unsure how I would actually implement that in Unity)

So far I'm just using Point Lights on blocks that should emit light. Is Unity's Point Light efficient enough on a Voxel map if there are many light sources? So far on my scene it works OK with several lights on it. Adding many lights slows down the game as expected but since my computer is not a gaming beast I don't know if it's because Unity's Point Light is not optimized for this type of map or if it's just due to my low end computer. (To give you a point of comparison, I run Minecraft with a lot of lag but Eldritch with absolutely no lag, if you're familiar with both those games)

I would like some thoughts from more experienced users on this subject. If you had to develop a Voxel game in Unity, that may include 100 torches and 100 cubes of glowing lava, would you just use the Point Lights?

If the answer is no, is playing with the RGB values of the block textures the way to go?

\$\endgroup\$
  • \$\begingroup\$ If you want so many lights, then you could look at "deferred shading", en.wikipedia.org/wiki/Deferred_shading - it doesn't limit you so much with the number of lights. And it's supported by Unity. \$\endgroup\$ – kolenda Feb 24 '14 at 17:35
2
\$\begingroup\$

I'm not such an experienced (esp. with unity) but if the scene is static, I would not render the block using white squares (faces) with a texture, but using some pre-computed colored square with the same texture. With a shader, this would imply multiplying color of the texture by the precomputed color of the square.

Thus no real-time light computation would be done for the lighting block's square faces. I believe minecraft does not use true light objects either, seeing how mobs blinks from and to a lit/unlit state and how it's impossible to have half-lit mobs.

If you want smooth lighting, you should store a color component per visible face and per vertex.

\$\endgroup\$
2
\$\begingroup\$

No. Using point lights, especially in Unity Free, is far more expensive than using voxel-based lighting.

Lighting is the least expensive part of generating a Voxel world in my experience. Not only that, but by using voxel-based lighting instead of constructs such as point lights, you can achieve a pseudo-radiosity. Essentially, the light will "wrap around" corners and other obstructions much as it would appear to in many real-life situations.

Here's a THREE.js implementation of a voxel generator. While it's not Unity, the voxel calculations are the same, and the overall threading setup is very similar to what you'd have to deal with in Unity. On my machine, it takes 200ms to do the lighting, compared to ~6s to generate the terrain itself.

Voxel based lighting is generally performed using a flood-fill algorithm. Many implementations are recursive, but you can get an increase in execution speed by using a queue or stack to process the flood-fill in one method call instead.

Also of note: you may encounter rendering artifacts with point lights with the light "leaking" between the quads used to render the voxel faces if you use traditional point lights.

Additionally, by using voxel-based lighting, you now have a nice, voxelized representation of your lighting information for your scene. In theory, this could be used on the GPU to calculate per-vertex lighting for characters and moving objects.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.