diff --git a/TestProjects/HDRP_DXR_Tests/ProjectSettings/HDRPProjectSettings.asset b/TestProjects/HDRP_DXR_Tests/ProjectSettings/HDRPProjectSettings.asset index e73d726d944..ac213ba68ad 100644 --- a/TestProjects/HDRP_DXR_Tests/ProjectSettings/HDRPProjectSettings.asset +++ b/TestProjects/HDRP_DXR_Tests/ProjectSettings/HDRPProjectSettings.asset @@ -19,4 +19,4 @@ MonoBehaviour: m_WizardActiveTab: 0 m_WizardNeedRestartAfterChangingToDX12: 0 m_WizardNeedToRunFixAllAgainAfterDomainReload: 0 - m_LastMaterialVersion: 9 + m_LastMaterialVersion: 10 diff --git a/TestProjects/HDRP_HybridTests/ProjectSettings/HDRPProjectSettings.asset b/TestProjects/HDRP_HybridTests/ProjectSettings/HDRPProjectSettings.asset index 5d3fef2b636..652258d83b0 100644 --- a/TestProjects/HDRP_HybridTests/ProjectSettings/HDRPProjectSettings.asset +++ b/TestProjects/HDRP_HybridTests/ProjectSettings/HDRPProjectSettings.asset @@ -22,4 +22,4 @@ MonoBehaviour: m_WizardActiveTab: 0 m_WizardNeedRestartAfterChangingToDX12: 0 m_WizardNeedToRunFixAllAgainAfterDomainReload: 0 - m_LastMaterialVersion: 9 + m_LastMaterialVersion: 10 diff --git a/TestProjects/HDRP_PerformanceTests/ProjectSettings/HDRPProjectSettings.asset b/TestProjects/HDRP_PerformanceTests/ProjectSettings/HDRPProjectSettings.asset index e73d726d944..ac213ba68ad 100644 --- a/TestProjects/HDRP_PerformanceTests/ProjectSettings/HDRPProjectSettings.asset +++ b/TestProjects/HDRP_PerformanceTests/ProjectSettings/HDRPProjectSettings.asset @@ -19,4 +19,4 @@ MonoBehaviour: m_WizardActiveTab: 0 m_WizardNeedRestartAfterChangingToDX12: 0 m_WizardNeedToRunFixAllAgainAfterDomainReload: 0 - m_LastMaterialVersion: 9 + m_LastMaterialVersion: 10 diff --git a/TestProjects/HDRP_RuntimeTests/ProjectSettings/HDRPProjectSettings.asset b/TestProjects/HDRP_RuntimeTests/ProjectSettings/HDRPProjectSettings.asset index 3ea8dc4cf74..0355a620489 100644 --- a/TestProjects/HDRP_RuntimeTests/ProjectSettings/HDRPProjectSettings.asset +++ b/TestProjects/HDRP_RuntimeTests/ProjectSettings/HDRPProjectSettings.asset @@ -22,4 +22,4 @@ MonoBehaviour: m_WizardActiveTab: 0 m_WizardNeedRestartAfterChangingToDX12: 0 m_WizardNeedToRunFixAllAgainAfterDomainReload: 0 - m_LastMaterialVersion: 9 + m_LastMaterialVersion: 10 diff --git a/TestProjects/HDRP_Tests/ProjectSettings/HDRPProjectSettings.asset b/TestProjects/HDRP_Tests/ProjectSettings/HDRPProjectSettings.asset index 2c7a9051eac..40a40448d38 100644 --- a/TestProjects/HDRP_Tests/ProjectSettings/HDRPProjectSettings.asset +++ b/TestProjects/HDRP_Tests/ProjectSettings/HDRPProjectSettings.asset @@ -22,4 +22,4 @@ MonoBehaviour: m_WizardActiveTab: 0 m_WizardNeedRestartAfterChangingToDX12: 0 m_WizardNeedToRunFixAllAgainAfterDomainReload: 0 - m_LastMaterialVersion: 9 + m_LastMaterialVersion: 10 diff --git a/TestProjects/SRP_SmokeTest/ProjectSettings/HDRPProjectSettings.asset b/TestProjects/SRP_SmokeTest/ProjectSettings/HDRPProjectSettings.asset index c479d53f6b3..3f61d8b8e10 100644 --- a/TestProjects/SRP_SmokeTest/ProjectSettings/HDRPProjectSettings.asset +++ b/TestProjects/SRP_SmokeTest/ProjectSettings/HDRPProjectSettings.asset @@ -18,4 +18,4 @@ MonoBehaviour: m_ProjectSettingFolderPath: HDRPDefaultResources m_WizardPopupAtStart: 0 m_WizardActiveTab: 0 - m_LastMaterialVersion: 9 + m_LastMaterialVersion: 10 diff --git a/TestProjects/VisualEffectGraph_HDRP/ProjectSettings/HDRPProjectSettings.asset b/TestProjects/VisualEffectGraph_HDRP/ProjectSettings/HDRPProjectSettings.asset index e73d726d944..ac213ba68ad 100644 --- a/TestProjects/VisualEffectGraph_HDRP/ProjectSettings/HDRPProjectSettings.asset +++ b/TestProjects/VisualEffectGraph_HDRP/ProjectSettings/HDRPProjectSettings.asset @@ -19,4 +19,4 @@ MonoBehaviour: m_WizardActiveTab: 0 m_WizardNeedRestartAfterChangingToDX12: 0 m_WizardNeedToRunFixAllAgainAfterDomainReload: 0 - m_LastMaterialVersion: 9 + m_LastMaterialVersion: 10 diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 3aaa81f28a2..29d1a83b544 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue where the Exposure Shader Graph node had clipped text. (case 1265057) - Fixed an issue when rendering into texture where alpha would not default to 1.0 when using 11_11_10 color buffer in non-dev builds. - Fixed issues with reordering and hiding graphics compositor layers (cases 1283903, 1285282, 1283886). +- Fixed the possibility to have a shader with a pre-refraction render queue and refraction enabled at the same time. +- Fixed a migration issue with the rendering queue in ShaderGraph when upgrading to 10.x; ### Changed @@ -50,6 +52,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added a new ray tracing only function that samples the specular part of the materials. - Adding missing marker for ray tracing profiling (RaytracingDeferredLighting) - Added the support of eye shader for ray tracing. +- Exposed Refraction Model to the material UI when using a Lit ShaderGraph. ### Fixed - Fixed several issues with physically-based DoF (TAA ghosting of the CoC buffer, smooth layer transitions, etc) @@ -173,7 +176,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed the denoising and multi-sample not being used for smooth multibounce RTReflections. - Fixed issue where multiple cameras would cause GC each frame. - Fixed after post process rendering pass options not showing for unlit ShaderGraphs. -- Fixed a migration issue with the rendering queue in ShaderGraph when upgrading to 10.x; - Fixed null reference in the Undo callback of the graphics compositor - Fixed cullmode for SceneSelectionPass. - Fixed issue that caused non-static object to not render at times in OnEnable reflection probes. diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Lit-Shader.md b/com.unity.render-pipelines.high-definition/Documentation~/Lit-Shader.md index ad5fd4dbb03..981e6398ac1 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Lit-Shader.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Lit-Shader.md @@ -69,6 +69,10 @@ To create a new Lit Material, navigate to your Project's Asset window, right-cli Unity exposes this section if you select **Transparent** from the **Surface Type** drop-down. For information on the properties in this section, see the [Surface Type documentation](Surface-Type.md#TransparencyInputs). +Be aware that when you enable **Refraction**, make sure to set **Blend Mode** to **Alpha**, otherwise the effect does not work as expected. If you enable **Refraction** and use a **Blend Mode** other than **Alpha**, a warning displays in the material Inspector. + +Also, be aware that HDRP does not support **Refraction** in the **Pre-Refraction** render pass. If you enable **Refraction** and use the **Pre-Refraction** render pass, a warning displays in the material and Shader Graph Inspector. + ### Emission inputs 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 e2d795010fa..3434746521b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/AssetProcessors/MaterialPostProcessor.cs @@ -201,6 +201,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse MigrateDecalRenderQueue, ExposedDecalInputsFromShaderGraph, FixIncorrectEmissiveColorSpace, + ExposeRefraction, }; #region Migrations @@ -590,6 +591,23 @@ static void FixIncorrectEmissiveColorSpace(Material material, HDShaderUtils.Shad } } + static void ExposeRefraction(Material material, HDShaderUtils.ShaderID id) + { + // Lit SG now have a shader feature for refraction instead of an hardcoded material + if (id == HDShaderUtils.ShaderID.SG_Lit) + { + // Sync the default refraction model from the shader graph to the shader + // We need to do this because the material may already have a refraction model information (from the Lit) + // In order to not break the rendering of the material, we patch the refraction model: + if (material.HasProperty(kRefractionModel)) + { + var refractionModel = material.shader.GetPropertyDefaultFloatValue(material.shader.FindPropertyIndex(kRefractionModel)); + material.SetFloat(kRefractionModel, refractionModel); + } + HDShaderUtils.ResetMaterialKeywords(material); + } + } + #region Serialization_API //Methods in this region interact on the serialized material //without filtering on what used shader knows diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs index 8e983ddb3b2..d9cc4c52f4b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs @@ -27,7 +27,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary passTemplateMaterialDirectories; - protected override string customInspector => "Rendering.HighDefinition.LightingShaderGraphGUI"; + protected override string customInspector => "Rendering.HighDefinition.LitShaderGraphGUI"; protected override GUID subTargetAssetGuid => kSubTargetSourceCodeGuid; protected override string postDecalsInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; @@ -83,10 +83,22 @@ protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() public static FieldDescriptor SpecularColor = new FieldDescriptor(kMaterial, "SpecularColor", "_MATERIAL_FEATURE_TRANSMISSION 1"); // Refraction - public static FieldDescriptor Refraction = new FieldDescriptor(string.Empty, "Refraction", "_HAS_REFRACTION 1"); - public static FieldDescriptor RefractionBox = new FieldDescriptor(string.Empty, "RefractionBox", "_REFRACTION_PLANE 1"); - public static FieldDescriptor RefractionSphere = new FieldDescriptor(string.Empty, "RefractionSphere", "_REFRACTION_SPHERE 1"); - public static FieldDescriptor RefractionThin = new FieldDescriptor(string.Empty, "RefractionThin", "_REFRACTION_THIN 1"); + public static FieldDescriptor Refraction = new FieldDescriptor(string.Empty, "Refraction", ""); + public static KeywordDescriptor RefractionKeyword = new KeywordDescriptor() + { + displayName = "Refraction Model", + referenceName = "_REFRACTION", + type = KeywordType.Enum, + definition = KeywordDefinition.ShaderFeature, + scope = KeywordScope.Local, + entries = new KeywordEntry[] + { + new KeywordEntry() { displayName = "Off", referenceName = "OFF" }, + new KeywordEntry() { displayName = "Plane", referenceName = "PLANE" }, + new KeywordEntry() { displayName = "Sphere", referenceName = "SPHERE" }, + new KeywordEntry() { displayName = "Thin", referenceName = "THIN" }, + } + }; public override void GetFields(ref TargetFieldContext context) { @@ -94,7 +106,7 @@ public override void GetFields(ref TargetFieldContext context) AddDistortionFields(ref context); var descs = context.blocks.Select(x => x.descriptor); - bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); + bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); // Lit specific properties context.AddField(DotsProperties, context.hasDotsProperties); @@ -111,9 +123,6 @@ public override void GetFields(ref TargetFieldContext context) // Refraction context.AddField(Refraction, hasRefraction); - context.AddField(RefractionBox, hasRefraction && litData.refractionModel == ScreenSpaceRefraction.RefractionModel.Box); - context.AddField(RefractionSphere, hasRefraction && litData.refractionModel == ScreenSpaceRefraction.RefractionModel.Sphere); - context.AddField(RefractionThin, hasRefraction && litData.refractionModel == ScreenSpaceRefraction.RefractionModel.Thin); // Misc context.AddField(EnergyConservingSpecular, litData.energyConservingSpecular); @@ -129,7 +138,7 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); + bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderQueueType != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); bool hasDistortion = (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); // Vertex @@ -163,6 +172,21 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera base.CollectShaderProperties(collector, generationMode); HDSubShaderUtilities.AddRayTracingProperty(collector, litData.rayTracing); + + // Refraction model property allow the material inspector to check if refraction is enabled in the shader. + collector.AddShaderProperty(new Vector1ShaderProperty{ + floatType = FloatType.Enum, + hidden = true, + value = (int)litData.refractionModel, + enumNames = Enum.GetNames(typeof(ScreenSpaceRefraction.RefractionModel)).ToList(), + overrideReferenceName = kRefractionModel, + }); + } + + protected override void CollectPassKeywords(ref PassDescriptor pass) + { + base.CollectPassKeywords(ref pass); + pass.keywords.Add(RefractionKeyword); } protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs deleted file mode 100644 index 8267f78039f..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; -using UnityEngine; - -// We share the name of the properties in the UI to avoid duplication -using static UnityEditor.Rendering.HighDefinition.DistortionUIBlock.Styles; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - class LitPropertyBlock : SubTargetPropertyBlock - { - protected override string title => "Lit Properties"; - protected override int foldoutIndex => 2; - - HDLitData litData; - - public LitPropertyBlock(HDLitData litData) - { - this.litData = litData; - } - - protected override void CreatePropertyGUI() - { - - } - } -} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs index 5092ef668ed..1412a2e0984 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs @@ -39,7 +39,17 @@ protected override void CreatePropertyGUI() { AddProperty(transmissionEnableText, () => litData.sssTransmission, (newValue) => litData.sssTransmission = newValue); } - AddProperty(refractionModelText, () => litData.refractionModel, (newValue) => litData.refractionModel = newValue); + if (systemData.surfaceType == SurfaceType.Transparent) + { + AddProperty(refractionModelText, () => litData.refractionModel, (newValue) => litData.refractionModel = newValue); + if (litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None) + { + if (systemData.blendMode != BlendMode.Alpha) + AddHelpBox(RefractionUIBlock.Styles.refractionBlendModeWarning, MessageType.Warning); + if (systemData.renderQueueType == HDRenderQueue.RenderQueueType.PreRefraction) + AddHelpBox(RefractionUIBlock.Styles.refractionRenderingPassWarning, MessageType.Warning); + } + } if (litData.materialType == HDLitData.MaterialType.SpecularColor) { AddProperty(energyConservingSpecularColorText, () => litData.energyConservingSpecular, (newValue) => litData.energyConservingSpecular = newValue); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/ShaderPass.template.hlsl b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/ShaderPass.template.hlsl index c5083be338f..a845c0a3a31 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/ShaderPass.template.hlsl +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/ShaderPass.template.hlsl @@ -20,7 +20,7 @@ void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDes $SurfaceDescription.IridescenceMask: surfaceData.iridescenceMask = surfaceDescription.IridescenceMask; $SurfaceDescription.IridescenceThickness: surfaceData.iridescenceThickness = surfaceDescription.IridescenceThickness; - #ifdef _HAS_REFRACTION + #if defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_THIN) if (_EnableSSRefraction) { $SurfaceDescription.RefractionIndex: surfaceData.ior = surfaceDescription.RefractionIndex; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/ShaderPassDefine.template.hlsl b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/ShaderPassDefine.template.hlsl index 4669984154c..9b0f6eaad96 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/ShaderPassDefine.template.hlsl +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/ShaderPassDefine.template.hlsl @@ -10,7 +10,6 @@ $SpecularOcclusionFromAOBentNormal: #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NOR $SpecularOcclusionCustom: #define _SPECULAR_OCCLUSION_CUSTOM 1 $Specular.EnergyConserving: #define _ENERGY_CONSERVING_SPECULAR 1 $Specular.AA: #define _ENABLE_GEOMETRIC_SPECULAR_AA 1 -$Refraction: #define _HAS_REFRACTION 1 $RefractionBox: #define _REFRACTION_PLANE 1 $RefractionSphere: #define _REFRACTION_SPHERE 1 $RefractionThin: #define _REFRACTION_THIN 1 diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/HDLitMasterNode1.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/HDLitMasterNode1.cs index 1bda6d3a24f..15eae5d6dee 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/HDLitMasterNode1.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Legacy/HDLitMasterNode1.cs @@ -187,5 +187,6 @@ public bool MaterialTypeUsesSlotMask(SlotMask mask) public int m_MaterialNeedsUpdateHash; public string m_ShaderGUIOverride; public bool m_OverrideEnabled; + public bool m_DrawBeforeRefraction; } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs index 375f4124b02..e4a071549b3 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs @@ -32,7 +32,7 @@ public LightingData lightingData protected override string renderQueue { - get => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(systemData.renderingPass, systemData.sortPriority, systemData.alphaTest, lightingData.receiveDecals)); + get => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(systemData.renderQueueType, systemData.sortPriority, systemData.alphaTest, lightingData.receiveDecals)); } protected override string renderType => HDRenderTypeTags.HDLitShader.ToString(); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs index 65991f1ff68..db21527273a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs @@ -113,6 +113,22 @@ protected void AddFoldout(GUIContent content, Func getter, Action se context.Add(foldout); } + protected void AddHelpBox(string message, MessageType type) + { + // We don't use UIElement HelpBox because it's width is not dynamic. + int indentLevel = context.globalIndentLevel; + var imgui = new IMGUIContainer(() => + { + float indentPadding = indentLevel * 15; + var rect = EditorGUILayout.GetControlRect(false, 42); + rect.x += indentPadding; + rect.width -= indentPadding; + EditorGUI.HelpBox(rect, message, type); + }); + + context.Add(imgui); + } + public void CreatePropertyGUIWithHeader() { if (!String.IsNullOrEmpty(title)) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs index 36d031ee8f8..dc3290a3f0e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs @@ -21,7 +21,7 @@ public enum Features ShowDoubleSidedNormal = 1 << 0, All = ~0, - Unlit = All ^ ShowDoubleSidedNormal, // hide double sided normal for unlit + Unlit = Lit ^ ShowDoubleSidedNormal, // hide double sided normal for unlit Lit = All, } @@ -42,13 +42,14 @@ protected override void CreatePropertyGUI() { AddProperty(surfaceTypeText, () => systemData.surfaceType, (newValue) => { systemData.surfaceType = newValue; - systemData.TryChangeRenderingPass(systemData.renderingPass); + systemData.TryChangeRenderingPass(systemData.renderQueueType); }); context.globalIndentLevel++; var renderingPassList = HDSubShaderUtilities.GetRenderingPassList(systemData.surfaceType == SurfaceType.Opaque, enabledFeatures == Features.Unlit); // Show after post process for unlit shaders - var renderingPassValue = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.GetOpaqueEquivalent(systemData.renderingPass) : HDRenderQueue.GetTransparentEquivalent(systemData.renderingPass); + var renderingPassValue = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.GetOpaqueEquivalent(systemData.renderQueueType) : HDRenderQueue.GetTransparentEquivalent(systemData.renderQueueType); var renderQueueType = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; + context.AddProperty(renderingPassText, new PopupField(renderingPassList, renderQueueType, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName) { value = renderingPassValue }, (evt) => { registerUndo(renderingPassText); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs index 0faba91cd3c..352d913b9be 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs @@ -32,7 +32,7 @@ public BuiltinData builtinData protected override string renderQueue { - get => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(systemData.renderingPass, systemData.sortPriority, systemData.alphaTest, false)); + get => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(systemData.renderQueueType, systemData.sortPriority, systemData.alphaTest, false)); } protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/ShaderGraph/Templates/ShaderPass.template"; @@ -289,7 +289,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera { overrideReferenceName = "_RenderQueueType", hidden = true, - value = (int)systemData.renderingPass, + value = (int)systemData.renderQueueType, }); //See SG-ADDITIONALVELOCITY-NOTE @@ -350,7 +350,7 @@ public override void ProcessPreviewMaterial(Material material) material.SetFloat(kTransparentZWrite, systemData.transparentZWrite ? 1.0f : 0.0f); // No sorting priority for shader graph preview - material.renderQueue = (int)HDRenderQueue.ChangeType(systemData.renderingPass, offset: 0, alphaTest: systemData.alphaTest, false); + material.renderQueue = (int)HDRenderQueue.ChangeType(systemData.renderQueueType, offset: 0, alphaTest: systemData.alphaTest, false); LightingShaderGraphGUI.SetupMaterialKeywordsAndPass(material); } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs index 6df41be68da..6068898f463 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs @@ -28,7 +28,7 @@ public SurfaceType surfaceType [SerializeField] RenderQueueType m_RenderingPass = RenderQueueType.Opaque; - public RenderQueueType renderingPass + public RenderQueueType renderQueueType { get => m_RenderingPass; set => m_RenderingPass = value; @@ -165,10 +165,10 @@ public static bool TryChangeRenderingPass(this SystemData systemData, HDRenderQu throw new ArgumentException("Unknown SurfaceType"); } - if (Equals(systemData.renderingPass, value)) + if (Equals(systemData.renderQueueType, value)) return false; - systemData.renderingPass = value; + systemData.renderQueueType = value; return true; } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs index 8a2a368a977..1a433fc948e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs @@ -27,7 +27,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LightingShaderGraphGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LightingShaderGraphGUI.cs index 96a23f8c2ec..9e8eb3d643b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LightingShaderGraphGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LightingShaderGraphGUI.cs @@ -15,13 +15,15 @@ internal class LightingShaderGraphGUI : HDShaderGUI const SurfaceOptionUIBlock.Features surfaceOptionFeatures = SurfaceOptionUIBlock.Features.Lit | SurfaceOptionUIBlock.Features.ShowDepthOffsetOnly; - MaterialUIBlockList uiBlocks = new MaterialUIBlockList + MaterialUIBlockList m_UIBlocks = new MaterialUIBlockList { new SurfaceOptionUIBlock(MaterialUIBlock.Expandable.Base, features: surfaceOptionFeatures), new ShaderGraphUIBlock(MaterialUIBlock.Expandable.ShaderGraph), new AdvancedOptionsUIBlock(MaterialUIBlock.Expandable.Advance, ~AdvancedOptionsUIBlock.Features.SpecularOcclusion) }; + protected MaterialUIBlockList uiBlocks => m_UIBlocks; + /// /// Implement your custom GUI in this function. To display a UI similar to HDRP shaders, use a MaterialUIBlock. /// @@ -31,8 +33,8 @@ protected override void OnMaterialGUI(MaterialEditor materialEditor, MaterialPro { using (var changed = new EditorGUI.ChangeCheckScope()) { - uiBlocks.OnGUI(materialEditor, props); - ApplyKeywordsAndPassesIfNeeded(changed.changed, uiBlocks.materials); + m_UIBlocks.OnGUI(materialEditor, props); + ApplyKeywordsAndPassesIfNeeded(changed.changed, m_UIBlocks.materials); } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LitShaderGraphGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LitShaderGraphGUI.cs new file mode 100644 index 00000000000..467d4358de9 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LitShaderGraphGUI.cs @@ -0,0 +1,20 @@ +using UnityEngine; +using UnityEngine.Rendering; + +// Include material common properties names +using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; + +namespace UnityEditor.Rendering.HighDefinition +{ + /// + /// Material GUI for Lit ShaderGraph + /// + internal class LitShaderGraphGUI : LightingShaderGraphGUI + { + public LitShaderGraphGUI() + { + // Lit SG have refraction block + uiBlocks.Insert(1, new TransparencyUIBlock(MaterialUIBlock.Expandable.Transparency, TransparencyUIBlock.Features.Refraction)); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LitShaderGraphGUI.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LitShaderGraphGUI.cs.meta index 08db573feab..223f2f3c9a6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LitShaderGraphGUI.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c3d42a05c18dfbd47af8937648d6ec0d +guid: 17883c55a4d63b147afb769cdcfd80d7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs index 4fc93e041e9..83568222420 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using System.Linq; @@ -21,12 +22,12 @@ internal static class Styles public static GUIContent thicknessMapText = new GUIContent("Thickness Map", "Specifies the Thickness Map (R) for this Material - This map describes the thickness of the object. When subsurface scattering is enabled, low values allow some light to transmit through the object."); public static GUIContent transmittanceColorText = new GUIContent("Transmittance Color", "Specifies the Transmittance Color (RGB) for this Material."); public static GUIContent atDistanceText = new GUIContent("Transmittance Absorption Distance", "Sets the absorption distance reference in meters."); + public static string refractionBlendModeWarning = "Refraction is only supported with the Blend Mode value Alpha. Please, set the Blend Mode to Alpha in the Surface Options to hide this mesage."; + public static string refractionRenderingPassWarning = "Refraction is not supported with the rendering pass Pre-Refraction. Please, use a different rendering pass."; } protected MaterialProperty refractionModel = null; protected const string kRefractionModel = "_RefractionModel"; - protected MaterialProperty ssrefractionProjectionModel = null; - protected const string kSSRefractionProjectionModel = "_SSRefractionProjectionModel"; protected MaterialProperty atDistance = null; protected const string kATDistance = "_ATDistance"; protected MaterialProperty[] thickness = null; @@ -41,6 +42,7 @@ internal static class Styles protected const string kTransmittanceColorMap = "_TransmittanceColorMap"; protected MaterialProperty transmittanceColor = null; protected const string kTransmittanceColor = "_TransmittanceColor"; + protected MaterialProperty blendMode = null; int m_LayerCount; @@ -52,23 +54,19 @@ public RefractionUIBlock(int layerCount) public override void LoadMaterialProperties() { refractionModel = FindProperty(kRefractionModel, false); - ssrefractionProjectionModel = FindProperty(kSSRefractionProjectionModel, false); atDistance = FindProperty(kATDistance, false); transmittanceColorMap = FindProperty(kTransmittanceColorMap, false); transmittanceColor = FindProperty(kTransmittanceColor, false); thicknessMap = FindPropertyLayered(kThicknessMap, m_LayerCount, false); thickness = FindPropertyLayered(kThickness, m_LayerCount, false); thicknessRemap = FindPropertyLayered(kThicknessRemap, m_LayerCount, false); + blendMode = FindProperty(kBlendMode, false); ior = FindProperty(kIor, false); } public override void OnGUI() { - var isPrepass = materials.All(m => HDRenderQueue.k_RenderQueue_PreRefraction.Contains(m.renderQueue)); - - if (refractionModel != null - // Refraction is not available for pre-refraction objects - && !isPrepass) + if (refractionModel != null) { materialEditor.ShaderProperty(refractionModel, Styles.refractionModelText); var mode = (ScreenSpaceRefraction.RefractionModel)refractionModel.floatValue; @@ -77,49 +75,65 @@ public override void OnGUI() case ScreenSpaceRefraction.RefractionModel.Box: case ScreenSpaceRefraction.RefractionModel.Sphere: { - materialEditor.ShaderProperty(ior, Styles.refractionIorText); - // TODO: change check - foreach (var material in materials) - { - // TODO - // material.SetBlendMode(BlendMode.Alpha); - // blendMode.floatValue = (float)BlendMode.Alpha; - } + if (ior != null) + materialEditor.ShaderProperty(ior, Styles.refractionIorText); - if (thicknessMap[0].textureValue == null) - { - materialEditor.TexturePropertySingleLine(Styles.refractionThicknessText, thicknessMap[0], thickness[0]); - } - else + if (thicknessMap[0] != null) { - materialEditor.TexturePropertySingleLine(Styles.refractionThicknessMapText, thicknessMap[0]); - // Display the remap of texture values. - Vector2 remap = thicknessRemap[0].vectorValue; - EditorGUI.BeginChangeCheck(); - EditorGUILayout.MinMaxSlider(Styles.refractionThicknessRemappingText, ref remap.x, ref remap.y, 0.0f, 1.0f); - if (EditorGUI.EndChangeCheck()) + if (thicknessMap[0].textureValue == null) + { + materialEditor.TexturePropertySingleLine(Styles.refractionThicknessText, thicknessMap[0], thickness[0]); + } + else { - thicknessRemap[0].vectorValue = remap; + materialEditor.TexturePropertySingleLine(Styles.refractionThicknessMapText, thicknessMap[0]); + // Display the remap of texture values. + Vector2 remap = thicknessRemap[0].vectorValue; + EditorGUI.BeginChangeCheck(); + EditorGUILayout.MinMaxSlider(Styles.refractionThicknessRemappingText, ref remap.x, ref remap.y, 0.0f, 1.0f); + if (EditorGUI.EndChangeCheck()) + { + thicknessRemap[0].vectorValue = remap; + } } } - - materialEditor.TexturePropertySingleLine(Styles.transmittanceColorText, transmittanceColorMap, transmittanceColor); - ++EditorGUI.indentLevel; - materialEditor.ShaderProperty(atDistance, Styles.atDistanceText); - atDistance.floatValue = Mathf.Max(atDistance.floatValue, 0); - --EditorGUI.indentLevel; + if (transmittanceColorMap != null) + { + materialEditor.TexturePropertySingleLine(Styles.transmittanceColorText, transmittanceColorMap, transmittanceColor); + ++EditorGUI.indentLevel; + materialEditor.ShaderProperty(atDistance, Styles.atDistanceText); + atDistance.floatValue = Mathf.Max(atDistance.floatValue, 0); + --EditorGUI.indentLevel; + } } break; case ScreenSpaceRefraction.RefractionModel.Thin: { - materialEditor.ShaderProperty(ior, Styles.refractionIorText); - materialEditor.TexturePropertySingleLine(Styles.transmittanceColorText, transmittanceColorMap, transmittanceColor); + if (ior != null) + materialEditor.ShaderProperty(ior, Styles.refractionIorText); + if (transmittanceColorMap != null) + materialEditor.TexturePropertySingleLine(Styles.transmittanceColorText, transmittanceColorMap, transmittanceColor); } break; default: break; } + + if (refractionModel.floatValue != 0 && blendMode != null) + { + if (blendMode.floatValue != (int)BlendMode.Alpha) + EditorGUILayout.HelpBox(Styles.refractionBlendModeWarning, MessageType.Warning); + + // Check for multi-selection render queue different values + if (materials.Length == 1 || materials.All(m => m.renderQueue == materials[0].renderQueue)) + { + var renderQueueType = HDRenderQueue.GetTypeByRenderQueueValue(materials[0].renderQueue); + + if (renderQueueType == HDRenderQueue.RenderQueueType.PreRefraction) + EditorGUILayout.HelpBox(Styles.refractionRenderingPassWarning, MessageType.Warning); + } + } } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs index a1f6ac429d3..39ea7e6284f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs @@ -217,7 +217,6 @@ internal static class Styles // Refraction (for show pre-refraction pass enum) protected MaterialProperty refractionModel = null; - protected const string kRefractionModel = "_RefractionModel"; MaterialProperty transparentZWrite = null; MaterialProperty stencilRef = null; @@ -482,11 +481,6 @@ void DrawDoubleSidedGUI() void DrawSurfaceGUI() { - // TODO: does not work with multi-selection - bool showBlendModePopup = refractionModel == null - || refractionModel.floatValue == 0 - || materials.All(m => HDRenderQueue.k_RenderQueue_PreRefraction.Contains(m.renderQueue)); - SurfaceTypePopup(); if (surfaceTypeValue == SurfaceType.Transparent) @@ -506,7 +500,7 @@ void DrawSurfaceGUI() using (new EditorGUI.DisabledScope(true)) EditorGUILayout.LabelField(Styles.blendModeText, Styles.notSupportedInMultiEdition); } - else if (blendMode != null && showBlendModePopup) + else if (blendMode != null) BlendModePopup(); if ((m_Features & Features.PreserveSpecularLighting) != 0) @@ -516,7 +510,7 @@ void DrawSurfaceGUI() using (new EditorGUI.DisabledScope(true)) EditorGUILayout.LabelField(Styles.enableBlendModePreserveSpecularLightingText, Styles.notSupportedInMultiEdition); } - else if (enableBlendModePreserveSpecularLighting != null && blendMode != null && showBlendModePopup) + else if (enableBlendModePreserveSpecularLighting != null && blendMode != null) materialEditor.ShaderProperty(enableBlendModePreserveSpecularLighting, Styles.enableBlendModePreserveSpecularLightingText); EditorGUI.indentLevel--; } @@ -646,7 +640,7 @@ void SurfaceTypePopup() case SurfaceType.Transparent: //GetTransparentEquivalent: prevent issue when switching surface type HDRenderQueue.TransparentRenderQueue renderQueueTransparentType = HDRenderQueue.ConvertToTransparentRenderQueue(HDRenderQueue.GetTransparentEquivalent(renderQueueType)); - var newRenderQueueTransparentType = (HDRenderQueue.TransparentRenderQueue)DoTransparentRenderingPassPopup(Styles.renderingPassText, (int)renderQueueTransparentType, showPreRefractionPass, showLowResolutionPass, showAfterPostProcessPass); + var newRenderQueueTransparentType = (HDRenderQueue.TransparentRenderQueue)DoTransparentRenderingPassPopup(Styles.renderingPassText, (int)renderQueueTransparentType, true, showLowResolutionPass, showAfterPostProcessPass); if (newRenderQueueTransparentType != renderQueueTransparentType || renderQueueTypeMismatchRenderQueue) //EditorGUI.EndChangeCheck is called even if value remain the same after the popup. Prefer not to use it here { materialEditor.RegisterPropertyChangeUndo("Rendering Pass"); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/TransparencyUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/TransparencyUIBlock.cs index 7161c860cc0..134d69f6140 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/TransparencyUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/TransparencyUIBlock.cs @@ -3,6 +3,7 @@ using UnityEngine; using UnityEngine.Rendering.HighDefinition; using System.Linq; +using UnityEditor.ShaderGraph; // Include material common properties names using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; @@ -49,6 +50,15 @@ public override void OnGUI() if (materials.Any(material => material.GetSurfaceType() != SurfaceType.Transparent)) return ; + // If refraction model is not enabled in SG, we don't show the section + var shader = materials[0].shader; + if (shader.IsShaderGraph()) + { + var defaultRefractionModel = shader.GetPropertyDefaultFloatValue(shader.FindPropertyIndex(kRefractionModel)); + if (defaultRefractionModel == 0) + return; + } + using (var header = new MaterialHeaderScope(Styles.header, (uint)m_ExpandableBit, materialEditor)) { if (header.expanded) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs index 6ca71bc7bb1..fbbecb664f3 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs @@ -40,7 +40,7 @@ void UpgradeUnlitMasterNode(UnlitMasterNode1 unlitMasterNode, out Dictionary