internal static HDRenderPipelineGlobalSettings Create(string path, HDRenderPipelineGlobalSettings dataSource = null)
        {
            HDRenderPipelineGlobalSettings assetCreated = null;

            //ensure folder tree exist
            CoreUtils.EnsureFolderTreeInAssetFilePath(path);

            //prevent any path conflict
            path = AssetDatabase.GenerateUniqueAssetPath(path);

            //asset creation
            assetCreated      = ScriptableObject.CreateInstance <HDRenderPipelineGlobalSettings>();
            assetCreated.name = Path.GetFileName(path);
            AssetDatabase.CreateAsset(assetCreated, path);
            Debug.Assert(assetCreated);

            // copy data from provided source
            if (dataSource != null)
            {
                EditorUtility.CopySerialized(dataSource, assetCreated);
            }

            // ensure resources are here
            assetCreated.EnsureEditorResources(forceReload: true);
            assetCreated.EnsureRuntimeResources(forceReload: true);
            assetCreated.EnsureRayTracingResources(forceReload: true);
            assetCreated.GetOrCreateDefaultVolumeProfile();
            assetCreated.GetOrAssignLookDevVolumeProfile();

            return(assetCreated);
        }
        //Making sure there is at least one HDRenderPipelineGlobalSettings instance in the project
        static internal HDRenderPipelineGlobalSettings Ensure(bool canCreateNewAsset = true)
        {
            if (instance == null || instance.Equals(null) || instance.m_Version == Version.First)
            {
                // Try to migrate HDRPAsset in Graphics. It can produce a HDRenderPipelineGlobalSettings
                // with data from former HDRPAsset if it is at a version allowing this.
                if (GraphicsSettings.defaultRenderPipeline is HDRenderPipelineAsset hdrpAsset && hdrpAsset.IsVersionBelowAddedHDRenderPipelineGlobalSettings())
                {
                    // if possible we need to finish migration of hdrpAsset in order to grab value from it
                    (hdrpAsset as IMigratableAsset).Migrate();
                }
            }

            if (instance == null || instance.Equals(null))
            {
                //try load at default path
                HDRenderPipelineGlobalSettings loaded = AssetDatabase.LoadAssetAtPath <HDRenderPipelineGlobalSettings>($"Assets/{HDProjectSettingsReadOnlyBase.projectSettingsFolderPath}/HDRenderPipelineGlobalSettings.asset");

                if (loaded == null)
                {
                    //Use any available
                    IEnumerator <HDRenderPipelineGlobalSettings> enumerator = CoreUtils.LoadAllAssets <HDRenderPipelineGlobalSettings>().GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        loaded = enumerator.Current;
                    }
                }

                if (loaded != null)
                {
                    UpdateGraphicsSettings(loaded);
                }

                // No migration available and no asset available? Create one if allowed
                if (canCreateNewAsset && instance == null)
                {
                    var createdAsset = Create($"Assets/{HDProjectSettingsReadOnlyBase.projectSettingsFolderPath}/HDRenderPipelineGlobalSettings.asset");
                    UpdateGraphicsSettings(createdAsset);

                    Debug.LogWarning("No HDRP Global Settings Asset is assigned. One has been created for you. If you want to modify it, go to Project Settings > Graphics > HDRP Settings.");
                }

                if (instance == null)
                {
                    Debug.LogError("Cannot find any HDRP Global Settings asset and Cannot create one from former used HDRP Asset.");
                }

                Debug.Assert(instance, "Could not create HDRP's Global Settings - HDRP may not work correctly - Open the Graphics Window for additional help.");
            }

            // Attempt upgrade (do notiong if up to date)
            IMigratableAsset migratableAsset = instance;

            if (!migratableAsset.IsAtLastVersion())
            {
                migratableAsset.Migrate();
            }

            return(instance);
        }
Exemplo n.º 3
0
        void Reset()
        {
#if UNITY_EDITOR
            // we need to ensure we have a global settings asset to be able to create an HDRP Asset
            HDRenderPipelineGlobalSettings.Ensure(canCreateNewAsset: true);
#endif
            OnValidate();
        }
Exemplo n.º 4
0
 static internal void UpdateGraphicsSettings(HDRenderPipelineGlobalSettings newSettings)
 {
     if (newSettings == null || newSettings == cachedInstance)
     {
         return;
     }
     GraphicsSettings.RegisterRenderPipelineSettings <HDRenderPipeline>(newSettings as RenderPipelineGlobalSettings);
     cachedInstance = newSettings;
 }
