diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 9b5cbc029a5..8372b190e2d 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -717,6 +717,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed issue with completely black AO on double sided materials when normal mode is set to None. - Fixed UI drawing of the quaternion (1251235) - Fix an issue with the quality mode and perf mode on RTR and RTGI and getting rid of unwanted nans (1256923). +- Fixed unitialized ray tracing resources when using non-default HDRP asset (case 1259467). ### Changed - Improve MIP selection for decals on Transparents 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 ea364157343..750e0cb0ffd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -572,57 +572,64 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau } #if UNITY_EDITOR - void UpgradeResourcesIfNeeded() + void UpgradeResourcesInAssetIfNeeded(HDRenderPipelineAsset asset) { - // The first thing we need to do is to set the defines that depend on the render pipeline settings - m_Asset.EvaluateSettings(); - // Check that the serialized Resources are not broken - if (HDRenderPipeline.defaultAsset.renderPipelineResources == null) - HDRenderPipeline.defaultAsset.renderPipelineResources + if (asset.renderPipelineResources == null) + asset.renderPipelineResources = UnityEditor.AssetDatabase.LoadAssetAtPath(HDUtils.GetHDRenderPipelinePath() + "Runtime/RenderPipelineResources/HDRenderPipelineResources.asset"); #if UNITY_EDITOR_LINUX // Temp hack to be able to make linux test run. To clarify - ResourceReloader.TryReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineResources, HDUtils.GetHDRenderPipelinePath()); + ResourceReloader.TryReloadAllNullIn(asset.renderPipelineResources, HDUtils.GetHDRenderPipelinePath()); #else - ResourceReloader.ReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineResources, HDUtils.GetHDRenderPipelinePath()); + ResourceReloader.ReloadAllNullIn(asset.renderPipelineResources, HDUtils.GetHDRenderPipelinePath()); #endif if (m_RayTracingSupported) { - if (HDRenderPipeline.defaultAsset.renderPipelineRayTracingResources == null) - HDRenderPipeline.defaultAsset.renderPipelineRayTracingResources + if (asset.renderPipelineRayTracingResources == null) + asset.renderPipelineRayTracingResources = UnityEditor.AssetDatabase.LoadAssetAtPath(HDUtils.GetHDRenderPipelinePath() + "Runtime/RenderPipelineResources/HDRenderPipelineRayTracingResources.asset"); #if UNITY_EDITOR_LINUX // Temp hack to be able to make linux test run. To clarify - ResourceReloader.TryReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineRayTracingResources, HDUtils.GetHDRenderPipelinePath()); + ResourceReloader.TryReloadAllNullIn(asset.renderPipelineRayTracingResources, HDUtils.GetHDRenderPipelinePath()); #else - ResourceReloader.ReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineRayTracingResources, HDUtils.GetHDRenderPipelinePath()); + ResourceReloader.ReloadAllNullIn(asset.renderPipelineRayTracingResources, HDUtils.GetHDRenderPipelinePath()); #endif } else { // If ray tracing is not enabled we do not want to have ray tracing resources referenced - HDRenderPipeline.defaultAsset.renderPipelineRayTracingResources = null; + asset.renderPipelineRayTracingResources = null; } var editorResourcesPath = HDUtils.GetHDRenderPipelinePath() + "Editor/RenderPipelineResources/HDRenderPipelineEditorResources.asset"; - if (HDRenderPipeline.defaultAsset.renderPipelineEditorResources == null) + if (asset.renderPipelineEditorResources == null) { var objs = InternalEditorUtility.LoadSerializedFileAndForget(editorResourcesPath); - HDRenderPipeline.defaultAsset.renderPipelineEditorResources = objs != null && objs.Length > 0 ? objs.First() as HDRenderPipelineEditorResources : null; + asset.renderPipelineEditorResources = objs != null && objs.Length > 0 ? objs.First() as HDRenderPipelineEditorResources : null; } - if (ResourceReloader.ReloadAllNullIn(HDRenderPipeline.defaultAsset.renderPipelineEditorResources, + if (ResourceReloader.ReloadAllNullIn(asset.renderPipelineEditorResources, HDUtils.GetHDRenderPipelinePath())) { InternalEditorUtility.SaveToSerializedFileAndForget( - new Object[]{HDRenderPipeline.defaultAsset.renderPipelineEditorResources }, + new Object[]{asset.renderPipelineEditorResources }, editorResourcesPath, true); } // Upgrade the resources (re-import every references in RenderPipelineResources) if the resource version mismatches // It's done here because we know every HDRP assets have been imported before - HDRenderPipeline.defaultAsset.renderPipelineResources?.UpgradeIfNeeded(); + asset.renderPipelineResources?.UpgradeIfNeeded(); + } + + void UpgradeResourcesIfNeeded() + { + // The first thing we need to do is to set the defines that depend on the render pipeline settings + m_Asset.EvaluateSettings(); + + // Check and fix both the default and current HDRP asset + UpgradeResourcesInAssetIfNeeded(HDRenderPipeline.defaultAsset); + UpgradeResourcesInAssetIfNeeded(HDRenderPipeline.currentAsset); } void ValidateResources()