diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index a42cfa4a88f..72f0dcfb7c8 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -69,6 +69,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added two toggles to control occluder rejection and receiver rejection for the ray traced ambient occlusion (case 1330168). - Added the receiver motion rejection toggle to RTGI (case 1330168). - Added info box when low resolution transparency is selected, but its not enabled in the HDRP settings. This will help new users find the correct knob in the HDRP Asset. +- Added a dialog box when you import a Material that has a diffusion profile to add the diffusion profile to global settings. ### Fixed - Fixed Intensity Multiplier not affecting realtime global illumination. diff --git a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs index 0742a0f906a..fee89dd184f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs @@ -362,6 +362,68 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse if (!HDShaderUtils.IsHDRPShader(material.shader, upgradable: true)) continue; + + void AddDiffusionProfileToSettings(string propName) + { + if (Application.isBatchMode || HDRenderPipelineGlobalSettings.instance == null + || HDRenderPipelineGlobalSettings.instance.diffusionProfileSettingsList == null) return; + + bool diffusionProfileCanBeAdded = HDRenderPipelineGlobalSettings.instance.diffusionProfileSettingsList.Length < 15; + DiffusionProfileSettings diffusionProfile = null; + + if (material.HasProperty(propName)) + { + var diffusionProfileAsset = material.GetVector(propName); + string guid = HDUtils.ConvertVector4ToGUID(diffusionProfileAsset); + diffusionProfile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid)); + + if (diffusionProfile != null && !HDRenderPipelineGlobalSettings.instance.diffusionProfileSettingsList.Any(d => d == diffusionProfile)) + { + string materialName = material.name; + string diffusionProfileName = diffusionProfile.name; + + if (!diffusionProfileCanBeAdded) + Debug.LogWarning("There is no space in the global settings to add the diffusion profile " + diffusionProfileName); + else if ((!Application.isBatchMode) && + (EditorUtility.DisplayDialog("Diffusion Profile Import", + "A Material (" + materialName + ") is being imported with a diffusion profile (" + diffusionProfileName + ") not already added to the HDRP Global Settings.\n If the Diffusion Profile is not referenced in the global settings, HDRP cannot use it.\nDo you want to add the diffusion profile to the HDRP Global Settings asset?", "Yes", "No"))) + { + diffusionProfileCanBeAdded = HDRenderPipelineGlobalSettings.instance.AddDiffusionProfile(diffusionProfile); + } + } + } + } + + AddDiffusionProfileToSettings("_DiffusionProfileAsset"); + + // Special Eye case that uses a node with diffusion profiles. + if (material.shader.IsShaderGraphAsset()) + { + var matProperties = MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { material }); + for (int propIdx = 0; propIdx < matProperties.Length; ++propIdx) + { + var attributes = material.shader.GetPropertyAttributes(propIdx); + bool hasDiffusionProfileAttribute = false; + foreach (var attribute in attributes) + { + if (attribute == "DiffusionProfile") + { + propIdx++; + hasDiffusionProfileAttribute = true; + break; + } + } + + var propName = ShaderUtil.GetPropertyName(material.shader, propIdx); + var type = ShaderUtil.GetPropertyType(material.shader, propIdx); + if (hasDiffusionProfileAttribute && + type == ShaderUtil.ShaderPropertyType.Vector) + { + AddDiffusionProfileToSettings(propName); + } + } + } + (HDShaderUtils.ShaderID id, GUID subTargetGUID) = HDShaderUtils.GetShaderIDsFromShader(material.shader); var latestVersion = k_Migrations.Length;