- Home /
Lightmapping; Baking in runtime
Hello! :)
I am making a voxel game, and so far, as I understand, lightmapping and baking can be done in the editor, by selecting the light sources, the terrains and then baking everything. However, I do not have anything in the Unity editor to bake, because terrain is generated at runtime.
Because google has not yielded anything in regards to baking at runtime, how can I bake my terrain after I have created it after running the game?
Basically, lets say it creates 4 chunks, and the game/map has a directional light, how can I script it so that lightmapping and baking starts after the terrain is generated?
Thank you! :)
BONUS QUESTION:
There seems to be this bug:
It seems like the shadows arent properly displaying at these type of locations, I assume this is due to not having shadows baked, am i correct? Adjusting the Bias also didnt help
Edit: I adjusted the light bias to show the problem more clearly:
Answer by Tanshaydar · Oct 13, 2014 at 05:59 PM
Lightmapping on runtime, even if it was possible, is not a good idea. See, thebeast.exe (32 or 64 bit) runs exclusively after you send your mesh renderers into its queue, and it starts to process them, using around 95% of your CPU and 3-4 GB Ram at the very least, making game (even the editor) unplayable / unusable.
So, here, lightmapping on runtime is not the answer to your question. You can either create chunks and lightmap them, then instantiate them to build something bigger, or stick to dynamic lightning.
Tanshaydar is correct. Baking is not a run time feature. It is designed to produce shadows at a lower performance cost than real time shadows by doing all the shadow calculations not at run time, producing lightmaps that affect the brightness of your textures. It is very power hungry when run and can kill my laptop for a day when generating the lightmaps for a simple scene. You need to look at realtime shadows for this, if you have Unity Pro. If not you need to create sections of terrain that join up seamlessly with each other. Bake each section. Then create your terrain by random assembly of these pre-baked/created sections at run time.
The gap you see is a baking issue that you sometimes get when the meshes(objects) in the scene that are being baked are not connected(all one single mesh). You can reduce this by overlapping your objects, or putting other objects in your scene while baking which you delete after. Or failing that join your meshes together.
I am making a game where first you have map editor where you build voxel terrain and then you hit the button to compute lighting and other stuff where player can wait a bit. For this I need to do baking at runtime and answering this question would actually help me a lot ins$$anonymous$$d of saying that it is "bad idea"
This is a 6 years old question with an answer specific to that question. If you're gonna complain that you don't like the answer, either answer it yourself, or ask another question, because the person who answered 6 years ago could not possibly foresee your today need, don't you think?
Your answer
Follow this Question
Related Questions
Why Lightmap disappear when i press Play ? 1 Answer
Lightmapping Problem 0 Answers
Scene gets darker after baking lightmap 2 Answers
Do I still need lightmaps? 1 Answer
Lightmaps on mobile inconsistant 4 Answers