概要
ライトマップデータをPrefabに保存するスクリプトです。UnityのAssetsタブから使用します。このスクリプトをルートに配置した状態で、Prefabをシーンに置いてください。ライティングを設定したら、エディターでAssets->Bake Prefab Lightmapsを実行します。処理後は、別のシーンにPrefabを生成しても、元のシーンのライトマップが適用されます。
開発ツール計測したスター増加
- 24時間
- 0
- 7日間
- +1
- 15日間
- 履歴を収集中
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルPrefabLightmapping
Script for saving lightmapping data to prefabs. Used through the Assets tab in Unity. Place your prefabs in the scene with this script at the root. Set up your lighting and in the editor go to Assets->Bake Prefab Lightmaps. After the bake is processed you can now spawn your prefabs in different scenes and they will use the lightmapping from the original scene.
Remember that if you are not instantiating your prefabs at runtime you should remove the static flag from the GameObjects, otherwise static batching will mess with uvs and the lightmap won't work properly.
If you find problems when building make sure to check your graphics settings under Project Settings, as shader stripping might be the cause of the issue. Try playing with the option "Lightmap Modes" and setting it to Custom if it's not working.

*There is also an issue with Probuilder Objects so make sure to bake those meshes down so you don't use Probuilder objects in the prefabs.
** I added an optional checkbox called "Release Shaders" that is true by default, this makes the system reassign the shaders when applying the lightmaps. In some cases this is not necessary and it might conflict with certain shader keywords, if you notice some of your materials losing shader features you can uncheck this and that might fix your specific issue. It is true by default.
Original idea came from Joachim_Ante in the Unity forums
Feel free to use this project in all commercial and personal projects ;)
Runtime Light Probes
I added a new script that can be used to use lightprobes with your lightmapped prefabs. It needs a special setup though. You need to create a uniform lightprobe group in the scene you are going to instantiate prefabs at, and then do an "empty" bake in that scene. Then this script (LightProbeRuntime.cs) should be placed in that scene where you instantiate prefabs, and it will wait a frame to calculate the light volume contribution from the lights (only point lights for now) in the scene (so for this to work properly you need to have those lights be a part of the prefabs rooms/assets you bake, so this script finds the lights and adds their "would be" contribution to the probes). You can easily tweak this to call it at will if you prefer to recalculate probes at different times.
関連プロジェクトを探す
読み込み中…