Exemplo n.º 5
0
        //Making sure there is at least one HDRenderPipelineGlobalSettings instance in the project
        static internal HDRenderPipelineGlobalSettings Ensure(bool canCreateNewAsset = true)
        {
            bool needsMigration = (assetToBeMigrated != null && !assetToBeMigrated.Equals(null));

            if (HDRenderPipelineGlobalSettings.instance && !needsMigration)
            {
                return(HDRenderPipelineGlobalSettings.instance);
            }

            HDRenderPipelineGlobalSettings assetCreated = null;
            string path = "Assets/HDRPDefaultResources/HDRenderPipelineGlobalSettings.asset";

            if (needsMigration)
            {
                if (HDRenderPipelineGlobalSettings.instance)
                {
                    path = AssetDatabase.GetAssetPath(HDRenderPipelineGlobalSettings.instance);
                }

                assetCreated = MigrateFromHDRPAsset(assetToBeMigrated, path, bClearObsoleteFields: false, canCreateNewAsset: canCreateNewAsset);
                if (assetCreated != null && !assetCreated.Equals(null))
                {
                    assetToBeMigrated = null;
                }
            }
            else
            {
                assetCreated = AssetDatabase.LoadAssetAtPath <HDRenderPipelineGlobalSettings>(path);
                if (assetCreated == null)
                {
                    var guidHDGlobalAssets = AssetDatabase.FindAssets("t:HDRenderPipelineGlobalSettings");
                    //If we could not find the asset at the default path, find the first one
                    if (guidHDGlobalAssets.Length > 0)
                    {
                        var curGUID = guidHDGlobalAssets[0];
                        path         = AssetDatabase.GUIDToAssetPath(curGUID);
                        assetCreated = AssetDatabase.LoadAssetAtPath <HDRenderPipelineGlobalSettings>(path);
                    }
                    else if (canCreateNewAsset)// or create one altogether
                    {
                        if (!AssetDatabase.IsValidFolder("Assets/HDRPDefaultResources/"))
                        {
                            AssetDatabase.CreateFolder("Assets", "HDRPDefaultResources");
                        }
                        assetCreated = Create(path);
                    }
                    else
                    {
                        Debug.LogError("Cannot migrate HDRP Asset to a new HDRP Global Settings asset. If you are building a Player, make sure to save an HDRP Global Settings asset by opening the project in the Editor.");
                        return(null);
                    }
                }
            }
            Debug.Assert(assetCreated, "Could not create HDRP's Global Settings - HDRP may not work correctly - Open the Graphics Window for additional help.");
            UpdateGraphicsSettings(assetCreated);
            return(HDRenderPipelineGlobalSettings.instance);
        }
 static internal void UpdateGraphicsSettings(HDRenderPipelineGlobalSettings newSettings)
 {
     if (newSettings == cachedInstance)
     {
         return;
     }
     if (newSettings != null)
     {
         GraphicsSettings.RegisterRenderPipelineSettings <HDRenderPipeline>(newSettings as RenderPipelineGlobalSettings);
     }
     else
     {
         GraphicsSettings.UnregisterRenderPipelineSettings <HDRenderPipeline>();
     }
     cachedInstance = newSettings;
 }
