diff --git a/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentListEditor.cs b/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentListEditor.cs index 21a110079a0..9669c56a435 100644 --- a/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentListEditor.cs +++ b/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentListEditor.cs @@ -199,10 +199,10 @@ public void OnGUI() // Even if the asset is not dirty, the list of component may have been changed by another inspector. // In this case, only the hash will tell us that we need to refresh. - if (asset.isDirty || asset.GetHashCode() != m_CurrentHashCode) + if (asset.isDirty || asset.GetComponentListHashCode() != m_CurrentHashCode) { RefreshEditors(); - m_CurrentHashCode = asset.GetHashCode(); + m_CurrentHashCode = asset.GetComponentListHashCode(); asset.isDirty = false; } diff --git a/com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs b/com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs index 198a44af7ac..a687a86fb4d 100644 --- a/com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs +++ b/com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs @@ -297,5 +297,18 @@ public override int GetHashCode() return hash; } } + + internal int GetComponentListHashCode() + { + unchecked + { + int hash = 17; + + for (int i = 0; i < components.Count; i++) + hash = hash * 23 + components[i].GetType().GetHashCode(); + + return hash; + } + } } } diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 79a2f40326b..f556ce37867 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -692,6 +692,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed warning in HDAdditionalLightData OnValidate (cases 1250864, 1244578) - Fixed a bug related to denoising ray traced reflections. - Fixed nullref in the layered lit material inspector. +- Fixed an issue where manipulating the color wheels in a volume component would reset the cursor every time. +- Fixed an issue where static sky lighting would not be updated for a new scene until it's reloaded at least once. ### Changed - Improve MIP selection for decals on Transparents diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Material-Upgrade.md b/com.unity.render-pipelines.high-definition/Documentation~/Material-Upgrade.md index bee7ef5fdd7..1e256c621e8 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Material-Upgrade.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Material-Upgrade.md @@ -18,4 +18,4 @@ Please note that if a version control system that requires check out operations In case the above process fails and a material is not working as expected when upgrading HDRP version, it is suggested to run the upgrade process manually. To do so, you can either: - Open the [Render Pipeline Wizard](Render-Pipeline-Wizard.html) and under the **Project Migration Quick-links** click on the Upgrade HDRP Materials to Latest Version button. Or: -- Select **Edit > Render Pipelines > Upgrade HDRP Materials to Latest Version** \ No newline at end of file +- Select **Edit > Render Pipelines > HD Render Pipeline > Upgrade from Previous Version > Upgrade HDRP Materials to Latest Version** diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Render-Pipeline-Wizard.md b/com.unity.render-pipelines.high-definition/Documentation~/Render-Pipeline-Wizard.md index eecbef60ef6..53753e37fa2 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Render-Pipeline-Wizard.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Render-Pipeline-Wizard.md @@ -93,9 +93,9 @@ Note that every **Fix** will be deactivated if your Hardware or OS do not suppor ## Project Migration Quick-links -When upgrading a project from the built-in render pipeline to HDRP, you need to do upgrade your Lights and your Materials. Use the following utility functions to help with the upgrade process: +When upgrading a project from the built-in render pipeline to HDRP, you need to do upgrade your Materials. Use the following utility functions to help with the upgrade process: - **Upgrade Project Materials to High Definition Materials**: Upgrades every Material in your Unity Project to HDRP Materials. - **Upgrade Selected Materials to High Definition Materials**: Upgrades every Material currently selected to HDRP Materials. -- **Multiply Unity Builtin Directional Light Intensity to match High Definition**: Multiply intensity of each Directional Light in the current Scene to match HDRP compatible intensity values. Caution: This script should be executed only once. +The lighting will not match as HDRP use a different attenuation function than built-in and use correct math to handle lighting model. There is no function that can convert the look. Thus the lighting will require to be redone. diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md index 86cc8613c78..de3badbfb51 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2020.1-to-2020.2.md @@ -41,7 +41,9 @@ The shader function `SampleShadow_PCSS` now requires you to pass in an additiona From Unity 2020.2, due to the change of shadow map, the enum HDShadowFilteringQuality have been moved to HDShadowManager.cs and the variables ShaderConfig.s_DeferredShadowFiltering as well as the option ShaderOptions.DeferredShadowFiltering have been removed from the code as they have no impact anymore. -From Unity 2020.2, a new option is available name ColoredShadow. It allow to control if the shadow will be chromatic or monochrome. ColoredShadow have a performance cost. ColoredShadow are the default and currently only work with Raytrace shadow. +From Unity 2020.2, a new option is available named ColoredShadow. It allows you to control whether a shadow is chromatic or monochrome. ColoredShadow is enabled by default and currently only works with [Ray-traced shadows](Ray-Traced-Shadows.md). Note that colored shadows are more resource-intensive to process than standard shadows. + +From Unity 2020.2, the Raytracing option and equivalent generated shader macro SHADEROPTIONS_RAYTRACING have been removed. It is not longer require to edit shader config file to use Raytracing features of HDRP. ## Shader code @@ -73,8 +75,9 @@ BSDFData bsdfData = ConvertSurfaceDataToBSDFData(posInput.positionSS, surfaceDat PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); ``` +From Unity 2020.2, HDRP includes a new rectangular area shadow evaluation function, EvaluateShadow_RectArea. The GetAreaLightAttenuation() function has been renamed to GetRectAreaShadowAttenuation(). Also the type DirectionalShadowType have been renamed SHADOW_TYPE. -From Unity 2020.2, a new rectangular area shadow have been introduce EvaluateShadow_RectArea and the function GetAreaLightAttenuation() have been rename to GetRectAreaShadowAttenuation(). Also the type DirectionalShadowType have been renamed SHADOW_TYPE. +From Unity 2020.2, the macro ENABLE_RAYTRACING, SHADEROPTIONS_RAYTRACING, and RAYTRACING_ENABLED have been removed. A new multicompile is introduce for forward pass: SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON. This allow to enable raytracing effect without requiring edition of shader config file. ## Custom pass API diff --git a/com.unity.render-pipelines.high-definition/Editor/PostProcessing/TonemappingEditor.cs b/com.unity.render-pipelines.high-definition/Editor/PostProcessing/TonemappingEditor.cs index 6df51c75676..256ffd2bcc5 100644 --- a/com.unity.render-pipelines.high-definition/Editor/PostProcessing/TonemappingEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/PostProcessing/TonemappingEditor.cs @@ -125,7 +125,7 @@ public override void OnInspectorGUI() PropertyField(m_LutContribution, EditorGUIUtility.TrTextContent("Contribution")); - EditorGUILayout.HelpBox("Use \"Edit > Render Pipeline > Render Selected Camera to Log EXR\" to export a log-encoded frame for external grading.", MessageType.Info); + EditorGUILayout.HelpBox("Use \"Edit > Render Pipeline > HD Render Pipeline > Render Selected Camera to Log EXR\" to export a log-encoded frame for external grading.", MessageType.Info); } } @@ -142,7 +142,7 @@ void CheckCurveRT(int width, int height) sealed class ExrExportMenu { - [MenuItem("Edit/Render Pipeline/Render Selected Camera to Log EXR %#&e", priority = CoreUtils.editMenuPriority3)] + [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Render Selected Camera to Log EXR %#&e")] static void Export() { var camera = Selection.activeGameObject?.GetComponent(); diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineMenuItems.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineMenuItems.cs index 106f326c19d..37c74e1f310 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineMenuItems.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineMenuItems.cs @@ -8,6 +8,7 @@ using UnityEngine.SceneManagement; using UnityEditor.SceneManagement; using UnityEngine.Rendering; +using UnityEngine.Assertions; namespace UnityEditor.Rendering.HighDefinition { @@ -45,7 +46,7 @@ static void RemoveTessellationMaterials() } } - [MenuItem("Edit/Render Pipeline/Export Sky to Image", priority = CoreUtils.editMenuPriority3)] + [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Export Sky to Image")] static void ExportSkyToImage() { var renderpipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline; @@ -95,160 +96,11 @@ static void CreateSceneSettingsGameObject(MenuCommand menuCommand) volume.sharedProfile = profile; } - [MenuItem("Edit/Render Pipeline/Upgrade Fog Volume Components", priority = CoreUtils.editMenuPriority2)] - static void UpgradeFogVolumeComponents(MenuCommand menuCommand) + [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Upgrade from Previous Version /Upgrade HDRP Materials to Latest Version")] + internal static void UpgradeMaterials() { - void OverrideCommonParameters(AtmosphericScattering input, Fog output) - { - if (input.colorMode.overrideState) - output.colorMode.Override(input.colorMode.value); - if (input.color.overrideState) - output.color.Override(input.color.value); - if (input.maxFogDistance.overrideState) - output.maxFogDistance.Override(input.maxFogDistance.value); - if (input.mipFogMaxMip.overrideState) - output.mipFogMaxMip.Override(input.mipFogMaxMip.value); - if (input.mipFogNear.overrideState) - output.mipFogNear.Override(input.mipFogNear.value); - if (input.mipFogFar.overrideState) - output.mipFogFar.Override(input.mipFogFar.value); - if (input.tint.overrideState) - output.tint.Override(input.tint.value); - } - - Fog CreateFogComponentIfNeeded(VolumeProfile profile) - { - Fog fogComponent = null; - if (!profile.TryGet(out fogComponent)) - { - fogComponent = VolumeProfileFactory.CreateVolumeComponent(profile, false, false); - } - - return fogComponent; - } - - if (!EditorUtility.DisplayDialog(DialogText.title, "This will upgrade all Volume Profiles containing Exponential or Volumetric Fog components to the new Fog component. " + DialogText.projectBackMessage, DialogText.proceed, DialogText.cancel)) - return; - - var profilePathList = AssetDatabase.FindAssets("t:VolumeProfile", new string[]{ "Assets" }); - - int profileCount = profilePathList.Length; - int profileIndex = 0; - foreach (string guid in profilePathList) - { - var assetPath = AssetDatabase.GUIDToAssetPath(guid); - profileIndex++; - if (EditorUtility.DisplayCancelableProgressBar("Upgrade Fog Volume Components", string.Format("({0} of {1}) {2}", profileIndex, profileCount, assetPath), (float)profileIndex / (float)profileCount)) - break; - - VolumeProfile profile = AssetDatabase.LoadAssetAtPath(assetPath, typeof(VolumeProfile)) as VolumeProfile; - - if (profile.TryGet(out var visualEnv)) - { - if (visualEnv.fogType.value == FogType.Exponential || visualEnv.fogType.value == FogType.Volumetric) - { - var fog = CreateFogComponentIfNeeded(profile); - fog.enabled.Override(true); - } - } - - - if (profile.TryGet(out var expFog)) - { - var fog = CreateFogComponentIfNeeded(profile); - - // We only migrate distance because the height parameters are not compatible. - if (expFog.fogDistance.overrideState) - fog.meanFreePath.Override(expFog.fogDistance.value); - - OverrideCommonParameters(expFog, fog); - EditorUtility.SetDirty(profile); - } - - if (profile.TryGet(out var volFog)) - { - var fog = CreateFogComponentIfNeeded(profile); - - fog.enableVolumetricFog.Override(true); - if (volFog.meanFreePath.overrideState) - fog.meanFreePath.Override(volFog.meanFreePath.value); - if (volFog.albedo.overrideState) - fog.albedo.Override(volFog.albedo.value); - if (volFog.baseHeight.overrideState) - fog.baseHeight.Override(volFog.baseHeight.value); - if (volFog.maximumHeight.overrideState) - fog.maximumHeight.Override(volFog.maximumHeight.value); - if (volFog.anisotropy.overrideState) - fog.anisotropy.Override(volFog.anisotropy.value); - if (volFog.globalLightProbeDimmer.overrideState) - fog.globalLightProbeDimmer.Override(volFog.globalLightProbeDimmer.value); - - OverrideCommonParameters(volFog, fog); - EditorUtility.SetDirty(profile); - } - - if (profile.TryGet(out var volController)) - { - var fog = CreateFogComponentIfNeeded(profile); - if (volController.depthExtent.overrideState) - fog.depthExtent.Override(volController.depthExtent.value); - if (volController.sliceDistributionUniformity.overrideState) - fog.sliceDistributionUniformity.Override(volController.sliceDistributionUniformity.value); - - EditorUtility.SetDirty(profile); - } - } - - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - EditorUtility.ClearProgressBar(); - } - - [MenuItem("Edit/Render Pipeline/Upgrade Sky Intensity Mode", priority = CoreUtils.editMenuPriority2)] - static void UpgradeSkyIntensityMode(MenuCommand menuCommand) - { - if (!EditorUtility.DisplayDialog(DialogText.title, "This will upgrade all Volume Profiles containing Sky components with the new intensity mode paradigm. " + DialogText.projectBackMessage, DialogText.proceed, DialogText.cancel)) - return; - - var profilePathList = AssetDatabase.FindAssets("t:VolumeProfile", new string[] { "Assets" }); - - int profileCount = profilePathList.Length; - int profileIndex = 0; - foreach (string guid in profilePathList) - { - var assetPath = AssetDatabase.GUIDToAssetPath(guid); - profileIndex++; - if (EditorUtility.DisplayCancelableProgressBar("Upgrade Sky Components", string.Format("({0} of {1}) {2}", profileIndex, profileCount, assetPath), (float)profileIndex / (float)profileCount)) - break; - - VolumeProfile profile = AssetDatabase.LoadAssetAtPath(assetPath, typeof(VolumeProfile)) as VolumeProfile; - - List m_VolumeSkyList = new List(); - if (profile.TryGetAllSubclassOf(typeof(SkySettings), m_VolumeSkyList)) - { - foreach (var sky in m_VolumeSkyList) - { - // Trivial case where multiplier is not used we ignore, otherwise we end up with a multiplier of 0.833 for a 0.0 EV100 exposure - if (sky.multiplier.value == 1.0f) - continue; - else if (sky.skyIntensityMode.value == SkyIntensityMode.Exposure) // Not Lux - { - // Any component using Exposure and Multiplier at the same time must switch to multiplier as we will convert exposure*multiplier into a multiplier. - sky.skyIntensityMode.Override(SkyIntensityMode.Multiplier); - } - - // Convert exposure * multiplier to multiplier and reset exposure for all non trivial cases. - sky.multiplier.Override(sky.multiplier.value * ColorUtils.ConvertEV100ToExposure(-sky.exposure.value)); - sky.exposure.Override(0.0f); - - EditorUtility.SetDirty(profile); - } - } - } - - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - EditorUtility.ClearProgressBar(); + // Force reimport of all materials, this will upgrade the needed one and save the assets if needed + MaterialReimporter.ReimportAllMaterials(); } class DoCreateNewAsset : ProjectWindowCallback.EndNameEditAction where TAssetType : ScriptableObject @@ -364,11 +216,12 @@ static void SynchronizeAllLayeredMaterial() } } + // We now do this automatically when upgrading Material version, so not required anymore - keep it in case you want to manually do it // The goal of this script is to help maintenance of data that have already been produced but need to update to the latest shader code change. // In case the shader code have change and the inspector have been update with new kind of keywords we need to regenerate the set of keywords use by the material. // This script will remove all keyword of a material and trigger the inspector that will re-setup all the used keywords. // It require that the inspector of the material have a static function call that update all keyword based on material properties. - [MenuItem("Edit/Render Pipeline/Reset All Loaded High Definition Materials Keywords", priority = CoreUtils.editMenuPriority3)] + // [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Reset All Loaded High Definition Materials Keywords")] static void ResetAllMaterialKeywords() { try @@ -382,7 +235,7 @@ static void ResetAllMaterialKeywords() } // Don't expose, ResetAllMaterialKeywordsInProjectAndScenes include it anyway - //[MenuItem("Edit/Render Pipeline/Reset All Material Asset's Keywords (Materials in Project)", priority = CoreUtils.editMenuPriority3)] + //[MenuItem("Edit/Render Pipeline/HD Render Pipeline/Reset All Material Asset's Keywords (Materials in Project)")] static void ResetAllMaterialAssetsKeywords() { try @@ -395,7 +248,8 @@ static void ResetAllMaterialAssetsKeywords() } } - [MenuItem("Edit/Render Pipeline/Reset All Project and Scene High Definition Materials Keywords", priority = CoreUtils.editMenuPriority3)] + // We now do this automatically when upgrading Material version, so not required anymore - keep it in case you want to manually do it + // [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Reset All Project and Scene High Definition Materials Keywords")] static void ResetAllMaterialKeywordsInProjectAndScenes() { var openedScenes = new string[EditorSceneManager.loadedSceneCount]; @@ -520,7 +374,7 @@ public void LogException(Exception exception, UnityObject context) } } - [MenuItem("Edit/Render Pipeline/Check Scene Content for Ray Tracing", priority = CoreUtils.editMenuPriority4)] + [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Check Scene Content for Ray Tracing")] static void CheckSceneContentForRayTracing(MenuCommand menuCommand) { // Flag that holds @@ -610,5 +464,50 @@ static void CheckSceneContentForRayTracing(MenuCommand menuCommand) Debug.Log("No errors were detected in the process."); } } + + [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Upgrade from Previous Version/Fix Warning 'referenced script in (Game Object 'SceneIDMap') is missing' in loaded scenes")] + static public void FixWarningGameObjectSceneIDMapIsMissingInLoadedScenes() + { + var rootCache = new List(); + for (var i = 0; i < SceneManager.sceneCount; ++i) + FixWarningGameObjectSceneIDMapIsMissingFor(SceneManager.GetSceneAt(i), rootCache); + } + + static void FixWarningGameObjectSceneIDMapIsMissingFor(Scene scene, List rootCache) + { + Assert.IsTrue(scene.isLoaded); + + var roots = rootCache ?? new List(); + roots.Clear(); + scene.GetRootGameObjects(roots); + bool markSceneAsDirty = false; + for (var i = roots.Count - 1; i >= 0; --i) + { + if (roots[i].name == "SceneIDMap") + { + if (roots[i].GetComponent() == null) + { + // This gameObject must have SceneObjectIDMapSceneAsset + // If not, then Unity can't find the component. + // We can remove it, it will be regenerated properly by rebaking + // the probes. + // + // This happens for scene with baked probes authored before renaming + // the HDRP's namespaces without the 'Experiemental' prefix. + // The serialization used this path explicitly, thus the Unity serialization + // system lost the reference to the MonoBehaviour + UnityEngine.Object.DestroyImmediate(roots[i]); + + // If we do any any modification on the scene + // we need to dirty it, otherwise, the editor won't commit the change to the disk + // and the issue will still persist. + if (!markSceneAsDirty) + markSceneAsDirty = true; + } + } + } + if (markSceneAsDirty) + SceneManagement.EditorSceneManager.MarkSceneDirty(scene); + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Sky/HDLightingWindowEnvironmentSection.cs b/com.unity.render-pipelines.high-definition/Editor/Sky/HDLightingWindowEnvironmentSection.cs index 009c168b822..5bfb71d8ac4 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Sky/HDLightingWindowEnvironmentSection.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Sky/HDLightingWindowEnvironmentSection.cs @@ -32,13 +32,16 @@ class SerializedStaticLightingSky { SerializedObject serializedObject; public SerializedProperty skyUniqueID; - public SerializedProperty profile; + public VolumeProfile volumeProfile + { + get => (serializedObject.targetObject as StaticLightingSky).profile; + set => (serializedObject.targetObject as StaticLightingSky).profile = value; + } public SerializedStaticLightingSky(StaticLightingSky staticLightingSky) { serializedObject = new SerializedObject(staticLightingSky); skyUniqueID = serializedObject.FindProperty("m_StaticLightingSkyUniqueID"); - profile = serializedObject.FindProperty("m_Profile"); } public void Apply() => serializedObject.ApplyModifiedProperties(); @@ -170,10 +173,12 @@ void DrawGUI() ++EditorGUI.indentLevel; //cannot use SerializeProperty due to logic in the property - var profile = m_SerializedActiveSceneLightingSky.profile.objectReferenceValue; - var newProfile = EditorGUILayout.ObjectField(EditorGUIUtility.TrTextContent("Profile"), m_SerializedActiveSceneLightingSky.profile.objectReferenceValue, typeof(VolumeProfile), allowSceneObjects: false) as VolumeProfile; + var profile = m_SerializedActiveSceneLightingSky.volumeProfile; + var newProfile = EditorGUILayout.ObjectField(EditorGUIUtility.TrTextContent("Profile"), profile, typeof(VolumeProfile), allowSceneObjects: false) as VolumeProfile; if (profile != newProfile) - m_SerializedActiveSceneLightingSky.profile.objectReferenceValue = newProfile; + { + m_SerializedActiveSceneLightingSky.volumeProfile = newProfile; + } using (new EditorGUI.DisabledScope(m_SkyClassNames.Count == 1)) // Only "None" { @@ -200,7 +205,7 @@ void UpdateSkyIntPopupData() m_SkyClassNames.Add(new GUIContent("None")); m_SkyUniqueIDs.Add(0); - VolumeProfile profile = m_SerializedActiveSceneLightingSky.profile.objectReferenceValue as VolumeProfile; + VolumeProfile profile = m_SerializedActiveSceneLightingSky.volumeProfile; if (profile != null) { var skyTypesDict = SkyManager.skyTypesDict; diff --git a/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeMenuItem.cs b/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeMenuItem.cs deleted file mode 100644 index b3c47bae415..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeMenuItem.cs +++ /dev/null @@ -1,247 +0,0 @@ -using System.IO; -using UnityEngine; -using UnityEngine.Rendering.HighDefinition; -using System.Collections.Generic; -using UnityEditor.Rendering; -using UnityEngine.Rendering; -using UnityEditor.ShaderGraph; - -// Include material common properties names -using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; -using UnityEngine.SceneManagement; -using UnityEngine.Assertions; - -namespace UnityEditor.Rendering.HighDefinition -{ - class UpgradeMenuItems - { - // Version 3 - - // Added RenderStates for shader graphs, we need to ovewrite the material prperties used for the rendering - // in these materials and synch them with the master node values (which are the shader default values, that's - // why we create a new material in this script). - - // List of the render state properties to sync - static readonly string[] floatPropertiesToReset = { - kStencilRef, kStencilWriteMask, - kStencilRefDepth, kStencilWriteMaskDepth, - kStencilRefMV, kStencilWriteMaskMV, - kStencilRefDistortionVec, kStencilWriteMaskDistortionVec, - kStencilRefGBuffer, kStencilWriteMaskGBuffer, kZTestGBuffer, - kSurfaceType, kBlendMode, "_SrcBlend", "_DstBlend", "_AlphaSrcBlend", "_AlphaDstBlend", - kZWrite, "_CullMode", "_CullModeForward", kTransparentCullMode, - kZTestDepthEqualForOpaque, - kAlphaCutoffEnabled, - kTransparentSortPriority, "_UseShadowThreshold", - kDoubleSidedEnable, kDoubleSidedNormalMode, - kTransparentBackfaceEnable, kReceivesSSR, kUseSplitLighting - }; - - static readonly string[] vectorPropertiesToReset = { - "_DoubleSidedConstants", - }; - - // This upgrade functioncopy all the keywords needed for the BlendStates - // to be synced with their master node values, then it calls the HDRP material keyword reset function and finally - // it set the render queue of the material to match the one on the shader graph. - // It's required to sync the shader default properties with the material because when you create a new material, - // by default the Lit shader is assigned to it and so write all his properties into the material. It's a problem - // because now that the shader graphs uses these properties, the material properties don't match the shader settings. - // This function basically fix this. - static bool UpdateMaterial_ShaderGraphRenderStates(string path, Material mat) - { - // We only need to upgrade shadergraphs materials - if (GraphUtil.IsShaderGraph(mat.shader)) - { - var defaultProperties = new Material(mat.shader); - - foreach (var floatToReset in floatPropertiesToReset) - if (mat.HasProperty(floatToReset)) - mat.SetFloat(floatToReset, defaultProperties.GetFloat(floatToReset)); - foreach (var vectorToReset in vectorPropertiesToReset) - if (mat.HasProperty(vectorToReset)) - mat.SetVector(vectorToReset, defaultProperties.GetVector(vectorToReset)); - - HDShaderUtils.ResetMaterialKeywords(mat); - - mat.renderQueue = mat.shader.renderQueue; - - defaultProperties = null; - - return true; - } - - return false; - } - - delegate bool UpdateMaterial(string path, Material mat); - delegate void UpdateMaterialFile(string path); - - static void ProcessUpdateMaterial(string caption, float scriptVersion, UpdateMaterial updateMaterial, UpdateMaterialFile updateMaterialFile = null) - { - bool VCSEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive); - var matIds = AssetDatabase.FindAssets("t:Material"); - List materialFiles = new List(); // Contain the list dirty files - - try - { - for (int i = 0, length = matIds.Length; i < length; i++) - { - var path = AssetDatabase.GUIDToAssetPath(matIds[i]); - var mat = AssetDatabase.LoadAssetAtPath(path); - - EditorUtility.DisplayProgressBar( - "Update material " + caption + "...", - string.Format("{0} / {1} materials updated.", i, length), - i / (float)(length - 1)); - - if (HDShaderUtils.IsHDRPShader(mat.shader)) - { - // We don't handle embed material as we can't rewrite fbx files - if (Path.GetExtension(path).ToLower() == ".fbx") - { - continue; - } - - bool dirty = updateMaterial(path, mat); - - // Checkout the file and tag it as dirty - if (dirty) - { - CoreEditorUtils.CheckOutFile(VCSEnabled, mat); - EditorUtility.SetDirty(mat); - materialFiles.Add(path); - } - } - } - } - finally - { - EditorUtility.ClearProgressBar(); - // Save all dirty assets - AssetDatabase.SaveAssets(); - } - - if (updateMaterialFile == null) - return; - - // Now that all the asset have been modified and save, we can safely update the .mat file and remove removed property - try - { - for (int i = 0, length = materialFiles.Count; i < length; i++) - { - string path = materialFiles[i]; - - EditorUtility.DisplayProgressBar( - "Update .mat files...", - string.Format("{0} / {1} materials .mat file updated.", i, length), - i / (float)(length - 1)); - - // Note: The file is supposed to be checkout by the previous loop - updateMaterialFile(path); - } - } - finally - { - EditorUtility.ClearProgressBar(); - // No need to save in this case - } - } - - // This function go through all loaded materials so it can be used to update any materials that is - // not serialized as an asset (i.e materials saved in scenes) - static void UpgradeSceneMaterials() - { -#pragma warning disable 618 - var hdAsset = HDRenderPipeline.currentAsset; - // For each loaded materials - foreach (var mat in Resources.FindObjectsOfTypeAll()) - { - DiffusionProfileSettings.UpgradeMaterial(mat, hdAsset.diffusionProfileSettings); - } -#pragma warning restore 618 - } - - [MenuItem("Edit/Render Pipeline/Upgrade all Materials to newer version", priority = CoreUtils.editMenuPriority3)] - static public void UpdateMaterialToNewerVersion() - { - // TODO: We need to handle material that are embed inside scene! + How to handle embed material in fbx? - - // Add here all the material upgrade functions - // Note: This is a slow path as we go through all files for each script + update the version number after each script execution, - // but it is the safest way to do it currently for incremental upgrade - // Caution: When calling SaveAsset, Unity will update the material with latest addition at the same time, so for example - // unity can add a supportDecal when executing script for version 1 whereas they only appear in version 2 because it is now part - // of the shader. Most of the time this have no consequence, but we never know. - - // Caution: Version of latest script and default version in all HDRP shader must match - - UpgradeSceneMaterials(); - } - - [MenuItem("Edit/Render Pipeline/Reset All ShaderGraph Materials BlendStates (Project)")] - static public void UpgradeAllShaderGraphMaterialBlendStatesProject() - { - ProcessUpdateMaterial("(ShaderGraphRenderStates_3)", 3.0f, UpdateMaterial_ShaderGraphRenderStates); - } - - [MenuItem("Edit/Render Pipeline/Reset All ShaderGraph Materials BlendStates (Scene)")] - static public void UpgradeAllShaderGraphMaterialBlendStatesScene() - { - var materials = Resources.FindObjectsOfTypeAll(); - - foreach (var mat in materials) - { - string path = AssetDatabase.GetAssetPath(mat); - - if (!string.IsNullOrEmpty(path)) - UpdateMaterial_ShaderGraphRenderStates(path, mat); - } - } - - [MenuItem("Edit/Render Pipeline/Fix Warning 'referenced script in (Game Object 'SceneIDMap') is missing' in loaded scenes")] - static public void FixWarningGameObjectSceneIDMapIsMissingInLoadedScenes() - { - var rootCache = new List(); - for (var i = 0; i < SceneManager.sceneCount; ++i) - FixWarningGameObjectSceneIDMapIsMissingFor(SceneManager.GetSceneAt(i), rootCache); - } - - static void FixWarningGameObjectSceneIDMapIsMissingFor(Scene scene, List rootCache) - { - Assert.IsTrue(scene.isLoaded); - - var roots = rootCache ?? new List(); - roots.Clear(); - scene.GetRootGameObjects(roots); - bool markSceneAsDirty = false; - for (var i = roots.Count - 1; i >= 0; --i) - { - if (roots[i].name == "SceneIDMap") - { - if (roots[i].GetComponent() == null) - { - // This gameObject must have SceneObjectIDMapSceneAsset - // If not, then Unity can't find the component. - // We can remove it, it will be regenerated properly by rebaking - // the probes. - // - // This happens for scene with baked probes authored before renaming - // the HDRP's namespaces without the 'Experiemental' prefix. - // The serialization used this path explicitly, thus the Unity serialization - // system lost the reference to the MonoBehaviour - Object.DestroyImmediate(roots[i]); - - // If we do any any modification on the scene - // we need to dirty it, otherwise, the editor won't commit the change to the disk - // and the issue will still persist. - if (!markSceneAsDirty) - markSceneAsDirty = true; - } - } - } - if(markSceneAsDirty) - SceneManagement.EditorSceneManager.MarkSceneDirty(scene); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeMenuItem.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeMenuItem.cs.meta deleted file mode 100644 index cab43d30f34..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeMenuItem.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9ba0cef4d0966574ab013f1cb2972ba3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeStandardShaderMaterials.cs b/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeStandardShaderMaterials.cs index e474ad3aa5c..a0d1dd2c185 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeStandardShaderMaterials.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Upgraders/UpgradeStandardShaderMaterials.cs @@ -24,26 +24,26 @@ static List GetHDUpgraders() return upgraders; } - [MenuItem("Edit/Render Pipeline/Upgrade Project Materials to High Definition Materials", priority = CoreUtils.editMenuPriority2)] + [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Upgrade from Builtin pipeline/Upgrade Project Materials to High Definition Materials")] internal static void UpgradeMaterialsProject() { MaterialUpgrader.UpgradeProjectFolder(GetHDUpgraders(), "Upgrade to HD Material"); } - [MenuItem("Edit/Render Pipeline/Upgrade Selected Materials to High Definition Materials", priority = CoreUtils.editMenuPriority2)] + [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Upgrade from Builtin pipeline/Upgrade Selected Materials to High Definition Materials")] internal static void UpgradeMaterialsSelection() { MaterialUpgrader.UpgradeSelection(GetHDUpgraders(), "Upgrade to HD Material"); } - [MenuItem("Edit/Render Pipeline/Upgrade Scene Terrains to High Definition Terrains", priority = CoreUtils.editMenuPriority2)] + [MenuItem("Edit/Render Pipeline/HD Render Pipeline/Upgrade from Builtin pipeline/Upgrade Scene Terrains to High Definition Terrains")] static void UpgradeSceneTerrainsToHighDefinitionTerrains(MenuCommand menuCommand) { var LegacyDefaultTerrainMat = AssetDatabase.GetBuiltinExtraResource("Default-Terrain-Standard.mat"); var HDRPTerrainMat = AssetDatabase.LoadAssetAtPath("Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultHDTerrainMaterial.mat"); var terrainArray = UnityEngine.GameObject.FindObjectsOfType(); - if(terrainArray.Length == 0) + if (terrainArray.Length == 0) { Debug.LogWarning("No terrains were found in the scene."); return; @@ -57,24 +57,5 @@ static void UpgradeSceneTerrainsToHighDefinitionTerrains(MenuCommand menuCommand } } } - - - [MenuItem("Edit/Render Pipeline/Multiply Unity Builtin Directional Light Intensity to match High Definition", priority = CoreUtils.editMenuPriority2)] - internal static void UpgradeLights() - { - Light[] lights = Light.GetLights(LightType.Directional, 0); - foreach (var l in lights) - { - Undo.RecordObject(l, "Light intensity x PI"); - l.intensity *= Mathf.PI; - } - } - - [MenuItem("Edit/Render Pipeline/Upgrade HDRP Materials to Latest Version", priority = CoreUtils.editMenuPriority2)] - internal static void UpgradeMaterials() - { - // Force reimport of all materials, this will upgrade the needed one and save the assets if needed - MaterialReimporter.ReimportAllMaterials(); - } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.Window.cs b/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.Window.cs index 11816e93f55..f9c1ff1fed5 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.Window.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.Window.cs @@ -41,7 +41,6 @@ static class Style public const string migrateAllButton = "Upgrade Project Materials to High Definition Materials"; public const string migrateSelectedButton = "Upgrade Selected Materials to High Definition Materials"; - public const string migrateLights = "Multiply Unity Builtin Directional Light Intensity to match High Definition"; public const string migrateMaterials = "Upgrade HDRP Materials to Latest Version"; public const string hdrpVersionLast = "You are using High-Definition Render Pipeline lastest {0} version."; //{0} will be replaced when displayed by the version number. @@ -337,8 +336,7 @@ private void OnEnable() container.Add(CreateTitle(Style.migrationTitle)); container.Add(CreateLargeButton(Style.migrateAllButton, UpgradeStandardShaderMaterials.UpgradeMaterialsProject)); container.Add(CreateLargeButton(Style.migrateSelectedButton, UpgradeStandardShaderMaterials.UpgradeMaterialsSelection)); - container.Add(CreateLargeButton(Style.migrateLights, UpgradeStandardShaderMaterials.UpgradeLights)); - container.Add(CreateLargeButton(Style.migrateMaterials, UpgradeStandardShaderMaterials.UpgradeMaterials)); + container.Add(CreateLargeButton(Style.migrateMaterials, HDRenderPipelineMenuItems.UpgradeMaterials)); container.Add(CreateWizardBehaviour()); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 769dab7c893..fe64cf971a4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -835,6 +835,7 @@ void SetRenderingFeatures() , overridesMaximumLODLevel = true , terrainDetailUnsupported = true , overridesShadowmask = true // Don't display the shadow mask UI in Quality Settings + , overrideShadowmaskMessage = "\nThe Shadowmask Mode used at run time can be found in the Shadows section of Light component." , overridesRealtimeReflectionProbes = true // Don't display the real time reflection probes checkbox UI in Quality Settings }; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset index 1ec9e7858a3..a00e82a23ce 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset @@ -206,6 +206,10 @@ MonoBehaviour: SMAAPS: {fileID: 4800000, guid: 9655f4aa89a469c49aceaceabf9bc77b, type: 3} temporalAntialiasingPS: {fileID: 4800000, guid: 3dd9fd928fdb83743b1f27d15df22179, type: 3} + dofCircleOfConfusion: {fileID: 7200000, guid: 75332b7b315c80d4babe506820aa0bfd, + type: 3} + dofGatherCS: {fileID: 7200000, guid: 1e6b16a7970a1494db74b1d3d007d1cc, type: 3} + DoFCoCPyramidCS: {fileID: 7200000, guid: df41a69211c03fe479b63a8bed3bfbb4, type: 3} contrastAdaptiveSharpenCS: {fileID: 7200000, guid: 560896aec2f412c48995be35551a4ac6, type: 3} accumulationCS: {fileID: 7200000, guid: ed80add7a217efa468d137d6f7c668f3, type: 3} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index 06d54830607..a68ed110d27 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -828,13 +828,10 @@ public void UpdateEnvironment(HDCamera hdCamera, ScriptableRenderContext renderC #endif if ((ambientMode == SkyAmbientMode.Static || forceStaticUpdate) && hdCamera.camera.cameraType != CameraType.Preview) { - if (staticLightingSky != null) - { - m_StaticLightingSky.skySettings = staticLightingSky.skySettings; - m_StaticLightingSky.cloudLayer = staticLightingSky.cloudLayer; - UpdateEnvironment(hdCamera, renderContext, m_StaticLightingSky, sunLight, m_StaticSkyUpdateRequired, true, true, SkyAmbientMode.Static, frameIndex, cmd); - m_StaticSkyUpdateRequired = false; - } + m_StaticLightingSky.skySettings = staticLightingSky != null ? staticLightingSky.skySettings : null; + m_StaticLightingSky.cloudLayer = staticLightingSky != null ? staticLightingSky.cloudLayer : null; + UpdateEnvironment(hdCamera, renderContext, m_StaticLightingSky, sunLight, m_StaticSkyUpdateRequired, true, true, SkyAmbientMode.Static, frameIndex, cmd); + m_StaticSkyUpdateRequired = false; } m_UpdateRequired = false;