/// <summary> /// Initialization method /// </summary> private void Initialize() { if (initialized) { return; } //Increase shadows distance var shadows = volume.profile.components.Find(component => component is HDShadowSettings) as HDShadowSettings; if (shadows != null) { shadows.maxShadowDistance.value *= QualityDistanceMultiplier; } QualitySettings.renderPipeline = vseHdrpSettings; HDRPUtilities.ReinitializeRenderPipeline(); initialized = true; }
private static void ReinitializeRenderPipeline() { // NOTE: This is a workaround for Vulkan. Even if HDRP is reinitialized, lighting data and depth buffers // on render targets (even ones created afterwards) will be corrupted. Reloading scene before // forcefully reinitializing HDRP will refresh both lighting and depth data appropriately. // This happens automatically for scene bundles, but is required for prefab ones. // If this is not called for scene bundles, however, command line execution from async method will // not create render pipeline at all when using Vulkan and crash with invalid memory access // Last tested on Unity 2019.3.15f1 and HDRP 7.3.1 const string loaderScenePath = "Assets/Scenes/LoaderScene.unity"; var openScenePaths = new List <string>(); var activeScenePath = SceneManager.GetActiveScene().path; for (var i = 0; i < EditorSceneManager.loadedSceneCount; ++i) { openScenePaths.Add(SceneManager.GetSceneAt(i).path); } EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); var mainScenePath = string.IsNullOrEmpty(activeScenePath) ? loaderScenePath : activeScenePath; EditorSceneManager.OpenScene(mainScenePath, OpenSceneMode.Single); foreach (var scenePath in openScenePaths) { if (string.Equals(scenePath, activeScenePath) || string.IsNullOrEmpty(scenePath)) { continue; } EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive); } HDRPUtilities.ReinitializeRenderPipeline(); }
/// <summary> /// Deinitialization method /// </summary> /// <param name="reinitializeRenderPipeline">Should reinitialize render pipeline after changes</param> private void Deinitialize(bool reinitializeRenderPipeline) { if (!initialized) { return; } //Revert shadows distance var shadows = volume.profile.components.Find(component => component is HDShadowSettings) as HDShadowSettings; if (shadows != null) { shadows.maxShadowDistance.value /= QualityDistanceMultiplier; } QualitySettings.renderPipeline = defaultHdrpSettings; if (reinitializeRenderPipeline) { HDRPUtilities.ReinitializeRenderPipeline(); } initialized = false; }