Exemplo n.º 7
0
        internal static HDRenderPipelineGlobalSettings Create(string path, HDRenderPipelineGlobalSettings src = null)
        {
            HDRenderPipelineGlobalSettings assetCreated = null;

            // make sure the asset does not already exists
            assetCreated = AssetDatabase.LoadAssetAtPath <HDRenderPipelineGlobalSettings>(path);
            if (assetCreated == null)
            {
                assetCreated = ScriptableObject.CreateInstance <HDRenderPipelineGlobalSettings>();
                AssetDatabase.CreateAsset(assetCreated, path);
                assetCreated.Init();
                if (assetCreated != null)
                {
                    assetCreated.name = Path.GetFileName(path);
                }
            }

            if (assetCreated)
            {
#if UNITY_EDITOR
                assetCreated.EnsureEditorResources(forceReload: true);
#endif
                if (src != null)
                {
                    assetCreated.renderPipelineResources           = src.renderPipelineResources;
                    assetCreated.renderPipelineRayTracingResources = src.renderPipelineRayTracingResources;

                    assetCreated.volumeProfile        = src.volumeProfile;
                    assetCreated.volumeProfileLookDev = src.volumeProfileLookDev;

                    assetCreated.m_RenderingPathDefaultCameraFrameSettings = src.m_RenderingPathDefaultCameraFrameSettings;
                    assetCreated.m_RenderingPathDefaultBakedOrCustomReflectionFrameSettings = src.m_RenderingPathDefaultBakedOrCustomReflectionFrameSettings;
                    assetCreated.m_RenderingPathDefaultRealtimeReflectionFrameSettings      = src.m_RenderingPathDefaultRealtimeReflectionFrameSettings;

                    assetCreated.beforeTransparentCustomPostProcesses.AddRange(src.beforeTransparentCustomPostProcesses);
                    assetCreated.beforePostProcessCustomPostProcesses.AddRange(src.beforePostProcessCustomPostProcesses);
                    assetCreated.afterPostProcessCustomPostProcesses.AddRange(src.afterPostProcessCustomPostProcesses);
                    assetCreated.beforeTAACustomPostProcesses.AddRange(src.beforeTAACustomPostProcesses);

                    assetCreated.lightLayerName0 = System.String.Copy(src.lightLayerName0);
                    assetCreated.lightLayerName1 = System.String.Copy(src.lightLayerName1);
                    assetCreated.lightLayerName2 = System.String.Copy(src.lightLayerName2);
                    assetCreated.lightLayerName3 = System.String.Copy(src.lightLayerName3);
                    assetCreated.lightLayerName4 = System.String.Copy(src.lightLayerName4);
                    assetCreated.lightLayerName5 = System.String.Copy(src.lightLayerName5);
                    assetCreated.lightLayerName6 = System.String.Copy(src.lightLayerName6);
                    assetCreated.lightLayerName7 = System.String.Copy(src.lightLayerName7);

                    assetCreated.decalLayerName0 = System.String.Copy(src.decalLayerName0);
                    assetCreated.decalLayerName1 = System.String.Copy(src.decalLayerName1);
                    assetCreated.decalLayerName2 = System.String.Copy(src.decalLayerName2);
                    assetCreated.decalLayerName3 = System.String.Copy(src.decalLayerName3);
                    assetCreated.decalLayerName4 = System.String.Copy(src.decalLayerName4);
                    assetCreated.decalLayerName5 = System.String.Copy(src.decalLayerName5);
                    assetCreated.decalLayerName6 = System.String.Copy(src.decalLayerName6);
                    assetCreated.decalLayerName7 = System.String.Copy(src.decalLayerName7);

                    assetCreated.shaderVariantLogLevel = src.shaderVariantLogLevel;
                    assetCreated.lensAttenuationMode   = src.lensAttenuationMode;

                    System.Array.Resize(ref assetCreated.diffusionProfileSettingsList, src.diffusionProfileSettingsList.Length);
                    for (int i = 0; i < src.diffusionProfileSettingsList.Length; ++i)
                    {
                        assetCreated.diffusionProfileSettingsList[i] = src.diffusionProfileSettingsList[i];
                    }
                }
                else
                {
                    assetCreated.EnsureRuntimeResources(forceReload: false);
                    assetCreated.EnsureRayTracingResources(forceReload: false);
                    assetCreated.GetOrCreateDefaultVolumeProfile();
                    assetCreated.GetOrAssignLookDevVolumeProfile();
                }
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }

            return(assetCreated);
        }
