参考链接:http://www.xuanyusong.com/archives/3807
其它关于Unity5的光照系统神马的,网上很多资源,这几个文章良大本人觉得是很有价值的:
Unity 5 中的全局光照技术详解
http://www.gameres.com/forum.php?mod=viewthread&tid=446301
详解Unity 5 全局光照系统Enlighten问题
http://forum.china.unity3d.com/thread-14559-1-1.html
http://forum.china.unity3d.com/thread-14700-1-1.html
为什么要动态更新Lightmap
项目内需要对项目进行动态更新或者制作如白天黑夜等,同一场景不同光照渲染的情况。
将场景(.unity)文件转换成(.prefab)文件,能够更加自由的操作场景资源的更换。
修改功能支持
- 添加多张光照贴图烘焙
具体代码如下:
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using GOE.Scene;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using SceneManager = UnityEngine.SceneManagement.SceneManager;
/// <summary>
/// 描述:动态烘焙场景光照模型,并产生对应的Prefab文件
/// <para>创建时间:2016-06-15</para>
/// </summary>
public sealed class LightMapEditor
{
private const string LightMapsDir = "Resources/Lightmaps/";
private static List<RemapTexture2D> sceneLightmaps = new List<RemapTexture2D>();
public static void UpdateLightmaps()
{
PrefabLightmapData pld = GameObject.FindObjectOfType<PrefabLightmapData>();
if (pld == null) return;
LightmapSettings.lightmaps = null;
PrefabLightmapData.ApplyLightmaps(pld.mRendererInfos , pld.mLightmapFars , pld.mLightmapNears);
Debug.Log("Prefab Lightmap updated");
}
public static void GenLightmap()
{
genBakeLightmapAndPrefab(false);
EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log("----------------Update to Prefab Lightmap Finish -------------------------");
}
/// <summary>
/// 生成lightmap和prefab资源
/// </summary>
private static void genBakeLightmapAndPrefab()
{
if (Lightmapping.giWorkflowMode != Lightmapping.GIWorkflowMode.OnDemand)
{
Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps