- Home /
How to create light like in minecraft?
How to create light like in Minecraft in unity3d where quads are fully and evenly lightened from corner to corner?
It may be simple but I am trying to find my answer up from hours. I found only descriptions how it works or how to create in own game engine.
Thanks for any help.
I believe it isn't a normal type of lighting, it's a type of vertex lighting because of how $$anonymous$$ecraft terrain works. I think it would be easier to replicate with a marching cubes terrain system, because at that point you're only applying lighting to a single section of a localized mesh. Sorry if this doesn't help, but what you want is rather complicated. A useful quoute from Stackoverflow
Voxel based lighting is generally performed using a flood-fill algorithm. $$anonymous$$any 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 ins$$anonymous$$d.
However it is worth nothing that if you user a Pixel light and set it's rendering importance to "not important" it will switch to a Vertex lighting method, which may be more of what you're looking for.
Yes, it is not normal lighting. Also, I actualy have combined meshes of all quads into one chunk that is single game object for better optimalization so material is applied to all quads in one chunk. I have an idea to create shader that will have in input 2 variables: 1. vec4 array that will be collection of coordinates xyz and block face id (1-6), 2. float array that will be collection of light power. I am newbie in creating shaders and I need help. Is it possible to use arrays in shaders as input? How to change then pixels in small part of chunk that is block face on xyz using shader? I think I have to go this way. If it is not nessesary, can you please help me finding better and easier way to make lighting like this? Thank you very much for helping.
You might not need to make a custom shader. mesh.colors and mesh.colors32 are arrays that match your mesh.vertices. So you'll just need to apply a flood-fill algorithm as Rob suggested to get your light values. Some tips for your light values is that only transparent and light emitting blocks have a light value (since light can't go through solid blocks) then have your solid blocks pick the neighbor with the highest lightValue - 1, and apply that to your mesh.colors.
You would have your light values in a separate data structure that matches your blocks (like light$$anonymous$$ap[x][y][z]) and preform the flood fill on that. Then afterward when you are building your vertices you can double up with colors for your mesh.colors.
I have found video on youtube where someone created exactly that lighting type what I want. https://www.youtube.com/watch?v=tmn-sa5x46s
Answer by JxWolfe · Feb 22, 2019 at 08:27 PM
ok, if you want you objects to be fully lit from any angle, you are going to want to set your texture to 'unlit'. Then lights will not effect the color. Hope that helps