Exemplo n.º 8
0
        internal static HDRenderPipelineGlobalSettings MigrateFromHDRPAsset(HDRenderPipelineAsset oldAsset, string path, bool bClearObsoleteFields = true, bool canCreateNewAsset = true)
        {
            HDRenderPipelineGlobalSettings assetCreated = null;

            // 1. Load or Create the HDAsset and save it on disk
            assetCreated = AssetDatabase.LoadAssetAtPath <HDRenderPipelineGlobalSettings>(path);
            if (assetCreated == null)
            {
                if (!canCreateNewAsset)
                {
                    Debug.LogError("Cannot migrate HDRP Asset to a new HDRP Global Settings asset. If you are building a Player, make sure to save an HDRP Global Settings asset by opening the project in the Editor.");
                    return(null);
                }
                if (!AssetDatabase.IsValidFolder("Assets/HDRPDefaultResources/"))
                {
                    AssetDatabase.CreateFolder("Assets", "HDRPDefaultResources");
                }
                assetCreated = ScriptableObject.CreateInstance <HDRenderPipelineGlobalSettings>();
                AssetDatabase.CreateAsset(assetCreated, path);
                assetCreated.Init();
            }

#pragma warning disable 618 // Type or member is obsolete
            //2. Migrate obsolete assets (version DefaultSettingsAsAnAsset)
            assetCreated.volumeProfile        = oldAsset.m_ObsoleteDefaultVolumeProfile;
            assetCreated.volumeProfileLookDev = oldAsset.m_ObsoleteDefaultLookDevProfile;

            assetCreated.m_RenderingPathDefaultCameraFrameSettings = oldAsset.m_ObsoleteFrameSettingsMovedToDefaultSettings;
            assetCreated.m_RenderingPathDefaultBakedOrCustomReflectionFrameSettings = oldAsset.m_ObsoleteBakedOrCustomReflectionFrameSettingsMovedToDefaultSettings;
            assetCreated.m_RenderingPathDefaultRealtimeReflectionFrameSettings      = oldAsset.m_ObsoleteRealtimeReflectionFrameSettingsMovedToDefaultSettings;

            assetCreated.m_RenderPipelineResources           = oldAsset.m_ObsoleteRenderPipelineResources;
            assetCreated.m_RenderPipelineRayTracingResources = oldAsset.m_ObsoleteRenderPipelineRayTracingResources;

            assetCreated.beforeTransparentCustomPostProcesses.AddRange(oldAsset.m_ObsoleteBeforeTransparentCustomPostProcesses);
            assetCreated.beforePostProcessCustomPostProcesses.AddRange(oldAsset.m_ObsoleteBeforePostProcessCustomPostProcesses);
            assetCreated.afterPostProcessCustomPostProcesses.AddRange(oldAsset.m_ObsoleteAfterPostProcessCustomPostProcesses);
            assetCreated.beforeTAACustomPostProcesses.AddRange(oldAsset.m_ObsoleteBeforeTAACustomPostProcesses);

            assetCreated.lightLayerName0 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteLightLayerName0);
            assetCreated.lightLayerName1 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteLightLayerName1);
            assetCreated.lightLayerName2 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteLightLayerName2);
            assetCreated.lightLayerName3 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteLightLayerName3);
            assetCreated.lightLayerName4 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteLightLayerName4);
            assetCreated.lightLayerName5 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteLightLayerName5);
            assetCreated.lightLayerName6 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteLightLayerName6);
            assetCreated.lightLayerName7 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteLightLayerName7);

            // Decal layer names were added in 2021 cycle
            if (oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName0 != null)
            {
                assetCreated.decalLayerName0 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName0);
                assetCreated.decalLayerName1 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName1);
                assetCreated.decalLayerName2 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName2);
                assetCreated.decalLayerName3 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName3);
                assetCreated.decalLayerName4 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName4);
                assetCreated.decalLayerName5 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName5);
                assetCreated.decalLayerName6 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName6);
                assetCreated.decalLayerName7 = System.String.Copy(oldAsset.currentPlatformRenderPipelineSettings.m_ObsoleteDecalLayerName7);
            }

            assetCreated.shaderVariantLogLevel = oldAsset.m_ObsoleteShaderVariantLogLevel;
            assetCreated.lensAttenuationMode   = oldAsset.m_ObsoleteLensAttenuation;

            // we need to make sure the old diffusion profile had time to upgrade before moving it away
            if (oldAsset.diffusionProfileSettings != null)
            {
                oldAsset.diffusionProfileSettings.TryToUpgrade();
            }

            System.Array.Resize(ref assetCreated.diffusionProfileSettingsList, oldAsset.m_ObsoleteDiffusionProfileSettingsList.Length);
            for (int i = 0; i < oldAsset.m_ObsoleteDiffusionProfileSettingsList.Length; ++i)
            {
                assetCreated.diffusionProfileSettingsList[i] = oldAsset.m_ObsoleteDiffusionProfileSettingsList[i];
            }

            //3. Clear obsolete fields
            if (bClearObsoleteFields)
            {
                oldAsset.m_ObsoleteDefaultVolumeProfile  = null;
                oldAsset.m_ObsoleteDefaultLookDevProfile = null;

                oldAsset.m_ObsoleteRenderPipelineResources           = null;
                oldAsset.m_ObsoleteRenderPipelineRayTracingResources = null;

                oldAsset.m_ObsoleteBeforeTransparentCustomPostProcesses = null;
                oldAsset.m_ObsoleteBeforePostProcessCustomPostProcesses = null;
                oldAsset.m_ObsoleteAfterPostProcessCustomPostProcesses  = null;
                oldAsset.m_ObsoleteBeforeTAACustomPostProcesses         = null;
                oldAsset.m_ObsoleteDiffusionProfileSettingsList         = null;
            }
#pragma warning restore 618

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            return(assetCreated);
        }