public IEnumerator BakingWithATrousFiltering_DoesNotFallback() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/BakeATrous.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.lightmapper = LightingSettings.Lightmapper.ProgressiveGPU; lightingSettings.mixedBakeMode = MixedLightingMode.IndirectOnly; lightingSettings.directionalityMode = LightmapsMode.NonDirectional; // Activate A-Trous filtering lightingSettings.filterTypeIndirect = LightingSettings.FilterType.ATrous; Lightmapping.Clear(); Lightmapping.Bake(); // Check that we did not fallback to CPULM Assert.AreEqual(lightingSettings.lightmapper, LightingSettings.Lightmapper.ProgressiveGPU); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
static void Init256() { LightmapEditorSettings.maxAtlasHeight = 256; LightmapEditorSettings.maxAtlasWidth = 256; Lightmapping.Clear(); Lightmapping.Bake(); }
void RunAutoLightBaker() { // Debug.Log("Starting bake process..."); int totalScenes = SceneManager.sceneCountInBuildSettings; isBaking = true; Scene tmpScene; EditorSceneManager.sceneSaved += SceneSavedCallback; Lightmapping.completed += SceneFinishedLightbaking; Debug.Log("Found " + totalScenes + " to get baked."); while (isBaking) { if (!isBusy) { isBusy = true; // Debug.Log("Preparing to bake " + SceneUtility.GetScenePathByBuildIndex(currentScene)); tmpScene = EditorSceneManager.OpenScene(SceneUtility.GetScenePathByBuildIndex(currentScene), OpenSceneMode.Single); isBakingCurrent = true; while (isBakingCurrent) { Lightmapping.Bake(); } EditorSceneManager.SaveScene(tmpScene, "", false); } if (finishedScenes == totalScenes) { FinishedBaking(); } } }
public void BakeMe() { SkinData[] data = CopySkinRenderers(); PrepareObjects(data); Lightmapping.Bake(); FixObjects(data); }
private static void BakeLightmap() { LightmapEditorSettings.maxAtlasHeight = 512; LightmapEditorSettings.maxAtlasSize = 512; Lightmapping.Clear(); Lightmapping.Bake(); }
public static void GenerateLightmapInfo() { if (Lightmapping.giWorkflowMode != Lightmapping.GIWorkflowMode.OnDemand) { Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled."); return; } Lightmapping.Bake(); PrefabLightmapData[] prefabs = FindObjectsOfType <PrefabLightmapData>(); foreach (PrefabLightmapData instance in prefabs) { GameObject gameObject = instance.gameObject; List <Renderer> renderers = new List <Renderer>(); List <Vector4> lightmapOffsetScales = new List <Vector4>(); List <Texture2D> lightmaps = new List <Texture2D>(); GenerateLightmapInfo(gameObject, renderers, lightmapOffsetScales, lightmaps); // ReSharper disable InconsistentNaming instance.m_Renderers = renderers.ToArray(); instance.m_LightmapOffsetScales = lightmapOffsetScales.ToArray(); instance.m_Lightmaps = lightmaps.ToArray(); // ReSharper restore InconsistentNaming var targetPrefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject); if (targetPrefab != null) { PrefabUtility.ReplacePrefab(gameObject, targetPrefab); } } }
public static void testBuildLightMap() { LightmapEditorSettings.maxAtlasHeight = 512; LightmapEditorSettings.maxAtlasWidth = 512; Lightmapping.Clear(); Lightmapping.Bake(); }
public IEnumerator TiledBaking_GPU_1k_lightmap_4_tiles() { EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.tiledBaking = LightingSettings.TiledBaking.Quarter; lightingSettings.lightmapResolution = 100; lightingSettings.lightmapMaxSize = 1024; Lightmapping.Clear(); Lightmapping.Bake(); LightmapConvergence lc = Lightmapping.GetLightmapConvergence(0); Assert.That(lc.GetTileCount(), Is.EqualTo(4), "Max tiling pass num should be 4"); while (Lightmapping.isRunning) { yield return(null); } Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
public IEnumerator TiledBaking_GPU_1k_lightmap_4_tiles_1_Empty_Tile() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/ThreePlanes.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.tiledBaking = LightingSettings.TiledBaking.Quarter; Lightmapping.Clear(); Lightmapping.Bake(); LightmapConvergence lc = Lightmapping.GetLightmapConvergence(0); Assert.That(lc.GetTileCount(), Is.EqualTo(4), "Max tiling pass num should be 4"); while (Lightmapping.isRunning) { yield return(null); } Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
static void Init512() { LightmapEditorSettings.maxAtlasHeight = 512; LightmapEditorSettings.maxAtlasWidth = 512; Lightmapping.Clear(); Lightmapping.Bake(); }
static void GenerateLightmapInfo() { if (Lightmapping.giWorkflowMode != Lightmapping.GIWorkflowMode.OnDemand) { Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled."); return; } Lightmapping.Bake(); PrefabLightmapData[] prefabs = GameObject.FindObjectsOfType <PrefabLightmapData>(); foreach (var instance in prefabs) { var gameObject = instance.gameObject; var rendererInfos = new List <PrefabLightmapData.RendererInfo>(); var lightmaps = new List <Texture2D>(); GenerateLightmapInfo(gameObject, rendererInfos, lightmaps); instance.m_RendererInfo = rendererInfos.ToArray(); instance.m_Lightmaps = lightmaps.ToArray(); //var targetPrefab = UnityEditor.PrefabUtility.GetPrefabParent(gameObject) as GameObject; var targetPrefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject) as GameObject; if (targetPrefab != null) { //UnityEditor.Prefab PrefabUtility.ReplacePrefab(gameObject, targetPrefab); } } }
void CreateScene() { openScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); CenterView(); GameObject obj = new GameObject(); obj.name = "Chunks Holder"; manager = obj.AddComponent <ChunkManager>(); //add light GameObject lightobj = new GameObject(); lightobj.name = "Light"; lightobj.transform.position = new Vector3(0, 100, 0); lightobj.transform.rotation = Quaternion.Euler(new Vector3(50, -30, 0)); var light = lightobj.AddComponent <Light>(); light.color = Color.white; light.type = LightType.Directional; Lightmapping.Bake(); //mark gameobject in scene hierarchy Selection.activeObject = obj; chunkObject = obj; }
static void GenerateLightMap() { if (!Lightmapping.Bake()) { Debug.LogError("Lightmap baking failed"); } }
static void Init1024() { LightmapEditorSettings.maxAtlasHeight = 1024; LightmapEditorSettings.maxAtlasWidth = 1024; Lightmapping.Clear(); Lightmapping.Bake(); }
void Bake() { LightmapEditorSettings.maxAtlasHeight = maxAtlasHeight; LightmapEditorSettings.maxAtlasWidth = maxAtlasWidth; Lightmapping.Clear(); Lightmapping.Bake(); }
public void GPULM_BakeSceneWithOnlyBlackLight_DoesNotFallbackToCPU() { // Open the initial scene EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/GPU-Rebake.unity"); // Clear baked data and cache clearAll(); // VerifySettings are correct SetupLightingSettings(); // Get the settings to be able to check for a fallback to CPU LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.IsTrue(lightingSettings != null, "Lighting settings are available."); // Get the light Light light = GameObject.Find("Directional Light").GetComponent <Light>(); Assert.IsNotNull(light); // Set the light color light.color = Color.black; // Bake the scene GI Lightmapping.Bake(); Assert.IsTrue(lightingSettings.lightmapper == LightingSettings.Lightmapper.ProgressiveGPU, "Using GPU Lightmapper after initial bake."); clearAll(); }
static void GenerateLightmapInfo() { Debug.ClearDeveloperConsole(); if (Lightmapping.giWorkflowMode != Lightmapping.GIWorkflowMode.OnDemand) { Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled."); return; } Lightmapping.Bake(); string lightMapPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), LIGHTMAP_RESOURCE_PATH); if (!Directory.Exists(lightMapPath)) { Directory.CreateDirectory(lightMapPath); } sceneLightmaps = new List <Texture2D_Remap>(); //var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); var sceneName = Path.GetFileNameWithoutExtension(EditorSceneManager.GetActiveScene().path); var resourcePath = LIGHTMAP_RESOURCE_PATH + sceneName; var scenePath = System.IO.Path.GetDirectoryName(EditorSceneManager.GetActiveScene().path) + "/" + sceneName + "/"; PrefabLightmapData[] prefabs = FindObjectsOfType <PrefabLightmapData>(); foreach (var instance in prefabs) { var gameObject = instance.gameObject; var rendererInfos = new List <RendererInfo>(); var lightmaps = new List <Texture2D>(); var lightmaps2 = new List <Texture2D>(); GenerateLightmapInfo(scenePath, resourcePath, gameObject, rendererInfos, lightmaps, lightmaps2); instance.m_RendererInfo = rendererInfos.ToArray(); instance.m_Lightmaps = lightmaps.ToArray(); instance.m_Lightmaps2 = lightmaps2.ToArray(); // var targetPrefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject); var parent = PrefabUtility.GetCorrespondingObjectFromSource(gameObject); var parentPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(parent); PrefabUtility.SaveAsPrefabAsset(gameObject, parentPath); //if (targetPrefab != null) //{ // //Prefab // //PrefabUtility.ReplacePrefab(gameObject, targetPrefab); //} ApplyLightmaps(instance.m_RendererInfo, instance.m_Lightmaps, instance.m_Lightmaps2); } Debug.Log("Update to prefab lightmaps finished"); }
public void LightmapBenchmark() { double TimeBefore = EditorApplication.timeSinceStartup; Lightmapping.Bake(); double TimeElapsed = EditorApplication.timeSinceStartup - TimeBefore; StoreResults(TimeElapsed); }
public static void bake_light_maps() { //Bake Lighting settings Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; LightmapEditorSettings.bakeResolution = 1f; Lightmapping.realtimeGI = false; // Realtime GI does not show up on WebGL build Lightmapping.Bake(); }
static void CreateLightmapAllScene() { string nowSceneName = EditorSceneManager.GetActiveScene().path; EditorSceneManager.OpenScene("Assets/Example/Scenes/CompleteScene.unity"); Lightmapping.Bake(); EditorSceneManager.OpenScene("Assets/Example/Scenes/Workshop01.unity"); Lightmapping.Bake(); EditorSceneManager.OpenScene(nowSceneName); }
public void Setup() { #if UNITY_EDITOR // Search for "InitTestSceneXXXXXXXX" generated by test runner and save the path in the EditorPrefs for (int i = 0; i < EditorSceneManagement.EditorSceneManager.sceneCount; ++i) { Scene scene = EditorSceneManagement.EditorSceneManager.GetSceneAt(i); if (scene.name.StartsWith("InitTestScene")) { EditorPrefs.SetString("InitTestScene", scene.path); break; } } string scenesWithAutoLightMap = ""; // For each scene in the build settings, force build of the lightmaps if it has "DoLightmap" label. foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes) { SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scene.path); var labels = new System.Collections.Generic.List <string>(AssetDatabase.GetLabels(sceneAsset)); if (labels.Contains("DoLightmap")) { EditorSceneManagement.EditorSceneManager.OpenScene(scene.path, EditorSceneManagement.OpenSceneMode.Single); Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; EditorSceneManagement.EditorSceneManager.SaveOpenScenes(); Lightmapping.Clear(); Lightmapping.Bake(); scenesWithAutoLightMap += scene.path + ";"; EditorSceneManagement.EditorSceneManager.SaveOpenScenes(); Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.Iterative; EditorSceneManagement.EditorSceneManager.SaveOpenScenes(); EditorSceneManagement.EditorSceneManager.NewScene(EditorSceneManagement.NewSceneSetup.EmptyScene); } } EditorPrefs.SetString("ScenesWithAutoLightMap", scenesWithAutoLightMap); // Re-open testrunner scene string initTestSceneString = EditorPrefs.GetString("InitTestScene"); if (!string.IsNullOrEmpty(initTestSceneString)) { EditorSceneManagement.EditorSceneManager.OpenScene(initTestSceneString, EditorSceneManagement.OpenSceneMode.Single); } #endif }
public static void saveToNewScene() { string folderName = "Autosaved Scenes"; string newTimestamp = "TS-" + getTimestamp(DateTime.Now, true, true); int tsLength = newTimestamp.Length; string newSceneName, oldSceneName; Scene newScene; int length = EditorSceneManager.GetActiveScene().name.IndexOf("TS-"); // delimiter // create the new scene // if we are not currently in a scene if (EditorSceneManager.GetActiveScene().name == "") // if we are not in a scene { newSceneName = "Autosaved Scene" + newTimestamp; oldSceneName = ""; newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); } else // if we are in a scene { if (length < 0) // if the scene name does not contain the delimiter { newSceneName = "Test Scene" + " " + newTimestamp; oldSceneName = EditorSceneManager.GetActiveScene().name; } // if there is an open scene else { // Get the new scene name oldSceneName = EditorSceneManager.GetActiveScene().name; newSceneName = oldSceneName.Substring(0, length - 1) + " " + newTimestamp; // got the new scene name } // create new scene newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive); // copy everything from old scene into new scene EditorSceneManager.MergeScenes(EditorSceneManager.GetSceneByName(oldSceneName), newScene); // copied everything from old scene into new scene } string savedScene = currentFolderPath + folderName + "/" + newSceneName + ".unity"; EditorSceneManager.SaveScene(newScene, savedScene, false); Lightmapping.Bake(); }
void bakeAllScenes() { scenesToBake = ReadNames(); //m_baking = true; for (int i = 1; i < scenesToBake.Length; i++) { EditorApplication.OpenScene(scenesToBake[i]); setUpScene(); Lightmapping.Clear(); Lightmapping.Bake(); EditorApplication.SaveScene(scenesToBake[i]); } }
static void Bake() { GameObject[] emissiveObjects = GameObject.FindGameObjectsWithTag("CustomEmissive"); foreach (GameObject emissiveObject in emissiveObjects) { Material material = emissiveObject.GetComponent <Renderer>().sharedMaterial; material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive; } Lightmapping.Bake(); }
public static void BakePrefabLightmaps() { if (Lightmapping.giWorkflowMode != Lightmapping.GIWorkflowMode.OnDemand) { Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled."); return; } PrefabLightmapData[] prefabs = Object.FindObjectsOfType <PrefabLightmapData>(); MakeSureRendererGameObjectIsLightmapStatic(prefabs); // Bake lightmap for scene. Lightmapping.Bake(); }
static void LightmapSaverEditorSimplePasses() { LightmapSaver[] dataHolders = GameObject.FindObjectsOfType<LightmapSaver>(); for(int i = 0; i < dataHolders.Length; i++) { var holder = dataHolders[i]; GameObject root = holder.gameObject; LightmapSaver pSaver = root.GetComponentInParent<LightmapSaver>(); if(null != pSaver && pSaver.gameObject != root) { EditorUtility.DisplayDialog("错误", string.Format("游戏物体{0}的父节点{1}包含有 LightmapSaver 组件,这是不允许的。", root.gameObject.name, pSaver.gameObject.name),"确定"); return; } var cSaver = root.GetComponentInChildren<LightmapSaver>(); if(null != cSaver && cSaver.gameObject != root) { EditorUtility.DisplayDialog("错误", string.Format("游戏物体{0}的子节点{1}包含有 LightmapSaver 组件,这是不允许的。", root.gameObject.name, cSaver.gameObject.name), "确定"); return; } Lightmapping.Clear(); Lightmapping.Bake();//开始烘焙 var renderers = root.GetComponentsInChildren<Renderer>(true); holder.RendererData = new LightmapSaver.LightmapRendererData[renderers.Length]; for (int j = 0; j < renderers.Length; j++) { var renderer = renderers[j]; holder.RendererData[j] = new LightmapSaver.LightmapRendererData(); Debug.Log(renderer.gameObject.name); if (renderer.lightmapIndex == -1) continue; var rendererData = holder.RendererData[j]; rendererData.renderer = renderer; rendererData.lightmapIndex = renderer.lightmapIndex; rendererData.lightmapScaleOffset = renderer.lightmapScaleOffset; } if(LightmapSettings.lightmaps.Length > 0) { holder.lightmapColor = LightmapSettings.lightmaps[0].lightmapColor; holder.lightmapDir = LightmapSettings.lightmaps[0].lightmapDir; } else { EditorUtility.DisplayDialog("烘焙失败", "没有成功生成光照贴图。", "确定"); return; } } EditorUtility.DisplayDialog("烘焙成功", "烘焙已经完成。", "确定"); }
private static void NewMethod(Light[] lights, int i) { #pragma warning disable CS0618 // Type or member is obsolete if (lights[i].type != LightType.Directional && !lights[i].isBaked && IsLightBaked(lights[i])) #pragma warning restore CS0618 // Type or member is obsolete { AddFix("Optimize Light Baking", "For GPU performance, please bake lightmaps to avoid realtime lighting cost.", delegate(UnityEngine.Object obj, bool last, int selected) { if (last) { Lightmapping.Bake(); } }, lights[i], "Bake Lightmaps"); } }
// [MenuItem("Tool/BakeLightMap", priority = 1001)] public static void BakeLightMap(Lightmapping.OnCompletedFunction complete) { string tempPath = MapScenePath + "/Map"; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); AssetDatabase.Refresh(); } //Debug.Log("giWorkflowMode :" + Lightmapping.giWorkflowMode); Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; Lightmapping.completed = complete; Lightmapping.Clear(); Lightmapping.Bake(); }
public static void BakeAndCall() { var result = Lightmapping.Bake(); SendWebHookInternal($"Lightmapping.Bake Complete. result is {result}", (isSuccess, msg) => { if (!isSuccess) { Debug.LogError("Send Fail. Error with :" + msg); return; } Debug.Log("Sent successfully"); }); }
public IEnumerator Export_Training_Data_With_AO_And_Tiled_Baking_On() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/ExtractTrainingDataScene.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.tiledBaking = LightingSettings.TiledBaking.Quarter; lightingSettings.exportTrainingData = false; lightingSettings.ao = true; Lightmapping.Clear(); Lightmapping.Bake(); while (Lightmapping.isRunning) { yield return(null); } Assert.That(!System.IO.Directory.Exists("Assets/TrainingData/Lightmap-0")); Assert.That(!System.IO.File.Exists("Assets/TrainingData/Lightmap-0/indirect.exr")); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); lightingSettings.exportTrainingData = true; Lightmapping.Bake(); while (Lightmapping.isRunning) { yield return(null); } Assert.That(System.IO.Directory.Exists("Assets/TrainingData/Lightmap-0")); Assert.That(System.IO.File.Exists("Assets/TrainingData/Lightmap-0/indirect.exr")); Assert.That(System.IO.File.Exists("Assets/TrainingData/Lightmap-0/ambient_occlusion.exr")); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); System.IO.Directory.Delete("Assets/TrainingData", true); Assert.That(!System.IO.Directory.Exists("Assets/TrainingData")); }