diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/CreateDecalShaderGraph.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/CreateDecalShaderGraph.cs index 70548cdd527..65eece1b4af 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/CreateDecalShaderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/CreateDecalShaderGraph.cs @@ -4,10 +4,11 @@ namespace UnityEditor.Rendering.HighDefinition { static class CreateDecalShaderGraph { - [MenuItem("Assets/Create/Shader/HDRP/Decal Graph", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new DecalMasterNode()); - } + // TODO: Reimplement + // [MenuItem("Assets/Create/Shader/HDRP/Decal Shader Graph", false, 208)] + // public static void CreateDecalGraph() + // { + // GraphUtil.CreateNewGraph(); + // } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalMasterNode.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalMasterNode.cs index 7cc71028619..b104480893c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalMasterNode.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalMasterNode.cs @@ -1,469 +1,469 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Rendering.HighDefinition.Drawing; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEditor.ShaderGraph.Internal; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.Rendering.HighDefinition.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition -{ - [Serializable] - [Title("Master", "Decal (HDRP)")] - [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.DecalMasterNode")] - class DecalMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string PositionSlotName = "Vertex Position"; - public const string PositionSlotDisplayName = "Vertex Position"; - public const int PositionSlotId = 0; - - public const string AlbedoSlotName = "Albedo"; - public const string AlbedoDisplaySlotName = "BaseColor"; - public const int AlbedoSlotId = 1; - - public const string BaseColorOpacitySlotName = "AlphaAlbedo"; - public const string BaseColorOpacityDisplaySlotName = "BaseColor Opacity"; - public const int BaseColorOpacitySlotId = 2; - - public const string NormalSlotName = "Normal"; - public const int NormalSlotId = 3; - - public const string NormaOpacitySlotName = "AlphaNormal"; - public const string NormaOpacityDisplaySlotName = "Normal Opacity"; - public const int NormaOpacitySlotId = 4; - - public const string MetallicSlotName = "Metallic"; - public const int MetallicSlotId = 5; - - public const string AmbientOcclusionSlotName = "Occlusion"; - public const string AmbientOcclusionDisplaySlotName = "Ambient Occlusion"; - public const int AmbientOcclusionSlotId = 6; - - public const string SmoothnessSlotName = "Smoothness"; - public const int SmoothnessSlotId = 7; - - public const string MAOSOpacitySlotName = "MAOSOpacity"; - public const string MAOSOpacityDisplaySlotName = "MAOS Opacity"; - public const int MAOSOpacitySlotId = 8; - - public const string EmissionSlotName = "Emission"; - public const string EmissionDisplaySlotName = "Emission"; - public const int EmissionSlotId = 9; - - public const string VertexNormalSlotName = "Vertex Normal"; - public const int VertexNormalSlotID = 10; - - public const string VertexTangentSlotName = "Vertex Tangent"; - public const int VertexTangentSlotID = 11; - - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - Dirty(ModificationScope.Graph); - } - } - - // Just for convenience of doing simple masks. We could run out of bits of course. - [Flags] - enum SlotMask - { - None = 0, - Position = 1 << PositionSlotId, - VertexNormal = 1 << VertexNormalSlotID, - VertexTangent = 1 << VertexTangentSlotID, - Albedo = 1 << AlbedoSlotId, - AlphaAlbedo = 1 << BaseColorOpacitySlotId, - Normal = 1 << NormalSlotId, - AlphaNormal = 1 << NormaOpacitySlotId, - Metallic = 1 << MetallicSlotId, - Occlusion = 1 << AmbientOcclusionSlotId, - Smoothness = 1 << SmoothnessSlotId, - AlphaMAOS = 1 << MAOSOpacitySlotId, - Emission = 1 << EmissionSlotId - } - - const SlotMask decalParameter = SlotMask.Position | SlotMask.VertexNormal | SlotMask.VertexTangent | SlotMask.Albedo | SlotMask.AlphaAlbedo | SlotMask.Normal | SlotMask.AlphaNormal | SlotMask.Metallic | SlotMask.Occlusion | SlotMask.Smoothness | SlotMask.AlphaMAOS | SlotMask.Emission; - - - // This could also be a simple array. For now, catch any mismatched data. - SlotMask GetActiveSlotMask() - { - return decalParameter; - } - - bool MaterialTypeUsesSlotMask(SlotMask mask) - { - SlotMask activeMask = GetActiveSlotMask(); - return (activeMask & mask) != 0; - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public DecalMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - public override string documentationURL - { - get { return null; } - } - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Decal Master"; - - List validSlots = new List(); - - // Position - if (MaterialTypeUsesSlotMask(SlotMask.Position)) - { - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(PositionSlotId); - } - - //Normal in Vertex - if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) - { - AddSlot(new NormalMaterialSlot(VertexNormalSlotID, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexNormalSlotID); - } - - //Tangent in Vertex - if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) - { - AddSlot(new TangentMaterialSlot(VertexTangentSlotID, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexTangentSlotID); - } - - // Albedo - if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) - { - AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(AlbedoSlotId); - } - - // AlphaAlbedo - if (MaterialTypeUsesSlotMask(SlotMask.AlphaAlbedo)) - { - AddSlot(new Vector1MaterialSlot(BaseColorOpacitySlotId, BaseColorOpacityDisplaySlotName, BaseColorOpacitySlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(BaseColorOpacitySlotId); - } - - // Normal - if (MaterialTypeUsesSlotMask(SlotMask.Normal)) - { - AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(NormalSlotId); - } - - // AlphaNormal - if (MaterialTypeUsesSlotMask(SlotMask.AlphaNormal)) - { - AddSlot(new Vector1MaterialSlot(NormaOpacitySlotId, NormaOpacityDisplaySlotName, NormaOpacitySlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(NormaOpacitySlotId); - } - - // Metal - if (MaterialTypeUsesSlotMask(SlotMask.Metallic)) - { - AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(MetallicSlotId); - } - - - // Ambient Occlusion - if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) - { - AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AmbientOcclusionSlotId); - } - - // Smoothness - if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) - { - AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(SmoothnessSlotId); - } - - // Alpha MAOS - if (MaterialTypeUsesSlotMask(SlotMask.AlphaMAOS)) - { - AddSlot(new Vector1MaterialSlot(MAOSOpacitySlotId, MAOSOpacityDisplaySlotName, MAOSOpacitySlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(MAOSOpacitySlotId); - } - - // Alpha MAOS - if (MaterialTypeUsesSlotMask(SlotMask.Emission)) - { - AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionDisplaySlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); - validSlots.Add(EmissionSlotId); - } - - RemoveSlotsNameNotMatching(validSlots, true); - } - - public VisualElement CreateSettingsElement() - { - return new DecalSettingsView(this); - } - - public string renderQueueTag - { - get - { - return HDRenderQueue.GetShaderTagValue( - HDRenderQueue.ChangeType(HDRenderQueue.RenderQueueType.Opaque, drawOrder, false)); - } - } - - public string renderTypeTag => HDRenderTypeTags.Opaque.ToString(); - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || - IsSlotConnected(VertexNormalSlotID) || - IsSlotConnected(VertexTangentSlotID)), - new ConditionalField(Fields.GraphPixel, true), - - // Material - new ConditionalField(HDFields.AffectsAlbedo, affectsAlbedo.isOn), - new ConditionalField(HDFields.AffectsNormal, affectsNormal.isOn), - new ConditionalField(HDFields.AffectsEmission, affectsEmission.isOn), - new ConditionalField(HDFields.AffectsMetal, affectsMetal.isOn), - new ConditionalField(HDFields.AffectsAO, affectsAO.isOn), - new ConditionalField(HDFields.AffectsSmoothness, affectsSmoothness.isOn), - new ConditionalField(HDFields.AffectsMaskMap, affectsSmoothness.isOn || affectsMetal.isOn || affectsAO.isOn), - new ConditionalField(HDFields.DecalDefault, affectsAlbedo.isOn || affectsNormal.isOn || affectsMetal.isOn || - affectsAO.isOn || affectsSmoothness.isOn ), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - Vector1ShaderProperty drawOrder = new Vector1ShaderProperty(); - drawOrder.overrideReferenceName = "_DrawOrder"; - drawOrder.displayName = "Draw Order"; - drawOrder.floatType = FloatType.Integer; - drawOrder.hidden = true; - drawOrder.value = 0; - collector.AddShaderProperty(drawOrder); - - Vector1ShaderProperty decalMeshDepthBias = new Vector1ShaderProperty(); - decalMeshDepthBias.overrideReferenceName = "_DecalMeshDepthBias"; - decalMeshDepthBias.displayName = "DecalMesh DepthBias"; - decalMeshDepthBias.hidden = true; - decalMeshDepthBias.floatType = FloatType.Default; - decalMeshDepthBias.value = 0; - collector.AddShaderProperty(decalMeshDepthBias); - - base.CollectShaderProperties(collector, generationMode); - } - - [SerializeField] - bool m_AffectsMetal = true; - - public ToggleData affectsMetal - { - get { return new ToggleData(m_AffectsMetal); } - set - { - if (m_AffectsMetal == value.isOn) - return; - m_AffectsMetal = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AffectsAO = true; - - public ToggleData affectsAO - { - get { return new ToggleData(m_AffectsAO); } - set - { - if (m_AffectsAO == value.isOn) - return; - m_AffectsAO = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AffectsSmoothness = true; - - public ToggleData affectsSmoothness - { - get { return new ToggleData(m_AffectsSmoothness); } - set - { - if (m_AffectsSmoothness == value.isOn) - return; - m_AffectsSmoothness = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AffectsAlbedo = true; - - public ToggleData affectsAlbedo - { - get { return new ToggleData(m_AffectsAlbedo); } - set - { - if (m_AffectsAlbedo == value.isOn) - return; - m_AffectsAlbedo = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AffectsNormal = true; - - public ToggleData affectsNormal - { - get { return new ToggleData(m_AffectsNormal); } - set - { - if (m_AffectsNormal == value.isOn) - return; - m_AffectsNormal = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AffectsEmission = true; - - public ToggleData affectsEmission - { - get { return new ToggleData(m_AffectsEmission); } - set - { - if (m_AffectsEmission == value.isOn) - return; - m_AffectsEmission = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - - [SerializeField] - int m_DrawOrder; - - public int drawOrder - { - get { return m_DrawOrder; } - set - { - if (m_DrawOrder == value) - return; - m_DrawOrder = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - } -} +// using System; +// using System.Linq; +// using System.Collections.Generic; +// using UnityEditor.Rendering.HighDefinition.Drawing; +// using UnityEditor.Graphing; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.Rendering.HighDefinition.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition +// { +// [Serializable] +// [Title("Master", "Decal (HDRP)")] +// [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.DecalMasterNode")] +// class DecalMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent +// { +// public const string PositionSlotName = "Vertex Position"; +// public const string PositionSlotDisplayName = "Vertex Position"; +// public const int PositionSlotId = 0; + +// public const string AlbedoSlotName = "Albedo"; +// public const string AlbedoDisplaySlotName = "BaseColor"; +// public const int AlbedoSlotId = 1; + +// public const string BaseColorOpacitySlotName = "AlphaAlbedo"; +// public const string BaseColorOpacityDisplaySlotName = "BaseColor Opacity"; +// public const int BaseColorOpacitySlotId = 2; + +// public const string NormalSlotName = "Normal"; +// public const int NormalSlotId = 3; + +// public const string NormaOpacitySlotName = "AlphaNormal"; +// public const string NormaOpacityDisplaySlotName = "Normal Opacity"; +// public const int NormaOpacitySlotId = 4; + +// public const string MetallicSlotName = "Metallic"; +// public const int MetallicSlotId = 5; + +// public const string AmbientOcclusionSlotName = "Occlusion"; +// public const string AmbientOcclusionDisplaySlotName = "Ambient Occlusion"; +// public const int AmbientOcclusionSlotId = 6; + +// public const string SmoothnessSlotName = "Smoothness"; +// public const int SmoothnessSlotId = 7; + +// public const string MAOSOpacitySlotName = "MAOSOpacity"; +// public const string MAOSOpacityDisplaySlotName = "MAOS Opacity"; +// public const int MAOSOpacitySlotId = 8; + +// public const string EmissionSlotName = "Emission"; +// public const string EmissionDisplaySlotName = "Emission"; +// public const int EmissionSlotId = 9; + +// public const string VertexNormalSlotName = "Vertex Normal"; +// public const int VertexNormalSlotID = 10; + +// public const string VertexTangentSlotName = "Vertex Tangent"; +// public const int VertexTangentSlotID = 11; + +// [SerializeField] +// SurfaceType m_SurfaceType; + +// public SurfaceType surfaceType +// { +// get { return m_SurfaceType; } +// set +// { +// if (m_SurfaceType == value) +// return; + +// m_SurfaceType = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// // Just for convenience of doing simple masks. We could run out of bits of course. +// [Flags] +// enum SlotMask +// { +// None = 0, +// Position = 1 << PositionSlotId, +// VertexNormal = 1 << VertexNormalSlotID, +// VertexTangent = 1 << VertexTangentSlotID, +// Albedo = 1 << AlbedoSlotId, +// AlphaAlbedo = 1 << BaseColorOpacitySlotId, +// Normal = 1 << NormalSlotId, +// AlphaNormal = 1 << NormaOpacitySlotId, +// Metallic = 1 << MetallicSlotId, +// Occlusion = 1 << AmbientOcclusionSlotId, +// Smoothness = 1 << SmoothnessSlotId, +// AlphaMAOS = 1 << MAOSOpacitySlotId, +// Emission = 1 << EmissionSlotId +// } + +// const SlotMask decalParameter = SlotMask.Position | SlotMask.VertexNormal | SlotMask.VertexTangent | SlotMask.Albedo | SlotMask.AlphaAlbedo | SlotMask.Normal | SlotMask.AlphaNormal | SlotMask.Metallic | SlotMask.Occlusion | SlotMask.Smoothness | SlotMask.AlphaMAOS | SlotMask.Emission; + + +// // This could also be a simple array. For now, catch any mismatched data. +// SlotMask GetActiveSlotMask() +// { +// return decalParameter; +// } + +// bool MaterialTypeUsesSlotMask(SlotMask mask) +// { +// SlotMask activeMask = GetActiveSlotMask(); +// return (activeMask & mask) != 0; +// } + +// [SerializeField] private string m_ShaderGUIOverride; +// public string ShaderGUIOverride +// { +// get => m_ShaderGUIOverride; +// set => m_ShaderGUIOverride = value; +// } + +// [SerializeField] private bool m_OverrideEnabled; +// public bool OverrideEnabled +// { +// get => m_OverrideEnabled; +// set => m_OverrideEnabled = value; +// } + +// public DecalMasterNode() +// { +// UpdateNodeAfterDeserialization(); +// } + +// public override string documentationURL +// { +// get { return null; } +// } + +// public sealed override void UpdateNodeAfterDeserialization() +// { +// base.UpdateNodeAfterDeserialization(); +// name = "Decal Master"; + +// List validSlots = new List(); + +// // Position +// if (MaterialTypeUsesSlotMask(SlotMask.Position)) +// { +// AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(PositionSlotId); +// } + +// //Normal in Vertex +// if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) +// { +// AddSlot(new NormalMaterialSlot(VertexNormalSlotID, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexNormalSlotID); +// } + +// //Tangent in Vertex +// if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) +// { +// AddSlot(new TangentMaterialSlot(VertexTangentSlotID, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexTangentSlotID); +// } + +// // Albedo +// if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) +// { +// AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(AlbedoSlotId); +// } + +// // AlphaAlbedo +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaAlbedo)) +// { +// AddSlot(new Vector1MaterialSlot(BaseColorOpacitySlotId, BaseColorOpacityDisplaySlotName, BaseColorOpacitySlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(BaseColorOpacitySlotId); +// } + +// // Normal +// if (MaterialTypeUsesSlotMask(SlotMask.Normal)) +// { +// AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(NormalSlotId); +// } + +// // AlphaNormal +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaNormal)) +// { +// AddSlot(new Vector1MaterialSlot(NormaOpacitySlotId, NormaOpacityDisplaySlotName, NormaOpacitySlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(NormaOpacitySlotId); +// } + +// // Metal +// if (MaterialTypeUsesSlotMask(SlotMask.Metallic)) +// { +// AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(MetallicSlotId); +// } + + +// // Ambient Occlusion +// if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) +// { +// AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AmbientOcclusionSlotId); +// } + +// // Smoothness +// if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) +// { +// AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(SmoothnessSlotId); +// } + +// // Alpha MAOS +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaMAOS)) +// { +// AddSlot(new Vector1MaterialSlot(MAOSOpacitySlotId, MAOSOpacityDisplaySlotName, MAOSOpacitySlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(MAOSOpacitySlotId); +// } + +// // Alpha MAOS +// if (MaterialTypeUsesSlotMask(SlotMask.Emission)) +// { +// AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionDisplaySlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); +// validSlots.Add(EmissionSlotId); +// } + +// RemoveSlotsNameNotMatching(validSlots, true); +// } + +// public VisualElement CreateSettingsElement() +// { +// return new DecalSettingsView(this); +// } + +// public string renderQueueTag +// { +// get +// { +// return HDRenderQueue.GetShaderTagValue( +// HDRenderQueue.ChangeType(HDRenderQueue.RenderQueueType.Opaque, drawOrder, false)); +// } +// } + +// public string renderTypeTag => HDRenderTypeTags.Opaque.ToString(); + +// public ConditionalField[] GetConditionalFields(PassDescriptor pass) +// { +// return new ConditionalField[] +// { +// // Features +// new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || +// IsSlotConnected(VertexNormalSlotID) || +// IsSlotConnected(VertexTangentSlotID)), +// new ConditionalField(Fields.GraphPixel, true), + +// // Material +// new ConditionalField(HDFields.AffectsAlbedo, affectsAlbedo.isOn), +// new ConditionalField(HDFields.AffectsNormal, affectsNormal.isOn), +// new ConditionalField(HDFields.AffectsEmission, affectsEmission.isOn), +// new ConditionalField(HDFields.AffectsMetal, affectsMetal.isOn), +// new ConditionalField(HDFields.AffectsAO, affectsAO.isOn), +// new ConditionalField(HDFields.AffectsSmoothness, affectsSmoothness.isOn), +// new ConditionalField(HDFields.AffectsMaskMap, affectsSmoothness.isOn || affectsMetal.isOn || affectsAO.isOn), +// new ConditionalField(HDFields.DecalDefault, affectsAlbedo.isOn || affectsNormal.isOn || affectsMetal.isOn || +// affectsAO.isOn || affectsSmoothness.isOn ), +// }; +// } + +// public void ProcessPreviewMaterial(Material material) +// { + +// } + +// public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); +// } + +// public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) +// { +// Vector1ShaderProperty drawOrder = new Vector1ShaderProperty(); +// drawOrder.overrideReferenceName = "_DrawOrder"; +// drawOrder.displayName = "Draw Order"; +// drawOrder.floatType = FloatType.Integer; +// drawOrder.hidden = true; +// drawOrder.value = 0; +// collector.AddShaderProperty(drawOrder); + +// Vector1ShaderProperty decalMeshDepthBias = new Vector1ShaderProperty(); +// decalMeshDepthBias.overrideReferenceName = "_DecalMeshDepthBias"; +// decalMeshDepthBias.displayName = "DecalMesh DepthBias"; +// decalMeshDepthBias.hidden = true; +// decalMeshDepthBias.floatType = FloatType.Default; +// decalMeshDepthBias.value = 0; +// collector.AddShaderProperty(decalMeshDepthBias); + +// base.CollectShaderProperties(collector, generationMode); +// } + +// [SerializeField] +// bool m_AffectsMetal = true; + +// public ToggleData affectsMetal +// { +// get { return new ToggleData(m_AffectsMetal); } +// set +// { +// if (m_AffectsMetal == value.isOn) +// return; +// m_AffectsMetal = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AffectsAO = true; + +// public ToggleData affectsAO +// { +// get { return new ToggleData(m_AffectsAO); } +// set +// { +// if (m_AffectsAO == value.isOn) +// return; +// m_AffectsAO = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AffectsSmoothness = true; + +// public ToggleData affectsSmoothness +// { +// get { return new ToggleData(m_AffectsSmoothness); } +// set +// { +// if (m_AffectsSmoothness == value.isOn) +// return; +// m_AffectsSmoothness = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AffectsAlbedo = true; + +// public ToggleData affectsAlbedo +// { +// get { return new ToggleData(m_AffectsAlbedo); } +// set +// { +// if (m_AffectsAlbedo == value.isOn) +// return; +// m_AffectsAlbedo = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AffectsNormal = true; + +// public ToggleData affectsNormal +// { +// get { return new ToggleData(m_AffectsNormal); } +// set +// { +// if (m_AffectsNormal == value.isOn) +// return; +// m_AffectsNormal = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AffectsEmission = true; + +// public ToggleData affectsEmission +// { +// get { return new ToggleData(m_AffectsEmission); } +// set +// { +// if (m_AffectsEmission == value.isOn) +// return; +// m_AffectsEmission = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + + +// [SerializeField] +// int m_DrawOrder; + +// public int drawOrder +// { +// get { return m_DrawOrder; } +// set +// { +// if (m_DrawOrder == value) +// return; +// m_DrawOrder = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_DOTSInstancing = false; + +// public ToggleData dotsInstancing +// { +// get { return new ToggleData(m_DOTSInstancing); } +// set +// { +// if (m_DOTSInstancing == value.isOn) +// return; + +// m_DOTSInstancing = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs index e3c1bc40a0f..9d4fac47a9c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs @@ -1,136 +1,136 @@ -using UnityEngine.UIElements; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; - -namespace UnityEditor.Rendering.HighDefinition.Drawing -{ - class DecalSettingsView : MasterNodeSettingsView - { - DecalMasterNode m_Node; - - Label CreateLabel(string text, int indentLevel) - { - string label = ""; - for (var i = 0; i < indentLevel; i++) - { - label += " "; - } - return new Label(label + text); - } - - public DecalSettingsView(DecalMasterNode node) : base(node) - { - m_Node = node; - PropertySheet ps = new PropertySheet(); - - int indentLevel = 0; - - ps.Add(new PropertyRow(CreateLabel("Affect BaseColor", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.affectsAlbedo.isOn; - toggle.RegisterValueChangedCallback(ChangeAffectsAlbedo); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Affects Normal", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.affectsNormal.isOn; - toggle.RegisterValueChangedCallback(ChangeAffectsNormal); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Affects Metal", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.affectsMetal.isOn; - toggle.RegisterValueChangedCallback(ChangeAffectsMetal); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Affects AO", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.affectsAO.isOn; - toggle.RegisterValueChangedCallback(ChangeAffectsAO); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Affects Smoothness", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.affectsSmoothness.isOn; - toggle.RegisterValueChangedCallback(ChangeAffectsSmoothness); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Affects Emission", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.affectsEmission.isOn; - toggle.RegisterValueChangedCallback(ChangeAffectsEmission); - }); - }); - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeAffectsAlbedo(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Albedo Change"); - ToggleData td = m_Node.affectsAlbedo; - td.isOn = evt.newValue; - m_Node.affectsAlbedo = td; - } - - void ChangeAffectsNormal(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Normal Change"); - ToggleData td = m_Node.affectsNormal; - td.isOn = evt.newValue; - m_Node.affectsNormal = td; - } - - void ChangeAffectsMetal(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Metal Change"); - ToggleData td = m_Node.affectsMetal; - td.isOn = evt.newValue; - m_Node.affectsMetal = td; - } - - void ChangeAffectsAO(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Affects AO Change"); - ToggleData td = m_Node.affectsAO; - td.isOn = evt.newValue; - m_Node.affectsAO = td; - } - - void ChangeAffectsSmoothness(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Smoothness Change"); - ToggleData td = m_Node.affectsSmoothness; - td.isOn = evt.newValue; - m_Node.affectsSmoothness = td; - } - - void ChangeAffectsEmission(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Emission Change"); - ToggleData td = m_Node.affectsEmission; - td.isOn = evt.newValue; - m_Node.affectsEmission = td; - } - - } -} +// using UnityEngine.UIElements; +// using UnityEditor.Graphing.Util; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; + +// namespace UnityEditor.Rendering.HighDefinition.Drawing +// { +// class DecalSettingsView : MasterNodeSettingsView +// { +// DecalMasterNode m_Node; + +// Label CreateLabel(string text, int indentLevel) +// { +// string label = ""; +// for (var i = 0; i < indentLevel; i++) +// { +// label += " "; +// } +// return new Label(label + text); +// } + +// public DecalSettingsView(DecalMasterNode node) : base(node) +// { +// m_Node = node; +// PropertySheet ps = new PropertySheet(); + +// int indentLevel = 0; + +// ps.Add(new PropertyRow(CreateLabel("Affect BaseColor", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.affectsAlbedo.isOn; +// toggle.RegisterValueChangedCallback(ChangeAffectsAlbedo); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Affects Normal", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.affectsNormal.isOn; +// toggle.RegisterValueChangedCallback(ChangeAffectsNormal); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Affects Metal", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.affectsMetal.isOn; +// toggle.RegisterValueChangedCallback(ChangeAffectsMetal); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Affects AO", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.affectsAO.isOn; +// toggle.RegisterValueChangedCallback(ChangeAffectsAO); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Affects Smoothness", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.affectsSmoothness.isOn; +// toggle.RegisterValueChangedCallback(ChangeAffectsSmoothness); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Affects Emission", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.affectsEmission.isOn; +// toggle.RegisterValueChangedCallback(ChangeAffectsEmission); +// }); +// }); + +// Add(ps); +// Add(GetShaderGUIOverridePropertySheet()); +// } + +// void ChangeAffectsAlbedo(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Albedo Change"); +// ToggleData td = m_Node.affectsAlbedo; +// td.isOn = evt.newValue; +// m_Node.affectsAlbedo = td; +// } + +// void ChangeAffectsNormal(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Normal Change"); +// ToggleData td = m_Node.affectsNormal; +// td.isOn = evt.newValue; +// m_Node.affectsNormal = td; +// } + +// void ChangeAffectsMetal(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Metal Change"); +// ToggleData td = m_Node.affectsMetal; +// td.isOn = evt.newValue; +// m_Node.affectsMetal = td; +// } + +// void ChangeAffectsAO(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Affects AO Change"); +// ToggleData td = m_Node.affectsAO; +// td.isOn = evt.newValue; +// m_Node.affectsAO = td; +// } + +// void ChangeAffectsSmoothness(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Smoothness Change"); +// ToggleData td = m_Node.affectsSmoothness; +// td.isOn = evt.newValue; +// m_Node.affectsSmoothness = td; +// } + +// void ChangeAffectsEmission(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Affects Emission Change"); +// ToggleData td = m_Node.affectsEmission; +// td.isOn = evt.newValue; +// m_Node.affectsEmission = td; +// } + +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/HDDecalSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/HDDecalSubTarget.cs index 51967091da5..b8f6332b7dc 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/HDDecalSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/HDDecalSubTarget.cs @@ -1,515 +1,515 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class HDDecalSubTarget : SubTarget - { - const string kAssetGuid = "3ec927dfcb5d60e4883b2c224857b6c2"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template"; - - public HDDecalSubTarget() - { - displayName = "Decal"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.DecalGUI"); - context.AddSubShader(SubShaders.Decal); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Decal = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { DecalPasses.Projector3RT, new FieldCondition(HDFields.DecalDefault, true) }, - { DecalPasses.Projector4RT, new FieldCondition(HDFields.DecalDefault, true) }, - { DecalPasses.ProjectorEmissive, new FieldCondition(HDFields.AffectsEmission, true) }, - { DecalPasses.Mesh3RT, new FieldCondition(HDFields.DecalDefault, true) }, - { DecalPasses.Mesh4RT, new FieldCondition(HDFields.DecalDefault, true) }, - { DecalPasses.MeshEmissive, new FieldCondition(HDFields.AffectsEmission, true) }, - { DecalPasses.Preview, new FieldCondition(Fields.IsPreview, true) }, - }, - }; - } -#endregion - -#region Passes - public static class DecalPasses - { - // CAUTION: c# code relies on the order in which the passes are declared, any change will need to be reflected in Decalsystem.cs - s_MaterialDecalNames and s_MaterialDecalSGNames array - // and DecalSet.InitializeMaterialValues() - public static PassDescriptor Projector3RT = new PassDescriptor() - { - // Definition - displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector3RT], - referenceName = "SHADERPASS_DBUFFER_PROJECTOR", - lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector3RT], - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - pixelPorts = DecalPortMasks.FragmentDefault, - - //Fields - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = DecalRenderStates.Projector3RT, - pragmas = DecalPragmas.Instanced, - defines = DecalDefines._3RT, - includes = DecalIncludes.Default, - }; - - public static PassDescriptor Projector4RT = new PassDescriptor() - { - // Definition - displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector4RT], - referenceName = "SHADERPASS_DBUFFER_PROJECTOR", - lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector4RT], - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - pixelPorts = DecalPortMasks.FragmentDefault, - - //Fields - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - - // Conditional State - renderStates = DecalRenderStates.Projector4RT, - pragmas = DecalPragmas.Instanced, - defines = DecalDefines._4RT, - includes = DecalIncludes.Default, - }; - - public static PassDescriptor ProjectorEmissive = new PassDescriptor() - { - // Definition - displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_ProjectorEmissive], - referenceName = "SHADERPASS_FORWARD_EMISSIVE_PROJECTOR", - lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_ProjectorEmissive], - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - pixelPorts = DecalPortMasks.FragmentEmissive, - - //Fields - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - - // Conditional State - renderStates = DecalRenderStates.ProjectorEmissive, - pragmas = DecalPragmas.Instanced, - includes = DecalIncludes.Default, - }; - - public static PassDescriptor Mesh3RT = new PassDescriptor() - { - // Definition - displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh3RT], - referenceName = "SHADERPASS_DBUFFER_MESH", - lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh3RT], - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - pixelPorts = DecalPortMasks.FragmentDefault, - - //Fields - structs = CoreStructCollections.Default, - requiredFields = DecalRequiredFields.Mesh, - fieldDependencies = CoreFieldDependencies.Default, - - // Conditional State - renderStates = DecalRenderStates.Mesh3RT, - pragmas = DecalPragmas.Instanced, - defines = DecalDefines._3RT, - includes = DecalIncludes.Default, - }; - - public static PassDescriptor Mesh4RT = new PassDescriptor() - { - // Definition - displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh4RT], - referenceName = "SHADERPASS_DBUFFER_MESH", - lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh4RT], - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - pixelPorts = DecalPortMasks.FragmentDefault, - - //Fields - structs = CoreStructCollections.Default, - requiredFields = DecalRequiredFields.Mesh, - fieldDependencies = CoreFieldDependencies.Default, - - // Conditional State - renderStates = DecalRenderStates.Mesh4RT, - pragmas = DecalPragmas.Instanced, - defines = DecalDefines._4RT, - includes = DecalIncludes.Default, - }; - - public static PassDescriptor MeshEmissive = new PassDescriptor() - { - // Definition - displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_MeshEmissive], - referenceName = "SHADERPASS_FORWARD_EMISSIVE_MESH", - lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_MeshEmissive], - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - pixelPorts = DecalPortMasks.FragmentMeshEmissive, - - //Fields - structs = CoreStructCollections.Default, - requiredFields = DecalRequiredFields.Mesh, - fieldDependencies = CoreFieldDependencies.Default, - - // Conditional State - renderStates = DecalRenderStates.MeshEmissive, - pragmas = DecalPragmas.Instanced, - includes = DecalIncludes.Default, - }; - - public static PassDescriptor Preview = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD_PREVIEW", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - pixelPorts = DecalPortMasks.FragmentMeshEmissive, - - //Fields - structs = CoreStructCollections.Default, - requiredFields = DecalRequiredFields.Mesh, - fieldDependencies = CoreFieldDependencies.Default, - - // Render state overrides - renderStates = DecalRenderStates.Preview, - pragmas = DecalPragmas.Instanced, - includes = DecalIncludes.Default, - }; - } -#endregion - -#region PortMasks - static class DecalPortMasks - { - public static int[] FragmentDefault = new int[] - { - DecalMasterNode.AlbedoSlotId, - DecalMasterNode.BaseColorOpacitySlotId, - DecalMasterNode.NormalSlotId, - DecalMasterNode.NormaOpacitySlotId, - DecalMasterNode.MetallicSlotId, - DecalMasterNode.AmbientOcclusionSlotId, - DecalMasterNode.SmoothnessSlotId, - DecalMasterNode.MAOSOpacitySlotId, - }; - - public static int[] FragmentEmissive = new int[] - { - DecalMasterNode.EmissionSlotId - }; - - public static int[] FragmentMeshEmissive = new int[] - { - DecalMasterNode.AlbedoSlotId, - DecalMasterNode.BaseColorOpacitySlotId, - DecalMasterNode.NormalSlotId, - DecalMasterNode.NormaOpacitySlotId, - DecalMasterNode.MetallicSlotId, - DecalMasterNode.AmbientOcclusionSlotId, - DecalMasterNode.SmoothnessSlotId, - DecalMasterNode.MAOSOpacitySlotId, - DecalMasterNode.EmissionSlotId, - }; - } -#endregion - -#region RequiredFields - static class DecalRequiredFields - { - public static FieldCollection Mesh = new FieldCollection() - { - HDStructFields.AttributesMesh.normalOS, - HDStructFields.AttributesMesh.tangentOS, - HDStructFields.AttributesMesh.uv0, - HDStructFields.FragInputs.tangentToWorld, - HDStructFields.FragInputs.positionRWS, - HDStructFields.FragInputs.texCoord0, - }; - } -#endregion - -#region RenderStates - static class DecalRenderStates - { - readonly static string[] s_DecalColorMasks = new string[8] - { - "ColorMask 0 2 ColorMask 0 3", // nothing - "ColorMask R 2 ColorMask R 3", // metal - "ColorMask G 2 ColorMask G 3", // AO - "ColorMask RG 2 ColorMask RG 3", // metal + AO - "ColorMask BA 2 ColorMask 0 3", // smoothness - "ColorMask RBA 2 ColorMask R 3", // metal + smoothness - "ColorMask GBA 2 ColorMask G 3", // AO + smoothness - "ColorMask RGBA 2 ColorMask RG 3", // metal + AO + smoothness - }; - - public static RenderStateCollection Projector3RT = new RenderStateCollection - { - { RenderState.Blend("Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha") }, - { RenderState.Cull(Cull.Front) }, - { RenderState.ZTest(ZTest.Greater) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ColorMask(s_DecalColorMasks[4]) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = ((int)StencilUsage.Decals).ToString(), - Ref = ((int)StencilUsage.Decals).ToString(), - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection Projector4RT = new RenderStateCollection - { - { RenderState.Blend("Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 3 Zero OneMinusSrcColor") }, - { RenderState.Cull(Cull.Front) }, - { RenderState.ZTest(ZTest.Greater) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = ((int)StencilUsage.Decals).ToString(), - Ref = ((int)StencilUsage.Decals).ToString(), - Comp = "Always", - Pass = "Replace", - }) }, - - // ColorMask per Affects Channel - { RenderState.ColorMask(s_DecalColorMasks[0]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, false), - new FieldCondition(HDFields.AffectsAO, false), - new FieldCondition(HDFields.AffectsSmoothness, false) } }, - { RenderState.ColorMask(s_DecalColorMasks[1]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, true), - new FieldCondition(HDFields.AffectsAO, false), - new FieldCondition(HDFields.AffectsSmoothness, false) } }, - { RenderState.ColorMask(s_DecalColorMasks[2]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, false), - new FieldCondition(HDFields.AffectsAO, true), - new FieldCondition(HDFields.AffectsSmoothness, false) } }, - { RenderState.ColorMask(s_DecalColorMasks[3]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, true), - new FieldCondition(HDFields.AffectsAO, true), - new FieldCondition(HDFields.AffectsSmoothness, false) } }, - { RenderState.ColorMask(s_DecalColorMasks[4]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, false), - new FieldCondition(HDFields.AffectsAO, false), - new FieldCondition(HDFields.AffectsSmoothness, true) } }, - { RenderState.ColorMask(s_DecalColorMasks[5]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, true), - new FieldCondition(HDFields.AffectsAO, false), - new FieldCondition(HDFields.AffectsSmoothness, true) } }, - { RenderState.ColorMask(s_DecalColorMasks[6]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, false), - new FieldCondition(HDFields.AffectsAO, true), - new FieldCondition(HDFields.AffectsSmoothness, true) } }, - { RenderState.ColorMask(s_DecalColorMasks[7]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, true), - new FieldCondition(HDFields.AffectsAO, true), - new FieldCondition(HDFields.AffectsSmoothness, true) } }, - }; - - public static RenderStateCollection ProjectorEmissive = new RenderStateCollection - { - { RenderState.Blend("Blend 0 SrcAlpha One") }, - { RenderState.Cull(Cull.Front) }, - { RenderState.ZTest(ZTest.Greater) }, - { RenderState.ZWrite(ZWrite.Off) }, - }; - - public static RenderStateCollection Mesh3RT = new RenderStateCollection - { - { RenderState.Blend("Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha") }, - { RenderState.ZTest(ZTest.LEqual) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ColorMask(s_DecalColorMasks[4]) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = ((int)StencilUsage.Decals).ToString(), - Ref = ((int)StencilUsage.Decals).ToString(), - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection Mesh4RT = new RenderStateCollection - { - { RenderState.Blend("Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 3 Zero OneMinusSrcColor") }, - { RenderState.ZTest(ZTest.LEqual) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = ((int)StencilUsage.Decals).ToString(), - Ref = ((int)StencilUsage.Decals).ToString(), - Comp = "Always", - Pass = "Replace", - }) }, - - // ColorMask per Affects Channel - { RenderState.ColorMask(s_DecalColorMasks[0]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, false), - new FieldCondition(HDFields.AffectsAO, false), - new FieldCondition(HDFields.AffectsSmoothness, false) } }, - { RenderState.ColorMask(s_DecalColorMasks[1]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, true), - new FieldCondition(HDFields.AffectsAO, false), - new FieldCondition(HDFields.AffectsSmoothness, false) } }, - { RenderState.ColorMask(s_DecalColorMasks[2]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, false), - new FieldCondition(HDFields.AffectsAO, true), - new FieldCondition(HDFields.AffectsSmoothness, false) } }, - { RenderState.ColorMask(s_DecalColorMasks[3]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, true), - new FieldCondition(HDFields.AffectsAO, true), - new FieldCondition(HDFields.AffectsSmoothness, false) } }, - { RenderState.ColorMask(s_DecalColorMasks[4]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, false), - new FieldCondition(HDFields.AffectsAO, false), - new FieldCondition(HDFields.AffectsSmoothness, true) } }, - { RenderState.ColorMask(s_DecalColorMasks[5]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, true), - new FieldCondition(HDFields.AffectsAO, false), - new FieldCondition(HDFields.AffectsSmoothness, true) } }, - { RenderState.ColorMask(s_DecalColorMasks[6]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, false), - new FieldCondition(HDFields.AffectsAO, true), - new FieldCondition(HDFields.AffectsSmoothness, true) } }, - { RenderState.ColorMask(s_DecalColorMasks[7]), new FieldCondition[] { - new FieldCondition(HDFields.AffectsMetal, true), - new FieldCondition(HDFields.AffectsAO, true), - new FieldCondition(HDFields.AffectsSmoothness, true) } }, - }; - - public static RenderStateCollection MeshEmissive = new RenderStateCollection - { - { RenderState.Blend("Blend 0 SrcAlpha One") }, - { RenderState.ZTest(ZTest.LEqual) }, - { RenderState.ZWrite(ZWrite.Off) }, - }; - - public static RenderStateCollection Preview = new RenderStateCollection - { - { RenderState.ZTest(ZTest.LEqual) }, - }; - } -#endregion - -#region Pragmas - static class DecalPragmas - { - public static PragmaCollection Instanced = new PragmaCollection - { - { CorePragmas.Basic }, - { Pragma.MultiCompileInstancing }, - }; - } -#endregion - -#region Defines - static class DecalDefines - { - static class Descriptors - { - public static KeywordDescriptor Decals3RT = new KeywordDescriptor() - { - displayName = "Decals 3RT", - referenceName = "DECALS_3RT", - type = KeywordType.Boolean, - definition = KeywordDefinition.ShaderFeature, - scope = KeywordScope.Global, - }; - - public static KeywordDescriptor Decals4RT = new KeywordDescriptor() - { - displayName = "Decals 4RT", - referenceName = "DECALS_4RT", - type = KeywordType.Boolean, - definition = KeywordDefinition.ShaderFeature, - scope = KeywordScope.Global, - }; - } - - public static DefineCollection _3RT = new DefineCollection - { - { Descriptors.Decals3RT, 1 }, - }; - - public static DefineCollection _4RT = new DefineCollection - { - { Descriptors.Decals4RT, 1 }, - }; - } -#endregion - -#region Includes - static class DecalIncludes - { - const string kPacking = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"; - const string kColor = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"; - const string kFunctions = "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"; - const string kDecal = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl"; - const string kPassDecal = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl"; - - public static IncludeCollection Default = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { kPacking, IncludeLocation.Pregraph }, - { kColor, IncludeLocation.Pregraph }, - { kFunctions, IncludeLocation.Pregraph }, - { kDecal, IncludeLocation.Pregraph }, - { kPassDecal, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class HDDecalSubTarget : SubTarget +// { +// const string kAssetGuid = "3ec927dfcb5d60e4883b2c224857b6c2"; +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template"; + +// public HDDecalSubTarget() +// { +// displayName = "Decal"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.DecalGUI"); +// context.AddSubShader(SubShaders.Decal); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Decal = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { DecalPasses.Projector3RT, new FieldCondition(HDFields.DecalDefault, true) }, +// { DecalPasses.Projector4RT, new FieldCondition(HDFields.DecalDefault, true) }, +// { DecalPasses.ProjectorEmissive, new FieldCondition(HDFields.AffectsEmission, true) }, +// { DecalPasses.Mesh3RT, new FieldCondition(HDFields.DecalDefault, true) }, +// { DecalPasses.Mesh4RT, new FieldCondition(HDFields.DecalDefault, true) }, +// { DecalPasses.MeshEmissive, new FieldCondition(HDFields.AffectsEmission, true) }, +// { DecalPasses.Preview, new FieldCondition(Fields.IsPreview, true) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class DecalPasses +// { +// // CAUTION: c# code relies on the order in which the passes are declared, any change will need to be reflected in Decalsystem.cs - s_MaterialDecalNames and s_MaterialDecalSGNames array +// // and DecalSet.InitializeMaterialValues() +// public static PassDescriptor Projector3RT = new PassDescriptor() +// { +// // Definition +// displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector3RT], +// referenceName = "SHADERPASS_DBUFFER_PROJECTOR", +// lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector3RT], +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// pixelPorts = DecalPortMasks.FragmentDefault, + +// //Fields +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = DecalRenderStates.Projector3RT, +// pragmas = DecalPragmas.Instanced, +// defines = DecalDefines._3RT, +// includes = DecalIncludes.Default, +// }; + +// public static PassDescriptor Projector4RT = new PassDescriptor() +// { +// // Definition +// displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector4RT], +// referenceName = "SHADERPASS_DBUFFER_PROJECTOR", +// lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector4RT], +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// pixelPorts = DecalPortMasks.FragmentDefault, + +// //Fields +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, + +// // Conditional State +// renderStates = DecalRenderStates.Projector4RT, +// pragmas = DecalPragmas.Instanced, +// defines = DecalDefines._4RT, +// includes = DecalIncludes.Default, +// }; + +// public static PassDescriptor ProjectorEmissive = new PassDescriptor() +// { +// // Definition +// displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_ProjectorEmissive], +// referenceName = "SHADERPASS_FORWARD_EMISSIVE_PROJECTOR", +// lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_ProjectorEmissive], +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// pixelPorts = DecalPortMasks.FragmentEmissive, + +// //Fields +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, + +// // Conditional State +// renderStates = DecalRenderStates.ProjectorEmissive, +// pragmas = DecalPragmas.Instanced, +// includes = DecalIncludes.Default, +// }; + +// public static PassDescriptor Mesh3RT = new PassDescriptor() +// { +// // Definition +// displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh3RT], +// referenceName = "SHADERPASS_DBUFFER_MESH", +// lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh3RT], +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// pixelPorts = DecalPortMasks.FragmentDefault, + +// //Fields +// structs = CoreStructCollections.Default, +// requiredFields = DecalRequiredFields.Mesh, +// fieldDependencies = CoreFieldDependencies.Default, + +// // Conditional State +// renderStates = DecalRenderStates.Mesh3RT, +// pragmas = DecalPragmas.Instanced, +// defines = DecalDefines._3RT, +// includes = DecalIncludes.Default, +// }; + +// public static PassDescriptor Mesh4RT = new PassDescriptor() +// { +// // Definition +// displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh4RT], +// referenceName = "SHADERPASS_DBUFFER_MESH", +// lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh4RT], +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// pixelPorts = DecalPortMasks.FragmentDefault, + +// //Fields +// structs = CoreStructCollections.Default, +// requiredFields = DecalRequiredFields.Mesh, +// fieldDependencies = CoreFieldDependencies.Default, + +// // Conditional State +// renderStates = DecalRenderStates.Mesh4RT, +// pragmas = DecalPragmas.Instanced, +// defines = DecalDefines._4RT, +// includes = DecalIncludes.Default, +// }; + +// public static PassDescriptor MeshEmissive = new PassDescriptor() +// { +// // Definition +// displayName = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_MeshEmissive], +// referenceName = "SHADERPASS_FORWARD_EMISSIVE_MESH", +// lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_MeshEmissive], +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// pixelPorts = DecalPortMasks.FragmentMeshEmissive, + +// //Fields +// structs = CoreStructCollections.Default, +// requiredFields = DecalRequiredFields.Mesh, +// fieldDependencies = CoreFieldDependencies.Default, + +// // Conditional State +// renderStates = DecalRenderStates.MeshEmissive, +// pragmas = DecalPragmas.Instanced, +// includes = DecalIncludes.Default, +// }; + +// public static PassDescriptor Preview = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD_PREVIEW", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// pixelPorts = DecalPortMasks.FragmentMeshEmissive, + +// //Fields +// structs = CoreStructCollections.Default, +// requiredFields = DecalRequiredFields.Mesh, +// fieldDependencies = CoreFieldDependencies.Default, + +// // Render state overrides +// renderStates = DecalRenderStates.Preview, +// pragmas = DecalPragmas.Instanced, +// includes = DecalIncludes.Default, +// }; +// } +// #endregion + +// #region PortMasks +// static class DecalPortMasks +// { +// public static int[] FragmentDefault = new int[] +// { +// DecalMasterNode.AlbedoSlotId, +// DecalMasterNode.BaseColorOpacitySlotId, +// DecalMasterNode.NormalSlotId, +// DecalMasterNode.NormaOpacitySlotId, +// DecalMasterNode.MetallicSlotId, +// DecalMasterNode.AmbientOcclusionSlotId, +// DecalMasterNode.SmoothnessSlotId, +// DecalMasterNode.MAOSOpacitySlotId, +// }; + +// public static int[] FragmentEmissive = new int[] +// { +// DecalMasterNode.EmissionSlotId +// }; + +// public static int[] FragmentMeshEmissive = new int[] +// { +// DecalMasterNode.AlbedoSlotId, +// DecalMasterNode.BaseColorOpacitySlotId, +// DecalMasterNode.NormalSlotId, +// DecalMasterNode.NormaOpacitySlotId, +// DecalMasterNode.MetallicSlotId, +// DecalMasterNode.AmbientOcclusionSlotId, +// DecalMasterNode.SmoothnessSlotId, +// DecalMasterNode.MAOSOpacitySlotId, +// DecalMasterNode.EmissionSlotId, +// }; +// } +// #endregion + +// #region RequiredFields +// static class DecalRequiredFields +// { +// public static FieldCollection Mesh = new FieldCollection() +// { +// HDStructFields.AttributesMesh.normalOS, +// HDStructFields.AttributesMesh.tangentOS, +// HDStructFields.AttributesMesh.uv0, +// HDStructFields.FragInputs.tangentToWorld, +// HDStructFields.FragInputs.positionRWS, +// HDStructFields.FragInputs.texCoord0, +// }; +// } +// #endregion + +// #region RenderStates +// static class DecalRenderStates +// { +// readonly static string[] s_DecalColorMasks = new string[8] +// { +// "ColorMask 0 2 ColorMask 0 3", // nothing +// "ColorMask R 2 ColorMask R 3", // metal +// "ColorMask G 2 ColorMask G 3", // AO +// "ColorMask RG 2 ColorMask RG 3", // metal + AO +// "ColorMask BA 2 ColorMask 0 3", // smoothness +// "ColorMask RBA 2 ColorMask R 3", // metal + smoothness +// "ColorMask GBA 2 ColorMask G 3", // AO + smoothness +// "ColorMask RGBA 2 ColorMask RG 3", // metal + AO + smoothness +// }; + +// public static RenderStateCollection Projector3RT = new RenderStateCollection +// { +// { RenderState.Blend("Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha") }, +// { RenderState.Cull(Cull.Front) }, +// { RenderState.ZTest(ZTest.Greater) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.ColorMask(s_DecalColorMasks[4]) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = ((int)StencilUsage.Decals).ToString(), +// Ref = ((int)StencilUsage.Decals).ToString(), +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection Projector4RT = new RenderStateCollection +// { +// { RenderState.Blend("Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 3 Zero OneMinusSrcColor") }, +// { RenderState.Cull(Cull.Front) }, +// { RenderState.ZTest(ZTest.Greater) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = ((int)StencilUsage.Decals).ToString(), +// Ref = ((int)StencilUsage.Decals).ToString(), +// Comp = "Always", +// Pass = "Replace", +// }) }, + +// // ColorMask per Affects Channel +// { RenderState.ColorMask(s_DecalColorMasks[0]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, false), +// new FieldCondition(HDFields.AffectsAO, false), +// new FieldCondition(HDFields.AffectsSmoothness, false) } }, +// { RenderState.ColorMask(s_DecalColorMasks[1]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, true), +// new FieldCondition(HDFields.AffectsAO, false), +// new FieldCondition(HDFields.AffectsSmoothness, false) } }, +// { RenderState.ColorMask(s_DecalColorMasks[2]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, false), +// new FieldCondition(HDFields.AffectsAO, true), +// new FieldCondition(HDFields.AffectsSmoothness, false) } }, +// { RenderState.ColorMask(s_DecalColorMasks[3]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, true), +// new FieldCondition(HDFields.AffectsAO, true), +// new FieldCondition(HDFields.AffectsSmoothness, false) } }, +// { RenderState.ColorMask(s_DecalColorMasks[4]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, false), +// new FieldCondition(HDFields.AffectsAO, false), +// new FieldCondition(HDFields.AffectsSmoothness, true) } }, +// { RenderState.ColorMask(s_DecalColorMasks[5]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, true), +// new FieldCondition(HDFields.AffectsAO, false), +// new FieldCondition(HDFields.AffectsSmoothness, true) } }, +// { RenderState.ColorMask(s_DecalColorMasks[6]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, false), +// new FieldCondition(HDFields.AffectsAO, true), +// new FieldCondition(HDFields.AffectsSmoothness, true) } }, +// { RenderState.ColorMask(s_DecalColorMasks[7]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, true), +// new FieldCondition(HDFields.AffectsAO, true), +// new FieldCondition(HDFields.AffectsSmoothness, true) } }, +// }; + +// public static RenderStateCollection ProjectorEmissive = new RenderStateCollection +// { +// { RenderState.Blend("Blend 0 SrcAlpha One") }, +// { RenderState.Cull(Cull.Front) }, +// { RenderState.ZTest(ZTest.Greater) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// }; + +// public static RenderStateCollection Mesh3RT = new RenderStateCollection +// { +// { RenderState.Blend("Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha") }, +// { RenderState.ZTest(ZTest.LEqual) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.ColorMask(s_DecalColorMasks[4]) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = ((int)StencilUsage.Decals).ToString(), +// Ref = ((int)StencilUsage.Decals).ToString(), +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection Mesh4RT = new RenderStateCollection +// { +// { RenderState.Blend("Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha Blend 3 Zero OneMinusSrcColor") }, +// { RenderState.ZTest(ZTest.LEqual) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = ((int)StencilUsage.Decals).ToString(), +// Ref = ((int)StencilUsage.Decals).ToString(), +// Comp = "Always", +// Pass = "Replace", +// }) }, + +// // ColorMask per Affects Channel +// { RenderState.ColorMask(s_DecalColorMasks[0]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, false), +// new FieldCondition(HDFields.AffectsAO, false), +// new FieldCondition(HDFields.AffectsSmoothness, false) } }, +// { RenderState.ColorMask(s_DecalColorMasks[1]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, true), +// new FieldCondition(HDFields.AffectsAO, false), +// new FieldCondition(HDFields.AffectsSmoothness, false) } }, +// { RenderState.ColorMask(s_DecalColorMasks[2]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, false), +// new FieldCondition(HDFields.AffectsAO, true), +// new FieldCondition(HDFields.AffectsSmoothness, false) } }, +// { RenderState.ColorMask(s_DecalColorMasks[3]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, true), +// new FieldCondition(HDFields.AffectsAO, true), +// new FieldCondition(HDFields.AffectsSmoothness, false) } }, +// { RenderState.ColorMask(s_DecalColorMasks[4]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, false), +// new FieldCondition(HDFields.AffectsAO, false), +// new FieldCondition(HDFields.AffectsSmoothness, true) } }, +// { RenderState.ColorMask(s_DecalColorMasks[5]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, true), +// new FieldCondition(HDFields.AffectsAO, false), +// new FieldCondition(HDFields.AffectsSmoothness, true) } }, +// { RenderState.ColorMask(s_DecalColorMasks[6]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, false), +// new FieldCondition(HDFields.AffectsAO, true), +// new FieldCondition(HDFields.AffectsSmoothness, true) } }, +// { RenderState.ColorMask(s_DecalColorMasks[7]), new FieldCondition[] { +// new FieldCondition(HDFields.AffectsMetal, true), +// new FieldCondition(HDFields.AffectsAO, true), +// new FieldCondition(HDFields.AffectsSmoothness, true) } }, +// }; + +// public static RenderStateCollection MeshEmissive = new RenderStateCollection +// { +// { RenderState.Blend("Blend 0 SrcAlpha One") }, +// { RenderState.ZTest(ZTest.LEqual) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// }; + +// public static RenderStateCollection Preview = new RenderStateCollection +// { +// { RenderState.ZTest(ZTest.LEqual) }, +// }; +// } +// #endregion + +// #region Pragmas +// static class DecalPragmas +// { +// public static PragmaCollection Instanced = new PragmaCollection +// { +// { CorePragmas.Basic }, +// { Pragma.MultiCompileInstancing }, +// }; +// } +// #endregion + +// #region Defines +// static class DecalDefines +// { +// static class Descriptors +// { +// public static KeywordDescriptor Decals3RT = new KeywordDescriptor() +// { +// displayName = "Decals 3RT", +// referenceName = "DECALS_3RT", +// type = KeywordType.Boolean, +// definition = KeywordDefinition.ShaderFeature, +// scope = KeywordScope.Global, +// }; + +// public static KeywordDescriptor Decals4RT = new KeywordDescriptor() +// { +// displayName = "Decals 4RT", +// referenceName = "DECALS_4RT", +// type = KeywordType.Boolean, +// definition = KeywordDefinition.ShaderFeature, +// scope = KeywordScope.Global, +// }; +// } + +// public static DefineCollection _3RT = new DefineCollection +// { +// { Descriptors.Decals3RT, 1 }, +// }; + +// public static DefineCollection _4RT = new DefineCollection +// { +// { Descriptors.Decals4RT, 1 }, +// }; +// } +// #endregion + +// #region Includes +// static class DecalIncludes +// { +// const string kPacking = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"; +// const string kColor = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"; +// const string kFunctions = "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"; +// const string kDecal = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl"; +// const string kPassDecal = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDecal.hlsl"; + +// public static IncludeCollection Default = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { kPacking, IncludeLocation.Pregraph }, +// { kColor, IncludeLocation.Pregraph }, +// { kFunctions, IncludeLocation.Pregraph }, +// { kDecal, IncludeLocation.Pregraph }, +// { kPassDecal, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs deleted file mode 100644 index 2a8794ad40a..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition -{ - static class CreateEyeShaderGraph - { - [MenuItem("Assets/Create/Shader/HDRP/Eye Graph (Experimental)", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new EyeMasterNode()); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeMasterNode.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeMasterNode.cs index f8c59e1e9a3..d763bf1fc6c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeMasterNode.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeMasterNode.cs @@ -1,900 +1,900 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEditor.ShaderGraph.Internal; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; -using UnityEditor.Rendering.HighDefinition.Drawing; -using UnityEditor.Rendering.HighDefinition.ShaderGraph; - -// Include material common properties names -using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; - -namespace UnityEditor.Rendering.HighDefinition -{ - [Serializable] - [Title("Master", "Eye (HDRP)(Preview)")] - class EyeMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string PositionSlotName = "Vertex Position"; - public const string PositionSlotDisplayName = "Vertex Position"; - public const int PositionSlotId = 0; - - public const string AlbedoSlotName = "Albedo"; - public const string AlbedoDisplaySlotName = "BaseColor"; - public const int AlbedoSlotId = 1; - - public const string SpecularOcclusionSlotName = "SpecularOcclusion"; - public const int SpecularOcclusionSlotId = 2; - - public const string NormalSlotName = "Normal"; - public const int NormalSlotId = 3; - - public const string IrisNormalSlotName = "IrisNormal"; - public const int IrisNormalSlotId = 4; - - public const string SmoothnessSlotName = "Smoothness"; - public const int SmoothnessSlotId = 5; - - public const string IORSlotName = "IOR"; - public const int IORSlotId = 6; - - public const string AmbientOcclusionSlotName = "Occlusion"; - public const string AmbientOcclusionDisplaySlotName = "AmbientOcclusion"; - public const int AmbientOcclusionSlotId = 7; - - public const string MaskSlotName = "Mask"; - public const int MaskSlotId = 8; - - public const string DiffusionProfileHashSlotName = "DiffusionProfileHash"; - public const string DiffusionProfileHashSlotDisplayName = "Diffusion Profile"; - public const int DiffusionProfileHashSlotId = 9; - - public const string SubsurfaceMaskSlotName = "SubsurfaceMask"; - public const int SubsurfaceMaskSlotId = 10; - - public const string EmissionSlotName = "Emission"; - public const int EmissionSlotId = 11; - - public const string AlphaSlotName = "Alpha"; - public const int AlphaSlotId = 12; - - public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; - public const int AlphaClipThresholdSlotId = 13; - - public const string BentNormalSlotName = "BentNormal"; - public const int BentNormalSlotId = 14; - - public const int LightingSlotId = 15; - public const string BakedGISlotName = "BakedGI"; - - public const int BackLightingSlotId = 16; - public const string BakedBackGISlotName = "BakedBackGI"; - - public const int DepthOffsetSlotId = 17; - public const string DepthOffsetSlotName = "DepthOffset"; - - public const string VertexNormalSlotName = "Vertex Normal"; - public const int VertexNormalSlotID = 18; - - public const string VertexTangentSlotName = "Vertex Tangent"; - public const int VertexTangentSlotID = 19; - - public enum MaterialType - { - Eye, - EyeCinematic - } - - // Don't support Multiply - public enum AlphaModeEye - { - Alpha, - Premultiply, - Additive, - } - - // Just for convenience of doing simple masks. We could run out of bits of course. - [Flags] - enum SlotMask - { - None = 0, - Position = 1 << PositionSlotId, - VertexNormal = 1 << VertexNormalSlotID, - VertexTangent = 1 << VertexTangentSlotID, - Albedo = 1 << AlbedoSlotId, - SpecularOcclusion = 1 << SpecularOcclusionSlotId, - Normal = 1 << NormalSlotId, - IrisNormal = 1 << IrisNormalSlotId, - Smoothness = 1 << SmoothnessSlotId, - IOR = 1 << IORSlotId, - Occlusion = 1 << AmbientOcclusionSlotId, - Mask = 1 << MaskSlotId, - DiffusionProfile = 1 << DiffusionProfileHashSlotId, - SubsurfaceMask = 1 << SubsurfaceMaskSlotId, - Emission = 1 << EmissionSlotId, - Alpha = 1 << AlphaSlotId, - AlphaClipThreshold = 1 << AlphaClipThresholdSlotId, - BentNormal = 1 << BentNormalSlotId, - BakedGI = 1 << LightingSlotId, - BakedBackGI = 1 << BackLightingSlotId, - DepthOffset = 1 << DepthOffsetSlotId, - } - - const SlotMask EyeSlotMask = SlotMask.Position | SlotMask.VertexNormal | SlotMask.VertexTangent | SlotMask.Albedo | SlotMask.SpecularOcclusion | SlotMask.Normal | SlotMask.IrisNormal | SlotMask.Smoothness | SlotMask.IOR | SlotMask.Occlusion | SlotMask.Mask | SlotMask.DiffusionProfile | SlotMask.SubsurfaceMask | SlotMask.Emission | SlotMask.Alpha | SlotMask.AlphaClipThreshold | SlotMask.BentNormal | SlotMask.BakedGI | SlotMask.DepthOffset; - const SlotMask EyeCinematicSlotMask = EyeSlotMask; - - // This could also be a simple array. For now, catch any mismatched data. - SlotMask GetActiveSlotMask() - { - switch (materialType) - { - case MaterialType.Eye: - return EyeSlotMask; - - case MaterialType.EyeCinematic: - return EyeCinematicSlotMask; - - default: - return SlotMask.None; - } - } - - bool MaterialTypeUsesSlotMask(SlotMask mask) - { - SlotMask activeMask = GetActiveSlotMask(); - return (activeMask & mask) != 0; - } - - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - AlphaMode m_AlphaMode; - - public AlphaMode alphaMode - { - get { return m_AlphaMode; } - set - { - if (m_AlphaMode == value) - return; - - m_AlphaMode = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_BlendPreserveSpecular = true; - - public ToggleData blendPreserveSpecular - { - get { return new ToggleData(m_BlendPreserveSpecular); } - set - { - if (m_BlendPreserveSpecular == value.isOn) - return; - m_BlendPreserveSpecular = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_TransparencyFog = true; - - public ToggleData transparencyFog - { - get { return new ToggleData(m_TransparencyFog); } - set - { - if (m_TransparencyFog == value.isOn) - return; - m_TransparencyFog = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaTest; - - public ToggleData alphaTest - { - get { return new ToggleData(m_AlphaTest); } - set - { - if (m_AlphaTest == value.isOn) - return; - m_AlphaTest = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } +// using System; +// using System.Linq; +// using System.Collections.Generic; +// using UnityEditor.Graphing; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; +// using UnityEditor.Rendering.HighDefinition.Drawing; +// using UnityEditor.Rendering.HighDefinition.ShaderGraph; + +// // Include material common properties names +// using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; + +// namespace UnityEditor.Rendering.HighDefinition +// { +// [Serializable] +// [Title("Master", "Eye (HDRP)(Preview)")] +// class EyeMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent +// { +// public const string PositionSlotName = "Vertex Position"; +// public const string PositionSlotDisplayName = "Vertex Position"; +// public const int PositionSlotId = 0; + +// public const string AlbedoSlotName = "Albedo"; +// public const string AlbedoDisplaySlotName = "BaseColor"; +// public const int AlbedoSlotId = 1; + +// public const string SpecularOcclusionSlotName = "SpecularOcclusion"; +// public const int SpecularOcclusionSlotId = 2; + +// public const string NormalSlotName = "Normal"; +// public const int NormalSlotId = 3; + +// public const string IrisNormalSlotName = "IrisNormal"; +// public const int IrisNormalSlotId = 4; + +// public const string SmoothnessSlotName = "Smoothness"; +// public const int SmoothnessSlotId = 5; + +// public const string IORSlotName = "IOR"; +// public const int IORSlotId = 6; + +// public const string AmbientOcclusionSlotName = "Occlusion"; +// public const string AmbientOcclusionDisplaySlotName = "AmbientOcclusion"; +// public const int AmbientOcclusionSlotId = 7; + +// public const string MaskSlotName = "Mask"; +// public const int MaskSlotId = 8; + +// public const string DiffusionProfileHashSlotName = "DiffusionProfileHash"; +// public const string DiffusionProfileHashSlotDisplayName = "Diffusion Profile"; +// public const int DiffusionProfileHashSlotId = 9; + +// public const string SubsurfaceMaskSlotName = "SubsurfaceMask"; +// public const int SubsurfaceMaskSlotId = 10; + +// public const string EmissionSlotName = "Emission"; +// public const int EmissionSlotId = 11; + +// public const string AlphaSlotName = "Alpha"; +// public const int AlphaSlotId = 12; + +// public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; +// public const int AlphaClipThresholdSlotId = 13; + +// public const string BentNormalSlotName = "BentNormal"; +// public const int BentNormalSlotId = 14; + +// public const int LightingSlotId = 15; +// public const string BakedGISlotName = "BakedGI"; + +// public const int BackLightingSlotId = 16; +// public const string BakedBackGISlotName = "BakedBackGI"; + +// public const int DepthOffsetSlotId = 17; +// public const string DepthOffsetSlotName = "DepthOffset"; + +// public const string VertexNormalSlotName = "Vertex Normal"; +// public const int VertexNormalSlotID = 18; + +// public const string VertexTangentSlotName = "Vertex Tangent"; +// public const int VertexTangentSlotID = 19; + +// public enum MaterialType +// { +// Eye, +// EyeCinematic +// } + +// // Don't support Multiply +// public enum AlphaModeEye +// { +// Alpha, +// Premultiply, +// Additive, +// } + +// // Just for convenience of doing simple masks. We could run out of bits of course. +// [Flags] +// enum SlotMask +// { +// None = 0, +// Position = 1 << PositionSlotId, +// VertexNormal = 1 << VertexNormalSlotID, +// VertexTangent = 1 << VertexTangentSlotID, +// Albedo = 1 << AlbedoSlotId, +// SpecularOcclusion = 1 << SpecularOcclusionSlotId, +// Normal = 1 << NormalSlotId, +// IrisNormal = 1 << IrisNormalSlotId, +// Smoothness = 1 << SmoothnessSlotId, +// IOR = 1 << IORSlotId, +// Occlusion = 1 << AmbientOcclusionSlotId, +// Mask = 1 << MaskSlotId, +// DiffusionProfile = 1 << DiffusionProfileHashSlotId, +// SubsurfaceMask = 1 << SubsurfaceMaskSlotId, +// Emission = 1 << EmissionSlotId, +// Alpha = 1 << AlphaSlotId, +// AlphaClipThreshold = 1 << AlphaClipThresholdSlotId, +// BentNormal = 1 << BentNormalSlotId, +// BakedGI = 1 << LightingSlotId, +// BakedBackGI = 1 << BackLightingSlotId, +// DepthOffset = 1 << DepthOffsetSlotId, +// } + +// const SlotMask EyeSlotMask = SlotMask.Position | SlotMask.VertexNormal | SlotMask.VertexTangent | SlotMask.Albedo | SlotMask.SpecularOcclusion | SlotMask.Normal | SlotMask.IrisNormal | SlotMask.Smoothness | SlotMask.IOR | SlotMask.Occlusion | SlotMask.Mask | SlotMask.DiffusionProfile | SlotMask.SubsurfaceMask | SlotMask.Emission | SlotMask.Alpha | SlotMask.AlphaClipThreshold | SlotMask.BentNormal | SlotMask.BakedGI | SlotMask.DepthOffset; +// const SlotMask EyeCinematicSlotMask = EyeSlotMask; + +// // This could also be a simple array. For now, catch any mismatched data. +// SlotMask GetActiveSlotMask() +// { +// switch (materialType) +// { +// case MaterialType.Eye: +// return EyeSlotMask; + +// case MaterialType.EyeCinematic: +// return EyeCinematicSlotMask; + +// default: +// return SlotMask.None; +// } +// } + +// bool MaterialTypeUsesSlotMask(SlotMask mask) +// { +// SlotMask activeMask = GetActiveSlotMask(); +// return (activeMask & mask) != 0; +// } + +// [SerializeField] +// SurfaceType m_SurfaceType; + +// public SurfaceType surfaceType +// { +// get { return m_SurfaceType; } +// set +// { +// if (m_SurfaceType == value) +// return; + +// m_SurfaceType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// AlphaMode m_AlphaMode; + +// public AlphaMode alphaMode +// { +// get { return m_AlphaMode; } +// set +// { +// if (m_AlphaMode == value) +// return; + +// m_AlphaMode = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_BlendPreserveSpecular = true; + +// public ToggleData blendPreserveSpecular +// { +// get { return new ToggleData(m_BlendPreserveSpecular); } +// set +// { +// if (m_BlendPreserveSpecular == value.isOn) +// return; +// m_BlendPreserveSpecular = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_TransparencyFog = true; + +// public ToggleData transparencyFog +// { +// get { return new ToggleData(m_TransparencyFog); } +// set +// { +// if (m_TransparencyFog == value.isOn) +// return; +// m_TransparencyFog = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaTest; + +// public ToggleData alphaTest +// { +// get { return new ToggleData(m_AlphaTest); } +// set +// { +// if (m_AlphaTest == value.isOn) +// return; +// m_AlphaTest = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } - [SerializeField] - bool m_AlphaToMask = false; - - public ToggleData alphaToMask - { - get { return new ToggleData(m_AlphaToMask); } - set - { - if (m_AlphaToMask == value.isOn) - return; - m_AlphaToMask = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaTestDepthPrepass; - - public ToggleData alphaTestDepthPrepass - { - get { return new ToggleData(m_AlphaTestDepthPrepass); } - set - { - if (m_AlphaTestDepthPrepass == value.isOn) - return; - m_AlphaTestDepthPrepass = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_AlphaTestDepthPostpass; - - public ToggleData alphaTestDepthPostpass - { - get { return new ToggleData(m_AlphaTestDepthPostpass); } - set - { - if (m_AlphaTestDepthPostpass == value.isOn) - return; - m_AlphaTestDepthPostpass = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - int m_SortPriority; - - public int sortPriority - { - get { return m_SortPriority; } - set - { - if (m_SortPriority == value) - return; - m_SortPriority = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - DoubleSidedMode m_DoubleSidedMode; - - public DoubleSidedMode doubleSidedMode - { - get { return m_DoubleSidedMode; } - set - { - if (m_DoubleSidedMode == value) - return; - - m_DoubleSidedMode = value; - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - MaterialType m_MaterialType; - - public MaterialType materialType - { - get { return m_MaterialType; } - set - { - if (m_MaterialType == value) - return; - - m_MaterialType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ReceiveDecals = true; - - public ToggleData receiveDecals - { - get { return new ToggleData(m_ReceiveDecals); } - set - { - if (m_ReceiveDecals == value.isOn) - return; - m_ReceiveDecals = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_ReceivesSSR = true; - public ToggleData receiveSSR - { - get { return new ToggleData(m_ReceivesSSR); } - set - { - if (m_ReceivesSSR == value.isOn) - return; - m_ReceivesSSR = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AddPrecomputedVelocity = false; - - public ToggleData addPrecomputedVelocity - { - get { return new ToggleData(m_AddPrecomputedVelocity); } - set - { - if (m_AddPrecomputedVelocity == value.isOn) - return; - m_AddPrecomputedVelocity = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SubsurfaceScattering = false; - - public ToggleData subsurfaceScattering - { - get { return new ToggleData(m_SubsurfaceScattering); } - set - { - if (m_SubsurfaceScattering == value.isOn) - return; - m_SubsurfaceScattering = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - SpecularOcclusionMode m_SpecularOcclusionMode; - - public SpecularOcclusionMode specularOcclusionMode - { - get { return m_SpecularOcclusionMode; } - set - { - if (m_SpecularOcclusionMode == value) - return; - - m_SpecularOcclusionMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_overrideBakedGI; - - public ToggleData overrideBakedGI - { - get { return new ToggleData(m_overrideBakedGI); } - set - { - if (m_overrideBakedGI == value.isOn) - return; - m_overrideBakedGI = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_depthOffset; - - public ToggleData depthOffset - { - get { return new ToggleData(m_depthOffset); } - set - { - if (m_depthOffset == value.isOn) - return; - m_depthOffset = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ZWrite; - - public ToggleData zWrite - { - get { return new ToggleData(m_ZWrite); } - set - { - if (m_ZWrite == value.isOn) - return; - m_ZWrite = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; - public TransparentCullMode transparentCullMode - { - get => m_transparentCullMode; - set - { - if (m_transparentCullMode == value) - return; - - m_transparentCullMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - CompareFunction m_ZTest = CompareFunction.LessEqual; - public CompareFunction zTest - { - get => m_ZTest; - set - { - if (m_ZTest == value) - return; - - m_ZTest = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SupportLodCrossFade; - - public ToggleData supportLodCrossFade - { - get { return new ToggleData(m_SupportLodCrossFade); } - set - { - if (m_SupportLodCrossFade == value.isOn) - return; - m_SupportLodCrossFade = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Node); - } - } - - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_MaterialNeedsUpdateHash = 0; - - int ComputeMaterialNeedsUpdateHash() - { - int hash = 0; - - hash |= (alphaTest.isOn ? 0 : 1) << 0; - hash |= (receiveSSR.isOn ? 0 : 1) << 1; - hash |= (RequiresSplitLighting() ? 0 : 1) << 2; - - return hash; - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public EyeMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - public override string documentationURL - { - get { return null; } - } - - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Eye Master"; - - List validSlots = new List(); - - // Position - if (MaterialTypeUsesSlotMask(SlotMask.Position)) - { - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(PositionSlotId); - } - - //Normal in Vertex - if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) - { - AddSlot(new NormalMaterialSlot(VertexNormalSlotID, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexNormalSlotID); - } - - //Tangent in Vertex - if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) - { - AddSlot(new TangentMaterialSlot(VertexTangentSlotID, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexTangentSlotID); - } - - // Albedo - if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) - { - AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(AlbedoSlotId); - } - - // Specular Occlusion - if (MaterialTypeUsesSlotMask(SlotMask.SpecularOcclusion) && specularOcclusionMode == SpecularOcclusionMode.Custom) - { - AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularOcclusionSlotId); - } - - // Normal - if (MaterialTypeUsesSlotMask(SlotMask.Normal)) - { - AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(NormalSlotId); - } - - // IrisNormal - if (MaterialTypeUsesSlotMask(SlotMask.IrisNormal)) - { - AddSlot(new NormalMaterialSlot(IrisNormalSlotId, IrisNormalSlotName, IrisNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(IrisNormalSlotId); - } - - // BentNormal - if (MaterialTypeUsesSlotMask(SlotMask.BentNormal)) - { - AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(BentNormalSlotId); - } - - // Smoothness - if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) - { - AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.9f, ShaderStageCapability.Fragment)); - validSlots.Add(SmoothnessSlotId); - } - - // IOR - if (MaterialTypeUsesSlotMask(SlotMask.IOR)) - { - AddSlot(new Vector1MaterialSlot(IORSlotId, IORSlotName, IORSlotName, SlotType.Input, 1.4f, ShaderStageCapability.Fragment)); - validSlots.Add(IORSlotId); - } - - // Ambient Occlusion - if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) - { - AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AmbientOcclusionSlotId); - } - - // Mask - if (MaterialTypeUsesSlotMask(SlotMask.Mask)) - { - AddSlot(new Vector2MaterialSlot(MaskSlotId, MaskSlotName, MaskSlotName, SlotType.Input, new Vector2(1.0f, 0.0f), ShaderStageCapability.Fragment)); - validSlots.Add(MaskSlotId); - } - - // Diffusion Profile - if (MaterialTypeUsesSlotMask(SlotMask.DiffusionProfile) && subsurfaceScattering.isOn) - { - AddSlot(new DiffusionProfileInputMaterialSlot(DiffusionProfileHashSlotId, DiffusionProfileHashSlotDisplayName, DiffusionProfileHashSlotName, ShaderStageCapability.Fragment)); - validSlots.Add(DiffusionProfileHashSlotId); - } - - // Subsurface mask - if (MaterialTypeUsesSlotMask(SlotMask.SubsurfaceMask) && subsurfaceScattering.isOn) - { - AddSlot(new Vector1MaterialSlot(SubsurfaceMaskSlotId, SubsurfaceMaskSlotName, SubsurfaceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SubsurfaceMaskSlotId); - } - - // Emission Normal - if (MaterialTypeUsesSlotMask(SlotMask.Emission)) - { - AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); - validSlots.Add(EmissionSlotId); - } - - // Alpha - if (MaterialTypeUsesSlotMask(SlotMask.Alpha)) - { - AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaSlotId); - } - - // Alpha threshold - if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThreshold) && alphaTest.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaClipThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaClipThresholdSlotId); - } - - if (MaterialTypeUsesSlotMask(SlotMask.BakedGI) && overrideBakedGI.isOn) - { - AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(LightingSlotId); - AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(BackLightingSlotId); - } - - if (depthOffset.isOn) - { - AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(DepthOffsetSlotId); - } - - RemoveSlotsNameNotMatching(validSlots, true); - } - - public VisualElement CreateSettingsElement() - { - return new EyeSettingsView(this); - } - - public string renderQueueTag - { - get - { - var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); - return HDRenderQueue.GetShaderTagValue(queue); - } - } - - public string renderTypeTag => "HDLitShader"; - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); - - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || - IsSlotConnected(VertexNormalSlotID) || - IsSlotConnected(VertexTangentSlotID)), - new ConditionalField(Fields.GraphPixel, true), - new ConditionalField(Fields.LodCrossFade, supportLodCrossFade.isOn), - - // Surface Type - new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), - new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), - - // Structs - new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && - !pass.Equals(HDEyeSubTarget.EyePasses.MotionVectors)), - - // Material - new ConditionalField(HDFields.Eye, materialType == MaterialType.Eye), - new ConditionalField(HDFields.EyeCinematic, materialType == MaterialType.EyeCinematic), - new ConditionalField(HDFields.SubsurfaceScattering, subsurfaceScattering.isOn && surfaceType != SurfaceType.Transparent), - - // Specular Occlusion - new ConditionalField(HDFields.SpecularOcclusionFromAO, specularOcclusionMode == SpecularOcclusionMode.FromAO), - new ConditionalField(HDFields.SpecularOcclusionFromAOBentNormal, specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal), - new ConditionalField(HDFields.SpecularOcclusionCustom, specularOcclusionMode == SpecularOcclusionMode.Custom), - - // Misc - new ConditionalField(Fields.AlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), - new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), - new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && alphaToMask.isOn), - new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), - new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), - new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), - new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), - new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), - new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && - pass.pixelPorts.Contains(BentNormalSlotId)), - new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && - (IsSlotConnected(AmbientOcclusionSlotId) || - ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), - new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && - pass.pixelPorts.Contains(LightingSlotId)), - new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && - pass.pixelPorts.Contains(BackLightingSlotId)), - new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); - material.SetFloat(kDoubleSidedEnable, doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); - material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); - material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)zTest); - material.SetFloat(kTransparentCullMode, (int)transparentCullMode); - material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); - // No sorting priority for shader graph preview - var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); - - EyeGUI.SetupMaterialKeywordsAndPass(material); - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public bool RequiresSplitLighting() - { - return subsurfaceScattering.isOn; - } - public override object saveContext - { - get - { - int hash = ComputeMaterialNeedsUpdateHash(); - - bool needsUpdate = hash != m_MaterialNeedsUpdateHash; - - if (needsUpdate) - m_MaterialNeedsUpdateHash = hash; - - return new HDSaveContext{ updateMaterials = needsUpdate }; - } - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (addPrecomputedVelocity.isOn) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, RequiresSplitLighting(), receiveSSR.isOn); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - surfaceType, - HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), - sortPriority, - alphaToMask.isOn, - zWrite.isOn, - transparentCullMode, - zTest, - false, - transparencyFog.isOn - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, false); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); - - base.CollectShaderProperties(collector, generationMode); - } - } -} +// [SerializeField] +// bool m_AlphaToMask = false; + +// public ToggleData alphaToMask +// { +// get { return new ToggleData(m_AlphaToMask); } +// set +// { +// if (m_AlphaToMask == value.isOn) +// return; +// m_AlphaToMask = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaTestDepthPrepass; + +// public ToggleData alphaTestDepthPrepass +// { +// get { return new ToggleData(m_AlphaTestDepthPrepass); } +// set +// { +// if (m_AlphaTestDepthPrepass == value.isOn) +// return; +// m_AlphaTestDepthPrepass = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_AlphaTestDepthPostpass; + +// public ToggleData alphaTestDepthPostpass +// { +// get { return new ToggleData(m_AlphaTestDepthPostpass); } +// set +// { +// if (m_AlphaTestDepthPostpass == value.isOn) +// return; +// m_AlphaTestDepthPostpass = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// int m_SortPriority; + +// public int sortPriority +// { +// get { return m_SortPriority; } +// set +// { +// if (m_SortPriority == value) +// return; +// m_SortPriority = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// DoubleSidedMode m_DoubleSidedMode; + +// public DoubleSidedMode doubleSidedMode +// { +// get { return m_DoubleSidedMode; } +// set +// { +// if (m_DoubleSidedMode == value) +// return; + +// m_DoubleSidedMode = value; +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// MaterialType m_MaterialType; + +// public MaterialType materialType +// { +// get { return m_MaterialType; } +// set +// { +// if (m_MaterialType == value) +// return; + +// m_MaterialType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ReceiveDecals = true; + +// public ToggleData receiveDecals +// { +// get { return new ToggleData(m_ReceiveDecals); } +// set +// { +// if (m_ReceiveDecals == value.isOn) +// return; +// m_ReceiveDecals = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_ReceivesSSR = true; +// public ToggleData receiveSSR +// { +// get { return new ToggleData(m_ReceivesSSR); } +// set +// { +// if (m_ReceivesSSR == value.isOn) +// return; +// m_ReceivesSSR = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AddPrecomputedVelocity = false; + +// public ToggleData addPrecomputedVelocity +// { +// get { return new ToggleData(m_AddPrecomputedVelocity); } +// set +// { +// if (m_AddPrecomputedVelocity == value.isOn) +// return; +// m_AddPrecomputedVelocity = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SubsurfaceScattering = false; + +// public ToggleData subsurfaceScattering +// { +// get { return new ToggleData(m_SubsurfaceScattering); } +// set +// { +// if (m_SubsurfaceScattering == value.isOn) +// return; +// m_SubsurfaceScattering = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// SpecularOcclusionMode m_SpecularOcclusionMode; + +// public SpecularOcclusionMode specularOcclusionMode +// { +// get { return m_SpecularOcclusionMode; } +// set +// { +// if (m_SpecularOcclusionMode == value) +// return; + +// m_SpecularOcclusionMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_overrideBakedGI; + +// public ToggleData overrideBakedGI +// { +// get { return new ToggleData(m_overrideBakedGI); } +// set +// { +// if (m_overrideBakedGI == value.isOn) +// return; +// m_overrideBakedGI = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_depthOffset; + +// public ToggleData depthOffset +// { +// get { return new ToggleData(m_depthOffset); } +// set +// { +// if (m_depthOffset == value.isOn) +// return; +// m_depthOffset = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ZWrite; + +// public ToggleData zWrite +// { +// get { return new ToggleData(m_ZWrite); } +// set +// { +// if (m_ZWrite == value.isOn) +// return; +// m_ZWrite = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; +// public TransparentCullMode transparentCullMode +// { +// get => m_transparentCullMode; +// set +// { +// if (m_transparentCullMode == value) +// return; + +// m_transparentCullMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// CompareFunction m_ZTest = CompareFunction.LessEqual; +// public CompareFunction zTest +// { +// get => m_ZTest; +// set +// { +// if (m_ZTest == value) +// return; + +// m_ZTest = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SupportLodCrossFade; + +// public ToggleData supportLodCrossFade +// { +// get { return new ToggleData(m_SupportLodCrossFade); } +// set +// { +// if (m_SupportLodCrossFade == value.isOn) +// return; +// m_SupportLodCrossFade = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Node); +// } +// } + +// [SerializeField] +// bool m_DOTSInstancing = false; + +// public ToggleData dotsInstancing +// { +// get { return new ToggleData(m_DOTSInstancing); } +// set +// { +// if (m_DOTSInstancing == value.isOn) +// return; + +// m_DOTSInstancing = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_MaterialNeedsUpdateHash = 0; + +// int ComputeMaterialNeedsUpdateHash() +// { +// int hash = 0; + +// hash |= (alphaTest.isOn ? 0 : 1) << 0; +// hash |= (receiveSSR.isOn ? 0 : 1) << 1; +// hash |= (RequiresSplitLighting() ? 0 : 1) << 2; + +// return hash; +// } + +// [SerializeField] private string m_ShaderGUIOverride; +// public string ShaderGUIOverride +// { +// get => m_ShaderGUIOverride; +// set => m_ShaderGUIOverride = value; +// } + +// [SerializeField] private bool m_OverrideEnabled; +// public bool OverrideEnabled +// { +// get => m_OverrideEnabled; +// set => m_OverrideEnabled = value; +// } + +// public EyeMasterNode() +// { +// UpdateNodeAfterDeserialization(); +// } + +// public override string documentationURL +// { +// get { return null; } +// } + + +// public sealed override void UpdateNodeAfterDeserialization() +// { +// base.UpdateNodeAfterDeserialization(); +// name = "Eye Master"; + +// List validSlots = new List(); + +// // Position +// if (MaterialTypeUsesSlotMask(SlotMask.Position)) +// { +// AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(PositionSlotId); +// } + +// //Normal in Vertex +// if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) +// { +// AddSlot(new NormalMaterialSlot(VertexNormalSlotID, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexNormalSlotID); +// } + +// //Tangent in Vertex +// if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) +// { +// AddSlot(new TangentMaterialSlot(VertexTangentSlotID, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexTangentSlotID); +// } + +// // Albedo +// if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) +// { +// AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(AlbedoSlotId); +// } + +// // Specular Occlusion +// if (MaterialTypeUsesSlotMask(SlotMask.SpecularOcclusion) && specularOcclusionMode == SpecularOcclusionMode.Custom) +// { +// AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularOcclusionSlotId); +// } + +// // Normal +// if (MaterialTypeUsesSlotMask(SlotMask.Normal)) +// { +// AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(NormalSlotId); +// } + +// // IrisNormal +// if (MaterialTypeUsesSlotMask(SlotMask.IrisNormal)) +// { +// AddSlot(new NormalMaterialSlot(IrisNormalSlotId, IrisNormalSlotName, IrisNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(IrisNormalSlotId); +// } + +// // BentNormal +// if (MaterialTypeUsesSlotMask(SlotMask.BentNormal)) +// { +// AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(BentNormalSlotId); +// } + +// // Smoothness +// if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) +// { +// AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.9f, ShaderStageCapability.Fragment)); +// validSlots.Add(SmoothnessSlotId); +// } + +// // IOR +// if (MaterialTypeUsesSlotMask(SlotMask.IOR)) +// { +// AddSlot(new Vector1MaterialSlot(IORSlotId, IORSlotName, IORSlotName, SlotType.Input, 1.4f, ShaderStageCapability.Fragment)); +// validSlots.Add(IORSlotId); +// } + +// // Ambient Occlusion +// if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) +// { +// AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AmbientOcclusionSlotId); +// } + +// // Mask +// if (MaterialTypeUsesSlotMask(SlotMask.Mask)) +// { +// AddSlot(new Vector2MaterialSlot(MaskSlotId, MaskSlotName, MaskSlotName, SlotType.Input, new Vector2(1.0f, 0.0f), ShaderStageCapability.Fragment)); +// validSlots.Add(MaskSlotId); +// } + +// // Diffusion Profile +// if (MaterialTypeUsesSlotMask(SlotMask.DiffusionProfile) && subsurfaceScattering.isOn) +// { +// AddSlot(new DiffusionProfileInputMaterialSlot(DiffusionProfileHashSlotId, DiffusionProfileHashSlotDisplayName, DiffusionProfileHashSlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(DiffusionProfileHashSlotId); +// } + +// // Subsurface mask +// if (MaterialTypeUsesSlotMask(SlotMask.SubsurfaceMask) && subsurfaceScattering.isOn) +// { +// AddSlot(new Vector1MaterialSlot(SubsurfaceMaskSlotId, SubsurfaceMaskSlotName, SubsurfaceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SubsurfaceMaskSlotId); +// } + +// // Emission Normal +// if (MaterialTypeUsesSlotMask(SlotMask.Emission)) +// { +// AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); +// validSlots.Add(EmissionSlotId); +// } + +// // Alpha +// if (MaterialTypeUsesSlotMask(SlotMask.Alpha)) +// { +// AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaSlotId); +// } + +// // Alpha threshold +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThreshold) && alphaTest.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaClipThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaClipThresholdSlotId); +// } + +// if (MaterialTypeUsesSlotMask(SlotMask.BakedGI) && overrideBakedGI.isOn) +// { +// AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(LightingSlotId); +// AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(BackLightingSlotId); +// } + +// if (depthOffset.isOn) +// { +// AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(DepthOffsetSlotId); +// } + +// RemoveSlotsNameNotMatching(validSlots, true); +// } + +// public VisualElement CreateSettingsElement() +// { +// return new EyeSettingsView(this); +// } + +// public string renderQueueTag +// { +// get +// { +// var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; +// int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); +// return HDRenderQueue.GetShaderTagValue(queue); +// } +// } + +// public string renderTypeTag => "HDLitShader"; + +// public ConditionalField[] GetConditionalFields(PassDescriptor pass) +// { +// var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); + +// return new ConditionalField[] +// { +// // Features +// new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || +// IsSlotConnected(VertexNormalSlotID) || +// IsSlotConnected(VertexTangentSlotID)), +// new ConditionalField(Fields.GraphPixel, true), +// new ConditionalField(Fields.LodCrossFade, supportLodCrossFade.isOn), + +// // Surface Type +// new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), +// new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), + +// // Structs +// new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && +// !pass.Equals(HDEyeSubTarget.EyePasses.MotionVectors)), + +// // Material +// new ConditionalField(HDFields.Eye, materialType == MaterialType.Eye), +// new ConditionalField(HDFields.EyeCinematic, materialType == MaterialType.EyeCinematic), +// new ConditionalField(HDFields.SubsurfaceScattering, subsurfaceScattering.isOn && surfaceType != SurfaceType.Transparent), + +// // Specular Occlusion +// new ConditionalField(HDFields.SpecularOcclusionFromAO, specularOcclusionMode == SpecularOcclusionMode.FromAO), +// new ConditionalField(HDFields.SpecularOcclusionFromAOBentNormal, specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal), +// new ConditionalField(HDFields.SpecularOcclusionCustom, specularOcclusionMode == SpecularOcclusionMode.Custom), + +// // Misc +// new ConditionalField(Fields.AlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), +// new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), +// new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && alphaToMask.isOn), +// new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), +// new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), +// new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), +// new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), +// new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), +// new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && +// pass.pixelPorts.Contains(BentNormalSlotId)), +// new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && +// (IsSlotConnected(AmbientOcclusionSlotId) || +// ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), +// new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && +// pass.pixelPorts.Contains(LightingSlotId)), +// new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && +// pass.pixelPorts.Contains(BackLightingSlotId)), +// new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), +// }; +// } + +// public void ProcessPreviewMaterial(Material material) +// { +// // Fixup the material settings: +// material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); +// material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); +// material.SetFloat(kDoubleSidedEnable, doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); +// material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); +// material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); +// material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); +// material.SetFloat(kZTestTransparent, (int)zTest); +// material.SetFloat(kTransparentCullMode, (int)transparentCullMode); +// material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); +// // No sorting priority for shader graph preview +// var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; +// material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); + +// EyeGUI.SetupMaterialKeywordsAndPass(material); +// } + +// public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); +// } + +// public bool RequiresSplitLighting() +// { +// return subsurfaceScattering.isOn; +// } +// public override object saveContext +// { +// get +// { +// int hash = ComputeMaterialNeedsUpdateHash(); + +// bool needsUpdate = hash != m_MaterialNeedsUpdateHash; + +// if (needsUpdate) +// m_MaterialNeedsUpdateHash = hash; + +// return new HDSaveContext{ updateMaterials = needsUpdate }; +// } +// } + +// public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) +// { +// // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. +// // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 +// // The user will then need to explicitly disable emissive GI if it is not needed. +// // To be able to automatically disable emission based on the ShaderGraph config when emission is black, +// // we will need a more general way to communicate this to the engine (not directly tied to a material property). +// collector.AddShaderProperty(new ColorShaderProperty() +// { +// overrideReferenceName = "_EmissionColor", +// hidden = true, +// value = new Color(1.0f, 1.0f, 1.0f, 1.0f) +// }); + +// //See SG-ADDITIONALVELOCITY-NOTE +// if (addPrecomputedVelocity.isOn) +// { +// collector.AddShaderProperty(new BooleanShaderProperty +// { +// value = true, +// hidden = true, +// overrideReferenceName = kAddPrecomputedVelocity, +// }); +// } + +// // Add all shader properties required by the inspector +// HDSubShaderUtilities.AddStencilShaderProperties(collector, RequiresSplitLighting(), receiveSSR.isOn); +// HDSubShaderUtilities.AddBlendingStatesShaderProperties( +// collector, +// surfaceType, +// HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), +// sortPriority, +// alphaToMask.isOn, +// zWrite.isOn, +// transparentCullMode, +// zTest, +// false, +// transparencyFog.isOn +// ); +// HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, false); +// HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); + +// base.CollectShaderProperties(collector, generationMode); +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs index f4834dc03dc..7249851b5ad 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs @@ -1,478 +1,478 @@ -using System; -using UnityEditor.UIElements; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; - -namespace UnityEditor.Rendering.HighDefinition.Drawing -{ - class EyeSettingsView : MasterNodeSettingsView - { - EyeMasterNode m_Node; - - IntegerField m_SortPiorityField; - - Label CreateLabel(string text, int indentLevel) - { - string label = ""; - for (var i = 0; i < indentLevel; i++) - { - label += " "; - } - return new Label(label + text); - } - - public EyeSettingsView(EyeMasterNode node) : base(node) - { - m_Node = node; - PropertySheet ps = new PropertySheet(); - - int indentLevel = 0; - ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => - { - row.Add(new EnumField(SurfaceType.Opaque), (field) => - { - field.value = m_Node.surfaceType; - field.RegisterValueChangedCallback(ChangeSurfaceType); - }); - }); - - if (m_Node.surfaceType == SurfaceType.Transparent) - { - ++indentLevel; - - ps.Add(new PropertyRow(CreateLabel("Blend Preserves Specular", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.blendPreserveSpecular.isOn; - toggle.OnToggleChanged(ChangeBlendPreserveSpecular); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Fog", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transparencyFog.isOn; - toggle.OnToggleChanged(ChangeTransparencyFog); - }); - }); - - m_SortPiorityField = new IntegerField(); - ps.Add(new PropertyRow(CreateLabel("Sort Priority", indentLevel)), (row) => - { - row.Add(m_SortPiorityField, (field) => - { - field.value = m_Node.sortPriority; - field.RegisterValueChangedCallback(ChangeSortPriority); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.zWrite.isOn; - toggle.OnToggleChanged(ChangeZWrite); - }); - }); - - if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) - { - ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.transparentCullMode), (e) => - { - e.value = m_Node.transparentCullMode; - e.RegisterValueChangedCallback(ChangeTransparentCullMode); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.zTest), (e) => - { - e.value = m_Node.zTest; - e.RegisterValueChangedCallback(ChangeZTest); - }); - }); - - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTest.isOn; - toggle.OnToggleChanged(ChangeAlphaTest); - }); - }); - - if (m_Node.alphaTest.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaToMask.isOn; - toggle.OnToggleChanged(ChangeAlphaToMask); - }); - }); +// using System; +// using UnityEditor.UIElements; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEditor.Graphing.Util; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; + +// namespace UnityEditor.Rendering.HighDefinition.Drawing +// { +// class EyeSettingsView : MasterNodeSettingsView +// { +// EyeMasterNode m_Node; + +// IntegerField m_SortPiorityField; + +// Label CreateLabel(string text, int indentLevel) +// { +// string label = ""; +// for (var i = 0; i < indentLevel; i++) +// { +// label += " "; +// } +// return new Label(label + text); +// } + +// public EyeSettingsView(EyeMasterNode node) : base(node) +// { +// m_Node = node; +// PropertySheet ps = new PropertySheet(); + +// int indentLevel = 0; +// ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(SurfaceType.Opaque), (field) => +// { +// field.value = m_Node.surfaceType; +// field.RegisterValueChangedCallback(ChangeSurfaceType); +// }); +// }); + +// if (m_Node.surfaceType == SurfaceType.Transparent) +// { +// ++indentLevel; + +// ps.Add(new PropertyRow(CreateLabel("Blend Preserves Specular", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.blendPreserveSpecular.isOn; +// toggle.OnToggleChanged(ChangeBlendPreserveSpecular); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Fog", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transparencyFog.isOn; +// toggle.OnToggleChanged(ChangeTransparencyFog); +// }); +// }); + +// m_SortPiorityField = new IntegerField(); +// ps.Add(new PropertyRow(CreateLabel("Sort Priority", indentLevel)), (row) => +// { +// row.Add(m_SortPiorityField, (field) => +// { +// field.value = m_Node.sortPriority; +// field.RegisterValueChangedCallback(ChangeSortPriority); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.zWrite.isOn; +// toggle.OnToggleChanged(ChangeZWrite); +// }); +// }); + +// if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) +// { +// ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.transparentCullMode), (e) => +// { +// e.value = m_Node.transparentCullMode; +// e.RegisterValueChangedCallback(ChangeTransparentCullMode); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.zTest), (e) => +// { +// e.value = m_Node.zTest; +// e.RegisterValueChangedCallback(ChangeZTest); +// }); +// }); + +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTest.isOn; +// toggle.OnToggleChanged(ChangeAlphaTest); +// }); +// }); + +// if (m_Node.alphaTest.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaToMask.isOn; +// toggle.OnToggleChanged(ChangeAlphaToMask); +// }); +// }); - if (m_Node.surfaceType == SurfaceType.Transparent) - { - ps.Add(new PropertyRow(CreateLabel("Alpha Cutoff Depth Prepass", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTestDepthPrepass.isOn; - toggle.OnToggleChanged(ChangeAlphaTestPrepass); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Alpha Cutoff Depth Postpass", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTestDepthPostpass.isOn; - toggle.OnToggleChanged(ChangeAlphaTestPostpass); - }); - }); - } - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => - { - row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => - { - field.value = m_Node.doubleSidedMode; - field.RegisterValueChangedCallback(ChangeDoubleSidedMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Material Type", indentLevel)), (row) => - { - row.Add(new EnumField(EyeMasterNode.MaterialType.Eye), (field) => - { - field.value = m_Node.materialType; - field.RegisterValueChangedCallback(ChangeMaterialType); - }); - }); - - if (m_Node.surfaceType != SurfaceType.Transparent) - { - ps.Add(new PropertyRow(CreateLabel("Subsurface Scattering", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.subsurfaceScattering.isOn; - toggle.OnToggleChanged(ChangeSubsurfaceScattering); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveDecals.isOn; - toggle.OnToggleChanged(ChangeDecal); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveSSR.isOn; - toggle.OnToggleChanged(ChangeSSR); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.addPrecomputedVelocity.isOn; - toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => - { - row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => - { - field.value = m_Node.specularOcclusionMode; - field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.overrideBakedGI.isOn; - toggle.OnToggleChanged(ChangeoverrideBakedGI); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.depthOffset.isOn; - toggle.OnToggleChanged(ChangeDepthOffset); - }); - }); - - - ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.supportLodCrossFade.isOn; - toggle.OnToggleChanged(ChangeSupportLODCrossFade); - }); - }); - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeSurfaceType(ChangeEvent evt) - { - if (Equals(m_Node.surfaceType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); - m_Node.surfaceType = (SurfaceType)evt.newValue; - } - - void ChangeDoubleSidedMode(ChangeEvent evt) - { - if (Equals(m_Node.doubleSidedMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); - m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; - } - - void ChangeMaterialType(ChangeEvent evt) - { - if (Equals(m_Node.materialType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Material Type Change"); - m_Node.materialType = (EyeMasterNode.MaterialType)evt.newValue; - } - - void ChangeSubsurfaceScattering(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SSS Change"); - ToggleData td = m_Node.subsurfaceScattering; - td.isOn = evt.newValue; - m_Node.subsurfaceScattering = td; - } - - void ChangeBlendMode(ChangeEvent evt) - { - // Make sure the mapping is correct by handling each case. - AlphaMode alphaMode = GetAlphaMode((EyeMasterNode.AlphaModeEye)evt.newValue); - - if (Equals(m_Node.alphaMode, alphaMode)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); - m_Node.alphaMode = alphaMode; - } - - void ChangeBlendPreserveSpecular(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); - ToggleData td = m_Node.blendPreserveSpecular; - td.isOn = evt.newValue; - m_Node.blendPreserveSpecular = td; - } - - void ChangeTransparencyFog(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); - ToggleData td = m_Node.transparencyFog; - td.isOn = evt.newValue; - m_Node.transparencyFog = td; - } - - void ChangeSortPriority(ChangeEvent evt) - { - m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - // Force the text to match. - m_SortPiorityField.value = m_Node.sortPriority; - if (Equals(m_Node.sortPriority, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); - } - - void ChangeZWrite(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); - ToggleData td = m_Node.zWrite; - td.isOn = evt.newValue; - m_Node.zWrite = td; - } - - void ChangeAlphaTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); - ToggleData td = m_Node.alphaTest; - td.isOn = evt.newValue; - m_Node.alphaTest = td; - } +// if (m_Node.surfaceType == SurfaceType.Transparent) +// { +// ps.Add(new PropertyRow(CreateLabel("Alpha Cutoff Depth Prepass", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTestDepthPrepass.isOn; +// toggle.OnToggleChanged(ChangeAlphaTestPrepass); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Alpha Cutoff Depth Postpass", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTestDepthPostpass.isOn; +// toggle.OnToggleChanged(ChangeAlphaTestPostpass); +// }); +// }); +// } +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => +// { +// row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => +// { +// field.value = m_Node.doubleSidedMode; +// field.RegisterValueChangedCallback(ChangeDoubleSidedMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Material Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(EyeMasterNode.MaterialType.Eye), (field) => +// { +// field.value = m_Node.materialType; +// field.RegisterValueChangedCallback(ChangeMaterialType); +// }); +// }); + +// if (m_Node.surfaceType != SurfaceType.Transparent) +// { +// ps.Add(new PropertyRow(CreateLabel("Subsurface Scattering", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.subsurfaceScattering.isOn; +// toggle.OnToggleChanged(ChangeSubsurfaceScattering); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveDecals.isOn; +// toggle.OnToggleChanged(ChangeDecal); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveSSR.isOn; +// toggle.OnToggleChanged(ChangeSSR); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.addPrecomputedVelocity.isOn; +// toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => +// { +// field.value = m_Node.specularOcclusionMode; +// field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.overrideBakedGI.isOn; +// toggle.OnToggleChanged(ChangeoverrideBakedGI); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.depthOffset.isOn; +// toggle.OnToggleChanged(ChangeDepthOffset); +// }); +// }); + + +// ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.supportLodCrossFade.isOn; +// toggle.OnToggleChanged(ChangeSupportLODCrossFade); +// }); +// }); + +// Add(ps); +// Add(GetShaderGUIOverridePropertySheet()); +// } + +// void ChangeSurfaceType(ChangeEvent evt) +// { +// if (Equals(m_Node.surfaceType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); +// m_Node.surfaceType = (SurfaceType)evt.newValue; +// } + +// void ChangeDoubleSidedMode(ChangeEvent evt) +// { +// if (Equals(m_Node.doubleSidedMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); +// m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; +// } + +// void ChangeMaterialType(ChangeEvent evt) +// { +// if (Equals(m_Node.materialType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Material Type Change"); +// m_Node.materialType = (EyeMasterNode.MaterialType)evt.newValue; +// } + +// void ChangeSubsurfaceScattering(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SSS Change"); +// ToggleData td = m_Node.subsurfaceScattering; +// td.isOn = evt.newValue; +// m_Node.subsurfaceScattering = td; +// } + +// void ChangeBlendMode(ChangeEvent evt) +// { +// // Make sure the mapping is correct by handling each case. +// AlphaMode alphaMode = GetAlphaMode((EyeMasterNode.AlphaModeEye)evt.newValue); + +// if (Equals(m_Node.alphaMode, alphaMode)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); +// m_Node.alphaMode = alphaMode; +// } + +// void ChangeBlendPreserveSpecular(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); +// ToggleData td = m_Node.blendPreserveSpecular; +// td.isOn = evt.newValue; +// m_Node.blendPreserveSpecular = td; +// } + +// void ChangeTransparencyFog(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); +// ToggleData td = m_Node.transparencyFog; +// td.isOn = evt.newValue; +// m_Node.transparencyFog = td; +// } + +// void ChangeSortPriority(ChangeEvent evt) +// { +// m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); +// // Force the text to match. +// m_SortPiorityField.value = m_Node.sortPriority; +// if (Equals(m_Node.sortPriority, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); +// } + +// void ChangeZWrite(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); +// ToggleData td = m_Node.zWrite; +// td.isOn = evt.newValue; +// m_Node.zWrite = td; +// } + +// void ChangeAlphaTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); +// ToggleData td = m_Node.alphaTest; +// td.isOn = evt.newValue; +// m_Node.alphaTest = td; +// } - void ChangeAlphaToMask(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); - ToggleData td = m_Node.alphaToMask; - td.isOn = evt.newValue; - m_Node.alphaToMask = td; - } - - void ChangeAlphaTestPrepass(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Prepass Change"); - ToggleData td = m_Node.alphaTestDepthPrepass; - td.isOn = evt.newValue; - m_Node.alphaTestDepthPrepass = td; - } - - void ChangeAlphaTestPostpass(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Postpass Change"); - ToggleData td = m_Node.alphaTestDepthPostpass; - td.isOn = evt.newValue; - m_Node.alphaTestDepthPostpass = td; - } - - void ChangeDecal(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Decal Change"); - ToggleData td = m_Node.receiveDecals; - td.isOn = evt.newValue; - m_Node.receiveDecals = td; - } - - void ChangeSSR(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); - ToggleData td = m_Node.receiveSSR; - td.isOn = evt.newValue; - m_Node.receiveSSR = td; - } - - void ChangeAddPrecomputedVelocity(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); - ToggleData td = m_Node.addPrecomputedVelocity; - td.isOn = evt.newValue; - m_Node.addPrecomputedVelocity = td; - } - - void ChangeSpecularOcclusionMode(ChangeEvent evt) - { - if (Equals(m_Node.specularOcclusionMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Specular Occlusion Mode Change"); - m_Node.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; - } - - void ChangeoverrideBakedGI(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); - ToggleData td = m_Node.overrideBakedGI; - td.isOn = evt.newValue; - m_Node.overrideBakedGI = td; - } - - void ChangeDepthOffset(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); - ToggleData td = m_Node.depthOffset; - td.isOn = evt.newValue; - m_Node.depthOffset = td; - } - - void ChangeTransparentCullMode(ChangeEvent evt) - { - if (Equals(m_Node.transparentCullMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); - m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; - } - - void ChangeZTest(ChangeEvent evt) - { - if (Equals(m_Node.zTest, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); - m_Node.zTest = (CompareFunction)evt.newValue; - } - - void ChangeSupportLODCrossFade(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); - ToggleData td = m_Node.supportLodCrossFade; - td.isOn = evt.newValue; - m_Node.supportLodCrossFade = td; - } - - public AlphaMode GetAlphaMode(EyeMasterNode.AlphaModeEye alphaModeLit) - { - switch (alphaModeLit) - { - case EyeMasterNode.AlphaModeEye.Alpha: - return AlphaMode.Alpha; - case EyeMasterNode.AlphaModeEye.Premultiply: - return AlphaMode.Premultiply; - case EyeMasterNode.AlphaModeEye.Additive: - return AlphaMode.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaModeLit); - return AlphaMode.Alpha; - } - - } - } - - public EyeMasterNode.AlphaModeEye GetAlphaModeLit(AlphaMode alphaMode) - { - switch (alphaMode) - { - case AlphaMode.Alpha: - return EyeMasterNode.AlphaModeEye.Alpha; - case AlphaMode.Premultiply: - return EyeMasterNode.AlphaModeEye.Premultiply; - case AlphaMode.Additive: - return EyeMasterNode.AlphaModeEye.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaMode); - return EyeMasterNode.AlphaModeEye.Alpha; - } - } - } - } -} +// void ChangeAlphaToMask(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); +// ToggleData td = m_Node.alphaToMask; +// td.isOn = evt.newValue; +// m_Node.alphaToMask = td; +// } + +// void ChangeAlphaTestPrepass(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Prepass Change"); +// ToggleData td = m_Node.alphaTestDepthPrepass; +// td.isOn = evt.newValue; +// m_Node.alphaTestDepthPrepass = td; +// } + +// void ChangeAlphaTestPostpass(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Postpass Change"); +// ToggleData td = m_Node.alphaTestDepthPostpass; +// td.isOn = evt.newValue; +// m_Node.alphaTestDepthPostpass = td; +// } + +// void ChangeDecal(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Decal Change"); +// ToggleData td = m_Node.receiveDecals; +// td.isOn = evt.newValue; +// m_Node.receiveDecals = td; +// } + +// void ChangeSSR(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); +// ToggleData td = m_Node.receiveSSR; +// td.isOn = evt.newValue; +// m_Node.receiveSSR = td; +// } + +// void ChangeAddPrecomputedVelocity(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); +// ToggleData td = m_Node.addPrecomputedVelocity; +// td.isOn = evt.newValue; +// m_Node.addPrecomputedVelocity = td; +// } + +// void ChangeSpecularOcclusionMode(ChangeEvent evt) +// { +// if (Equals(m_Node.specularOcclusionMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Specular Occlusion Mode Change"); +// m_Node.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; +// } + +// void ChangeoverrideBakedGI(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); +// ToggleData td = m_Node.overrideBakedGI; +// td.isOn = evt.newValue; +// m_Node.overrideBakedGI = td; +// } + +// void ChangeDepthOffset(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); +// ToggleData td = m_Node.depthOffset; +// td.isOn = evt.newValue; +// m_Node.depthOffset = td; +// } + +// void ChangeTransparentCullMode(ChangeEvent evt) +// { +// if (Equals(m_Node.transparentCullMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); +// m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; +// } + +// void ChangeZTest(ChangeEvent evt) +// { +// if (Equals(m_Node.zTest, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); +// m_Node.zTest = (CompareFunction)evt.newValue; +// } + +// void ChangeSupportLODCrossFade(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); +// ToggleData td = m_Node.supportLodCrossFade; +// td.isOn = evt.newValue; +// m_Node.supportLodCrossFade = td; +// } + +// public AlphaMode GetAlphaMode(EyeMasterNode.AlphaModeEye alphaModeLit) +// { +// switch (alphaModeLit) +// { +// case EyeMasterNode.AlphaModeEye.Alpha: +// return AlphaMode.Alpha; +// case EyeMasterNode.AlphaModeEye.Premultiply: +// return AlphaMode.Premultiply; +// case EyeMasterNode.AlphaModeEye.Additive: +// return AlphaMode.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaModeLit); +// return AlphaMode.Alpha; +// } + +// } +// } + +// public EyeMasterNode.AlphaModeEye GetAlphaModeLit(AlphaMode alphaMode) +// { +// switch (alphaMode) +// { +// case AlphaMode.Alpha: +// return EyeMasterNode.AlphaModeEye.Alpha; +// case AlphaMode.Premultiply: +// return EyeMasterNode.AlphaModeEye.Premultiply; +// case AlphaMode.Additive: +// return EyeMasterNode.AlphaModeEye.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaMode); +// return EyeMasterNode.AlphaModeEye.Alpha; +// } +// } +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/HDEyeSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/HDEyeSubTarget.cs index 56fbb0a4a68..949c414c2e7 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/HDEyeSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/HDEyeSubTarget.cs @@ -1,319 +1,319 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class HDEyeSubTarget : SubTarget - { - const string kAssetGuid = "864e4e09d6293cf4d98457f740bb3301"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; - - public HDEyeSubTarget() - { - displayName = "Eye"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.EyeGUI"); - context.AddSubShader(SubShaders.Eye); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Eye = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { EyePasses.ShadowCaster }, - { EyePasses.META }, - { EyePasses.SceneSelection }, - { EyePasses.DepthForwardOnly }, - { EyePasses.MotionVectors }, - { EyePasses.ForwardOnly }, - }, - }; - } -#endregion - -#region Passes - public static class EyePasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - pixelPorts = EyePortMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = EyeIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = EyePortMasks.Vertex, - pixelPorts = EyePortMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = EyeIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = EyePortMasks.Vertex, - pixelPorts = EyePortMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = EyeIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = EyePortMasks.Vertex, - pixelPorts = EyePortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = EyeIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = EyePortMasks.Vertex, - pixelPorts = EyePortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = EyeIncludes.MotionVectors, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = EyePortMasks.Vertex, - pixelPorts = EyePortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = EyeIncludes.ForwardOnly, - }; - } -#endregion - -#region PortMasks - static class EyePortMasks - { - public static int[] Vertex = new int[] - { - EyeMasterNode.PositionSlotId, - EyeMasterNode.VertexNormalSlotID, - EyeMasterNode.VertexTangentSlotID, - }; - - public static int[] FragmentMETA = new int[] - { - EyeMasterNode.AlbedoSlotId, - EyeMasterNode.SpecularOcclusionSlotId, - EyeMasterNode.NormalSlotId, - EyeMasterNode.IrisNormalSlotId, - EyeMasterNode.SmoothnessSlotId, - EyeMasterNode.IORSlotId, - EyeMasterNode.AmbientOcclusionSlotId, - EyeMasterNode.MaskSlotId, - EyeMasterNode.DiffusionProfileHashSlotId, - EyeMasterNode.SubsurfaceMaskSlotId, - EyeMasterNode.EmissionSlotId, - EyeMasterNode.AlphaSlotId, - EyeMasterNode.AlphaClipThresholdSlotId, - }; - - public static int[] FragmentAlphaDepth = new int[] - { - EyeMasterNode.AlphaSlotId, - EyeMasterNode.AlphaClipThresholdSlotId, - EyeMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentDepthMotionVectors = new int[] - { - EyeMasterNode.NormalSlotId, - EyeMasterNode.SmoothnessSlotId, - EyeMasterNode.AlphaSlotId, - EyeMasterNode.AlphaClipThresholdSlotId, - EyeMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentForward = new int[] - { - EyeMasterNode.AlbedoSlotId, - EyeMasterNode.SpecularOcclusionSlotId, - EyeMasterNode.NormalSlotId, - EyeMasterNode.IrisNormalSlotId, - EyeMasterNode.SmoothnessSlotId, - EyeMasterNode.IORSlotId, - EyeMasterNode.AmbientOcclusionSlotId, - EyeMasterNode.MaskSlotId, - EyeMasterNode.DiffusionProfileHashSlotId, - EyeMasterNode.SubsurfaceMaskSlotId, - EyeMasterNode.EmissionSlotId, - EyeMasterNode.AlphaSlotId, - EyeMasterNode.AlphaClipThresholdSlotId, - EyeMasterNode.LightingSlotId, - EyeMasterNode.BackLightingSlotId, - EyeMasterNode.DepthOffsetSlotId, - }; - } -#endregion - -#region Includes - static class EyeIncludes - { - const string kEye = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; - - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { kEye, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { kEye, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class HDEyeSubTarget : SubTarget +// { +// const string kAssetGuid = "864e4e09d6293cf4d98457f740bb3301"; +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; + +// public HDEyeSubTarget() +// { +// displayName = "Eye"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.EyeGUI"); +// context.AddSubShader(SubShaders.Eye); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Eye = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { EyePasses.ShadowCaster }, +// { EyePasses.META }, +// { EyePasses.SceneSelection }, +// { EyePasses.DepthForwardOnly }, +// { EyePasses.MotionVectors }, +// { EyePasses.ForwardOnly }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class EyePasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// pixelPorts = EyePortMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = EyeIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = EyePortMasks.Vertex, +// pixelPorts = EyePortMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = EyeIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = EyePortMasks.Vertex, +// pixelPorts = EyePortMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = EyeIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = EyePortMasks.Vertex, +// pixelPorts = EyePortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = EyeIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = EyePortMasks.Vertex, +// pixelPorts = EyePortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = EyeIncludes.MotionVectors, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = EyePortMasks.Vertex, +// pixelPorts = EyePortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = EyeIncludes.ForwardOnly, +// }; +// } +// #endregion + +// #region PortMasks +// static class EyePortMasks +// { +// public static int[] Vertex = new int[] +// { +// EyeMasterNode.PositionSlotId, +// EyeMasterNode.VertexNormalSlotID, +// EyeMasterNode.VertexTangentSlotID, +// }; + +// public static int[] FragmentMETA = new int[] +// { +// EyeMasterNode.AlbedoSlotId, +// EyeMasterNode.SpecularOcclusionSlotId, +// EyeMasterNode.NormalSlotId, +// EyeMasterNode.IrisNormalSlotId, +// EyeMasterNode.SmoothnessSlotId, +// EyeMasterNode.IORSlotId, +// EyeMasterNode.AmbientOcclusionSlotId, +// EyeMasterNode.MaskSlotId, +// EyeMasterNode.DiffusionProfileHashSlotId, +// EyeMasterNode.SubsurfaceMaskSlotId, +// EyeMasterNode.EmissionSlotId, +// EyeMasterNode.AlphaSlotId, +// EyeMasterNode.AlphaClipThresholdSlotId, +// }; + +// public static int[] FragmentAlphaDepth = new int[] +// { +// EyeMasterNode.AlphaSlotId, +// EyeMasterNode.AlphaClipThresholdSlotId, +// EyeMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentDepthMotionVectors = new int[] +// { +// EyeMasterNode.NormalSlotId, +// EyeMasterNode.SmoothnessSlotId, +// EyeMasterNode.AlphaSlotId, +// EyeMasterNode.AlphaClipThresholdSlotId, +// EyeMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentForward = new int[] +// { +// EyeMasterNode.AlbedoSlotId, +// EyeMasterNode.SpecularOcclusionSlotId, +// EyeMasterNode.NormalSlotId, +// EyeMasterNode.IrisNormalSlotId, +// EyeMasterNode.SmoothnessSlotId, +// EyeMasterNode.IORSlotId, +// EyeMasterNode.AmbientOcclusionSlotId, +// EyeMasterNode.MaskSlotId, +// EyeMasterNode.DiffusionProfileHashSlotId, +// EyeMasterNode.SubsurfaceMaskSlotId, +// EyeMasterNode.EmissionSlotId, +// EyeMasterNode.AlphaSlotId, +// EyeMasterNode.AlphaClipThresholdSlotId, +// EyeMasterNode.LightingSlotId, +// EyeMasterNode.BackLightingSlotId, +// EyeMasterNode.DepthOffsetSlotId, +// }; +// } +// #endregion + +// #region Includes +// static class EyeIncludes +// { +// const string kEye = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; + +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { kEye, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { kEye, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/CreateFabricShaderGraph.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/CreateFabricShaderGraph.cs deleted file mode 100644 index c9623bc80ea..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/CreateFabricShaderGraph.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition -{ - static class CreateFabricShaderGraph - { - [MenuItem("Assets/Create/Shader/HDRP/Fabric Graph", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new FabricMasterNode()); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricMasterNode.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricMasterNode.cs index 094fbfcb32a..f127480aac0 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricMasterNode.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricMasterNode.cs @@ -1,915 +1,915 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; -using UnityEditor.Rendering.HighDefinition.Drawing; -using UnityEditor.ShaderGraph.Internal; -using UnityEditor.Rendering.HighDefinition.ShaderGraph; - -// Include material common properties names -using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; - -namespace UnityEditor.Rendering.HighDefinition -{ - [Serializable] - [Title("Master", "Fabric (HDRP)")] - [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.FabricMasterNode")] - [FormerName("UnityEditor.ShaderGraph.FabricMasterNode")] - class FabricMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string PositionSlotName = "Vertex Position"; - public const string PositionSlotDisplayName = "Vertex Position"; - public const int PositionSlotId = 0; - - public const string AlbedoSlotName = "Albedo"; - public const string AlbedoDisplaySlotName = "BaseColor"; - public const int AlbedoSlotId = 1; - - public const string SpecularOcclusionSlotName = "SpecularOcclusion"; - public const int SpecularOcclusionSlotId = 2; - - public const string NormalSlotName = "Normal"; - public const int NormalSlotId = 3; - - public const string SmoothnessSlotName = "Smoothness"; - public const int SmoothnessSlotId = 4; - - public const string AmbientOcclusionSlotName = "Occlusion"; - public const string AmbientOcclusionDisplaySlotName = "AmbientOcclusion"; - public const int AmbientOcclusionSlotId = 5; - - public const string SpecularColorSlotName = "Specular"; - public const string SpecularColorDisplaySlotName = "SpecularColor"; - public const int SpecularColorSlotId = 6; - - public const string DiffusionProfileHashSlotName = "DiffusionProfileHash"; - public const string DiffusionProfileHashSlotDisplayName = "Diffusion Profile"; - public const int DiffusionProfileHashSlotId = 7; - - public const string SubsurfaceMaskSlotName = "SubsurfaceMask"; - public const int SubsurfaceMaskSlotId = 8; - - public const string ThicknessSlotName = "Thickness"; - public const int ThicknessSlotId = 9; - - public const string TangentSlotName = "Tangent"; - public const int TangentSlotId = 10; - - public const string AnisotropySlotName = "Anisotropy"; - public const int AnisotropySlotId = 11; - - public const string EmissionSlotName = "Emission"; - public const int EmissionSlotId = 12; - - public const string AlphaSlotName = "Alpha"; - public const int AlphaSlotId = 13; - - public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; - public const int AlphaClipThresholdSlotId = 14; - - public const string BentNormalSlotName = "BentNormal"; - public const int BentNormalSlotId = 15; - - public const int LightingSlotId = 16; - public const string BakedGISlotName = "BakedGI"; - - public const int BackLightingSlotId = 17; - public const string BakedBackGISlotName = "BakedBackGI"; - - public const int DepthOffsetSlotId = 18; - public const string DepthOffsetSlotName = "DepthOffset"; - public const int VertexNormalSlotId = 19; - public const string VertexNormalSlotName = "Vertex Normal"; - public const int VertexTangentSlotId = 20; - public const string VertexTangentSlotName = "Vertex Tangent"; - - public enum MaterialType - { - CottonWool, - Silk - } - - // Don't support Multiply - public enum AlphaModeFabric - { - Alpha, - Premultiply, - Additive, - } - - // Just for convenience of doing simple masks. We could run out of bits of course. - [Flags] - enum SlotMask - { - None = 0, - Position = 1 << PositionSlotId, - Albedo = 1 << AlbedoSlotId, - SpecularOcclusion = 1 << SpecularOcclusionSlotId, - Normal = 1 << NormalSlotId, - Smoothness = 1 << SmoothnessSlotId, - Occlusion = 1 << AmbientOcclusionSlotId, - Specular = 1 << SpecularColorSlotId, - DiffusionProfile = 1 << DiffusionProfileHashSlotId, - SubsurfaceMask = 1 << SubsurfaceMaskSlotId, - Thickness = 1 << ThicknessSlotId, - Tangent = 1 << TangentSlotId, - Anisotropy = 1 << AnisotropySlotId, - Emission = 1 << EmissionSlotId, - Alpha = 1 << AlphaSlotId, - AlphaClipThreshold = 1 << AlphaClipThresholdSlotId, - BentNormal = 1 << BentNormalSlotId, - BakedGI = 1 << LightingSlotId, - BakedBackGI = 1 << BackLightingSlotId, - DepthOffset = 1 << DepthOffsetSlotId, - VertexNormal = 1 << VertexNormalSlotId, - VertexTangent = 1 << VertexTangentSlotId, - } - - const SlotMask CottonWoolSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.SpecularOcclusion | SlotMask.Normal | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.Specular | SlotMask.DiffusionProfile | SlotMask.SubsurfaceMask | SlotMask.Thickness | SlotMask.Emission | SlotMask.Alpha | SlotMask.AlphaClipThreshold | SlotMask.BentNormal | SlotMask.BakedGI | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; - const SlotMask SilkSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.SpecularOcclusion | SlotMask.Normal | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.Specular | SlotMask.DiffusionProfile | SlotMask.SubsurfaceMask | SlotMask.Thickness | SlotMask.Tangent | SlotMask.Anisotropy | SlotMask.Emission | SlotMask.Alpha | SlotMask.AlphaClipThreshold | SlotMask.BentNormal | SlotMask.BakedGI | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; - - // This could also be a simple array. For now, catch any mismatched data. - SlotMask GetActiveSlotMask() - { - switch (materialType) - { - case MaterialType.CottonWool: - return CottonWoolSlotMask; - - case MaterialType.Silk: - return SilkSlotMask; - - default: - return SlotMask.None; - } - } - - bool MaterialTypeUsesSlotMask(SlotMask mask) - { - SlotMask activeMask = GetActiveSlotMask(); - return (activeMask & mask) != 0; - } - - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - AlphaMode m_AlphaMode; - - public AlphaMode alphaMode - { - get { return m_AlphaMode; } - set - { - if (m_AlphaMode == value) - return; - - m_AlphaMode = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_BlendPreserveSpecular = true; - - public ToggleData blendPreserveSpecular - { - get { return new ToggleData(m_BlendPreserveSpecular); } - set - { - if (m_BlendPreserveSpecular == value.isOn) - return; - m_BlendPreserveSpecular = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_TransparencyFog = true; - - public ToggleData transparencyFog - { - get { return new ToggleData(m_TransparencyFog); } - set - { - if (m_TransparencyFog == value.isOn) - return; - m_TransparencyFog = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaTest; - - public ToggleData alphaTest - { - get { return new ToggleData(m_AlphaTest); } - set - { - if (m_AlphaTest == value.isOn) - return; - m_AlphaTest = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } +// using System; +// using System.Linq; +// using System.Collections.Generic; +// using UnityEditor.Graphing; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; +// using UnityEditor.Rendering.HighDefinition.Drawing; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEditor.Rendering.HighDefinition.ShaderGraph; + +// // Include material common properties names +// using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; + +// namespace UnityEditor.Rendering.HighDefinition +// { +// [Serializable] +// [Title("Master", "Fabric (HDRP)")] +// [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.FabricMasterNode")] +// [FormerName("UnityEditor.ShaderGraph.FabricMasterNode")] +// class FabricMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent +// { +// public const string PositionSlotName = "Vertex Position"; +// public const string PositionSlotDisplayName = "Vertex Position"; +// public const int PositionSlotId = 0; + +// public const string AlbedoSlotName = "Albedo"; +// public const string AlbedoDisplaySlotName = "BaseColor"; +// public const int AlbedoSlotId = 1; + +// public const string SpecularOcclusionSlotName = "SpecularOcclusion"; +// public const int SpecularOcclusionSlotId = 2; + +// public const string NormalSlotName = "Normal"; +// public const int NormalSlotId = 3; + +// public const string SmoothnessSlotName = "Smoothness"; +// public const int SmoothnessSlotId = 4; + +// public const string AmbientOcclusionSlotName = "Occlusion"; +// public const string AmbientOcclusionDisplaySlotName = "AmbientOcclusion"; +// public const int AmbientOcclusionSlotId = 5; + +// public const string SpecularColorSlotName = "Specular"; +// public const string SpecularColorDisplaySlotName = "SpecularColor"; +// public const int SpecularColorSlotId = 6; + +// public const string DiffusionProfileHashSlotName = "DiffusionProfileHash"; +// public const string DiffusionProfileHashSlotDisplayName = "Diffusion Profile"; +// public const int DiffusionProfileHashSlotId = 7; + +// public const string SubsurfaceMaskSlotName = "SubsurfaceMask"; +// public const int SubsurfaceMaskSlotId = 8; + +// public const string ThicknessSlotName = "Thickness"; +// public const int ThicknessSlotId = 9; + +// public const string TangentSlotName = "Tangent"; +// public const int TangentSlotId = 10; + +// public const string AnisotropySlotName = "Anisotropy"; +// public const int AnisotropySlotId = 11; + +// public const string EmissionSlotName = "Emission"; +// public const int EmissionSlotId = 12; + +// public const string AlphaSlotName = "Alpha"; +// public const int AlphaSlotId = 13; + +// public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; +// public const int AlphaClipThresholdSlotId = 14; + +// public const string BentNormalSlotName = "BentNormal"; +// public const int BentNormalSlotId = 15; + +// public const int LightingSlotId = 16; +// public const string BakedGISlotName = "BakedGI"; + +// public const int BackLightingSlotId = 17; +// public const string BakedBackGISlotName = "BakedBackGI"; + +// public const int DepthOffsetSlotId = 18; +// public const string DepthOffsetSlotName = "DepthOffset"; +// public const int VertexNormalSlotId = 19; +// public const string VertexNormalSlotName = "Vertex Normal"; +// public const int VertexTangentSlotId = 20; +// public const string VertexTangentSlotName = "Vertex Tangent"; + +// public enum MaterialType +// { +// CottonWool, +// Silk +// } + +// // Don't support Multiply +// public enum AlphaModeFabric +// { +// Alpha, +// Premultiply, +// Additive, +// } + +// // Just for convenience of doing simple masks. We could run out of bits of course. +// [Flags] +// enum SlotMask +// { +// None = 0, +// Position = 1 << PositionSlotId, +// Albedo = 1 << AlbedoSlotId, +// SpecularOcclusion = 1 << SpecularOcclusionSlotId, +// Normal = 1 << NormalSlotId, +// Smoothness = 1 << SmoothnessSlotId, +// Occlusion = 1 << AmbientOcclusionSlotId, +// Specular = 1 << SpecularColorSlotId, +// DiffusionProfile = 1 << DiffusionProfileHashSlotId, +// SubsurfaceMask = 1 << SubsurfaceMaskSlotId, +// Thickness = 1 << ThicknessSlotId, +// Tangent = 1 << TangentSlotId, +// Anisotropy = 1 << AnisotropySlotId, +// Emission = 1 << EmissionSlotId, +// Alpha = 1 << AlphaSlotId, +// AlphaClipThreshold = 1 << AlphaClipThresholdSlotId, +// BentNormal = 1 << BentNormalSlotId, +// BakedGI = 1 << LightingSlotId, +// BakedBackGI = 1 << BackLightingSlotId, +// DepthOffset = 1 << DepthOffsetSlotId, +// VertexNormal = 1 << VertexNormalSlotId, +// VertexTangent = 1 << VertexTangentSlotId, +// } + +// const SlotMask CottonWoolSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.SpecularOcclusion | SlotMask.Normal | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.Specular | SlotMask.DiffusionProfile | SlotMask.SubsurfaceMask | SlotMask.Thickness | SlotMask.Emission | SlotMask.Alpha | SlotMask.AlphaClipThreshold | SlotMask.BentNormal | SlotMask.BakedGI | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; +// const SlotMask SilkSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.SpecularOcclusion | SlotMask.Normal | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.Specular | SlotMask.DiffusionProfile | SlotMask.SubsurfaceMask | SlotMask.Thickness | SlotMask.Tangent | SlotMask.Anisotropy | SlotMask.Emission | SlotMask.Alpha | SlotMask.AlphaClipThreshold | SlotMask.BentNormal | SlotMask.BakedGI | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; + +// // This could also be a simple array. For now, catch any mismatched data. +// SlotMask GetActiveSlotMask() +// { +// switch (materialType) +// { +// case MaterialType.CottonWool: +// return CottonWoolSlotMask; + +// case MaterialType.Silk: +// return SilkSlotMask; + +// default: +// return SlotMask.None; +// } +// } + +// bool MaterialTypeUsesSlotMask(SlotMask mask) +// { +// SlotMask activeMask = GetActiveSlotMask(); +// return (activeMask & mask) != 0; +// } + +// [SerializeField] +// SurfaceType m_SurfaceType; + +// public SurfaceType surfaceType +// { +// get { return m_SurfaceType; } +// set +// { +// if (m_SurfaceType == value) +// return; + +// m_SurfaceType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// AlphaMode m_AlphaMode; + +// public AlphaMode alphaMode +// { +// get { return m_AlphaMode; } +// set +// { +// if (m_AlphaMode == value) +// return; + +// m_AlphaMode = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_BlendPreserveSpecular = true; + +// public ToggleData blendPreserveSpecular +// { +// get { return new ToggleData(m_BlendPreserveSpecular); } +// set +// { +// if (m_BlendPreserveSpecular == value.isOn) +// return; +// m_BlendPreserveSpecular = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_TransparencyFog = true; + +// public ToggleData transparencyFog +// { +// get { return new ToggleData(m_TransparencyFog); } +// set +// { +// if (m_TransparencyFog == value.isOn) +// return; +// m_TransparencyFog = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaTest; + +// public ToggleData alphaTest +// { +// get { return new ToggleData(m_AlphaTest); } +// set +// { +// if (m_AlphaTest == value.isOn) +// return; +// m_AlphaTest = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } - [SerializeField] - bool m_AlphaToMask = false; - - public ToggleData alphaToMask - { - get { return new ToggleData(m_AlphaToMask); } - set - { - if (m_AlphaToMask == value.isOn) - return; - m_AlphaToMask = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_SortPriority; - - public int sortPriority - { - get { return m_SortPriority; } - set - { - if (m_SortPriority == value) - return; - m_SortPriority = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - DoubleSidedMode m_DoubleSidedMode; - - public DoubleSidedMode doubleSidedMode - { - get { return m_DoubleSidedMode; } - set - { - if (m_DoubleSidedMode == value) - return; - - m_DoubleSidedMode = value; - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - MaterialType m_MaterialType; - - public MaterialType materialType - { - get { return m_MaterialType; } - set - { - if (m_MaterialType == value) - return; - - m_MaterialType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ReceiveDecals = true; - - public ToggleData receiveDecals - { - get { return new ToggleData(m_ReceiveDecals); } - set - { - if (m_ReceiveDecals == value.isOn) - return; - m_ReceiveDecals = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_ReceivesSSR = true; - public ToggleData receiveSSR - { - get { return new ToggleData(m_ReceivesSSR); } - set - { - if (m_ReceivesSSR == value.isOn) - return; - m_ReceivesSSR = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AddPrecomputedVelocity = false; - - public ToggleData addPrecomputedVelocity - { - get { return new ToggleData(m_AddPrecomputedVelocity); } - set - { - if (m_AddPrecomputedVelocity == value.isOn) - return; - m_AddPrecomputedVelocity = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_EnergyConservingSpecular = true; - - public ToggleData energyConservingSpecular - { - get { return new ToggleData(m_EnergyConservingSpecular); } - set - { - if (m_EnergyConservingSpecular == value.isOn) - return; - m_EnergyConservingSpecular = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_Transmission = false; - - public ToggleData transmission - { - get { return new ToggleData(m_Transmission); } - set - { - if (m_Transmission == value.isOn) - return; - m_Transmission = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SubsurfaceScattering = false; - - public ToggleData subsurfaceScattering - { - get { return new ToggleData(m_SubsurfaceScattering); } - set - { - if (m_SubsurfaceScattering == value.isOn) - return; - m_SubsurfaceScattering = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - SpecularOcclusionMode m_SpecularOcclusionMode; - - public SpecularOcclusionMode specularOcclusionMode - { - get { return m_SpecularOcclusionMode; } - set - { - if (m_SpecularOcclusionMode == value) - return; - - m_SpecularOcclusionMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_overrideBakedGI; - - public ToggleData overrideBakedGI - { - get { return new ToggleData(m_overrideBakedGI); } - set - { - if (m_overrideBakedGI == value.isOn) - return; - m_overrideBakedGI = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_depthOffset; - - public ToggleData depthOffset - { - get { return new ToggleData(m_depthOffset); } - set - { - if (m_depthOffset == value.isOn) - return; - m_depthOffset = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ZWrite; - - public ToggleData zWrite - { - get { return new ToggleData(m_ZWrite); } - set - { - if (m_ZWrite == value.isOn) - return; - m_ZWrite = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; - public TransparentCullMode transparentCullMode - { - get => m_transparentCullMode; - set - { - if (m_transparentCullMode == value) - return; - - m_transparentCullMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - CompareFunction m_ZTest = CompareFunction.LessEqual; - public CompareFunction zTest - { - get => m_ZTest; - set - { - if (m_ZTest == value) - return; - - m_ZTest = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SupportLodCrossFade; - - public ToggleData supportLodCrossFade - { - get { return new ToggleData(m_SupportLodCrossFade); } - set - { - if (m_SupportLodCrossFade == value.isOn) - return; - m_SupportLodCrossFade = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Node); - } - } - - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_MaterialNeedsUpdateHash = 0; - - int ComputeMaterialNeedsUpdateHash() - { - int hash = 0; - - hash |= (alphaTest.isOn ? 0 : 1) << 0; - hash |= (receiveSSR.isOn ? 0 : 1) << 1; - hash |= (RequiresSplitLighting() ? 0 : 1) << 2; - - return hash; - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public FabricMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - public override string documentationURL - { - get { return null; } - } - - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Fabric Master"; - - List validSlots = new List(); - - // Position - if (MaterialTypeUsesSlotMask(SlotMask.Position)) - { - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(PositionSlotId); - } - - // Normal in Vertex - if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) - { - AddSlot(new NormalMaterialSlot(VertexNormalSlotId, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexNormalSlotId); - } - - // tangent in Vertex - if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) - { - AddSlot(new TangentMaterialSlot(VertexTangentSlotId, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexTangentSlotId); - } - - // Albedo - if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) - { - AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(AlbedoSlotId); - } - - // Specular Occlusion - if (MaterialTypeUsesSlotMask(SlotMask.SpecularOcclusion) && specularOcclusionMode == SpecularOcclusionMode.Custom) - { - AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularOcclusionSlotId); - } - - // Normal - if (MaterialTypeUsesSlotMask(SlotMask.Normal)) - { - AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(NormalSlotId); - } - - // BentNormal - if (MaterialTypeUsesSlotMask(SlotMask.BentNormal)) - { - AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(BentNormalSlotId); - } - - // Smoothness - if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) - { - AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(SmoothnessSlotId); - } - - // Ambient Occlusion - if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) - { - AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AmbientOcclusionSlotId); - } - - // Specular Color - if (MaterialTypeUsesSlotMask(SlotMask.Specular)) - { - AddSlot(new ColorRGBMaterialSlot(SpecularColorSlotId, SpecularColorDisplaySlotName, SpecularColorSlotName, SlotType.Input, new Color(0.2f,0.2f,0.2f,1.0f), ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularColorSlotId); - } - - // Diffusion Profile - if (MaterialTypeUsesSlotMask(SlotMask.DiffusionProfile) && (subsurfaceScattering.isOn || transmission.isOn)) - { - AddSlot(new DiffusionProfileInputMaterialSlot(DiffusionProfileHashSlotId, DiffusionProfileHashSlotDisplayName, DiffusionProfileHashSlotName, ShaderStageCapability.Fragment)); - validSlots.Add(DiffusionProfileHashSlotId); - } - - // Subsurface mask - if (MaterialTypeUsesSlotMask(SlotMask.SubsurfaceMask) && subsurfaceScattering.isOn) - { - AddSlot(new Vector1MaterialSlot(SubsurfaceMaskSlotId, SubsurfaceMaskSlotName, SubsurfaceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SubsurfaceMaskSlotId); - } - - // Thickness - if (MaterialTypeUsesSlotMask(SlotMask.Thickness) && transmission.isOn) - { - AddSlot(new Vector1MaterialSlot(ThicknessSlotId, ThicknessSlotName, ThicknessSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(ThicknessSlotId); - } - - // Tangent - if (MaterialTypeUsesSlotMask(SlotMask.Tangent)) - { - AddSlot(new TangentMaterialSlot(TangentSlotId, TangentSlotName, TangentSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(TangentSlotId); - } - - // Anisotropy - if (MaterialTypeUsesSlotMask(SlotMask.Anisotropy)) - { - AddSlot(new Vector1MaterialSlot(AnisotropySlotId, AnisotropySlotName, AnisotropySlotName, SlotType.Input, 0.8f, ShaderStageCapability.Fragment)); - validSlots.Add(AnisotropySlotId); - } - - // Emission Normal - if (MaterialTypeUsesSlotMask(SlotMask.Emission)) - { - AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); - validSlots.Add(EmissionSlotId); - } - - // Alpha - if (MaterialTypeUsesSlotMask(SlotMask.Alpha)) - { - AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaSlotId); - } - - // Alpha threshold - if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThreshold) && alphaTest.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaClipThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaClipThresholdSlotId); - } - - if (MaterialTypeUsesSlotMask(SlotMask.BakedGI) && overrideBakedGI.isOn) - { - AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(LightingSlotId); - AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(BackLightingSlotId); - } - - if (depthOffset.isOn) - { - AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(DepthOffsetSlotId); - } - - RemoveSlotsNameNotMatching(validSlots, true); - } - - public VisualElement CreateSettingsElement() - { - return new FabricSettingsView(this); - } - - public string renderQueueTag - { - get - { - var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); - return HDRenderQueue.GetShaderTagValue(queue); - } - } - - public string renderTypeTag => HDRenderTypeTags.HDLitShader.ToString(); - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); - - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || - IsSlotConnected(VertexNormalSlotId) || - IsSlotConnected(VertexTangentSlotId)), - new ConditionalField(Fields.GraphPixel, true), - new ConditionalField(Fields.LodCrossFade, supportLodCrossFade.isOn), - - // Surface Type - new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), - new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), - - // Structs - new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && - !pass.Equals(HDFabricSubTarget.FabricPasses.MotionVectors)), - // Material - new ConditionalField(HDFields.CottonWool, materialType == MaterialType.CottonWool), - new ConditionalField(HDFields.Silk, materialType == MaterialType.Silk), - new ConditionalField(HDFields.SubsurfaceScattering, subsurfaceScattering.isOn && surfaceType != SurfaceType.Transparent), - new ConditionalField(HDFields.Transmission, transmission.isOn), - - // Specular Occlusion - new ConditionalField(HDFields.SpecularOcclusionFromAO, specularOcclusionMode == SpecularOcclusionMode.FromAO), - new ConditionalField(HDFields.SpecularOcclusionFromAOBentNormal, specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal), - new ConditionalField(HDFields.SpecularOcclusionCustom, specularOcclusionMode == SpecularOcclusionMode.Custom), - - // Misc - new ConditionalField(Fields.AlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), - new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), - new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && alphaToMask.isOn), - new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), - new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), - new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), - new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), - new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), - new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && - pass.pixelPorts.Contains(BentNormalSlotId)), - new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && - (IsSlotConnected(AmbientOcclusionSlotId) || - ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), - new ConditionalField(HDFields.Tangent, IsSlotConnected(TangentSlotId) && - pass.pixelPorts.Contains(TangentSlotId)), - new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && - pass.pixelPorts.Contains(LightingSlotId)), - new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && - pass.pixelPorts.Contains(BackLightingSlotId)), - new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), - new ConditionalField(HDFields.EnergyConservingSpecular, energyConservingSpecular.isOn), - - }; - } - - public void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); - material.SetFloat(kDoubleSidedEnable, doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); - material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); - material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)zTest); - material.SetFloat(kTransparentCullMode, (int)transparentCullMode); - material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); - // No sorting priority for shader graph preview - var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); - - FabricGUI.SetupMaterialKeywordsAndPass(material); - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public bool RequiresSplitLighting() - { - return subsurfaceScattering.isOn; - } - public override object saveContext - { - get - { - int hash = ComputeMaterialNeedsUpdateHash(); - - bool needsUpdate = hash != m_MaterialNeedsUpdateHash; - - if (needsUpdate) - m_MaterialNeedsUpdateHash = hash; - - return new HDSaveContext{ updateMaterials = needsUpdate }; - } - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (addPrecomputedVelocity.isOn) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, RequiresSplitLighting(), receiveSSR.isOn); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - surfaceType, - HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), - sortPriority, - alphaToMask.isOn, - zWrite.isOn, - transparentCullMode, - zTest, - false, - transparencyFog.isOn - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, false); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); - - base.CollectShaderProperties(collector, generationMode); - } - } -} +// [SerializeField] +// bool m_AlphaToMask = false; + +// public ToggleData alphaToMask +// { +// get { return new ToggleData(m_AlphaToMask); } +// set +// { +// if (m_AlphaToMask == value.isOn) +// return; +// m_AlphaToMask = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_SortPriority; + +// public int sortPriority +// { +// get { return m_SortPriority; } +// set +// { +// if (m_SortPriority == value) +// return; +// m_SortPriority = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// DoubleSidedMode m_DoubleSidedMode; + +// public DoubleSidedMode doubleSidedMode +// { +// get { return m_DoubleSidedMode; } +// set +// { +// if (m_DoubleSidedMode == value) +// return; + +// m_DoubleSidedMode = value; +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// MaterialType m_MaterialType; + +// public MaterialType materialType +// { +// get { return m_MaterialType; } +// set +// { +// if (m_MaterialType == value) +// return; + +// m_MaterialType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ReceiveDecals = true; + +// public ToggleData receiveDecals +// { +// get { return new ToggleData(m_ReceiveDecals); } +// set +// { +// if (m_ReceiveDecals == value.isOn) +// return; +// m_ReceiveDecals = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_ReceivesSSR = true; +// public ToggleData receiveSSR +// { +// get { return new ToggleData(m_ReceivesSSR); } +// set +// { +// if (m_ReceivesSSR == value.isOn) +// return; +// m_ReceivesSSR = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AddPrecomputedVelocity = false; + +// public ToggleData addPrecomputedVelocity +// { +// get { return new ToggleData(m_AddPrecomputedVelocity); } +// set +// { +// if (m_AddPrecomputedVelocity == value.isOn) +// return; +// m_AddPrecomputedVelocity = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_EnergyConservingSpecular = true; + +// public ToggleData energyConservingSpecular +// { +// get { return new ToggleData(m_EnergyConservingSpecular); } +// set +// { +// if (m_EnergyConservingSpecular == value.isOn) +// return; +// m_EnergyConservingSpecular = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_Transmission = false; + +// public ToggleData transmission +// { +// get { return new ToggleData(m_Transmission); } +// set +// { +// if (m_Transmission == value.isOn) +// return; +// m_Transmission = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SubsurfaceScattering = false; + +// public ToggleData subsurfaceScattering +// { +// get { return new ToggleData(m_SubsurfaceScattering); } +// set +// { +// if (m_SubsurfaceScattering == value.isOn) +// return; +// m_SubsurfaceScattering = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// SpecularOcclusionMode m_SpecularOcclusionMode; + +// public SpecularOcclusionMode specularOcclusionMode +// { +// get { return m_SpecularOcclusionMode; } +// set +// { +// if (m_SpecularOcclusionMode == value) +// return; + +// m_SpecularOcclusionMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_overrideBakedGI; + +// public ToggleData overrideBakedGI +// { +// get { return new ToggleData(m_overrideBakedGI); } +// set +// { +// if (m_overrideBakedGI == value.isOn) +// return; +// m_overrideBakedGI = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_depthOffset; + +// public ToggleData depthOffset +// { +// get { return new ToggleData(m_depthOffset); } +// set +// { +// if (m_depthOffset == value.isOn) +// return; +// m_depthOffset = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ZWrite; + +// public ToggleData zWrite +// { +// get { return new ToggleData(m_ZWrite); } +// set +// { +// if (m_ZWrite == value.isOn) +// return; +// m_ZWrite = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; +// public TransparentCullMode transparentCullMode +// { +// get => m_transparentCullMode; +// set +// { +// if (m_transparentCullMode == value) +// return; + +// m_transparentCullMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// CompareFunction m_ZTest = CompareFunction.LessEqual; +// public CompareFunction zTest +// { +// get => m_ZTest; +// set +// { +// if (m_ZTest == value) +// return; + +// m_ZTest = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SupportLodCrossFade; + +// public ToggleData supportLodCrossFade +// { +// get { return new ToggleData(m_SupportLodCrossFade); } +// set +// { +// if (m_SupportLodCrossFade == value.isOn) +// return; +// m_SupportLodCrossFade = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Node); +// } +// } + +// [SerializeField] +// bool m_DOTSInstancing = false; + +// public ToggleData dotsInstancing +// { +// get { return new ToggleData(m_DOTSInstancing); } +// set +// { +// if (m_DOTSInstancing == value.isOn) +// return; + +// m_DOTSInstancing = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_MaterialNeedsUpdateHash = 0; + +// int ComputeMaterialNeedsUpdateHash() +// { +// int hash = 0; + +// hash |= (alphaTest.isOn ? 0 : 1) << 0; +// hash |= (receiveSSR.isOn ? 0 : 1) << 1; +// hash |= (RequiresSplitLighting() ? 0 : 1) << 2; + +// return hash; +// } + +// [SerializeField] private string m_ShaderGUIOverride; +// public string ShaderGUIOverride +// { +// get => m_ShaderGUIOverride; +// set => m_ShaderGUIOverride = value; +// } + +// [SerializeField] private bool m_OverrideEnabled; +// public bool OverrideEnabled +// { +// get => m_OverrideEnabled; +// set => m_OverrideEnabled = value; +// } + +// public FabricMasterNode() +// { +// UpdateNodeAfterDeserialization(); +// } + +// public override string documentationURL +// { +// get { return null; } +// } + + +// public sealed override void UpdateNodeAfterDeserialization() +// { +// base.UpdateNodeAfterDeserialization(); +// name = "Fabric Master"; + +// List validSlots = new List(); + +// // Position +// if (MaterialTypeUsesSlotMask(SlotMask.Position)) +// { +// AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(PositionSlotId); +// } + +// // Normal in Vertex +// if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) +// { +// AddSlot(new NormalMaterialSlot(VertexNormalSlotId, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexNormalSlotId); +// } + +// // tangent in Vertex +// if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) +// { +// AddSlot(new TangentMaterialSlot(VertexTangentSlotId, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexTangentSlotId); +// } + +// // Albedo +// if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) +// { +// AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(AlbedoSlotId); +// } + +// // Specular Occlusion +// if (MaterialTypeUsesSlotMask(SlotMask.SpecularOcclusion) && specularOcclusionMode == SpecularOcclusionMode.Custom) +// { +// AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularOcclusionSlotId); +// } + +// // Normal +// if (MaterialTypeUsesSlotMask(SlotMask.Normal)) +// { +// AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(NormalSlotId); +// } + +// // BentNormal +// if (MaterialTypeUsesSlotMask(SlotMask.BentNormal)) +// { +// AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(BentNormalSlotId); +// } + +// // Smoothness +// if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) +// { +// AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(SmoothnessSlotId); +// } + +// // Ambient Occlusion +// if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) +// { +// AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AmbientOcclusionSlotId); +// } + +// // Specular Color +// if (MaterialTypeUsesSlotMask(SlotMask.Specular)) +// { +// AddSlot(new ColorRGBMaterialSlot(SpecularColorSlotId, SpecularColorDisplaySlotName, SpecularColorSlotName, SlotType.Input, new Color(0.2f,0.2f,0.2f,1.0f), ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularColorSlotId); +// } + +// // Diffusion Profile +// if (MaterialTypeUsesSlotMask(SlotMask.DiffusionProfile) && (subsurfaceScattering.isOn || transmission.isOn)) +// { +// AddSlot(new DiffusionProfileInputMaterialSlot(DiffusionProfileHashSlotId, DiffusionProfileHashSlotDisplayName, DiffusionProfileHashSlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(DiffusionProfileHashSlotId); +// } + +// // Subsurface mask +// if (MaterialTypeUsesSlotMask(SlotMask.SubsurfaceMask) && subsurfaceScattering.isOn) +// { +// AddSlot(new Vector1MaterialSlot(SubsurfaceMaskSlotId, SubsurfaceMaskSlotName, SubsurfaceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SubsurfaceMaskSlotId); +// } + +// // Thickness +// if (MaterialTypeUsesSlotMask(SlotMask.Thickness) && transmission.isOn) +// { +// AddSlot(new Vector1MaterialSlot(ThicknessSlotId, ThicknessSlotName, ThicknessSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(ThicknessSlotId); +// } + +// // Tangent +// if (MaterialTypeUsesSlotMask(SlotMask.Tangent)) +// { +// AddSlot(new TangentMaterialSlot(TangentSlotId, TangentSlotName, TangentSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(TangentSlotId); +// } + +// // Anisotropy +// if (MaterialTypeUsesSlotMask(SlotMask.Anisotropy)) +// { +// AddSlot(new Vector1MaterialSlot(AnisotropySlotId, AnisotropySlotName, AnisotropySlotName, SlotType.Input, 0.8f, ShaderStageCapability.Fragment)); +// validSlots.Add(AnisotropySlotId); +// } + +// // Emission Normal +// if (MaterialTypeUsesSlotMask(SlotMask.Emission)) +// { +// AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); +// validSlots.Add(EmissionSlotId); +// } + +// // Alpha +// if (MaterialTypeUsesSlotMask(SlotMask.Alpha)) +// { +// AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaSlotId); +// } + +// // Alpha threshold +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThreshold) && alphaTest.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaClipThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaClipThresholdSlotId); +// } + +// if (MaterialTypeUsesSlotMask(SlotMask.BakedGI) && overrideBakedGI.isOn) +// { +// AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(LightingSlotId); +// AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(BackLightingSlotId); +// } + +// if (depthOffset.isOn) +// { +// AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(DepthOffsetSlotId); +// } + +// RemoveSlotsNameNotMatching(validSlots, true); +// } + +// public VisualElement CreateSettingsElement() +// { +// return new FabricSettingsView(this); +// } + +// public string renderQueueTag +// { +// get +// { +// var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; +// int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); +// return HDRenderQueue.GetShaderTagValue(queue); +// } +// } + +// public string renderTypeTag => HDRenderTypeTags.HDLitShader.ToString(); + +// public ConditionalField[] GetConditionalFields(PassDescriptor pass) +// { +// var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); + +// return new ConditionalField[] +// { +// // Features +// new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || +// IsSlotConnected(VertexNormalSlotId) || +// IsSlotConnected(VertexTangentSlotId)), +// new ConditionalField(Fields.GraphPixel, true), +// new ConditionalField(Fields.LodCrossFade, supportLodCrossFade.isOn), + +// // Surface Type +// new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), +// new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), + +// // Structs +// new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && +// !pass.Equals(HDFabricSubTarget.FabricPasses.MotionVectors)), +// // Material +// new ConditionalField(HDFields.CottonWool, materialType == MaterialType.CottonWool), +// new ConditionalField(HDFields.Silk, materialType == MaterialType.Silk), +// new ConditionalField(HDFields.SubsurfaceScattering, subsurfaceScattering.isOn && surfaceType != SurfaceType.Transparent), +// new ConditionalField(HDFields.Transmission, transmission.isOn), + +// // Specular Occlusion +// new ConditionalField(HDFields.SpecularOcclusionFromAO, specularOcclusionMode == SpecularOcclusionMode.FromAO), +// new ConditionalField(HDFields.SpecularOcclusionFromAOBentNormal, specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal), +// new ConditionalField(HDFields.SpecularOcclusionCustom, specularOcclusionMode == SpecularOcclusionMode.Custom), + +// // Misc +// new ConditionalField(Fields.AlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), +// new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), +// new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && alphaToMask.isOn), +// new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), +// new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), +// new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), +// new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), +// new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), +// new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && +// pass.pixelPorts.Contains(BentNormalSlotId)), +// new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && +// (IsSlotConnected(AmbientOcclusionSlotId) || +// ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), +// new ConditionalField(HDFields.Tangent, IsSlotConnected(TangentSlotId) && +// pass.pixelPorts.Contains(TangentSlotId)), +// new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && +// pass.pixelPorts.Contains(LightingSlotId)), +// new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && +// pass.pixelPorts.Contains(BackLightingSlotId)), +// new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), +// new ConditionalField(HDFields.EnergyConservingSpecular, energyConservingSpecular.isOn), + +// }; +// } + +// public void ProcessPreviewMaterial(Material material) +// { +// // Fixup the material settings: +// material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); +// material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); +// material.SetFloat(kDoubleSidedEnable, doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); +// material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); +// material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); +// material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); +// material.SetFloat(kZTestTransparent, (int)zTest); +// material.SetFloat(kTransparentCullMode, (int)transparentCullMode); +// material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); +// // No sorting priority for shader graph preview +// var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; +// material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); + +// FabricGUI.SetupMaterialKeywordsAndPass(material); +// } + +// public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); +// } + +// public bool RequiresSplitLighting() +// { +// return subsurfaceScattering.isOn; +// } +// public override object saveContext +// { +// get +// { +// int hash = ComputeMaterialNeedsUpdateHash(); + +// bool needsUpdate = hash != m_MaterialNeedsUpdateHash; + +// if (needsUpdate) +// m_MaterialNeedsUpdateHash = hash; + +// return new HDSaveContext{ updateMaterials = needsUpdate }; +// } +// } + +// public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) +// { +// // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. +// // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 +// // The user will then need to explicitly disable emissive GI if it is not needed. +// // To be able to automatically disable emission based on the ShaderGraph config when emission is black, +// // we will need a more general way to communicate this to the engine (not directly tied to a material property). +// collector.AddShaderProperty(new ColorShaderProperty() +// { +// overrideReferenceName = "_EmissionColor", +// hidden = true, +// value = new Color(1.0f, 1.0f, 1.0f, 1.0f) +// }); + +// //See SG-ADDITIONALVELOCITY-NOTE +// if (addPrecomputedVelocity.isOn) +// { +// collector.AddShaderProperty(new BooleanShaderProperty +// { +// value = true, +// hidden = true, +// overrideReferenceName = kAddPrecomputedVelocity, +// }); +// } + +// // Add all shader properties required by the inspector +// HDSubShaderUtilities.AddStencilShaderProperties(collector, RequiresSplitLighting(), receiveSSR.isOn); +// HDSubShaderUtilities.AddBlendingStatesShaderProperties( +// collector, +// surfaceType, +// HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), +// sortPriority, +// alphaToMask.isOn, +// zWrite.isOn, +// transparentCullMode, +// zTest, +// false, +// transparencyFog.isOn +// ); +// HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, false); +// HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); + +// base.CollectShaderProperties(collector, generationMode); +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs index b3f07f59c12..8ce19876128 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs @@ -1,474 +1,474 @@ -using System; -using UnityEditor.UIElements; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; - -namespace UnityEditor.Rendering.HighDefinition.Drawing -{ - class FabricSettingsView : MasterNodeSettingsView - { - FabricMasterNode m_Node; - - IntegerField m_SortPiorityField; - - Label CreateLabel(string text, int indentLevel) - { - string label = ""; - for (var i = 0; i < indentLevel; i++) - { - label += " "; - } - return new Label(label + text); - } - - public FabricSettingsView(FabricMasterNode node) : base(node) - { - m_Node = node; - PropertySheet ps = new PropertySheet(); - - int indentLevel = 0; - ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => - { - row.Add(new EnumField(SurfaceType.Opaque), (field) => - { - field.value = m_Node.surfaceType; - field.RegisterValueChangedCallback(ChangeSurfaceType); - }); - }); - - if (m_Node.surfaceType == SurfaceType.Transparent) - { - ++indentLevel; - - ps.Add(new PropertyRow(CreateLabel("Blend Preserves Specular", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.blendPreserveSpecular.isOn; - toggle.OnToggleChanged(ChangeBlendPreserveSpecular); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Fog", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transparencyFog.isOn; - toggle.OnToggleChanged(ChangeTransparencyFog); - }); - }); - - m_SortPiorityField = new IntegerField(); - ps.Add(new PropertyRow(CreateLabel("Sort Priority", indentLevel)), (row) => - { - row.Add(m_SortPiorityField, (field) => - { - field.value = m_Node.sortPriority; - field.RegisterValueChangedCallback(ChangeSortPriority); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.zWrite.isOn; - toggle.OnToggleChanged(ChangeZWrite); - }); - }); - - if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) - { - ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.transparentCullMode), (e) => - { - e.value = m_Node.transparentCullMode; - e.RegisterValueChangedCallback(ChangeTransparentCullMode); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.zTest), (e) => - { - e.value = m_Node.zTest; - e.RegisterValueChangedCallback(ChangeZTest); - }); - }); - - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTest.isOn; - toggle.OnToggleChanged(ChangeAlphaTest); - }); - }); - - if (m_Node.alphaTest.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaToMask.isOn; - toggle.OnToggleChanged(ChangeAlphaToMask); - }); - }); - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => - { - row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => - { - field.value = m_Node.doubleSidedMode; - field.RegisterValueChangedCallback(ChangeDoubleSidedMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Energy Conserving Specular", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.energyConservingSpecular.isOn; - toggle.OnToggleChanged(ChangeEnergyConservingSpecular); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Material Type", indentLevel)), (row) => - { - row.Add(new EnumField(FabricMasterNode.MaterialType.CottonWool), (field) => - { - field.value = m_Node.materialType; - field.RegisterValueChangedCallback(ChangeMaterialType); - }); - }); - - if (m_Node.surfaceType != SurfaceType.Transparent) - { - ps.Add(new PropertyRow(CreateLabel("Subsurface Scattering", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.subsurfaceScattering.isOn; - toggle.OnToggleChanged(ChangeSubsurfaceScattering); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Transmission", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transmission.isOn; - toggle.OnToggleChanged(ChangeTransmission); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveDecals.isOn; - toggle.OnToggleChanged(ChangeDecal); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveSSR.isOn; - toggle.OnToggleChanged(ChangeSSR); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.addPrecomputedVelocity.isOn; - toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => - { - row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => - { - field.value = m_Node.specularOcclusionMode; - field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.overrideBakedGI.isOn; - toggle.OnToggleChanged(ChangeoverrideBakedGI); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.depthOffset.isOn; - toggle.OnToggleChanged(ChangeDepthOffset); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.supportLodCrossFade.isOn; - toggle.OnToggleChanged(ChangeSupportLODCrossFade); - }); - }); - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeSurfaceType(ChangeEvent evt) - { - if (Equals(m_Node.surfaceType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); - m_Node.surfaceType = (SurfaceType)evt.newValue; - } - - void ChangeDoubleSidedMode(ChangeEvent evt) - { - if (Equals(m_Node.doubleSidedMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); - m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; - } - - void ChangeMaterialType(ChangeEvent evt) - { - if (Equals(m_Node.materialType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Material Type Change"); - m_Node.materialType = (FabricMasterNode.MaterialType)evt.newValue; - } - - void ChangeTransmission(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transmission Change"); - ToggleData td = m_Node.transmission; - td.isOn = evt.newValue; - m_Node.transmission = td; - } - - void ChangeSubsurfaceScattering(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SSS Change"); - ToggleData td = m_Node.subsurfaceScattering; - td.isOn = evt.newValue; - m_Node.subsurfaceScattering = td; - } - - void ChangeBlendMode(ChangeEvent evt) - { - // Make sure the mapping is correct by handling each case. - AlphaMode alphaMode = GetAlphaMode((FabricMasterNode.AlphaModeFabric)evt.newValue); - - if (Equals(m_Node.alphaMode, alphaMode)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); - m_Node.alphaMode = alphaMode; - } - - void ChangeBlendPreserveSpecular(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); - ToggleData td = m_Node.blendPreserveSpecular; - td.isOn = evt.newValue; - m_Node.blendPreserveSpecular = td; - } - - void ChangeTransparencyFog(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); - ToggleData td = m_Node.transparencyFog; - td.isOn = evt.newValue; - m_Node.transparencyFog = td; - } - - void ChangeSortPriority(ChangeEvent evt) - { - m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - // Force the text to match. - m_SortPiorityField.value = m_Node.sortPriority; - if (Equals(m_Node.sortPriority, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); - } - - void ChangeZWrite(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); - ToggleData td = m_Node.zWrite; - td.isOn = evt.newValue; - m_Node.zWrite = td; - } - - void ChangeAlphaTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); - ToggleData td = m_Node.alphaTest; - td.isOn = evt.newValue; - m_Node.alphaTest = td; - } - - void ChangeAlphaToMask(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); - ToggleData td = m_Node.alphaToMask; - td.isOn = evt.newValue; - m_Node.alphaToMask = td; - } - - void ChangeDecal(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Decal Change"); - ToggleData td = m_Node.receiveDecals; - td.isOn = evt.newValue; - m_Node.receiveDecals = td; - } - - void ChangeSSR(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); - ToggleData td = m_Node.receiveSSR; - td.isOn = evt.newValue; - m_Node.receiveSSR = td; - } - - void ChangeAddPrecomputedVelocity(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); - ToggleData td = m_Node.addPrecomputedVelocity; - td.isOn = evt.newValue; - m_Node.addPrecomputedVelocity = td; - } - - void ChangeEnergyConservingSpecular(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Energy Conserving Specular Change"); - ToggleData td = m_Node.energyConservingSpecular; - td.isOn = evt.newValue; - m_Node.energyConservingSpecular = td; - } - - void ChangeSpecularOcclusionMode(ChangeEvent evt) - { - if (Equals(m_Node.specularOcclusionMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Specular Occlusion Mode Change"); - m_Node.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; - } - - void ChangeoverrideBakedGI(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); - ToggleData td = m_Node.overrideBakedGI; - td.isOn = evt.newValue; - m_Node.overrideBakedGI = td; - } - - void ChangeDepthOffset(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); - ToggleData td = m_Node.depthOffset; - td.isOn = evt.newValue; - m_Node.depthOffset = td; - } - - void ChangeTransparentCullMode(ChangeEvent evt) - { - if (Equals(m_Node.transparentCullMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); - m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; - } - - void ChangeZTest(ChangeEvent evt) - { - if (Equals(m_Node.zTest, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); - m_Node.zTest = (CompareFunction)evt.newValue; - } - - void ChangeSupportLODCrossFade(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); - ToggleData td = m_Node.supportLodCrossFade; - td.isOn = evt.newValue; - m_Node.supportLodCrossFade = td; - } - - public AlphaMode GetAlphaMode(FabricMasterNode.AlphaModeFabric alphaModeLit) - { - switch (alphaModeLit) - { - case FabricMasterNode.AlphaModeFabric.Alpha: - return AlphaMode.Alpha; - case FabricMasterNode.AlphaModeFabric.Premultiply: - return AlphaMode.Premultiply; - case FabricMasterNode.AlphaModeFabric.Additive: - return AlphaMode.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaModeLit); - return AlphaMode.Alpha; - } - - } - } - - public FabricMasterNode.AlphaModeFabric GetAlphaModeLit(AlphaMode alphaMode) - { - switch (alphaMode) - { - case AlphaMode.Alpha: - return FabricMasterNode.AlphaModeFabric.Alpha; - case AlphaMode.Premultiply: - return FabricMasterNode.AlphaModeFabric.Premultiply; - case AlphaMode.Additive: - return FabricMasterNode.AlphaModeFabric.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaMode); - return FabricMasterNode.AlphaModeFabric.Alpha; - } - } - } - } -} +// using System; +// using UnityEditor.UIElements; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEditor.Graphing.Util; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; + +// namespace UnityEditor.Rendering.HighDefinition.Drawing +// { +// class FabricSettingsView : MasterNodeSettingsView +// { +// FabricMasterNode m_Node; + +// IntegerField m_SortPiorityField; + +// Label CreateLabel(string text, int indentLevel) +// { +// string label = ""; +// for (var i = 0; i < indentLevel; i++) +// { +// label += " "; +// } +// return new Label(label + text); +// } + +// public FabricSettingsView(FabricMasterNode node) : base(node) +// { +// m_Node = node; +// PropertySheet ps = new PropertySheet(); + +// int indentLevel = 0; +// ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(SurfaceType.Opaque), (field) => +// { +// field.value = m_Node.surfaceType; +// field.RegisterValueChangedCallback(ChangeSurfaceType); +// }); +// }); + +// if (m_Node.surfaceType == SurfaceType.Transparent) +// { +// ++indentLevel; + +// ps.Add(new PropertyRow(CreateLabel("Blend Preserves Specular", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.blendPreserveSpecular.isOn; +// toggle.OnToggleChanged(ChangeBlendPreserveSpecular); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Fog", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transparencyFog.isOn; +// toggle.OnToggleChanged(ChangeTransparencyFog); +// }); +// }); + +// m_SortPiorityField = new IntegerField(); +// ps.Add(new PropertyRow(CreateLabel("Sort Priority", indentLevel)), (row) => +// { +// row.Add(m_SortPiorityField, (field) => +// { +// field.value = m_Node.sortPriority; +// field.RegisterValueChangedCallback(ChangeSortPriority); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.zWrite.isOn; +// toggle.OnToggleChanged(ChangeZWrite); +// }); +// }); + +// if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) +// { +// ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.transparentCullMode), (e) => +// { +// e.value = m_Node.transparentCullMode; +// e.RegisterValueChangedCallback(ChangeTransparentCullMode); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.zTest), (e) => +// { +// e.value = m_Node.zTest; +// e.RegisterValueChangedCallback(ChangeZTest); +// }); +// }); + +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTest.isOn; +// toggle.OnToggleChanged(ChangeAlphaTest); +// }); +// }); + +// if (m_Node.alphaTest.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaToMask.isOn; +// toggle.OnToggleChanged(ChangeAlphaToMask); +// }); +// }); +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => +// { +// row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => +// { +// field.value = m_Node.doubleSidedMode; +// field.RegisterValueChangedCallback(ChangeDoubleSidedMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Energy Conserving Specular", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.energyConservingSpecular.isOn; +// toggle.OnToggleChanged(ChangeEnergyConservingSpecular); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Material Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(FabricMasterNode.MaterialType.CottonWool), (field) => +// { +// field.value = m_Node.materialType; +// field.RegisterValueChangedCallback(ChangeMaterialType); +// }); +// }); + +// if (m_Node.surfaceType != SurfaceType.Transparent) +// { +// ps.Add(new PropertyRow(CreateLabel("Subsurface Scattering", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.subsurfaceScattering.isOn; +// toggle.OnToggleChanged(ChangeSubsurfaceScattering); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Transmission", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transmission.isOn; +// toggle.OnToggleChanged(ChangeTransmission); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveDecals.isOn; +// toggle.OnToggleChanged(ChangeDecal); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveSSR.isOn; +// toggle.OnToggleChanged(ChangeSSR); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.addPrecomputedVelocity.isOn; +// toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => +// { +// field.value = m_Node.specularOcclusionMode; +// field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.overrideBakedGI.isOn; +// toggle.OnToggleChanged(ChangeoverrideBakedGI); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.depthOffset.isOn; +// toggle.OnToggleChanged(ChangeDepthOffset); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.supportLodCrossFade.isOn; +// toggle.OnToggleChanged(ChangeSupportLODCrossFade); +// }); +// }); + +// Add(ps); +// Add(GetShaderGUIOverridePropertySheet()); +// } + +// void ChangeSurfaceType(ChangeEvent evt) +// { +// if (Equals(m_Node.surfaceType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); +// m_Node.surfaceType = (SurfaceType)evt.newValue; +// } + +// void ChangeDoubleSidedMode(ChangeEvent evt) +// { +// if (Equals(m_Node.doubleSidedMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); +// m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; +// } + +// void ChangeMaterialType(ChangeEvent evt) +// { +// if (Equals(m_Node.materialType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Material Type Change"); +// m_Node.materialType = (FabricMasterNode.MaterialType)evt.newValue; +// } + +// void ChangeTransmission(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transmission Change"); +// ToggleData td = m_Node.transmission; +// td.isOn = evt.newValue; +// m_Node.transmission = td; +// } + +// void ChangeSubsurfaceScattering(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SSS Change"); +// ToggleData td = m_Node.subsurfaceScattering; +// td.isOn = evt.newValue; +// m_Node.subsurfaceScattering = td; +// } + +// void ChangeBlendMode(ChangeEvent evt) +// { +// // Make sure the mapping is correct by handling each case. +// AlphaMode alphaMode = GetAlphaMode((FabricMasterNode.AlphaModeFabric)evt.newValue); + +// if (Equals(m_Node.alphaMode, alphaMode)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); +// m_Node.alphaMode = alphaMode; +// } + +// void ChangeBlendPreserveSpecular(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); +// ToggleData td = m_Node.blendPreserveSpecular; +// td.isOn = evt.newValue; +// m_Node.blendPreserveSpecular = td; +// } + +// void ChangeTransparencyFog(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); +// ToggleData td = m_Node.transparencyFog; +// td.isOn = evt.newValue; +// m_Node.transparencyFog = td; +// } + +// void ChangeSortPriority(ChangeEvent evt) +// { +// m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); +// // Force the text to match. +// m_SortPiorityField.value = m_Node.sortPriority; +// if (Equals(m_Node.sortPriority, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); +// } + +// void ChangeZWrite(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); +// ToggleData td = m_Node.zWrite; +// td.isOn = evt.newValue; +// m_Node.zWrite = td; +// } + +// void ChangeAlphaTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); +// ToggleData td = m_Node.alphaTest; +// td.isOn = evt.newValue; +// m_Node.alphaTest = td; +// } + +// void ChangeAlphaToMask(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); +// ToggleData td = m_Node.alphaToMask; +// td.isOn = evt.newValue; +// m_Node.alphaToMask = td; +// } + +// void ChangeDecal(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Decal Change"); +// ToggleData td = m_Node.receiveDecals; +// td.isOn = evt.newValue; +// m_Node.receiveDecals = td; +// } + +// void ChangeSSR(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); +// ToggleData td = m_Node.receiveSSR; +// td.isOn = evt.newValue; +// m_Node.receiveSSR = td; +// } + +// void ChangeAddPrecomputedVelocity(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); +// ToggleData td = m_Node.addPrecomputedVelocity; +// td.isOn = evt.newValue; +// m_Node.addPrecomputedVelocity = td; +// } + +// void ChangeEnergyConservingSpecular(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Energy Conserving Specular Change"); +// ToggleData td = m_Node.energyConservingSpecular; +// td.isOn = evt.newValue; +// m_Node.energyConservingSpecular = td; +// } + +// void ChangeSpecularOcclusionMode(ChangeEvent evt) +// { +// if (Equals(m_Node.specularOcclusionMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Specular Occlusion Mode Change"); +// m_Node.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; +// } + +// void ChangeoverrideBakedGI(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); +// ToggleData td = m_Node.overrideBakedGI; +// td.isOn = evt.newValue; +// m_Node.overrideBakedGI = td; +// } + +// void ChangeDepthOffset(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); +// ToggleData td = m_Node.depthOffset; +// td.isOn = evt.newValue; +// m_Node.depthOffset = td; +// } + +// void ChangeTransparentCullMode(ChangeEvent evt) +// { +// if (Equals(m_Node.transparentCullMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); +// m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; +// } + +// void ChangeZTest(ChangeEvent evt) +// { +// if (Equals(m_Node.zTest, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); +// m_Node.zTest = (CompareFunction)evt.newValue; +// } + +// void ChangeSupportLODCrossFade(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); +// ToggleData td = m_Node.supportLodCrossFade; +// td.isOn = evt.newValue; +// m_Node.supportLodCrossFade = td; +// } + +// public AlphaMode GetAlphaMode(FabricMasterNode.AlphaModeFabric alphaModeLit) +// { +// switch (alphaModeLit) +// { +// case FabricMasterNode.AlphaModeFabric.Alpha: +// return AlphaMode.Alpha; +// case FabricMasterNode.AlphaModeFabric.Premultiply: +// return AlphaMode.Premultiply; +// case FabricMasterNode.AlphaModeFabric.Additive: +// return AlphaMode.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaModeLit); +// return AlphaMode.Alpha; +// } + +// } +// } + +// public FabricMasterNode.AlphaModeFabric GetAlphaModeLit(AlphaMode alphaMode) +// { +// switch (alphaMode) +// { +// case AlphaMode.Alpha: +// return FabricMasterNode.AlphaModeFabric.Alpha; +// case AlphaMode.Premultiply: +// return FabricMasterNode.AlphaModeFabric.Premultiply; +// case AlphaMode.Additive: +// return FabricMasterNode.AlphaModeFabric.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaMode); +// return FabricMasterNode.AlphaModeFabric.Alpha; +// } +// } +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/HDFabricSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/HDFabricSubTarget.cs index 45a75ea3669..43b18cabea2 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/HDFabricSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/HDFabricSubTarget.cs @@ -1,482 +1,482 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class HDFabricSubTarget : SubTarget - { - const string kAssetGuid = "74f1a4749bab90d429ac01d094be0aeb"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; - - public HDFabricSubTarget() - { - displayName = "Fabric"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.FabricGUI"); - context.AddSubShader(SubShaders.Fabric); - context.AddSubShader(SubShaders.FabricRaytracing); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Fabric = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { FabricPasses.ShadowCaster }, - { FabricPasses.META }, - { FabricPasses.SceneSelection }, - { FabricPasses.DepthForwardOnly }, - { FabricPasses.MotionVectors }, - { FabricPasses.ForwardOnly }, - }, - }; - - public static SubShaderDescriptor FabricRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { FabricPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class FabricPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - pixelPorts = FabricPortMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = FabricIncludes.MotionVectors, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = FabricIncludes.ForwardOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - vertexPorts = FabricPortMasks.Vertex, - pixelPorts = FabricPortMasks.FragmentForward, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region PortMasks - static class FabricPortMasks - { - public static int[] Vertex = new int[] - { - FabricMasterNode.PositionSlotId, - FabricMasterNode.VertexNormalSlotId, - FabricMasterNode.VertexTangentSlotId, - }; - - public static int[] FragmentMETA = new int[] - { - FabricMasterNode.AlbedoSlotId, - FabricMasterNode.SpecularOcclusionSlotId, - FabricMasterNode.NormalSlotId, - FabricMasterNode.SmoothnessSlotId, - FabricMasterNode.AmbientOcclusionSlotId, - FabricMasterNode.SpecularColorSlotId, - FabricMasterNode.DiffusionProfileHashSlotId, - FabricMasterNode.SubsurfaceMaskSlotId, - FabricMasterNode.ThicknessSlotId, - FabricMasterNode.TangentSlotId, - FabricMasterNode.AnisotropySlotId, - FabricMasterNode.EmissionSlotId, - FabricMasterNode.AlphaSlotId, - FabricMasterNode.AlphaClipThresholdSlotId, - }; - - public static int[] FragmentAlphaDepth = new int[] - { - FabricMasterNode.AlphaSlotId, - FabricMasterNode.AlphaClipThresholdSlotId, - FabricMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentDepthMotionVectors = new int[] - { - FabricMasterNode.NormalSlotId, - FabricMasterNode.SmoothnessSlotId, - FabricMasterNode.AlphaSlotId, - FabricMasterNode.AlphaClipThresholdSlotId, - FabricMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentForward = new int[] - { - FabricMasterNode.AlbedoSlotId, - FabricMasterNode.SpecularOcclusionSlotId, - FabricMasterNode.NormalSlotId, - FabricMasterNode.BentNormalSlotId, - FabricMasterNode.SmoothnessSlotId, - FabricMasterNode.AmbientOcclusionSlotId, - FabricMasterNode.SpecularColorSlotId, - FabricMasterNode.DiffusionProfileHashSlotId, - FabricMasterNode.SubsurfaceMaskSlotId, - FabricMasterNode.ThicknessSlotId, - FabricMasterNode.TangentSlotId, - FabricMasterNode.AnisotropySlotId, - FabricMasterNode.EmissionSlotId, - FabricMasterNode.AlphaSlotId, - FabricMasterNode.AlphaClipThresholdSlotId, - FabricMasterNode.LightingSlotId, - FabricMasterNode.BackLightingSlotId, - FabricMasterNode.DepthOffsetSlotId, - }; - } -#endregion - -#region Defines - static class FabricDefines - { - public static DefineCollection RaytracingForwardIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - }; - } -#endregion - -#region Includes - static class FabricIncludes - { - const string kFabric = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; - - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { kFabric, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { kFabric, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class HDFabricSubTarget : SubTarget +// { +// const string kAssetGuid = "74f1a4749bab90d429ac01d094be0aeb"; +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; + +// public HDFabricSubTarget() +// { +// displayName = "Fabric"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.FabricGUI"); +// context.AddSubShader(SubShaders.Fabric); +// context.AddSubShader(SubShaders.FabricRaytracing); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Fabric = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { FabricPasses.ShadowCaster }, +// { FabricPasses.META }, +// { FabricPasses.SceneSelection }, +// { FabricPasses.DepthForwardOnly }, +// { FabricPasses.MotionVectors }, +// { FabricPasses.ForwardOnly }, +// }, +// }; + +// public static SubShaderDescriptor FabricRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { FabricPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class FabricPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// pixelPorts = FabricPortMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = FabricIncludes.MotionVectors, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = FabricIncludes.ForwardOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// vertexPorts = FabricPortMasks.Vertex, +// pixelPorts = FabricPortMasks.FragmentForward, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region PortMasks +// static class FabricPortMasks +// { +// public static int[] Vertex = new int[] +// { +// FabricMasterNode.PositionSlotId, +// FabricMasterNode.VertexNormalSlotId, +// FabricMasterNode.VertexTangentSlotId, +// }; + +// public static int[] FragmentMETA = new int[] +// { +// FabricMasterNode.AlbedoSlotId, +// FabricMasterNode.SpecularOcclusionSlotId, +// FabricMasterNode.NormalSlotId, +// FabricMasterNode.SmoothnessSlotId, +// FabricMasterNode.AmbientOcclusionSlotId, +// FabricMasterNode.SpecularColorSlotId, +// FabricMasterNode.DiffusionProfileHashSlotId, +// FabricMasterNode.SubsurfaceMaskSlotId, +// FabricMasterNode.ThicknessSlotId, +// FabricMasterNode.TangentSlotId, +// FabricMasterNode.AnisotropySlotId, +// FabricMasterNode.EmissionSlotId, +// FabricMasterNode.AlphaSlotId, +// FabricMasterNode.AlphaClipThresholdSlotId, +// }; + +// public static int[] FragmentAlphaDepth = new int[] +// { +// FabricMasterNode.AlphaSlotId, +// FabricMasterNode.AlphaClipThresholdSlotId, +// FabricMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentDepthMotionVectors = new int[] +// { +// FabricMasterNode.NormalSlotId, +// FabricMasterNode.SmoothnessSlotId, +// FabricMasterNode.AlphaSlotId, +// FabricMasterNode.AlphaClipThresholdSlotId, +// FabricMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentForward = new int[] +// { +// FabricMasterNode.AlbedoSlotId, +// FabricMasterNode.SpecularOcclusionSlotId, +// FabricMasterNode.NormalSlotId, +// FabricMasterNode.BentNormalSlotId, +// FabricMasterNode.SmoothnessSlotId, +// FabricMasterNode.AmbientOcclusionSlotId, +// FabricMasterNode.SpecularColorSlotId, +// FabricMasterNode.DiffusionProfileHashSlotId, +// FabricMasterNode.SubsurfaceMaskSlotId, +// FabricMasterNode.ThicknessSlotId, +// FabricMasterNode.TangentSlotId, +// FabricMasterNode.AnisotropySlotId, +// FabricMasterNode.EmissionSlotId, +// FabricMasterNode.AlphaSlotId, +// FabricMasterNode.AlphaClipThresholdSlotId, +// FabricMasterNode.LightingSlotId, +// FabricMasterNode.BackLightingSlotId, +// FabricMasterNode.DepthOffsetSlotId, +// }; +// } +// #endregion + +// #region Defines +// static class FabricDefines +// { +// public static DefineCollection RaytracingForwardIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// }; +// } +// #endregion + +// #region Includes +// static class FabricIncludes +// { +// const string kFabric = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; + +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { kFabric, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { kFabric, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/CreateHairShaderGraph.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/CreateHairShaderGraph.cs deleted file mode 100644 index 6e02ecf93c8..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/CreateHairShaderGraph.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition -{ - static class CreateHairShaderGraph - { - [MenuItem("Assets/Create/Shader/HDRP/Hair Graph", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new HairMasterNode()); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HDHairSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HDHairSubTarget.cs index b2ddd71c3a0..ffbe9dcc895 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HDHairSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HDHairSubTarget.cs @@ -1,634 +1,634 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class HDHairSubTarget : SubTarget - { - const string kAssetGuid = "7e681cc79dd8e6c46ba1e8412d519e26"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; - - public HDHairSubTarget() - { - displayName = "Hair"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.HairGUI"); - context.AddSubShader(SubShaders.Hair); - context.AddSubShader(SubShaders.HairRaytracing); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Hair = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { HairPasses.ShadowCaster }, - { HairPasses.META }, - { HairPasses.SceneSelection }, - { HairPasses.DepthForwardOnly }, - { HairPasses.MotionVectors }, - { HairPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, - { HairPasses.TransparentDepthPrepass, new FieldCondition(HDFields.TransparentDepthPrePass, true) }, - { HairPasses.ForwardOnly }, - { HairPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, - }, - }; - - public static SubShaderDescriptor HairRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { HairPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class HairPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - pixelPorts = HairPortMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentShadowCaster, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = HairRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = HairIncludes.MotionVectors, - }; - - public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPrepass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPrepass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentTransparentDepthPrepass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePostPass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.TransparentDepthPrepass, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor TransparentBackface = new PassDescriptor() - { - // Definition - displayName = "TransparentBackface", - referenceName = "SHADERPASS_FORWARD", - lightMode = "TransparentBackface", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentTransparentBackface, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentBackface, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = HairIncludes.ForwardOnly, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ForwardColorMask, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = HairIncludes.ForwardOnly, - }; - - public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPostpass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPostpass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentTransparentDepthPostpass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePostPass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = HairPortMasks.Vertex, - pixelPorts = HairPortMasks.FragmentForward, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region PortMasks - static class HairPortMasks - { - public static int[] Vertex = new int[] - { - HairMasterNode.PositionSlotId, - HairMasterNode.VertexNormalSlotId, - HairMasterNode.VertexTangentSlotId, - }; - - public static int[] FragmentMETA = new int[] - { - HairMasterNode.AlbedoSlotId, - HairMasterNode.NormalSlotId, - HairMasterNode.SpecularOcclusionSlotId, - HairMasterNode.BentNormalSlotId, - HairMasterNode.HairStrandDirectionSlotId, - HairMasterNode.TransmittanceSlotId, - HairMasterNode.RimTransmissionIntensitySlotId, - HairMasterNode.SmoothnessSlotId, - HairMasterNode.AmbientOcclusionSlotId, - HairMasterNode.EmissionSlotId, - HairMasterNode.AlphaSlotId, - HairMasterNode.AlphaClipThresholdSlotId, - HairMasterNode.SpecularAAScreenSpaceVarianceSlotId, - HairMasterNode.SpecularAAThresholdSlotId, - HairMasterNode.SpecularTintSlotId, - HairMasterNode.SpecularShiftSlotId, - HairMasterNode.SecondarySpecularTintSlotId, - HairMasterNode.SecondarySmoothnessSlotId, - HairMasterNode.SecondarySpecularShiftSlotId, - }; - - public static int[] FragmentShadowCaster = new int[] - { - HairMasterNode.AlphaSlotId, - HairMasterNode.AlphaClipThresholdSlotId, - HairMasterNode.AlphaClipThresholdShadowSlotId, - HairMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentAlphaDepth = new int[] - { - HairMasterNode.AlphaSlotId, - HairMasterNode.AlphaClipThresholdSlotId, - HairMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentDepthMotionVectors = new int[] - { - HairMasterNode.NormalSlotId, - HairMasterNode.SmoothnessSlotId, - HairMasterNode.AlphaSlotId, - HairMasterNode.AlphaClipThresholdSlotId, - HairMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentTransparentDepthPrepass = new int[] - { - HairMasterNode.AlphaSlotId, - HairMasterNode.AlphaClipThresholdDepthPrepassSlotId, - HairMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentTransparentBackface = new int[] - { - HairMasterNode.AlbedoSlotId, - HairMasterNode.NormalSlotId, - HairMasterNode.SpecularOcclusionSlotId, - HairMasterNode.BentNormalSlotId, - HairMasterNode.HairStrandDirectionSlotId, - HairMasterNode.TransmittanceSlotId, - HairMasterNode.RimTransmissionIntensitySlotId, - HairMasterNode.SmoothnessSlotId, - HairMasterNode.AmbientOcclusionSlotId, - HairMasterNode.EmissionSlotId, - HairMasterNode.AlphaSlotId, - HairMasterNode.AlphaClipThresholdSlotId, - HairMasterNode.SpecularAAScreenSpaceVarianceSlotId, - HairMasterNode.SpecularAAThresholdSlotId, - HairMasterNode.SpecularTintSlotId, - HairMasterNode.SpecularShiftSlotId, - HairMasterNode.SecondarySpecularTintSlotId, - HairMasterNode.SecondarySmoothnessSlotId, - HairMasterNode.SecondarySpecularShiftSlotId, - HairMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentForward = new int[] - { - HairMasterNode.AlbedoSlotId, - HairMasterNode.NormalSlotId, - HairMasterNode.SpecularOcclusionSlotId, - HairMasterNode.BentNormalSlotId, - HairMasterNode.HairStrandDirectionSlotId, - HairMasterNode.TransmittanceSlotId, - HairMasterNode.RimTransmissionIntensitySlotId, - HairMasterNode.SmoothnessSlotId, - HairMasterNode.AmbientOcclusionSlotId, - HairMasterNode.EmissionSlotId, - HairMasterNode.AlphaSlotId, - HairMasterNode.AlphaClipThresholdSlotId, - HairMasterNode.SpecularAAScreenSpaceVarianceSlotId, - HairMasterNode.SpecularAAThresholdSlotId, - HairMasterNode.SpecularTintSlotId, - HairMasterNode.SpecularShiftSlotId, - HairMasterNode.SecondarySpecularTintSlotId, - HairMasterNode.SecondarySmoothnessSlotId, - HairMasterNode.SecondarySpecularShiftSlotId, - HairMasterNode.LightingSlotId, - HairMasterNode.BackLightingSlotId, - HairMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentTransparentDepthPostpass = new int[] - { - HairMasterNode.AlphaSlotId, - HairMasterNode.AlphaClipThresholdDepthPostpassSlotId, - HairMasterNode.DepthOffsetSlotId, - }; - } -#endregion - -#region RenderStates - static class HairRenderStates - { - public static RenderStateCollection MotionVectors = new RenderStateCollection - { - { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, - Ref = CoreRenderStates.Uniforms.stencilRefMV, - Comp = "Always", - Pass = "Replace", - }) }, - }; - } -#endregion - -#region Defines - static class HairDefines - { - public static DefineCollection RaytracingForwardIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - }; - } -#endregion - -#region Includes - static class HairIncludes - { - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kHair, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { CoreIncludes.kHair, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class HDHairSubTarget : SubTarget +// { +// const string kAssetGuid = "7e681cc79dd8e6c46ba1e8412d519e26"; +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; + +// public HDHairSubTarget() +// { +// displayName = "Hair"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.HairGUI"); +// context.AddSubShader(SubShaders.Hair); +// context.AddSubShader(SubShaders.HairRaytracing); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Hair = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { HairPasses.ShadowCaster }, +// { HairPasses.META }, +// { HairPasses.SceneSelection }, +// { HairPasses.DepthForwardOnly }, +// { HairPasses.MotionVectors }, +// { HairPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, +// { HairPasses.TransparentDepthPrepass, new FieldCondition(HDFields.TransparentDepthPrePass, true) }, +// { HairPasses.ForwardOnly }, +// { HairPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, +// }, +// }; + +// public static SubShaderDescriptor HairRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { HairPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class HairPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// pixelPorts = HairPortMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentShadowCaster, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = HairRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = HairIncludes.MotionVectors, +// }; + +// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPrepass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPrepass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentTransparentDepthPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePostPass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.TransparentDepthPrepass, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor TransparentBackface = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentBackface", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "TransparentBackface", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentTransparentBackface, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentBackface, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = HairIncludes.ForwardOnly, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ForwardColorMask, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = HairIncludes.ForwardOnly, +// }; + +// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPostpass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPostpass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentTransparentDepthPostpass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePostPass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = HairPortMasks.Vertex, +// pixelPorts = HairPortMasks.FragmentForward, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region PortMasks +// static class HairPortMasks +// { +// public static int[] Vertex = new int[] +// { +// HairMasterNode.PositionSlotId, +// HairMasterNode.VertexNormalSlotId, +// HairMasterNode.VertexTangentSlotId, +// }; + +// public static int[] FragmentMETA = new int[] +// { +// HairMasterNode.AlbedoSlotId, +// HairMasterNode.NormalSlotId, +// HairMasterNode.SpecularOcclusionSlotId, +// HairMasterNode.BentNormalSlotId, +// HairMasterNode.HairStrandDirectionSlotId, +// HairMasterNode.TransmittanceSlotId, +// HairMasterNode.RimTransmissionIntensitySlotId, +// HairMasterNode.SmoothnessSlotId, +// HairMasterNode.AmbientOcclusionSlotId, +// HairMasterNode.EmissionSlotId, +// HairMasterNode.AlphaSlotId, +// HairMasterNode.AlphaClipThresholdSlotId, +// HairMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// HairMasterNode.SpecularAAThresholdSlotId, +// HairMasterNode.SpecularTintSlotId, +// HairMasterNode.SpecularShiftSlotId, +// HairMasterNode.SecondarySpecularTintSlotId, +// HairMasterNode.SecondarySmoothnessSlotId, +// HairMasterNode.SecondarySpecularShiftSlotId, +// }; + +// public static int[] FragmentShadowCaster = new int[] +// { +// HairMasterNode.AlphaSlotId, +// HairMasterNode.AlphaClipThresholdSlotId, +// HairMasterNode.AlphaClipThresholdShadowSlotId, +// HairMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentAlphaDepth = new int[] +// { +// HairMasterNode.AlphaSlotId, +// HairMasterNode.AlphaClipThresholdSlotId, +// HairMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentDepthMotionVectors = new int[] +// { +// HairMasterNode.NormalSlotId, +// HairMasterNode.SmoothnessSlotId, +// HairMasterNode.AlphaSlotId, +// HairMasterNode.AlphaClipThresholdSlotId, +// HairMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentTransparentDepthPrepass = new int[] +// { +// HairMasterNode.AlphaSlotId, +// HairMasterNode.AlphaClipThresholdDepthPrepassSlotId, +// HairMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentTransparentBackface = new int[] +// { +// HairMasterNode.AlbedoSlotId, +// HairMasterNode.NormalSlotId, +// HairMasterNode.SpecularOcclusionSlotId, +// HairMasterNode.BentNormalSlotId, +// HairMasterNode.HairStrandDirectionSlotId, +// HairMasterNode.TransmittanceSlotId, +// HairMasterNode.RimTransmissionIntensitySlotId, +// HairMasterNode.SmoothnessSlotId, +// HairMasterNode.AmbientOcclusionSlotId, +// HairMasterNode.EmissionSlotId, +// HairMasterNode.AlphaSlotId, +// HairMasterNode.AlphaClipThresholdSlotId, +// HairMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// HairMasterNode.SpecularAAThresholdSlotId, +// HairMasterNode.SpecularTintSlotId, +// HairMasterNode.SpecularShiftSlotId, +// HairMasterNode.SecondarySpecularTintSlotId, +// HairMasterNode.SecondarySmoothnessSlotId, +// HairMasterNode.SecondarySpecularShiftSlotId, +// HairMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentForward = new int[] +// { +// HairMasterNode.AlbedoSlotId, +// HairMasterNode.NormalSlotId, +// HairMasterNode.SpecularOcclusionSlotId, +// HairMasterNode.BentNormalSlotId, +// HairMasterNode.HairStrandDirectionSlotId, +// HairMasterNode.TransmittanceSlotId, +// HairMasterNode.RimTransmissionIntensitySlotId, +// HairMasterNode.SmoothnessSlotId, +// HairMasterNode.AmbientOcclusionSlotId, +// HairMasterNode.EmissionSlotId, +// HairMasterNode.AlphaSlotId, +// HairMasterNode.AlphaClipThresholdSlotId, +// HairMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// HairMasterNode.SpecularAAThresholdSlotId, +// HairMasterNode.SpecularTintSlotId, +// HairMasterNode.SpecularShiftSlotId, +// HairMasterNode.SecondarySpecularTintSlotId, +// HairMasterNode.SecondarySmoothnessSlotId, +// HairMasterNode.SecondarySpecularShiftSlotId, +// HairMasterNode.LightingSlotId, +// HairMasterNode.BackLightingSlotId, +// HairMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentTransparentDepthPostpass = new int[] +// { +// HairMasterNode.AlphaSlotId, +// HairMasterNode.AlphaClipThresholdDepthPostpassSlotId, +// HairMasterNode.DepthOffsetSlotId, +// }; +// } +// #endregion + +// #region RenderStates +// static class HairRenderStates +// { +// public static RenderStateCollection MotionVectors = new RenderStateCollection +// { +// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, +// Ref = CoreRenderStates.Uniforms.stencilRefMV, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Defines +// static class HairDefines +// { +// public static DefineCollection RaytracingForwardIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// }; +// } +// #endregion + +// #region Includes +// static class HairIncludes +// { +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kHair, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { CoreIncludes.kHair, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairMasterNode.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairMasterNode.cs index e20236fa9fb..ee15b97e1b7 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairMasterNode.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairMasterNode.cs @@ -1,1038 +1,1038 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; -using UnityEditor.Rendering.HighDefinition.Drawing; -using UnityEditor.ShaderGraph.Internal; -using UnityEditor.Rendering.HighDefinition.ShaderGraph; +// using System; +// using System.Linq; +// using System.Collections.Generic; +// using UnityEditor.Graphing; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; +// using UnityEditor.Rendering.HighDefinition.Drawing; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEditor.Rendering.HighDefinition.ShaderGraph; -// Include material common properties names -using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; +// // Include material common properties names +// using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; -namespace UnityEditor.Rendering.HighDefinition -{ - [Serializable] - [Title("Master", "Hair (HDRP)")] - [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.HairMasterNode")] - class HairMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string PositionSlotName = "Vertex Position"; - public const string PositionSlotDisplayName = "Vertex Position"; - public const int PositionSlotId = 0; +// namespace UnityEditor.Rendering.HighDefinition +// { +// [Serializable] +// [Title("Master", "Hair (HDRP)")] +// [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.HairMasterNode")] +// class HairMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent +// { +// public const string PositionSlotName = "Vertex Position"; +// public const string PositionSlotDisplayName = "Vertex Position"; +// public const int PositionSlotId = 0; - public const string AlbedoSlotName = "Albedo"; - public const string AlbedoDisplaySlotName = "DiffuseColor"; - public const int AlbedoSlotId = 1; +// public const string AlbedoSlotName = "Albedo"; +// public const string AlbedoDisplaySlotName = "DiffuseColor"; +// public const int AlbedoSlotId = 1; - public const string NormalSlotName = "Normal"; - public const int NormalSlotId = 2; +// public const string NormalSlotName = "Normal"; +// public const int NormalSlotId = 2; - public const string SpecularOcclusionSlotName = "SpecularOcclusion"; - public const int SpecularOcclusionSlotId = 3; - - public const string BentNormalSlotName = "BentNormal"; - public const int BentNormalSlotId = 4; - - public const string HairStrandDirectionSlotName = "HairStrandDirection"; - public const int HairStrandDirectionSlotId = 5; - - public const int UnusedSlot6 = 6; - - public const string TransmittanceSlotName = "Transmittance"; - public const int TransmittanceSlotId = 7; - - public const string RimTransmissionIntensitySlotName = "RimTransmissionIntensity"; - public const int RimTransmissionIntensitySlotId = 8; - - public const string SmoothnessSlotName = "Smoothness"; - public const int SmoothnessSlotId = 9; - - public const string AmbientOcclusionSlotName = "Occlusion"; - public const string AmbientOcclusionDisplaySlotName = "AmbientOcclusion"; - public const int AmbientOcclusionSlotId = 10; - - public const string EmissionSlotName = "Emission"; - public const int EmissionSlotId = 11; - - public const string AlphaSlotName = "Alpha"; - public const int AlphaSlotId = 12; - - public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; - public const int AlphaClipThresholdSlotId = 13; - - public const string AlphaClipThresholdDepthPrepassSlotName = "AlphaClipThresholdDepthPrepass"; - public const int AlphaClipThresholdDepthPrepassSlotId = 14; - - public const string AlphaClipThresholdDepthPostpassSlotName = "AlphaClipThresholdDepthPostpass"; - public const int AlphaClipThresholdDepthPostpassSlotId = 15; - - public const string SpecularAAScreenSpaceVarianceSlotName = "SpecularAAScreenSpaceVariance"; - public const int SpecularAAScreenSpaceVarianceSlotId = 16; - - public const string SpecularAAThresholdSlotName = "SpecularAAThreshold"; - public const int SpecularAAThresholdSlotId = 17; - - //Hair Specific - public const string SpecularTintSlotName = "SpecularTint"; - public const int SpecularTintSlotId = 18; - - public const string SpecularShiftSlotName = "SpecularShift"; - public const int SpecularShiftSlotId = 19; - - public const string SecondarySpecularTintSlotName = "SecondarySpecularTint"; - public const int SecondarySpecularTintSlotId = 20; - - public const string SecondarySmoothnessSlotName = "SecondarySmoothness"; - public const int SecondarySmoothnessSlotId = 21; - - public const string SecondarySpecularShiftSlotName = "SecondarySpecularShift"; - public const int SecondarySpecularShiftSlotId = 22; - - public const string AlphaClipThresholdShadowSlotName = "AlphaClipThresholdShadow"; - public const int AlphaClipThresholdShadowSlotId = 23; - - public const string BakedGISlotName = "BakedGI"; - public const int LightingSlotId = 24; - - public const string BakedBackGISlotName = "BakedBackGI"; - public const int BackLightingSlotId = 25; - - public const string DepthOffsetSlotName = "DepthOffset"; - public const int DepthOffsetSlotId = 26; - - public const int VertexNormalSlotId = 27; - public const string VertexNormalSlotName = "Vertex Normal"; - - public const int VertexTangentSlotId = 28; - public const string VertexTangentSlotName = "Vertex Tangent"; - - public enum MaterialType - { - KajiyaKay - } - - // Don't support Multiply - public enum AlphaModeLit - { - Alpha, - Premultiply, - Additive, - } - - // Just for convenience of doing simple masks. We could run out of bits of course. - [Flags] - enum SlotMask - { - None = 0, - Position = 1 << PositionSlotId, - Albedo = 1 << AlbedoSlotId, - Normal = 1 << NormalSlotId, - SpecularOcclusion = 1 << SpecularOcclusionSlotId, - BentNormal = 1 << BentNormalSlotId, - HairStrandDirection = 1 << HairStrandDirectionSlotId, - Slot6 = 1 << UnusedSlot6, - Transmittance = 1 << TransmittanceSlotId, - RimTransmissionIntensity = 1 << RimTransmissionIntensitySlotId, - Smoothness = 1 << SmoothnessSlotId, - Occlusion = 1 << AmbientOcclusionSlotId, - Emission = 1 << EmissionSlotId, - Alpha = 1 << AlphaSlotId, - AlphaClipThreshold = 1 << AlphaClipThresholdSlotId, - AlphaClipThresholdDepthPrepass = 1 << AlphaClipThresholdDepthPrepassSlotId, - AlphaClipThresholdDepthPostpass = 1 << AlphaClipThresholdDepthPostpassSlotId, - SpecularTint = 1 << SpecularTintSlotId, - SpecularShift = 1 << SpecularShiftSlotId, - SecondarySpecularTint = 1 << SecondarySpecularTintSlotId, - SecondarySmoothness = 1 << SecondarySmoothnessSlotId, - SecondarySpecularShift = 1 << SecondarySpecularShiftSlotId, - AlphaClipThresholdShadow = 1 << AlphaClipThresholdShadowSlotId, - BakedGI = 1 << LightingSlotId, - BakedBackGI = 1 << BackLightingSlotId, - DepthOffset = 1 << DepthOffsetSlotId, - VertexNormal = 1 << VertexNormalSlotId, - VertexTangent = 1 << VertexTangentSlotId, - } - - const SlotMask KajiyaKaySlotMask = SlotMask.Position | SlotMask.VertexNormal | SlotMask.VertexTangent | SlotMask.Albedo | SlotMask.Normal | SlotMask.SpecularOcclusion | SlotMask.BentNormal | SlotMask.HairStrandDirection | SlotMask.Slot6 - | SlotMask.Transmittance | SlotMask.RimTransmissionIntensity | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.Alpha | SlotMask.AlphaClipThreshold | SlotMask.AlphaClipThresholdDepthPrepass - | SlotMask.AlphaClipThresholdDepthPostpass | SlotMask.SpecularTint | SlotMask.SpecularShift | SlotMask.SecondarySpecularTint | SlotMask.SecondarySmoothness | SlotMask.SecondarySpecularShift | SlotMask.AlphaClipThresholdShadow | SlotMask.BakedGI | SlotMask.DepthOffset; - - // This could also be a simple array. For now, catch any mismatched data. - SlotMask GetActiveSlotMask() - { - switch (materialType) - { - case MaterialType.KajiyaKay: - return KajiyaKaySlotMask; - default: - return KajiyaKaySlotMask; - } - } - - bool MaterialTypeUsesSlotMask(SlotMask mask) - { - SlotMask activeMask = GetActiveSlotMask(); - return (activeMask & mask) != 0; - } - - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - AlphaMode m_AlphaMode; - - public AlphaMode alphaMode - { - get { return m_AlphaMode; } - set - { - if (m_AlphaMode == value) - return; - - m_AlphaMode = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_BlendPreserveSpecular = true; - - public ToggleData blendPreserveSpecular - { - get { return new ToggleData(m_BlendPreserveSpecular); } - set - { - if (m_BlendPreserveSpecular == value.isOn) - return; - m_BlendPreserveSpecular = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_TransparencyFog = true; - - public ToggleData transparencyFog - { - get { return new ToggleData(m_TransparencyFog); } - set - { - if (m_TransparencyFog == value.isOn) - return; - m_TransparencyFog = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaTest; - - public ToggleData alphaTest - { - get { return new ToggleData(m_AlphaTest); } - set - { - if (m_AlphaTest == value.isOn) - return; - m_AlphaTest = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } +// public const string SpecularOcclusionSlotName = "SpecularOcclusion"; +// public const int SpecularOcclusionSlotId = 3; + +// public const string BentNormalSlotName = "BentNormal"; +// public const int BentNormalSlotId = 4; + +// public const string HairStrandDirectionSlotName = "HairStrandDirection"; +// public const int HairStrandDirectionSlotId = 5; + +// public const int UnusedSlot6 = 6; + +// public const string TransmittanceSlotName = "Transmittance"; +// public const int TransmittanceSlotId = 7; + +// public const string RimTransmissionIntensitySlotName = "RimTransmissionIntensity"; +// public const int RimTransmissionIntensitySlotId = 8; + +// public const string SmoothnessSlotName = "Smoothness"; +// public const int SmoothnessSlotId = 9; + +// public const string AmbientOcclusionSlotName = "Occlusion"; +// public const string AmbientOcclusionDisplaySlotName = "AmbientOcclusion"; +// public const int AmbientOcclusionSlotId = 10; + +// public const string EmissionSlotName = "Emission"; +// public const int EmissionSlotId = 11; + +// public const string AlphaSlotName = "Alpha"; +// public const int AlphaSlotId = 12; + +// public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; +// public const int AlphaClipThresholdSlotId = 13; + +// public const string AlphaClipThresholdDepthPrepassSlotName = "AlphaClipThresholdDepthPrepass"; +// public const int AlphaClipThresholdDepthPrepassSlotId = 14; + +// public const string AlphaClipThresholdDepthPostpassSlotName = "AlphaClipThresholdDepthPostpass"; +// public const int AlphaClipThresholdDepthPostpassSlotId = 15; + +// public const string SpecularAAScreenSpaceVarianceSlotName = "SpecularAAScreenSpaceVariance"; +// public const int SpecularAAScreenSpaceVarianceSlotId = 16; + +// public const string SpecularAAThresholdSlotName = "SpecularAAThreshold"; +// public const int SpecularAAThresholdSlotId = 17; + +// //Hair Specific +// public const string SpecularTintSlotName = "SpecularTint"; +// public const int SpecularTintSlotId = 18; + +// public const string SpecularShiftSlotName = "SpecularShift"; +// public const int SpecularShiftSlotId = 19; + +// public const string SecondarySpecularTintSlotName = "SecondarySpecularTint"; +// public const int SecondarySpecularTintSlotId = 20; + +// public const string SecondarySmoothnessSlotName = "SecondarySmoothness"; +// public const int SecondarySmoothnessSlotId = 21; + +// public const string SecondarySpecularShiftSlotName = "SecondarySpecularShift"; +// public const int SecondarySpecularShiftSlotId = 22; + +// public const string AlphaClipThresholdShadowSlotName = "AlphaClipThresholdShadow"; +// public const int AlphaClipThresholdShadowSlotId = 23; + +// public const string BakedGISlotName = "BakedGI"; +// public const int LightingSlotId = 24; + +// public const string BakedBackGISlotName = "BakedBackGI"; +// public const int BackLightingSlotId = 25; + +// public const string DepthOffsetSlotName = "DepthOffset"; +// public const int DepthOffsetSlotId = 26; + +// public const int VertexNormalSlotId = 27; +// public const string VertexNormalSlotName = "Vertex Normal"; + +// public const int VertexTangentSlotId = 28; +// public const string VertexTangentSlotName = "Vertex Tangent"; + +// public enum MaterialType +// { +// KajiyaKay +// } + +// // Don't support Multiply +// public enum AlphaModeLit +// { +// Alpha, +// Premultiply, +// Additive, +// } + +// // Just for convenience of doing simple masks. We could run out of bits of course. +// [Flags] +// enum SlotMask +// { +// None = 0, +// Position = 1 << PositionSlotId, +// Albedo = 1 << AlbedoSlotId, +// Normal = 1 << NormalSlotId, +// SpecularOcclusion = 1 << SpecularOcclusionSlotId, +// BentNormal = 1 << BentNormalSlotId, +// HairStrandDirection = 1 << HairStrandDirectionSlotId, +// Slot6 = 1 << UnusedSlot6, +// Transmittance = 1 << TransmittanceSlotId, +// RimTransmissionIntensity = 1 << RimTransmissionIntensitySlotId, +// Smoothness = 1 << SmoothnessSlotId, +// Occlusion = 1 << AmbientOcclusionSlotId, +// Emission = 1 << EmissionSlotId, +// Alpha = 1 << AlphaSlotId, +// AlphaClipThreshold = 1 << AlphaClipThresholdSlotId, +// AlphaClipThresholdDepthPrepass = 1 << AlphaClipThresholdDepthPrepassSlotId, +// AlphaClipThresholdDepthPostpass = 1 << AlphaClipThresholdDepthPostpassSlotId, +// SpecularTint = 1 << SpecularTintSlotId, +// SpecularShift = 1 << SpecularShiftSlotId, +// SecondarySpecularTint = 1 << SecondarySpecularTintSlotId, +// SecondarySmoothness = 1 << SecondarySmoothnessSlotId, +// SecondarySpecularShift = 1 << SecondarySpecularShiftSlotId, +// AlphaClipThresholdShadow = 1 << AlphaClipThresholdShadowSlotId, +// BakedGI = 1 << LightingSlotId, +// BakedBackGI = 1 << BackLightingSlotId, +// DepthOffset = 1 << DepthOffsetSlotId, +// VertexNormal = 1 << VertexNormalSlotId, +// VertexTangent = 1 << VertexTangentSlotId, +// } + +// const SlotMask KajiyaKaySlotMask = SlotMask.Position | SlotMask.VertexNormal | SlotMask.VertexTangent | SlotMask.Albedo | SlotMask.Normal | SlotMask.SpecularOcclusion | SlotMask.BentNormal | SlotMask.HairStrandDirection | SlotMask.Slot6 +// | SlotMask.Transmittance | SlotMask.RimTransmissionIntensity | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.Alpha | SlotMask.AlphaClipThreshold | SlotMask.AlphaClipThresholdDepthPrepass +// | SlotMask.AlphaClipThresholdDepthPostpass | SlotMask.SpecularTint | SlotMask.SpecularShift | SlotMask.SecondarySpecularTint | SlotMask.SecondarySmoothness | SlotMask.SecondarySpecularShift | SlotMask.AlphaClipThresholdShadow | SlotMask.BakedGI | SlotMask.DepthOffset; + +// // This could also be a simple array. For now, catch any mismatched data. +// SlotMask GetActiveSlotMask() +// { +// switch (materialType) +// { +// case MaterialType.KajiyaKay: +// return KajiyaKaySlotMask; +// default: +// return KajiyaKaySlotMask; +// } +// } + +// bool MaterialTypeUsesSlotMask(SlotMask mask) +// { +// SlotMask activeMask = GetActiveSlotMask(); +// return (activeMask & mask) != 0; +// } + +// [SerializeField] +// SurfaceType m_SurfaceType; + +// public SurfaceType surfaceType +// { +// get { return m_SurfaceType; } +// set +// { +// if (m_SurfaceType == value) +// return; + +// m_SurfaceType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// AlphaMode m_AlphaMode; + +// public AlphaMode alphaMode +// { +// get { return m_AlphaMode; } +// set +// { +// if (m_AlphaMode == value) +// return; + +// m_AlphaMode = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_BlendPreserveSpecular = true; + +// public ToggleData blendPreserveSpecular +// { +// get { return new ToggleData(m_BlendPreserveSpecular); } +// set +// { +// if (m_BlendPreserveSpecular == value.isOn) +// return; +// m_BlendPreserveSpecular = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_TransparencyFog = true; + +// public ToggleData transparencyFog +// { +// get { return new ToggleData(m_TransparencyFog); } +// set +// { +// if (m_TransparencyFog == value.isOn) +// return; +// m_TransparencyFog = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaTest; + +// public ToggleData alphaTest +// { +// get { return new ToggleData(m_AlphaTest); } +// set +// { +// if (m_AlphaTest == value.isOn) +// return; +// m_AlphaTest = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } - [SerializeField] - bool m_AlphaToMask = false; - - public ToggleData alphaToMask - { - get { return new ToggleData(m_AlphaToMask); } - set - { - if (m_AlphaToMask == value.isOn) - return; - m_AlphaToMask = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaTestDepthPrepass; - - public ToggleData alphaTestDepthPrepass - { - get { return new ToggleData(m_AlphaTestDepthPrepass); } - set - { - if (m_AlphaTestDepthPrepass == value.isOn) - return; - m_AlphaTestDepthPrepass = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_AlphaTestDepthPostpass; - - public ToggleData alphaTestDepthPostpass - { - get { return new ToggleData(m_AlphaTestDepthPostpass); } - set - { - if (m_AlphaTestDepthPostpass == value.isOn) - return; - m_AlphaTestDepthPostpass = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_TransparentWritesMotionVec; - - public ToggleData transparentWritesMotionVec - { - get { return new ToggleData(m_TransparentWritesMotionVec); } - set - { - if (m_TransparentWritesMotionVec == value.isOn) - return; - m_TransparentWritesMotionVec = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_AlphaTestShadow; - - public ToggleData alphaTestShadow - { - get { return new ToggleData(m_AlphaTestShadow); } - set - { - if (m_AlphaTestShadow == value.isOn) - return; - m_AlphaTestShadow = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_BackThenFrontRendering; - - public ToggleData backThenFrontRendering - { - get { return new ToggleData(m_BackThenFrontRendering); } - set - { - if (m_BackThenFrontRendering == value.isOn) - return; - m_BackThenFrontRendering = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_SortPriority; - - public int sortPriority - { - get { return m_SortPriority; } - set - { - if (m_SortPriority == value) - return; - m_SortPriority = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - DoubleSidedMode m_DoubleSidedMode; - - public DoubleSidedMode doubleSidedMode - { - get { return m_DoubleSidedMode; } - set - { - if (m_DoubleSidedMode == value) - return; - - m_DoubleSidedMode = value; - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - MaterialType m_MaterialType; - - public MaterialType materialType - { - get { return m_MaterialType; } - set - { - if (m_MaterialType == value) - return; - - m_MaterialType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ReceiveDecals = true; - - public ToggleData receiveDecals - { - get { return new ToggleData(m_ReceiveDecals); } - set - { - if (m_ReceiveDecals == value.isOn) - return; - m_ReceiveDecals = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_ReceivesSSR = true; - public ToggleData receiveSSR - { - get { return new ToggleData(m_ReceivesSSR); } - set - { - if (m_ReceivesSSR == value.isOn) - return; - m_ReceivesSSR = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AddPrecomputedVelocity = false; - - public ToggleData addPrecomputedVelocity - { - get { return new ToggleData(m_AddPrecomputedVelocity); } - set - { - if (m_AddPrecomputedVelocity == value.isOn) - return; - m_AddPrecomputedVelocity = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - - - [SerializeField] - bool m_UseLightFacingNormal = false; - public ToggleData useLightFacingNormal - { - get { return new ToggleData(m_UseLightFacingNormal); } - set - { - if (m_UseLightFacingNormal == value.isOn) - return; - m_UseLightFacingNormal = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SpecularAA; - - public ToggleData specularAA - { - get { return new ToggleData(m_SpecularAA); } - set - { - if (m_SpecularAA == value.isOn) - return; - m_SpecularAA = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - float m_SpecularAAScreenSpaceVariance; - - public float specularAAScreenSpaceVariance - { - get { return m_SpecularAAScreenSpaceVariance; } - set - { - if (m_SpecularAAScreenSpaceVariance == value) - return; - m_SpecularAAScreenSpaceVariance = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - float m_SpecularAAThreshold; - - public float specularAAThreshold - { - get { return m_SpecularAAThreshold; } - set - { - if (m_SpecularAAThreshold == value) - return; - m_SpecularAAThreshold = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - SpecularOcclusionMode m_SpecularOcclusionMode; - - public SpecularOcclusionMode specularOcclusionMode - { - get { return m_SpecularOcclusionMode; } - set - { - if (m_SpecularOcclusionMode == value) - return; - - m_SpecularOcclusionMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_overrideBakedGI; - - public ToggleData overrideBakedGI - { - get { return new ToggleData(m_overrideBakedGI); } - set - { - if (m_overrideBakedGI == value.isOn) - return; - m_overrideBakedGI = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_depthOffset; - - public ToggleData depthOffset - { - get { return new ToggleData(m_depthOffset); } - set - { - if (m_depthOffset == value.isOn) - return; - m_depthOffset = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ZWrite; - - public ToggleData zWrite - { - get { return new ToggleData(m_ZWrite); } - set - { - if (m_ZWrite == value.isOn) - return; - m_ZWrite = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; - public TransparentCullMode transparentCullMode - { - get => m_transparentCullMode; - set - { - if (m_transparentCullMode == value) - return; - - m_transparentCullMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - CompareFunction m_ZTest = CompareFunction.LessEqual; - public CompareFunction zTest - { - get => m_ZTest; - set - { - if (m_ZTest == value) - return; - - m_ZTest = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SupportLodCrossFade; - - public ToggleData supportLodCrossFade - { - get { return new ToggleData(m_SupportLodCrossFade); } - set - { - if (m_SupportLodCrossFade == value.isOn) - return; - m_SupportLodCrossFade = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Node); - } - } - - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_MaterialNeedsUpdateHash = 0; - - int ComputeMaterialNeedsUpdateHash() - { - int hash = 0; - - hash |= (alphaTest.isOn ? 0 : 1) << 0; - hash |= (alphaTestShadow.isOn ? 0 : 1) << 1; - hash |= (receiveSSR.isOn ? 0 : 1) << 2; - - return hash; - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public HairMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - public override string documentationURL => Documentation.GetPageLink("Master-Node-Hair"); - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Hair Master"; - - List validSlots = new List(); - - if (MaterialTypeUsesSlotMask(SlotMask.Position)) - { - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(PositionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) - { - AddSlot(new NormalMaterialSlot(VertexNormalSlotId, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexNormalSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) - { - AddSlot(new TangentMaterialSlot(VertexTangentSlotId, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexTangentSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) - { - AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(AlbedoSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.SpecularOcclusion) && specularOcclusionMode == SpecularOcclusionMode.Custom) - { - AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularOcclusionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Normal)) - { - AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(NormalSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.BentNormal)) - { - AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(BentNormalSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) - { - AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(SmoothnessSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) - { - AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AmbientOcclusionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Transmittance)) - { - AddSlot(new Vector3MaterialSlot(TransmittanceSlotId, TransmittanceSlotName, TransmittanceSlotName, SlotType.Input, 0.3f * new Vector3(1.0f, 0.65f, 0.3f), ShaderStageCapability.Fragment)); - validSlots.Add(TransmittanceSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.RimTransmissionIntensity)) - { - AddSlot(new Vector1MaterialSlot(RimTransmissionIntensitySlotId, RimTransmissionIntensitySlotName, RimTransmissionIntensitySlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); - validSlots.Add(RimTransmissionIntensitySlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.HairStrandDirection)) - { - AddSlot(new Vector3MaterialSlot(HairStrandDirectionSlotId, HairStrandDirectionSlotName, HairStrandDirectionSlotName, SlotType.Input, new Vector3(0, -1, 0), ShaderStageCapability.Fragment)); - validSlots.Add(HairStrandDirectionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Emission)) - { - AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); - validSlots.Add(EmissionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Alpha)) - { - AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThreshold) && alphaTest.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaClipThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaClipThresholdSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThresholdDepthPrepass) && surfaceType == SurfaceType.Transparent && alphaTest.isOn && alphaTestDepthPrepass.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaClipThresholdDepthPrepassSlotId, AlphaClipThresholdDepthPrepassSlotName, AlphaClipThresholdDepthPrepassSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaClipThresholdDepthPrepassSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThresholdDepthPostpass) && surfaceType == SurfaceType.Transparent && alphaTest.isOn && alphaTestDepthPostpass.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaClipThresholdDepthPostpassSlotId, AlphaClipThresholdDepthPostpassSlotName, AlphaClipThresholdDepthPostpassSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaClipThresholdDepthPostpassSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThresholdShadow) && alphaTest.isOn && alphaTestShadow.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaClipThresholdShadowSlotId, AlphaClipThresholdShadowSlotName, AlphaClipThresholdShadowSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaClipThresholdShadowSlotId); - } - if (specularAA.isOn) - { - AddSlot(new Vector1MaterialSlot(SpecularAAScreenSpaceVarianceSlotId, SpecularAAScreenSpaceVarianceSlotName, SpecularAAScreenSpaceVarianceSlotName, SlotType.Input, 0.1f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularAAScreenSpaceVarianceSlotId); - - AddSlot(new Vector1MaterialSlot(SpecularAAThresholdSlotId, SpecularAAThresholdSlotName, SpecularAAThresholdSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularAAThresholdSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.SpecularTint)) - { - AddSlot(new ColorRGBMaterialSlot(SpecularTintSlotId, SpecularTintSlotName, SpecularTintSlotName, SlotType.Input, Color.white, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularTintSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.SpecularShift)) - { - AddSlot(new Vector1MaterialSlot(SpecularShiftSlotId, SpecularShiftSlotName, SpecularShiftSlotName, SlotType.Input, 0.1f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularShiftSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.SecondarySpecularTint)) - { - AddSlot(new ColorRGBMaterialSlot(SecondarySpecularTintSlotId, SecondarySpecularTintSlotName, SecondarySpecularTintSlotName, SlotType.Input, Color.grey, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(SecondarySpecularTintSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.SecondarySmoothness)) - { - AddSlot(new Vector1MaterialSlot(SecondarySmoothnessSlotId, SecondarySmoothnessSlotName, SecondarySmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(SecondarySmoothnessSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.SecondarySpecularShift)) - { - AddSlot(new Vector1MaterialSlot(SecondarySpecularShiftSlotId, SecondarySpecularShiftSlotName, SecondarySpecularShiftSlotName, SlotType.Input, -0.1f, ShaderStageCapability.Fragment)); - validSlots.Add(SecondarySpecularShiftSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.BakedGI) && overrideBakedGI.isOn) - { - AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(LightingSlotId); - AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(BackLightingSlotId); - } - if (depthOffset.isOn) - { - AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(DepthOffsetSlotId); - } - - RemoveSlotsNameNotMatching(validSlots, true); - } - - public VisualElement CreateSettingsElement() - { - return new HairSettingsView(this); - } - - public string renderQueueTag - { - get - { - var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); - return HDRenderQueue.GetShaderTagValue(queue); - } - } - - public string renderTypeTag => HDRenderTypeTags.HDLitShader.ToString(); - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); - - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || - IsSlotConnected(VertexNormalSlotId) || - IsSlotConnected(VertexTangentSlotId)), - new ConditionalField(Fields.GraphPixel, true), - new ConditionalField(Fields.LodCrossFade, supportLodCrossFade.isOn), - - // Surface Type - new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), - new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), - - // Structs - new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && - !pass.Equals(HDHairSubTarget.HairPasses.MotionVectors)), - // Material - new ConditionalField(HDFields.KajiyaKay, materialType == MaterialType.KajiyaKay), - - // Specular Occlusion - new ConditionalField(HDFields.SpecularOcclusionFromAO, specularOcclusionMode == SpecularOcclusionMode.FromAO), - new ConditionalField(HDFields.SpecularOcclusionFromAOBentNormal, specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal), - new ConditionalField(HDFields.SpecularOcclusionCustom, specularOcclusionMode == SpecularOcclusionMode.Custom), - - // Misc - // We always generate the keyword ALPHATEST_ON - new ConditionalField(Fields.AlphaTest, alphaTest.isOn && (pass.pixelPorts.Contains(AlphaClipThresholdSlotId) || pass.pixelPorts.Contains(AlphaClipThresholdShadowSlotId) || - pass.pixelPorts.Contains(AlphaClipThresholdDepthPrepassSlotId) || pass.pixelPorts.Contains(AlphaClipThresholdDepthPostpassSlotId))), - // All the DoAlphaXXX field drive the generation of which code to use for alpha test in the template - // Do alpha test only if we aren't using the TestShadow one - new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && (pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && - !(alphaTestShadow.isOn && pass.pixelPorts.Contains(AlphaClipThresholdShadowSlotId)))), - new ConditionalField(HDFields.DoAlphaTestShadow, alphaTest.isOn && alphaTestShadow.isOn && pass.pixelPorts.Contains(AlphaClipThresholdShadowSlotId)), - new ConditionalField(HDFields.DoAlphaTestPrepass, alphaTest.isOn && alphaTestDepthPrepass.isOn && pass.pixelPorts.Contains(AlphaClipThresholdDepthPrepassSlotId)), - new ConditionalField(HDFields.DoAlphaTestPostpass, alphaTest.isOn && alphaTestDepthPostpass.isOn && pass.pixelPorts.Contains(AlphaClipThresholdDepthPostpassSlotId)), - new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && alphaToMask.isOn), - new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), - new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), - new ConditionalField(HDFields.TransparentWritesMotionVec, surfaceType != SurfaceType.Opaque && transparentWritesMotionVec.isOn), - new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), - new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), - new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), - new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && - pass.pixelPorts.Contains(BentNormalSlotId)), - new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && - (IsSlotConnected(AmbientOcclusionSlotId) || - ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), - new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && - pass.pixelPorts.Contains(LightingSlotId)), - new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && - pass.pixelPorts.Contains(BackLightingSlotId)), - new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), - new ConditionalField(HDFields.SpecularAA, specularAA.isOn && - pass.pixelPorts.Contains(SpecularAAThresholdSlotId) && - pass.pixelPorts.Contains(SpecularAAScreenSpaceVarianceSlotId)), - - new ConditionalField(HDFields.HairStrandDirection, IsSlotConnected(HairStrandDirectionSlotId) && - pass.pixelPorts.Contains(HairStrandDirectionSlotId)), - new ConditionalField(HDFields.Transmittance, IsSlotConnected(TransmittanceSlotId) && - pass.pixelPorts.Contains(TransmittanceSlotId)), - new ConditionalField(HDFields.RimTransmissionIntensity, IsSlotConnected(RimTransmissionIntensitySlotId) && - pass.pixelPorts.Contains(RimTransmissionIntensitySlotId)), - new ConditionalField(HDFields.UseLightFacingNormal, useLightFacingNormal.isOn), - new ConditionalField(HDFields.TransparentBackFace, surfaceType != SurfaceType.Opaque && backThenFrontRendering.isOn), - new ConditionalField(HDFields.TransparentDepthPrePass, surfaceType != SurfaceType.Opaque && alphaTestDepthPrepass.isOn), - new ConditionalField(HDFields.TransparentDepthPostPass, surfaceType != SurfaceType.Opaque && alphaTestDepthPrepass.isOn), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); - material.SetFloat(kDoubleSidedEnable, doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); - material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); - material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)zTest); - material.SetFloat(kTransparentCullMode, (int)transparentCullMode); - material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); - // No sorting priority for shader graph preview - var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); - - HairGUI.SetupMaterialKeywordsAndPass(material); - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public override object saveContext - { - get - { - int hash = ComputeMaterialNeedsUpdateHash(); - - bool needsUpdate = hash != m_MaterialNeedsUpdateHash; - - if (needsUpdate) - m_MaterialNeedsUpdateHash = hash; - - return new HDSaveContext{ updateMaterials = needsUpdate }; - } - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (addPrecomputedVelocity.isOn) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, false, receiveSSR.isOn); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - surfaceType, - HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), - sortPriority, - alphaToMask.isOn, - zWrite.isOn, - transparentCullMode, - zTest, - backThenFrontRendering.isOn, - transparencyFog.isOn - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, alphaTestShadow.isOn); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); - - base.CollectShaderProperties(collector, generationMode); - } - } -} +// [SerializeField] +// bool m_AlphaToMask = false; + +// public ToggleData alphaToMask +// { +// get { return new ToggleData(m_AlphaToMask); } +// set +// { +// if (m_AlphaToMask == value.isOn) +// return; +// m_AlphaToMask = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaTestDepthPrepass; + +// public ToggleData alphaTestDepthPrepass +// { +// get { return new ToggleData(m_AlphaTestDepthPrepass); } +// set +// { +// if (m_AlphaTestDepthPrepass == value.isOn) +// return; +// m_AlphaTestDepthPrepass = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_AlphaTestDepthPostpass; + +// public ToggleData alphaTestDepthPostpass +// { +// get { return new ToggleData(m_AlphaTestDepthPostpass); } +// set +// { +// if (m_AlphaTestDepthPostpass == value.isOn) +// return; +// m_AlphaTestDepthPostpass = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_TransparentWritesMotionVec; + +// public ToggleData transparentWritesMotionVec +// { +// get { return new ToggleData(m_TransparentWritesMotionVec); } +// set +// { +// if (m_TransparentWritesMotionVec == value.isOn) +// return; +// m_TransparentWritesMotionVec = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_AlphaTestShadow; + +// public ToggleData alphaTestShadow +// { +// get { return new ToggleData(m_AlphaTestShadow); } +// set +// { +// if (m_AlphaTestShadow == value.isOn) +// return; +// m_AlphaTestShadow = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_BackThenFrontRendering; + +// public ToggleData backThenFrontRendering +// { +// get { return new ToggleData(m_BackThenFrontRendering); } +// set +// { +// if (m_BackThenFrontRendering == value.isOn) +// return; +// m_BackThenFrontRendering = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_SortPriority; + +// public int sortPriority +// { +// get { return m_SortPriority; } +// set +// { +// if (m_SortPriority == value) +// return; +// m_SortPriority = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// DoubleSidedMode m_DoubleSidedMode; + +// public DoubleSidedMode doubleSidedMode +// { +// get { return m_DoubleSidedMode; } +// set +// { +// if (m_DoubleSidedMode == value) +// return; + +// m_DoubleSidedMode = value; +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// MaterialType m_MaterialType; + +// public MaterialType materialType +// { +// get { return m_MaterialType; } +// set +// { +// if (m_MaterialType == value) +// return; + +// m_MaterialType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ReceiveDecals = true; + +// public ToggleData receiveDecals +// { +// get { return new ToggleData(m_ReceiveDecals); } +// set +// { +// if (m_ReceiveDecals == value.isOn) +// return; +// m_ReceiveDecals = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_ReceivesSSR = true; +// public ToggleData receiveSSR +// { +// get { return new ToggleData(m_ReceivesSSR); } +// set +// { +// if (m_ReceivesSSR == value.isOn) +// return; +// m_ReceivesSSR = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AddPrecomputedVelocity = false; + +// public ToggleData addPrecomputedVelocity +// { +// get { return new ToggleData(m_AddPrecomputedVelocity); } +// set +// { +// if (m_AddPrecomputedVelocity == value.isOn) +// return; +// m_AddPrecomputedVelocity = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + + + +// [SerializeField] +// bool m_UseLightFacingNormal = false; +// public ToggleData useLightFacingNormal +// { +// get { return new ToggleData(m_UseLightFacingNormal); } +// set +// { +// if (m_UseLightFacingNormal == value.isOn) +// return; +// m_UseLightFacingNormal = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SpecularAA; + +// public ToggleData specularAA +// { +// get { return new ToggleData(m_SpecularAA); } +// set +// { +// if (m_SpecularAA == value.isOn) +// return; +// m_SpecularAA = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// float m_SpecularAAScreenSpaceVariance; + +// public float specularAAScreenSpaceVariance +// { +// get { return m_SpecularAAScreenSpaceVariance; } +// set +// { +// if (m_SpecularAAScreenSpaceVariance == value) +// return; +// m_SpecularAAScreenSpaceVariance = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// float m_SpecularAAThreshold; + +// public float specularAAThreshold +// { +// get { return m_SpecularAAThreshold; } +// set +// { +// if (m_SpecularAAThreshold == value) +// return; +// m_SpecularAAThreshold = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// SpecularOcclusionMode m_SpecularOcclusionMode; + +// public SpecularOcclusionMode specularOcclusionMode +// { +// get { return m_SpecularOcclusionMode; } +// set +// { +// if (m_SpecularOcclusionMode == value) +// return; + +// m_SpecularOcclusionMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_overrideBakedGI; + +// public ToggleData overrideBakedGI +// { +// get { return new ToggleData(m_overrideBakedGI); } +// set +// { +// if (m_overrideBakedGI == value.isOn) +// return; +// m_overrideBakedGI = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_depthOffset; + +// public ToggleData depthOffset +// { +// get { return new ToggleData(m_depthOffset); } +// set +// { +// if (m_depthOffset == value.isOn) +// return; +// m_depthOffset = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ZWrite; + +// public ToggleData zWrite +// { +// get { return new ToggleData(m_ZWrite); } +// set +// { +// if (m_ZWrite == value.isOn) +// return; +// m_ZWrite = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; +// public TransparentCullMode transparentCullMode +// { +// get => m_transparentCullMode; +// set +// { +// if (m_transparentCullMode == value) +// return; + +// m_transparentCullMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// CompareFunction m_ZTest = CompareFunction.LessEqual; +// public CompareFunction zTest +// { +// get => m_ZTest; +// set +// { +// if (m_ZTest == value) +// return; + +// m_ZTest = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SupportLodCrossFade; + +// public ToggleData supportLodCrossFade +// { +// get { return new ToggleData(m_SupportLodCrossFade); } +// set +// { +// if (m_SupportLodCrossFade == value.isOn) +// return; +// m_SupportLodCrossFade = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Node); +// } +// } + +// [SerializeField] +// bool m_DOTSInstancing = false; + +// public ToggleData dotsInstancing +// { +// get { return new ToggleData(m_DOTSInstancing); } +// set +// { +// if (m_DOTSInstancing == value.isOn) +// return; + +// m_DOTSInstancing = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_MaterialNeedsUpdateHash = 0; + +// int ComputeMaterialNeedsUpdateHash() +// { +// int hash = 0; + +// hash |= (alphaTest.isOn ? 0 : 1) << 0; +// hash |= (alphaTestShadow.isOn ? 0 : 1) << 1; +// hash |= (receiveSSR.isOn ? 0 : 1) << 2; + +// return hash; +// } + +// [SerializeField] private string m_ShaderGUIOverride; +// public string ShaderGUIOverride +// { +// get => m_ShaderGUIOverride; +// set => m_ShaderGUIOverride = value; +// } + +// [SerializeField] private bool m_OverrideEnabled; +// public bool OverrideEnabled +// { +// get => m_OverrideEnabled; +// set => m_OverrideEnabled = value; +// } + +// public HairMasterNode() +// { +// UpdateNodeAfterDeserialization(); +// } + +// public override string documentationURL => Documentation.GetPageLink("Master-Node-Hair"); + +// public sealed override void UpdateNodeAfterDeserialization() +// { +// base.UpdateNodeAfterDeserialization(); +// name = "Hair Master"; + +// List validSlots = new List(); + +// if (MaterialTypeUsesSlotMask(SlotMask.Position)) +// { +// AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(PositionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) +// { +// AddSlot(new NormalMaterialSlot(VertexNormalSlotId, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexNormalSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) +// { +// AddSlot(new TangentMaterialSlot(VertexTangentSlotId, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexTangentSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) +// { +// AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(AlbedoSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.SpecularOcclusion) && specularOcclusionMode == SpecularOcclusionMode.Custom) +// { +// AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularOcclusionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Normal)) +// { +// AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(NormalSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.BentNormal)) +// { +// AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(BentNormalSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) +// { +// AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(SmoothnessSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) +// { +// AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AmbientOcclusionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Transmittance)) +// { +// AddSlot(new Vector3MaterialSlot(TransmittanceSlotId, TransmittanceSlotName, TransmittanceSlotName, SlotType.Input, 0.3f * new Vector3(1.0f, 0.65f, 0.3f), ShaderStageCapability.Fragment)); +// validSlots.Add(TransmittanceSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.RimTransmissionIntensity)) +// { +// AddSlot(new Vector1MaterialSlot(RimTransmissionIntensitySlotId, RimTransmissionIntensitySlotName, RimTransmissionIntensitySlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); +// validSlots.Add(RimTransmissionIntensitySlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.HairStrandDirection)) +// { +// AddSlot(new Vector3MaterialSlot(HairStrandDirectionSlotId, HairStrandDirectionSlotName, HairStrandDirectionSlotName, SlotType.Input, new Vector3(0, -1, 0), ShaderStageCapability.Fragment)); +// validSlots.Add(HairStrandDirectionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Emission)) +// { +// AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); +// validSlots.Add(EmissionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Alpha)) +// { +// AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThreshold) && alphaTest.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaClipThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaClipThresholdSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThresholdDepthPrepass) && surfaceType == SurfaceType.Transparent && alphaTest.isOn && alphaTestDepthPrepass.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaClipThresholdDepthPrepassSlotId, AlphaClipThresholdDepthPrepassSlotName, AlphaClipThresholdDepthPrepassSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaClipThresholdDepthPrepassSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThresholdDepthPostpass) && surfaceType == SurfaceType.Transparent && alphaTest.isOn && alphaTestDepthPostpass.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaClipThresholdDepthPostpassSlotId, AlphaClipThresholdDepthPostpassSlotName, AlphaClipThresholdDepthPostpassSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaClipThresholdDepthPostpassSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaClipThresholdShadow) && alphaTest.isOn && alphaTestShadow.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaClipThresholdShadowSlotId, AlphaClipThresholdShadowSlotName, AlphaClipThresholdShadowSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaClipThresholdShadowSlotId); +// } +// if (specularAA.isOn) +// { +// AddSlot(new Vector1MaterialSlot(SpecularAAScreenSpaceVarianceSlotId, SpecularAAScreenSpaceVarianceSlotName, SpecularAAScreenSpaceVarianceSlotName, SlotType.Input, 0.1f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularAAScreenSpaceVarianceSlotId); + +// AddSlot(new Vector1MaterialSlot(SpecularAAThresholdSlotId, SpecularAAThresholdSlotName, SpecularAAThresholdSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularAAThresholdSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.SpecularTint)) +// { +// AddSlot(new ColorRGBMaterialSlot(SpecularTintSlotId, SpecularTintSlotName, SpecularTintSlotName, SlotType.Input, Color.white, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularTintSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.SpecularShift)) +// { +// AddSlot(new Vector1MaterialSlot(SpecularShiftSlotId, SpecularShiftSlotName, SpecularShiftSlotName, SlotType.Input, 0.1f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularShiftSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.SecondarySpecularTint)) +// { +// AddSlot(new ColorRGBMaterialSlot(SecondarySpecularTintSlotId, SecondarySpecularTintSlotName, SecondarySpecularTintSlotName, SlotType.Input, Color.grey, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(SecondarySpecularTintSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.SecondarySmoothness)) +// { +// AddSlot(new Vector1MaterialSlot(SecondarySmoothnessSlotId, SecondarySmoothnessSlotName, SecondarySmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(SecondarySmoothnessSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.SecondarySpecularShift)) +// { +// AddSlot(new Vector1MaterialSlot(SecondarySpecularShiftSlotId, SecondarySpecularShiftSlotName, SecondarySpecularShiftSlotName, SlotType.Input, -0.1f, ShaderStageCapability.Fragment)); +// validSlots.Add(SecondarySpecularShiftSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.BakedGI) && overrideBakedGI.isOn) +// { +// AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(LightingSlotId); +// AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(BackLightingSlotId); +// } +// if (depthOffset.isOn) +// { +// AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(DepthOffsetSlotId); +// } + +// RemoveSlotsNameNotMatching(validSlots, true); +// } + +// public VisualElement CreateSettingsElement() +// { +// return new HairSettingsView(this); +// } + +// public string renderQueueTag +// { +// get +// { +// var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; +// int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); +// return HDRenderQueue.GetShaderTagValue(queue); +// } +// } + +// public string renderTypeTag => HDRenderTypeTags.HDLitShader.ToString(); + +// public ConditionalField[] GetConditionalFields(PassDescriptor pass) +// { +// var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); + +// return new ConditionalField[] +// { +// // Features +// new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || +// IsSlotConnected(VertexNormalSlotId) || +// IsSlotConnected(VertexTangentSlotId)), +// new ConditionalField(Fields.GraphPixel, true), +// new ConditionalField(Fields.LodCrossFade, supportLodCrossFade.isOn), + +// // Surface Type +// new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), +// new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), + +// // Structs +// new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && +// !pass.Equals(HDHairSubTarget.HairPasses.MotionVectors)), +// // Material +// new ConditionalField(HDFields.KajiyaKay, materialType == MaterialType.KajiyaKay), + +// // Specular Occlusion +// new ConditionalField(HDFields.SpecularOcclusionFromAO, specularOcclusionMode == SpecularOcclusionMode.FromAO), +// new ConditionalField(HDFields.SpecularOcclusionFromAOBentNormal, specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal), +// new ConditionalField(HDFields.SpecularOcclusionCustom, specularOcclusionMode == SpecularOcclusionMode.Custom), + +// // Misc +// // We always generate the keyword ALPHATEST_ON +// new ConditionalField(Fields.AlphaTest, alphaTest.isOn && (pass.pixelPorts.Contains(AlphaClipThresholdSlotId) || pass.pixelPorts.Contains(AlphaClipThresholdShadowSlotId) || +// pass.pixelPorts.Contains(AlphaClipThresholdDepthPrepassSlotId) || pass.pixelPorts.Contains(AlphaClipThresholdDepthPostpassSlotId))), +// // All the DoAlphaXXX field drive the generation of which code to use for alpha test in the template +// // Do alpha test only if we aren't using the TestShadow one +// new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && (pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && +// !(alphaTestShadow.isOn && pass.pixelPorts.Contains(AlphaClipThresholdShadowSlotId)))), +// new ConditionalField(HDFields.DoAlphaTestShadow, alphaTest.isOn && alphaTestShadow.isOn && pass.pixelPorts.Contains(AlphaClipThresholdShadowSlotId)), +// new ConditionalField(HDFields.DoAlphaTestPrepass, alphaTest.isOn && alphaTestDepthPrepass.isOn && pass.pixelPorts.Contains(AlphaClipThresholdDepthPrepassSlotId)), +// new ConditionalField(HDFields.DoAlphaTestPostpass, alphaTest.isOn && alphaTestDepthPostpass.isOn && pass.pixelPorts.Contains(AlphaClipThresholdDepthPostpassSlotId)), +// new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && alphaToMask.isOn), +// new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), +// new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), +// new ConditionalField(HDFields.TransparentWritesMotionVec, surfaceType != SurfaceType.Opaque && transparentWritesMotionVec.isOn), +// new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), +// new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), +// new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), +// new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && +// pass.pixelPorts.Contains(BentNormalSlotId)), +// new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && +// (IsSlotConnected(AmbientOcclusionSlotId) || +// ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), +// new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && +// pass.pixelPorts.Contains(LightingSlotId)), +// new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && +// pass.pixelPorts.Contains(BackLightingSlotId)), +// new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), +// new ConditionalField(HDFields.SpecularAA, specularAA.isOn && +// pass.pixelPorts.Contains(SpecularAAThresholdSlotId) && +// pass.pixelPorts.Contains(SpecularAAScreenSpaceVarianceSlotId)), + +// new ConditionalField(HDFields.HairStrandDirection, IsSlotConnected(HairStrandDirectionSlotId) && +// pass.pixelPorts.Contains(HairStrandDirectionSlotId)), +// new ConditionalField(HDFields.Transmittance, IsSlotConnected(TransmittanceSlotId) && +// pass.pixelPorts.Contains(TransmittanceSlotId)), +// new ConditionalField(HDFields.RimTransmissionIntensity, IsSlotConnected(RimTransmissionIntensitySlotId) && +// pass.pixelPorts.Contains(RimTransmissionIntensitySlotId)), +// new ConditionalField(HDFields.UseLightFacingNormal, useLightFacingNormal.isOn), +// new ConditionalField(HDFields.TransparentBackFace, surfaceType != SurfaceType.Opaque && backThenFrontRendering.isOn), +// new ConditionalField(HDFields.TransparentDepthPrePass, surfaceType != SurfaceType.Opaque && alphaTestDepthPrepass.isOn), +// new ConditionalField(HDFields.TransparentDepthPostPass, surfaceType != SurfaceType.Opaque && alphaTestDepthPrepass.isOn), +// }; +// } + +// public void ProcessPreviewMaterial(Material material) +// { +// // Fixup the material settings: +// material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); +// material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); +// material.SetFloat(kDoubleSidedEnable, doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); +// material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); +// material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); +// material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); +// material.SetFloat(kZTestTransparent, (int)zTest); +// material.SetFloat(kTransparentCullMode, (int)transparentCullMode); +// material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); +// // No sorting priority for shader graph preview +// var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; +// material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); + +// HairGUI.SetupMaterialKeywordsAndPass(material); +// } + +// public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); +// } + +// public override object saveContext +// { +// get +// { +// int hash = ComputeMaterialNeedsUpdateHash(); + +// bool needsUpdate = hash != m_MaterialNeedsUpdateHash; + +// if (needsUpdate) +// m_MaterialNeedsUpdateHash = hash; + +// return new HDSaveContext{ updateMaterials = needsUpdate }; +// } +// } + +// public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) +// { +// // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. +// // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 +// // The user will then need to explicitly disable emissive GI if it is not needed. +// // To be able to automatically disable emission based on the ShaderGraph config when emission is black, +// // we will need a more general way to communicate this to the engine (not directly tied to a material property). +// collector.AddShaderProperty(new ColorShaderProperty() +// { +// overrideReferenceName = "_EmissionColor", +// hidden = true, +// value = new Color(1.0f, 1.0f, 1.0f, 1.0f) +// }); + +// //See SG-ADDITIONALVELOCITY-NOTE +// if (addPrecomputedVelocity.isOn) +// { +// collector.AddShaderProperty(new BooleanShaderProperty +// { +// value = true, +// hidden = true, +// overrideReferenceName = kAddPrecomputedVelocity, +// }); +// } + +// // Add all shader properties required by the inspector +// HDSubShaderUtilities.AddStencilShaderProperties(collector, false, receiveSSR.isOn); +// HDSubShaderUtilities.AddBlendingStatesShaderProperties( +// collector, +// surfaceType, +// HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), +// sortPriority, +// alphaToMask.isOn, +// zWrite.isOn, +// transparentCullMode, +// zTest, +// backThenFrontRendering.isOn, +// transparencyFog.isOn +// ); +// HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, alphaTestShadow.isOn); +// HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); + +// base.CollectShaderProperties(collector, generationMode); +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs index 948ffdbdf55..88582cbb671 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs @@ -1,521 +1,521 @@ -using System; -using UnityEditor.UIElements; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; - -namespace UnityEditor.Rendering.HighDefinition.Drawing -{ - class HairSettingsView : MasterNodeSettingsView - { - HairMasterNode m_Node; - - IntegerField m_SortPriorityField; - - Label CreateLabel(string text, int indentLevel) - { - string label = ""; - for (var i = 0; i < indentLevel; i++) - { - label += " "; - } - return new Label(label + text); - } - - public HairSettingsView(HairMasterNode node) : base(node) - { - m_Node = node; - PropertySheet ps = new PropertySheet(); - - int indentLevel = 0; - ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => - { - row.Add(new EnumField(SurfaceType.Opaque), (field) => - { - field.value = m_Node.surfaceType; - field.RegisterValueChangedCallback(ChangeSurfaceType); - }); - }); - - if (m_Node.surfaceType == SurfaceType.Transparent) - { - ++indentLevel; - - ps.Add(new PropertyRow(CreateLabel("Preserve Specular Lighting", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.blendPreserveSpecular.isOn; - toggle.OnToggleChanged(ChangeBlendPreserveSpecular); - }); - }); - - m_SortPriorityField = new IntegerField(); - ps.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => - { - row.Add(m_SortPriorityField, (field) => - { - field.value = m_Node.sortPriority; - field.RegisterValueChangedCallback(ChangeSortPriority); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transparencyFog.isOn; - toggle.OnToggleChanged(ChangeTransparencyFog); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Back Then Front Rendering", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.backThenFrontRendering.isOn; - toggle.OnToggleChanged(ChangeBackThenFrontRendering); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Transparent Depth Prepass", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTestDepthPrepass.isOn; - toggle.OnToggleChanged(ChangeAlphaTestPrepass); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Transparent Depth Postpass", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTestDepthPostpass.isOn; - toggle.OnToggleChanged(ChangeAlphaTestPostpass); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Transparent Writes Motion Vector", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transparentWritesMotionVec.isOn; - toggle.OnToggleChanged(ChangeTransparentWritesMotionVec); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.zWrite.isOn; - toggle.OnToggleChanged(ChangeZWrite); - }); - }); - - if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) - { - ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.transparentCullMode), (e) => - { - e.value = m_Node.transparentCullMode; - e.RegisterValueChangedCallback(ChangeTransparentCullMode); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.zTest), (e) => - { - e.value = m_Node.zTest; - e.RegisterValueChangedCallback(ChangeZTest); - }); - }); - - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => - { - row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => - { - field.value = m_Node.doubleSidedMode; - field.RegisterValueChangedCallback(ChangeDoubleSidedMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTest.isOn; - toggle.OnToggleChanged(ChangeAlphaTest); - }); - }); - - if (m_Node.alphaTest.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Use Shadow Threshold", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTestShadow.isOn; - toggle.OnToggleChanged(ChangeAlphaTestShadow); - }); - }); +// using System; +// using UnityEditor.UIElements; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEditor.Graphing.Util; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; + +// namespace UnityEditor.Rendering.HighDefinition.Drawing +// { +// class HairSettingsView : MasterNodeSettingsView +// { +// HairMasterNode m_Node; + +// IntegerField m_SortPriorityField; + +// Label CreateLabel(string text, int indentLevel) +// { +// string label = ""; +// for (var i = 0; i < indentLevel; i++) +// { +// label += " "; +// } +// return new Label(label + text); +// } + +// public HairSettingsView(HairMasterNode node) : base(node) +// { +// m_Node = node; +// PropertySheet ps = new PropertySheet(); + +// int indentLevel = 0; +// ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(SurfaceType.Opaque), (field) => +// { +// field.value = m_Node.surfaceType; +// field.RegisterValueChangedCallback(ChangeSurfaceType); +// }); +// }); + +// if (m_Node.surfaceType == SurfaceType.Transparent) +// { +// ++indentLevel; + +// ps.Add(new PropertyRow(CreateLabel("Preserve Specular Lighting", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.blendPreserveSpecular.isOn; +// toggle.OnToggleChanged(ChangeBlendPreserveSpecular); +// }); +// }); + +// m_SortPriorityField = new IntegerField(); +// ps.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => +// { +// row.Add(m_SortPriorityField, (field) => +// { +// field.value = m_Node.sortPriority; +// field.RegisterValueChangedCallback(ChangeSortPriority); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transparencyFog.isOn; +// toggle.OnToggleChanged(ChangeTransparencyFog); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Back Then Front Rendering", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.backThenFrontRendering.isOn; +// toggle.OnToggleChanged(ChangeBackThenFrontRendering); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Transparent Depth Prepass", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTestDepthPrepass.isOn; +// toggle.OnToggleChanged(ChangeAlphaTestPrepass); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Transparent Depth Postpass", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTestDepthPostpass.isOn; +// toggle.OnToggleChanged(ChangeAlphaTestPostpass); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Transparent Writes Motion Vector", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transparentWritesMotionVec.isOn; +// toggle.OnToggleChanged(ChangeTransparentWritesMotionVec); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.zWrite.isOn; +// toggle.OnToggleChanged(ChangeZWrite); +// }); +// }); + +// if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) +// { +// ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.transparentCullMode), (e) => +// { +// e.value = m_Node.transparentCullMode; +// e.RegisterValueChangedCallback(ChangeTransparentCullMode); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.zTest), (e) => +// { +// e.value = m_Node.zTest; +// e.RegisterValueChangedCallback(ChangeZTest); +// }); +// }); + +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => +// { +// row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => +// { +// field.value = m_Node.doubleSidedMode; +// field.RegisterValueChangedCallback(ChangeDoubleSidedMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTest.isOn; +// toggle.OnToggleChanged(ChangeAlphaTest); +// }); +// }); + +// if (m_Node.alphaTest.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Use Shadow Threshold", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTestShadow.isOn; +// toggle.OnToggleChanged(ChangeAlphaTestShadow); +// }); +// }); - ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaToMask.isOn; - toggle.OnToggleChanged(ChangeAlphaToMask); - }); - }); - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveDecals.isOn; - toggle.OnToggleChanged(ChangeDecal); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveSSR.isOn; - toggle.OnToggleChanged(ChangeSSR); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.addPrecomputedVelocity.isOn; - toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Geometric Specular AA", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.specularAA.isOn; - toggle.OnToggleChanged(ChangeSpecularAA); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => - { - row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => - { - field.value = m_Node.specularOcclusionMode; - field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.overrideBakedGI.isOn; - toggle.OnToggleChanged(ChangeoverrideBakedGI); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.depthOffset.isOn; - toggle.OnToggleChanged(ChangeDepthOffset); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Use Light Facing Normal", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.useLightFacingNormal.isOn; - toggle.OnToggleChanged(ChangeUseLightFacingNormal); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.supportLodCrossFade.isOn; - toggle.OnToggleChanged(ChangeSupportLODCrossFade); - }); - }); - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeSurfaceType(ChangeEvent evt) - { - if (Equals(m_Node.surfaceType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); - m_Node.surfaceType = (SurfaceType)evt.newValue; - } - - void ChangeDoubleSidedMode(ChangeEvent evt) - { - if (Equals(m_Node.doubleSidedMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); - m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; - } - - void ChangeBlendMode(ChangeEvent evt) - { - // Make sure the mapping is correct by handling each case. - AlphaMode alphaMode = GetAlphaMode((HairMasterNode.AlphaModeLit)evt.newValue); - - if (Equals(m_Node.alphaMode, alphaMode)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); - m_Node.alphaMode = alphaMode; - } - - void ChangeBlendPreserveSpecular(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); - ToggleData td = m_Node.blendPreserveSpecular; - td.isOn = evt.newValue; - m_Node.blendPreserveSpecular = td; - } - - void ChangeTransparencyFog(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); - ToggleData td = m_Node.transparencyFog; - td.isOn = evt.newValue; - m_Node.transparencyFog = td; - } - - void ChangeBackThenFrontRendering(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Back Then Front Rendering Change"); - ToggleData td = m_Node.backThenFrontRendering; - td.isOn = evt.newValue; - m_Node.backThenFrontRendering = td; - } - - void ChangeSortPriority(ChangeEvent evt) - { - m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - // Force the text to match. - m_SortPriorityField.value = m_Node.sortPriority; - if (Equals(m_Node.sortPriority, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); - } - - void ChangeAlphaTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); - ToggleData td = m_Node.alphaTest; - td.isOn = evt.newValue; - m_Node.alphaTest = td; - } - - void ChangeAlphaToMask(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); - ToggleData td = m_Node.alphaToMask; - td.isOn = evt.newValue; - m_Node.alphaToMask = td; - } - - void ChangeAlphaTestPrepass(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Prepass Change"); - ToggleData td = m_Node.alphaTestDepthPrepass; - td.isOn = evt.newValue; - m_Node.alphaTestDepthPrepass = td; - } - - void ChangeAlphaTestPostpass(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Postpass Change"); - ToggleData td = m_Node.alphaTestDepthPostpass; - td.isOn = evt.newValue; - m_Node.alphaTestDepthPostpass = td; - } - - void ChangeTransparentWritesMotionVec(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Writes Motion Vector Change"); - ToggleData td = m_Node.transparentWritesMotionVec; - td.isOn = evt.newValue; - m_Node.transparentWritesMotionVec = td; - } - - void ChangeAlphaTestShadow(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Shadow Change"); - ToggleData td = m_Node.alphaTestShadow; - td.isOn = evt.newValue; - m_Node.alphaTestShadow = td; - } - - void ChangeDecal(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Decal Change"); - ToggleData td = m_Node.receiveDecals; - td.isOn = evt.newValue; - m_Node.receiveDecals = td; - } - - void ChangeSSR(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); - ToggleData td = m_Node.receiveSSR; - td.isOn = evt.newValue; - m_Node.receiveSSR = td; - } - - void ChangeAddPrecomputedVelocity(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); - ToggleData td = m_Node.addPrecomputedVelocity; - td.isOn = evt.newValue; - m_Node.addPrecomputedVelocity = td; - } - - void ChangeUseLightFacingNormal(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Use Light Facing Normal Change"); - ToggleData td = m_Node.useLightFacingNormal; - td.isOn = evt.newValue; - m_Node.useLightFacingNormal = td; - } - - void ChangeSpecularAA(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Specular AA Change"); - ToggleData td = m_Node.specularAA; - td.isOn = evt.newValue; - m_Node.specularAA = td; - } - - void ChangeSpecularOcclusionMode(ChangeEvent evt) - { - if (Equals(m_Node.specularOcclusionMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Specular Occlusion Mode Change"); - m_Node.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; - } - - void ChangeoverrideBakedGI(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); - ToggleData td = m_Node.overrideBakedGI; - td.isOn = evt.newValue; - m_Node.overrideBakedGI = td; - } - - void ChangeDepthOffset(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); - ToggleData td = m_Node.depthOffset; - td.isOn = evt.newValue; - m_Node.depthOffset = td; - } - - void ChangeZWrite(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); - ToggleData td = m_Node.zWrite; - td.isOn = evt.newValue; - m_Node.zWrite = td; - } - - void ChangeTransparentCullMode(ChangeEvent evt) - { - if (Equals(m_Node.transparentCullMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); - m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; - } - - void ChangeZTest(ChangeEvent evt) - { - if (Equals(m_Node.zTest, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); - m_Node.zTest = (CompareFunction)evt.newValue; - } - - void ChangeSupportLODCrossFade(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); - ToggleData td = m_Node.supportLodCrossFade; - td.isOn = evt.newValue; - m_Node.supportLodCrossFade = td; - } - - public AlphaMode GetAlphaMode(HairMasterNode.AlphaModeLit alphaModeLit) - { - switch (alphaModeLit) - { - case HairMasterNode.AlphaModeLit.Alpha: - return AlphaMode.Alpha; - case HairMasterNode.AlphaModeLit.Premultiply: - return AlphaMode.Premultiply; - case HairMasterNode.AlphaModeLit.Additive: - return AlphaMode.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaModeLit); - return AlphaMode.Alpha; - } - - } - } - - public HairMasterNode.AlphaModeLit GetAlphaModeLit(AlphaMode alphaMode) - { - switch (alphaMode) - { - case AlphaMode.Alpha: - return HairMasterNode.AlphaModeLit.Alpha; - case AlphaMode.Premultiply: - return HairMasterNode.AlphaModeLit.Premultiply; - case AlphaMode.Additive: - return HairMasterNode.AlphaModeLit.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaMode); - return HairMasterNode.AlphaModeLit.Alpha; - } - } - } - } -} +// ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaToMask.isOn; +// toggle.OnToggleChanged(ChangeAlphaToMask); +// }); +// }); +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveDecals.isOn; +// toggle.OnToggleChanged(ChangeDecal); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveSSR.isOn; +// toggle.OnToggleChanged(ChangeSSR); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.addPrecomputedVelocity.isOn; +// toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Geometric Specular AA", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.specularAA.isOn; +// toggle.OnToggleChanged(ChangeSpecularAA); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => +// { +// field.value = m_Node.specularOcclusionMode; +// field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.overrideBakedGI.isOn; +// toggle.OnToggleChanged(ChangeoverrideBakedGI); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.depthOffset.isOn; +// toggle.OnToggleChanged(ChangeDepthOffset); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Use Light Facing Normal", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.useLightFacingNormal.isOn; +// toggle.OnToggleChanged(ChangeUseLightFacingNormal); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.supportLodCrossFade.isOn; +// toggle.OnToggleChanged(ChangeSupportLODCrossFade); +// }); +// }); + +// Add(ps); +// Add(GetShaderGUIOverridePropertySheet()); +// } + +// void ChangeSurfaceType(ChangeEvent evt) +// { +// if (Equals(m_Node.surfaceType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); +// m_Node.surfaceType = (SurfaceType)evt.newValue; +// } + +// void ChangeDoubleSidedMode(ChangeEvent evt) +// { +// if (Equals(m_Node.doubleSidedMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); +// m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; +// } + +// void ChangeBlendMode(ChangeEvent evt) +// { +// // Make sure the mapping is correct by handling each case. +// AlphaMode alphaMode = GetAlphaMode((HairMasterNode.AlphaModeLit)evt.newValue); + +// if (Equals(m_Node.alphaMode, alphaMode)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); +// m_Node.alphaMode = alphaMode; +// } + +// void ChangeBlendPreserveSpecular(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); +// ToggleData td = m_Node.blendPreserveSpecular; +// td.isOn = evt.newValue; +// m_Node.blendPreserveSpecular = td; +// } + +// void ChangeTransparencyFog(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); +// ToggleData td = m_Node.transparencyFog; +// td.isOn = evt.newValue; +// m_Node.transparencyFog = td; +// } + +// void ChangeBackThenFrontRendering(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Back Then Front Rendering Change"); +// ToggleData td = m_Node.backThenFrontRendering; +// td.isOn = evt.newValue; +// m_Node.backThenFrontRendering = td; +// } + +// void ChangeSortPriority(ChangeEvent evt) +// { +// m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); +// // Force the text to match. +// m_SortPriorityField.value = m_Node.sortPriority; +// if (Equals(m_Node.sortPriority, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); +// } + +// void ChangeAlphaTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); +// ToggleData td = m_Node.alphaTest; +// td.isOn = evt.newValue; +// m_Node.alphaTest = td; +// } + +// void ChangeAlphaToMask(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); +// ToggleData td = m_Node.alphaToMask; +// td.isOn = evt.newValue; +// m_Node.alphaToMask = td; +// } + +// void ChangeAlphaTestPrepass(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Prepass Change"); +// ToggleData td = m_Node.alphaTestDepthPrepass; +// td.isOn = evt.newValue; +// m_Node.alphaTestDepthPrepass = td; +// } + +// void ChangeAlphaTestPostpass(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Postpass Change"); +// ToggleData td = m_Node.alphaTestDepthPostpass; +// td.isOn = evt.newValue; +// m_Node.alphaTestDepthPostpass = td; +// } + +// void ChangeTransparentWritesMotionVec(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Writes Motion Vector Change"); +// ToggleData td = m_Node.transparentWritesMotionVec; +// td.isOn = evt.newValue; +// m_Node.transparentWritesMotionVec = td; +// } + +// void ChangeAlphaTestShadow(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Shadow Change"); +// ToggleData td = m_Node.alphaTestShadow; +// td.isOn = evt.newValue; +// m_Node.alphaTestShadow = td; +// } + +// void ChangeDecal(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Decal Change"); +// ToggleData td = m_Node.receiveDecals; +// td.isOn = evt.newValue; +// m_Node.receiveDecals = td; +// } + +// void ChangeSSR(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); +// ToggleData td = m_Node.receiveSSR; +// td.isOn = evt.newValue; +// m_Node.receiveSSR = td; +// } + +// void ChangeAddPrecomputedVelocity(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); +// ToggleData td = m_Node.addPrecomputedVelocity; +// td.isOn = evt.newValue; +// m_Node.addPrecomputedVelocity = td; +// } + +// void ChangeUseLightFacingNormal(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Use Light Facing Normal Change"); +// ToggleData td = m_Node.useLightFacingNormal; +// td.isOn = evt.newValue; +// m_Node.useLightFacingNormal = td; +// } + +// void ChangeSpecularAA(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Specular AA Change"); +// ToggleData td = m_Node.specularAA; +// td.isOn = evt.newValue; +// m_Node.specularAA = td; +// } + +// void ChangeSpecularOcclusionMode(ChangeEvent evt) +// { +// if (Equals(m_Node.specularOcclusionMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Specular Occlusion Mode Change"); +// m_Node.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; +// } + +// void ChangeoverrideBakedGI(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); +// ToggleData td = m_Node.overrideBakedGI; +// td.isOn = evt.newValue; +// m_Node.overrideBakedGI = td; +// } + +// void ChangeDepthOffset(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); +// ToggleData td = m_Node.depthOffset; +// td.isOn = evt.newValue; +// m_Node.depthOffset = td; +// } + +// void ChangeZWrite(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); +// ToggleData td = m_Node.zWrite; +// td.isOn = evt.newValue; +// m_Node.zWrite = td; +// } + +// void ChangeTransparentCullMode(ChangeEvent evt) +// { +// if (Equals(m_Node.transparentCullMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); +// m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; +// } + +// void ChangeZTest(ChangeEvent evt) +// { +// if (Equals(m_Node.zTest, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); +// m_Node.zTest = (CompareFunction)evt.newValue; +// } + +// void ChangeSupportLODCrossFade(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); +// ToggleData td = m_Node.supportLodCrossFade; +// td.isOn = evt.newValue; +// m_Node.supportLodCrossFade = td; +// } + +// public AlphaMode GetAlphaMode(HairMasterNode.AlphaModeLit alphaModeLit) +// { +// switch (alphaModeLit) +// { +// case HairMasterNode.AlphaModeLit.Alpha: +// return AlphaMode.Alpha; +// case HairMasterNode.AlphaModeLit.Premultiply: +// return AlphaMode.Premultiply; +// case HairMasterNode.AlphaModeLit.Additive: +// return AlphaMode.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaModeLit); +// return AlphaMode.Alpha; +// } + +// } +// } + +// public HairMasterNode.AlphaModeLit GetAlphaModeLit(AlphaMode alphaMode) +// { +// switch (alphaMode) +// { +// case AlphaMode.Alpha: +// return HairMasterNode.AlphaModeLit.Alpha; +// case AlphaMode.Premultiply: +// return HairMasterNode.AlphaModeLit.Premultiply; +// case AlphaMode.Additive: +// return HairMasterNode.AlphaModeLit.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaMode); +// return HairMasterNode.AlphaModeLit.Alpha; +// } +// } +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitShaderPreprocessor.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitShaderPreprocessor.cs index 11e21446424..6031f4ae9ae 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitShaderPreprocessor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/LitShaderPreprocessor.cs @@ -26,17 +26,18 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade // Cache Shader Graph lookup data so we don't continually keep reloading graphs from disk. // TODO: Should really be able to answer the questions "is shader graph" and "uses HDLitMasterNode" without // hitting disk on every invoke. - if (!m_ShaderGraphMasterNodeType.TryGetValue(shader, out var shaderGraphMasterNodeType)) - { - if (shader.IsShaderGraph()) - { - string shaderPath = AssetDatabase.GetAssetPath(shader); - shaderGraphMasterNodeType = GraphUtil.GetOutputNodeType(shaderPath); - } - - m_ShaderGraphMasterNodeType[shader] = shaderGraphMasterNodeType; - } - isBuiltInLit |= shaderGraphMasterNodeType == typeof(HDLitMasterNode); + // TODO: Reintroduce shader stripping from metadata + // if (!m_ShaderGraphMasterNodeType.TryGetValue(shader, out var shaderGraphMasterNodeType)) + // { + // if (shader.IsShaderGraph()) + // { + // string shaderPath = AssetDatabase.GetAssetPath(shader); + // shaderGraphMasterNodeType = GraphUtil.GetOutputNodeType(shaderPath); + // } + + // m_ShaderGraphMasterNodeType[shader] = shaderGraphMasterNodeType; + // } + // isBuiltInLit |= shaderGraphMasterNodeType == typeof(HDLitMasterNode); // Caution: Currently only HDRP/TerrainLit is using keyword _ALPHATEST_ON with multi compile, we shouldn't test any other built in shader if (isBuiltInTerrainLit) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/CreateHDLitShaderGraph.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/CreateHDLitShaderGraph.cs deleted file mode 100644 index 60693a3005a..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/CreateHDLitShaderGraph.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition -{ - static class CreateHDLitShaderGraph - { - [MenuItem("Assets/Create/Shader/HDRP/Lit Graph", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new HDLitMasterNode()); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitMasterNode.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitMasterNode.cs index bb447f64ca2..9e17287f92a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitMasterNode.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitMasterNode.cs @@ -1,1383 +1,1383 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; -using UnityEditor.Rendering.HighDefinition.Drawing; -using UnityEditor.ShaderGraph.Internal; -using UnityEditor.Rendering.HighDefinition.ShaderGraph; - -// Include material common properties names -using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; - -namespace UnityEditor.Rendering.HighDefinition -{ - [Serializable] - [Title("Master", "Lit (HDRP)")] - [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.HDLitMasterNode")] - [FormerName("UnityEditor.ShaderGraph.HDLitMasterNode")] - class HDLitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string AlbedoSlotName = "Albedo"; - public const string AlbedoDisplaySlotName = "BaseColor"; - public const string NormalSlotName = "Normal"; - public const string BentNormalSlotName = "BentNormal"; - public const string TangentSlotName = "Tangent"; - public const string SubsurfaceMaskSlotName = "SubsurfaceMask"; - public const string ThicknessSlotName = "Thickness"; - public const string DiffusionProfileHashSlotName = "DiffusionProfileHash"; - public const string DiffusionProfileHashSlotDisplayName = "Diffusion Profile"; - public const string IridescenceMaskSlotName = "IridescenceMask"; - public const string IridescenceThicknessSlotName = "IridescenceThickness"; - public const string IridescenceThicknessSlotDisplayName = "Iridescence Layer Thickness"; - public const string SpecularColorSlotName = "Specular"; - public const string SpecularColorDisplaySlotName = "SpecularColor"; - public const string CoatMaskSlotName = "CoatMask"; - public const string EmissionSlotName = "Emission"; - public const string MetallicSlotName = "Metallic"; - public const string SmoothnessSlotName = "Smoothness"; - public const string AmbientOcclusionSlotName = "Occlusion"; - public const string AmbientOcclusionDisplaySlotName = "AmbientOcclusion"; - public const string AlphaSlotName = "Alpha"; - public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; - public const string AlphaClipThresholdDepthPrepassSlotName = "AlphaClipThresholdDepthPrepass"; - public const string AlphaClipThresholdDepthPostpassSlotName = "AlphaClipThresholdDepthPostpass"; - public const string AnisotropySlotName = "Anisotropy"; - public const string PositionSlotName = "Vertex Position"; - public const string PositionSlotDisplayName = "Vertex Position"; - public const string VertexNormalSlotName = "Vertex Normal"; - public const string VertexTangentSlotName = "Vertex Tangent"; - public const string SpecularAAScreenSpaceVarianceSlotName = "SpecularAAScreenSpaceVariance"; - public const string SpecularAAThresholdSlotName = "SpecularAAThreshold"; - public const string RefractionIndexSlotName = "RefractionIndex"; - public const string RefractionColorSlotName = "RefractionColor"; - public const string RefractionColorSlotDisplayName = "Transmittance Color"; - public const string RefractionDistanceSlotName = "RefractionDistance"; - public const string RefractionDistanceSlotDisplayName = "Transmittance Absorption Distance"; - public const string DistortionSlotName = "Distortion"; - public const string DistortionSlotDisplayName = "Distortion Vector"; - public const string DistortionBlurSlotName = "DistortionBlur"; - public const string SpecularOcclusionSlotName = "SpecularOcclusion"; - public const string AlphaClipThresholdShadowSlotName = "AlphaClipThresholdShadow"; - public const string BakedGISlotName = "Baked GI"; - public const string BakedBackGISlotName = "Baked Back GI"; - public const string DepthOffsetSlotName = "DepthOffset"; - - public const int PositionSlotId = 0; - public const int AlbedoSlotId = 1; - public const int NormalSlotId = 2; - public const int BentNormalSlotId = 3; - public const int TangentSlotId = 4; - public const int SubsurfaceMaskSlotId = 5; - public const int ThicknessSlotId = 6; - public const int DiffusionProfileHashSlotId = 7; - public const int IridescenceMaskSlotId = 8; - public const int IridescenceThicknessSlotId = 9; - public const int SpecularColorSlotId = 10; - public const int CoatMaskSlotId = 11; - public const int MetallicSlotId = 12; - public const int EmissionSlotId = 13; - public const int SmoothnessSlotId = 14; - public const int AmbientOcclusionSlotId = 15; - public const int AlphaSlotId = 16; - public const int AlphaThresholdSlotId = 17; - public const int AlphaThresholdDepthPrepassSlotId = 18; - public const int AlphaThresholdDepthPostpassSlotId = 19; - public const int AnisotropySlotId = 20; - public const int SpecularAAScreenSpaceVarianceSlotId = 21; - public const int SpecularAAThresholdSlotId = 22; - public const int RefractionIndexSlotId = 23; - public const int RefractionColorSlotId = 24; - public const int RefractionDistanceSlotId = 25; - public const int DistortionSlotId = 26; - public const int DistortionBlurSlotId = 27; - public const int SpecularOcclusionSlotId = 28; - public const int AlphaThresholdShadowSlotId = 29; - public const int LightingSlotId = 30; - public const int BackLightingSlotId = 31; - public const int DepthOffsetSlotId = 32; - public const int VertexNormalSlotID = 33; - public const int VertexTangentSlotID = 34; - - public enum MaterialType - { - Standard, - SubsurfaceScattering, - Anisotropy, - Iridescence, - SpecularColor, - Translucent - } - - // Don't support Multiply - public enum AlphaModeLit - { - Alpha, - Premultiply, - Additive, - } - - // Just for convenience of doing simple masks. We could run out of bits of course. - [Flags] - enum SlotMask - { - None = 0, - Position = 1 << PositionSlotId, - Albedo = 1 << AlbedoSlotId, - Normal = 1 << NormalSlotId, - BentNormal = 1 << BentNormalSlotId, - Tangent = 1 << TangentSlotId, - SubsurfaceMask = 1 << SubsurfaceMaskSlotId, - Thickness = 1 << ThicknessSlotId, - DiffusionProfile = 1 << DiffusionProfileHashSlotId, - IridescenceMask = 1 << IridescenceMaskSlotId, - IridescenceLayerThickness = 1 << IridescenceThicknessSlotId, - Specular = 1 << SpecularColorSlotId, - CoatMask = 1 << CoatMaskSlotId, - Metallic = 1 << MetallicSlotId, - Emission = 1 << EmissionSlotId, - Smoothness = 1 << SmoothnessSlotId, - Occlusion = 1 << AmbientOcclusionSlotId, - Alpha = 1 << AlphaSlotId, - AlphaThreshold = 1 << AlphaThresholdSlotId, - AlphaThresholdDepthPrepass = 1 << AlphaThresholdDepthPrepassSlotId, - AlphaThresholdDepthPostpass = 1 << AlphaThresholdDepthPostpassSlotId, - Anisotropy = 1 << AnisotropySlotId, - SpecularOcclusion = 1 << SpecularOcclusionSlotId, - AlphaThresholdShadow = 1 << AlphaThresholdShadowSlotId, - Lighting = 1 << LightingSlotId, - BackLighting = 1 << BackLightingSlotId, - DepthOffset = 1 << DepthOffsetSlotId, - VertexNormal = 1 << VertexNormalSlotID, - VertexTangent = 1 << VertexTangentSlotID - } - - const SlotMask StandardSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Metallic | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; - const SlotMask SubsurfaceScatteringSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.SubsurfaceMask | SlotMask.Thickness | SlotMask.DiffusionProfile | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; - const SlotMask AnisotropySlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.Tangent | SlotMask.Anisotropy | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Metallic | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; - const SlotMask IridescenceSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.IridescenceMask | SlotMask.IridescenceLayerThickness | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Metallic | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; - const SlotMask SpecularColorSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.Specular | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; - const SlotMask TranslucentSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.Thickness | SlotMask.DiffusionProfile | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; - - // This could also be a simple array. For now, catch any mismatched data. - SlotMask GetActiveSlotMask() - { - switch (materialType) - { - case MaterialType.Standard: - return StandardSlotMask; - - case MaterialType.SubsurfaceScattering: - return SubsurfaceScatteringSlotMask; - - case MaterialType.Anisotropy: - return AnisotropySlotMask; - - case MaterialType.Iridescence: - return IridescenceSlotMask; - - case MaterialType.SpecularColor: - return SpecularColorSlotMask; - - case MaterialType.Translucent: - return TranslucentSlotMask; - - default: - return SlotMask.None; - } - } - - bool MaterialTypeUsesSlotMask(SlotMask mask) - { - SlotMask activeMask = GetActiveSlotMask(); - return (activeMask & mask) != 0; - } - - [SerializeField] - bool m_RayTracing; - - public ToggleData rayTracing - { - get { return new ToggleData(m_RayTracing); } - set - { - if (m_RayTracing == value.isOn) - return; - - m_RayTracing = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - AlphaMode m_AlphaMode; - - public AlphaMode alphaMode - { - get { return m_AlphaMode; } - set - { - if (m_AlphaMode == value) - return; - - m_AlphaMode = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - HDRenderQueue.RenderQueueType m_RenderingPass = HDRenderQueue.RenderQueueType.Opaque; - - public HDRenderQueue.RenderQueueType renderingPass - { - get { return m_RenderingPass; } - set - { - if (m_RenderingPass == value) - return; - - m_RenderingPass = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_BlendPreserveSpecular = true; - - public ToggleData blendPreserveSpecular - { - get { return new ToggleData(m_BlendPreserveSpecular); } - set - { - if (m_BlendPreserveSpecular == value.isOn) - return; - m_BlendPreserveSpecular = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_TransparencyFog = true; - - public ToggleData transparencyFog - { - get { return new ToggleData(m_TransparencyFog); } - set - { - if (m_TransparencyFog == value.isOn) - return; - m_TransparencyFog = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField, Obsolete("Kept for data migration")] - internal bool m_DrawBeforeRefraction; - - [SerializeField] - ScreenSpaceRefraction.RefractionModel m_RefractionModel; - - public ScreenSpaceRefraction.RefractionModel refractionModel - { - get { return m_RefractionModel; } - set - { - if (m_RefractionModel == value) - return; - - m_RefractionModel = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_Distortion; - - public ToggleData distortion - { - get { return new ToggleData(m_Distortion); } - set - { - if (m_Distortion == value.isOn) - return; - m_Distortion = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - DistortionMode m_DistortionMode; - - public DistortionMode distortionMode - { - get { return m_DistortionMode; } - set - { - if (m_DistortionMode == value) - return; - - m_DistortionMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_DistortionDepthTest = true; - - public ToggleData distortionDepthTest - { - get { return new ToggleData(m_DistortionDepthTest); } - set - { - if (m_DistortionDepthTest == value.isOn) - return; - m_DistortionDepthTest = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaTest; - - public ToggleData alphaTest - { - get { return new ToggleData(m_AlphaTest); } - set - { - if (m_AlphaTest == value.isOn) - return; - m_AlphaTest = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_AlphaTestDepthPrepass; - - public ToggleData alphaTestDepthPrepass - { - get { return new ToggleData(m_AlphaTestDepthPrepass); } - set - { - if (m_AlphaTestDepthPrepass == value.isOn) - return; - m_AlphaTestDepthPrepass = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_AlphaTestDepthPostpass; - - public ToggleData alphaTestDepthPostpass - { - get { return new ToggleData(m_AlphaTestDepthPostpass); } - set - { - if (m_AlphaTestDepthPostpass == value.isOn) - return; - m_AlphaTestDepthPostpass = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_TransparentWritesMotionVec; - - public ToggleData transparentWritesMotionVec - { - get { return new ToggleData(m_TransparentWritesMotionVec); } - set - { - if (m_TransparentWritesMotionVec == value.isOn) - return; - m_TransparentWritesMotionVec = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_AlphaTestShadow; - - public ToggleData alphaTestShadow - { - get { return new ToggleData(m_AlphaTestShadow); } - set - { - if (m_AlphaTestShadow == value.isOn) - return; - m_AlphaTestShadow = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_BackThenFrontRendering; - - public ToggleData backThenFrontRendering - { - get { return new ToggleData(m_BackThenFrontRendering); } - set - { - if (m_BackThenFrontRendering == value.isOn) - return; - m_BackThenFrontRendering = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_SortPriority; - - public int sortPriority - { - get { return m_SortPriority; } - set - { - if (m_SortPriority == value) - return; - m_SortPriority = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - DoubleSidedMode m_DoubleSidedMode; - - public DoubleSidedMode doubleSidedMode - { - get { return m_DoubleSidedMode; } - set - { - if (m_DoubleSidedMode == value) - return; - - m_DoubleSidedMode = value; - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - NormalDropOffSpace m_NormalDropOffSpace; - public NormalDropOffSpace normalDropOffSpace - { - get { return m_NormalDropOffSpace; } - set - { - if (m_NormalDropOffSpace == value) - return; - - m_NormalDropOffSpace = value; - if (!IsSlotConnected(NormalSlotId)) - updateNormalSlot = true; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - bool updateNormalSlot; - - - [SerializeField] - MaterialType m_MaterialType; - - public MaterialType materialType - { - get { return m_MaterialType; } - set - { - if (m_MaterialType == value) - return; - - m_MaterialType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_SSSTransmission = true; - - public ToggleData sssTransmission - { - get { return new ToggleData(m_SSSTransmission); } - set - { - m_SSSTransmission = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ReceiveDecals = true; - - public ToggleData receiveDecals - { - get { return new ToggleData(m_ReceiveDecals); } - set - { - if (m_ReceiveDecals == value.isOn) - return; - m_ReceiveDecals = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_ReceivesSSR = true; - public ToggleData receiveSSR - { - get { return new ToggleData(m_ReceivesSSR); } - set - { - if (m_ReceivesSSR == value.isOn) - return; - m_ReceivesSSR = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_ReceivesSSRTransparent = true; - public ToggleData receiveSSRTransparent - { - get { return new ToggleData(m_ReceivesSSRTransparent); } - set - { - if (m_ReceivesSSRTransparent == value.isOn) - return; - m_ReceivesSSRTransparent = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AddPrecomputedVelocity = false; - - public ToggleData addPrecomputedVelocity - { - get { return new ToggleData(m_AddPrecomputedVelocity); } - set - { - if (m_AddPrecomputedVelocity == value.isOn) - return; - m_AddPrecomputedVelocity = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_EnergyConservingSpecular = true; - - public ToggleData energyConservingSpecular - { - get { return new ToggleData(m_EnergyConservingSpecular); } - set - { - if (m_EnergyConservingSpecular == value.isOn) - return; - m_EnergyConservingSpecular = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SpecularAA; - - public ToggleData specularAA - { - get { return new ToggleData(m_SpecularAA); } - set - { - if (m_SpecularAA == value.isOn) - return; - m_SpecularAA = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - float m_SpecularAAScreenSpaceVariance; - - public float specularAAScreenSpaceVariance - { - get { return m_SpecularAAScreenSpaceVariance; } - set - { - if (m_SpecularAAScreenSpaceVariance == value) - return; - m_SpecularAAScreenSpaceVariance = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - float m_SpecularAAThreshold; - - public float specularAAThreshold - { - get { return m_SpecularAAThreshold; } - set - { - if (m_SpecularAAThreshold == value) - return; - m_SpecularAAThreshold = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - SpecularOcclusionMode m_SpecularOcclusionMode; - - public SpecularOcclusionMode specularOcclusionMode - { - get { return m_SpecularOcclusionMode; } - set - { - if (m_SpecularOcclusionMode == value) - return; - - m_SpecularOcclusionMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - int m_DiffusionProfile; - - public int diffusionProfile - { - get { return m_DiffusionProfile; } - set - { - if (m_DiffusionProfile == value) - return; - - m_DiffusionProfile = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_overrideBakedGI; - - public ToggleData overrideBakedGI - { - get { return new ToggleData(m_overrideBakedGI); } - set - { - if (m_overrideBakedGI == value.isOn) - return; - m_overrideBakedGI = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_depthOffset; - - public ToggleData depthOffset - { - get { return new ToggleData(m_depthOffset); } - set - { - if (m_depthOffset == value.isOn) - return; - m_depthOffset = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ZWrite = false; - public ToggleData zWrite - { - get { return new ToggleData(m_ZWrite); } - set - { - if (m_ZWrite == value.isOn) - return; - - m_ZWrite = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; - public TransparentCullMode transparentCullMode - { - get => m_transparentCullMode; - set - { - if (m_transparentCullMode == value) - return; - - m_transparentCullMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - CompareFunction m_ZTest = CompareFunction.LessEqual; - public CompareFunction zTest - { - get => m_ZTest; - set - { - if (m_ZTest == value) - return; - - m_ZTest = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SupportLodCrossFade; - - public ToggleData supportLodCrossFade - { - get { return new ToggleData(m_SupportLodCrossFade); } - set - { - if (m_SupportLodCrossFade == value.isOn) - return; - m_SupportLodCrossFade = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Node); - } - } - - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaToMask = false; - - public ToggleData alphaToMask - { - get { return new ToggleData(m_AlphaToMask); } - set - { - if (m_AlphaToMask == value.isOn) - return; - - m_AlphaToMask = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - - - [SerializeField] - int m_MaterialNeedsUpdateHash = 0; - - int ComputeMaterialNeedsUpdateHash() - { - int hash = 0; - - hash |= (alphaTest.isOn ? 0 : 1) << 0; - hash |= (alphaTestShadow.isOn ? 0 : 1) << 1; - hash |= (receiveSSR.isOn ? 0 : 1) << 2; - hash |= (receiveSSRTransparent.isOn ? 0 : 1) << 3; - hash |= (RequiresSplitLighting() ? 0 : 1) << 4; - - return hash; - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public HDLitMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - public override string documentationURL - { - get { return null; } - } - - public bool HasRefraction() - { - return (surfaceType == SurfaceType.Transparent && renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && refractionModel != ScreenSpaceRefraction.RefractionModel.None); - } - - public bool HasDistortion() - { - return (surfaceType == SurfaceType.Transparent && distortion.isOn); - } - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Lit Master"; - - List validSlots = new List(); - if (MaterialTypeUsesSlotMask(SlotMask.Position)) - { - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(PositionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) - { - AddSlot(new NormalMaterialSlot(VertexNormalSlotID, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexNormalSlotID); - } - if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) - { - AddSlot(new TangentMaterialSlot(VertexTangentSlotID, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexTangentSlotID); - } - if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) - { - AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(AlbedoSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Normal)) - { - var coordSpace = CoordinateSpace.Tangent; - if (updateNormalSlot) - { - RemoveSlot(NormalSlotId); - switch (m_NormalDropOffSpace) - { - case NormalDropOffSpace.Tangent: - coordSpace = CoordinateSpace.Tangent; - break; - case NormalDropOffSpace.World: - coordSpace = CoordinateSpace.World; - break; - case NormalDropOffSpace.Object: - coordSpace = CoordinateSpace.Object; - break; - } - updateNormalSlot = false; - } - AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, coordSpace, ShaderStageCapability.Fragment)); - validSlots.Add(NormalSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.BentNormal)) - { - AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(BentNormalSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Tangent)) - { - AddSlot(new TangentMaterialSlot(TangentSlotId, TangentSlotName, TangentSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(TangentSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Anisotropy)) - { - AddSlot(new Vector1MaterialSlot(AnisotropySlotId, AnisotropySlotName, AnisotropySlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AnisotropySlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.SubsurfaceMask)) - { - AddSlot(new Vector1MaterialSlot(SubsurfaceMaskSlotId, SubsurfaceMaskSlotName, SubsurfaceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SubsurfaceMaskSlotId); - } - if ((MaterialTypeUsesSlotMask(SlotMask.Thickness) && (sssTransmission.isOn || materialType == MaterialType.Translucent)) || HasRefraction()) - { - AddSlot(new Vector1MaterialSlot(ThicknessSlotId, ThicknessSlotName, ThicknessSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(ThicknessSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.DiffusionProfile)) - { - AddSlot(new DiffusionProfileInputMaterialSlot(DiffusionProfileHashSlotId, DiffusionProfileHashSlotDisplayName, DiffusionProfileHashSlotName, ShaderStageCapability.Fragment)); - validSlots.Add(DiffusionProfileHashSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.IridescenceMask)) - { - AddSlot(new Vector1MaterialSlot(IridescenceMaskSlotId, IridescenceMaskSlotName, IridescenceMaskSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(IridescenceMaskSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.IridescenceLayerThickness)) - { - AddSlot(new Vector1MaterialSlot(IridescenceThicknessSlotId, IridescenceThicknessSlotDisplayName, IridescenceThicknessSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(IridescenceThicknessSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Specular)) - { - AddSlot(new ColorRGBMaterialSlot(SpecularColorSlotId, SpecularColorDisplaySlotName, SpecularColorSlotName, SlotType.Input, Color.white, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularColorSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.CoatMask)) - { - AddSlot(new Vector1MaterialSlot(CoatMaskSlotId, CoatMaskSlotName, CoatMaskSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(CoatMaskSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Metallic)) - { - AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(MetallicSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) - { - AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(SmoothnessSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) - { - AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AmbientOcclusionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.SpecularOcclusion) && specularOcclusionMode == SpecularOcclusionMode.Custom) - { - AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularOcclusionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Emission)) - { - AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); - validSlots.Add(EmissionSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Alpha)) - { - AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.AlphaThreshold) && alphaTest.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaThresholdSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.AlphaThresholdDepthPrepass) && surfaceType == SurfaceType.Transparent && alphaTest.isOn && alphaTestDepthPrepass.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaThresholdDepthPrepassSlotId, AlphaClipThresholdDepthPrepassSlotName, AlphaClipThresholdDepthPrepassSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaThresholdDepthPrepassSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.AlphaThresholdDepthPostpass) && surfaceType == SurfaceType.Transparent && alphaTest.isOn && alphaTestDepthPostpass.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaThresholdDepthPostpassSlotId, AlphaClipThresholdDepthPostpassSlotName, AlphaClipThresholdDepthPostpassSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaThresholdDepthPostpassSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.AlphaThresholdShadow) && alphaTest.isOn && alphaTestShadow.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaThresholdShadowSlotId, AlphaClipThresholdShadowSlotName, AlphaClipThresholdShadowSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaThresholdShadowSlotId); - } - if (specularAA.isOn) - { - AddSlot(new Vector1MaterialSlot(SpecularAAScreenSpaceVarianceSlotId, SpecularAAScreenSpaceVarianceSlotName, SpecularAAScreenSpaceVarianceSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularAAScreenSpaceVarianceSlotId); - - AddSlot(new Vector1MaterialSlot(SpecularAAThresholdSlotId, SpecularAAThresholdSlotName, SpecularAAThresholdSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularAAThresholdSlotId); - } - if (HasRefraction()) - { - AddSlot(new Vector1MaterialSlot(RefractionIndexSlotId, RefractionIndexSlotName, RefractionIndexSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(RefractionIndexSlotId); - - AddSlot(new ColorRGBMaterialSlot(RefractionColorSlotId, RefractionColorSlotDisplayName, RefractionColorSlotName, SlotType.Input, Color.white, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(RefractionColorSlotId); - - AddSlot(new Vector1MaterialSlot(RefractionDistanceSlotId, RefractionDistanceSlotDisplayName, RefractionDistanceSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(RefractionDistanceSlotId); - } - if (HasDistortion()) - { - AddSlot(new Vector2MaterialSlot(DistortionSlotId, DistortionSlotDisplayName, DistortionSlotName, SlotType.Input, new Vector2(2.0f, -1.0f), ShaderStageCapability.Fragment)); - validSlots.Add(DistortionSlotId); - - AddSlot(new Vector1MaterialSlot(DistortionBlurSlotId, DistortionBlurSlotName, DistortionBlurSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(DistortionBlurSlotId); - } - if (MaterialTypeUsesSlotMask(SlotMask.Lighting) && overrideBakedGI.isOn) - { - AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(LightingSlotId); - AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(BackLightingSlotId); - } - if (depthOffset.isOn) - { - AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(DepthOffsetSlotId); - } - - RemoveSlotsNameNotMatching(validSlots, true); - } - - public VisualElement CreateSettingsElement() - { - return new HDLitSettingsView(this); - } - - public string renderQueueTag - { - get - { - if(renderingPass == HDRenderQueue.RenderQueueType.Unknown) - { - switch(surfaceType) - { - case SurfaceType.Opaque: - renderingPass = HDRenderQueue.RenderQueueType.Opaque; - break; - case SurfaceType.Transparent: - #pragma warning disable CS0618 // Type or member is obsolete - if (m_DrawBeforeRefraction) - { - m_DrawBeforeRefraction = false; - #pragma warning restore CS0618 // Type or member is obsolete - renderingPass = HDRenderQueue.RenderQueueType.PreRefraction; - } - else - { - renderingPass = HDRenderQueue.RenderQueueType.Transparent; - } - break; - } - } - int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); - return HDRenderQueue.GetShaderTagValue(queue); - } - } - - public string renderTypeTag => HDRenderTypeTags.HDLitShader.ToString(); - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); - var coatMaskSlot = FindSlot(CoatMaskSlotId); - - // We need this to know if there are any Dots properties active - // Ideally we do this another way but HDLit needs this for conditional pragmas - var shaderProperties = new PropertyCollector(); - owner.CollectShaderProperties(shaderProperties, GenerationMode.ForReals); - bool hasDotsProperties = shaderProperties.GetDotsInstancingPropertiesCount(GenerationMode.ForReals) > 0; - - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || - IsSlotConnected(VertexNormalSlotID) || - IsSlotConnected(VertexTangentSlotID)), - new ConditionalField(Fields.GraphPixel, true), - new ConditionalField(Fields.LodCrossFade, supportLodCrossFade.isOn), - - // Structs - new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && - !pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)), - - // Dots - new ConditionalField(HDFields.DotsInstancing, dotsInstancing.isOn), - new ConditionalField(HDFields.DotsProperties, hasDotsProperties), - - // Material - new ConditionalField(HDFields.Anisotropy, materialType == MaterialType.Anisotropy), - new ConditionalField(HDFields.Iridescence, materialType == MaterialType.Iridescence), - new ConditionalField(HDFields.SpecularColor, materialType == MaterialType.SpecularColor), - new ConditionalField(HDFields.Standard, materialType == MaterialType.Standard), - new ConditionalField(HDFields.SubsurfaceScattering, materialType == MaterialType.SubsurfaceScattering && - surfaceType != SurfaceType.Transparent), - new ConditionalField(HDFields.Transmission, (materialType == MaterialType.SubsurfaceScattering && sssTransmission.isOn) || - (materialType == MaterialType.Translucent)), - new ConditionalField(HDFields.Translucent, materialType == MaterialType.Translucent), - - // Surface Type - new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), - new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), - - // Blend Mode - new ConditionalField(Fields.BlendAdd, surfaceType != SurfaceType.Opaque && alphaMode == AlphaMode.Additive), - new ConditionalField(Fields.BlendAlpha, surfaceType != SurfaceType.Opaque && alphaMode == AlphaMode.Alpha), - new ConditionalField(Fields.BlendMultiply, surfaceType != SurfaceType.Opaque && alphaMode == AlphaMode.Multiply), - new ConditionalField(Fields.BlendPremultiply, surfaceType != SurfaceType.Opaque && alphaMode == AlphaMode.Premultiply), - - // Double Sided - new ConditionalField(HDFields.DoubleSided, doubleSidedMode != DoubleSidedMode.Disabled), - new ConditionalField(HDFields.DoubleSidedFlip, doubleSidedMode == DoubleSidedMode.FlippedNormals && - !pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)), - new ConditionalField(HDFields.DoubleSidedMirror, doubleSidedMode == DoubleSidedMode.MirroredNormals && - !pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)), - - // Specular Occlusion - new ConditionalField(HDFields.SpecularOcclusionFromAO, specularOcclusionMode == SpecularOcclusionMode.FromAO), - new ConditionalField(HDFields.SpecularOcclusionFromAOBentNormal, specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal), - new ConditionalField(HDFields.SpecularOcclusionCustom, specularOcclusionMode == SpecularOcclusionMode.Custom), - - //Distortion - new ConditionalField(HDFields.DistortionDepthTest, distortionDepthTest.isOn), - new ConditionalField(HDFields.DistortionAdd, distortionMode == DistortionMode.Add), - new ConditionalField(HDFields.DistortionMultiply, distortionMode == DistortionMode.Multiply), - new ConditionalField(HDFields.DistortionReplace, distortionMode == DistortionMode.Replace), - new ConditionalField(HDFields.TransparentDistortion, surfaceType != SurfaceType.Opaque && distortion.isOn), - - // Refraction - new ConditionalField(HDFields.Refraction, HasRefraction()), - new ConditionalField(HDFields.RefractionBox, HasRefraction() && refractionModel == ScreenSpaceRefraction.RefractionModel.Box), - new ConditionalField(HDFields.RefractionSphere, HasRefraction() && refractionModel == ScreenSpaceRefraction.RefractionModel.Sphere), - - //Normal Drop Off Space - new ConditionalField(Fields.NormalDropOffOS, normalDropOffSpace == NormalDropOffSpace.Object), - new ConditionalField(Fields.NormalDropOffTS, normalDropOffSpace == NormalDropOffSpace.Tangent), - new ConditionalField(Fields.NormalDropOffWS, normalDropOffSpace == NormalDropOffSpace.World), - - // Misc - // We always generate the keyword ALPHATEST_ON - new ConditionalField(Fields.AlphaTest, alphaTest.isOn && (pass.pixelPorts.Contains(AlphaThresholdSlotId) || pass.pixelPorts.Contains(AlphaThresholdShadowSlotId) || - pass.pixelPorts.Contains(AlphaThresholdDepthPrepassSlotId) || pass.pixelPorts.Contains(AlphaThresholdDepthPostpassSlotId))), - // All the DoAlphaXXX field drive the generation of which code to use for alpha test in the template - // Do alpha test only if we aren't using the TestShadow one - // Note: we always generate the code for DoAlphaTestXXX as it is then the keyword _ALPHATEST_ON that will define if it is enabled or not - new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && (pass.pixelPorts.Contains(AlphaThresholdSlotId) && - !(alphaTestShadow.isOn && pass.pixelPorts.Contains(AlphaThresholdShadowSlotId)))), - new ConditionalField(HDFields.DoAlphaTestShadow, alphaTest.isOn && alphaTestShadow.isOn && pass.pixelPorts.Contains(AlphaThresholdShadowSlotId)), - new ConditionalField(HDFields.DoAlphaTestPrepass, alphaTest.isOn && alphaTestDepthPrepass.isOn && pass.pixelPorts.Contains(AlphaThresholdDepthPrepassSlotId)), - new ConditionalField(HDFields.DoAlphaTestPostpass, alphaTest.isOn && alphaTestDepthPostpass.isOn && pass.pixelPorts.Contains(AlphaThresholdDepthPostpassSlotId)), - new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaThresholdSlotId) && alphaToMask.isOn), - new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), - new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), - new ConditionalField(HDFields.TransparentWritesMotionVec, surfaceType != SurfaceType.Opaque && transparentWritesMotionVec.isOn), - new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), - new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), - new ConditionalField(HDFields.DisableSSRTransparent, !receiveSSRTransparent.isOn), - new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), - new ConditionalField(HDFields.SpecularAA, specularAA.isOn && - pass.pixelPorts.Contains(SpecularAAThresholdSlotId) && - pass.pixelPorts.Contains(SpecularAAScreenSpaceVarianceSlotId)), - new ConditionalField(HDFields.EnergyConservingSpecular, energyConservingSpecular.isOn), - new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && - pass.pixelPorts.Contains(BentNormalSlotId)), - new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && - (IsSlotConnected(AmbientOcclusionSlotId) || - ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), - new ConditionalField(HDFields.CoatMask, pass.pixelPorts.Contains(CoatMaskSlotId) && - (IsSlotConnected(CoatMaskSlotId) || coatMaskSlot.value > 0.0f)), - new ConditionalField(HDFields.Tangent, IsSlotConnected(TangentSlotId) && - pass.pixelPorts.Contains(TangentSlotId)), - new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && - pass.pixelPorts.Contains(LightingSlotId)), - new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && - pass.pixelPorts.Contains(BackLightingSlotId)), - new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), - new ConditionalField(HDFields.TransparentBackFace, surfaceType != SurfaceType.Opaque && backThenFrontRendering.isOn), - new ConditionalField(HDFields.TransparentDepthPrePass, surfaceType != SurfaceType.Opaque && alphaTestDepthPrepass.isOn), - new ConditionalField(HDFields.TransparentDepthPostPass, surfaceType != SurfaceType.Opaque && alphaTestDepthPostpass.isOn), - new ConditionalField(HDFields.RayTracing, rayTracing.isOn), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); - material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); - material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); - material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)zTest); - material.SetFloat(kTransparentCullMode, (int)transparentCullMode); - material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); - // No sorting priority for shader graph preview - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); - - HDLitGUI.SetupMaterialKeywordsAndPass(material); - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public bool RequiresSplitLighting() - { - return materialType == HDLitMasterNode.MaterialType.SubsurfaceScattering; - } - public override object saveContext - { - get - { - int hash = ComputeMaterialNeedsUpdateHash(); - - bool needsUpdate = hash != m_MaterialNeedsUpdateHash; - - if (needsUpdate) - m_MaterialNeedsUpdateHash = hash; - - return new HDSaveContext{ updateMaterials = needsUpdate }; - } - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - // ShaderGraph only property used to send the RenderQueueType to the material - collector.AddShaderProperty(new Vector1ShaderProperty - { - overrideReferenceName = "_RenderQueueType", - hidden = true, - value = (int)renderingPass, - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (addPrecomputedVelocity.isOn) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, RequiresSplitLighting(), receiveSSR.isOn, receiveSSRTransparent.isOn); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - surfaceType, - HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), - sortPriority, - alphaToMask.isOn, - zWrite.isOn, - transparentCullMode, - zTest, - backThenFrontRendering.isOn, - transparencyFog.isOn - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, alphaTestShadow.isOn); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); - HDSubShaderUtilities.AddRayTracingProperty(collector, rayTracing.isOn); - - base.CollectShaderProperties(collector, generationMode); - } - - public override void Setup() - { - base.Setup(); - var hdPipelineAsset = HDRenderPipeline.currentAsset; - - if (hdPipelineAsset == null) - return; - - var diffusionProfileSlot = FindSlot(DiffusionProfileHashSlotId); - - if (diffusionProfileSlot == null) - return; - - if ((diffusionProfileSlot.diffusionProfile) != null && !hdPipelineAsset.diffusionProfileSettingsList.Any(d => d == diffusionProfileSlot.diffusionProfile)) - { - //owner.AddSetupError(tempId, $"Diffusion profile '{diffusionProfileSlot.diffusionProfile.name}' is not referenced in the current HDRP asset", ShaderCompilerMessageSeverity.Warning); - } - - } - } -} +// using System; +// using System.Linq; +// using System.Collections.Generic; +// using UnityEditor.Graphing; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; +// using UnityEditor.Rendering.HighDefinition.Drawing; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEditor.Rendering.HighDefinition.ShaderGraph; + +// // Include material common properties names +// using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; + +// namespace UnityEditor.Rendering.HighDefinition +// { +// [Serializable] +// [Title("Master", "Lit (HDRP)")] +// [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.HDLitMasterNode")] +// [FormerName("UnityEditor.ShaderGraph.HDLitMasterNode")] +// class HDLitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent +// { +// public const string AlbedoSlotName = "Albedo"; +// public const string AlbedoDisplaySlotName = "BaseColor"; +// public const string NormalSlotName = "Normal"; +// public const string BentNormalSlotName = "BentNormal"; +// public const string TangentSlotName = "Tangent"; +// public const string SubsurfaceMaskSlotName = "SubsurfaceMask"; +// public const string ThicknessSlotName = "Thickness"; +// public const string DiffusionProfileHashSlotName = "DiffusionProfileHash"; +// public const string DiffusionProfileHashSlotDisplayName = "Diffusion Profile"; +// public const string IridescenceMaskSlotName = "IridescenceMask"; +// public const string IridescenceThicknessSlotName = "IridescenceThickness"; +// public const string IridescenceThicknessSlotDisplayName = "Iridescence Layer Thickness"; +// public const string SpecularColorSlotName = "Specular"; +// public const string SpecularColorDisplaySlotName = "SpecularColor"; +// public const string CoatMaskSlotName = "CoatMask"; +// public const string EmissionSlotName = "Emission"; +// public const string MetallicSlotName = "Metallic"; +// public const string SmoothnessSlotName = "Smoothness"; +// public const string AmbientOcclusionSlotName = "Occlusion"; +// public const string AmbientOcclusionDisplaySlotName = "AmbientOcclusion"; +// public const string AlphaSlotName = "Alpha"; +// public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; +// public const string AlphaClipThresholdDepthPrepassSlotName = "AlphaClipThresholdDepthPrepass"; +// public const string AlphaClipThresholdDepthPostpassSlotName = "AlphaClipThresholdDepthPostpass"; +// public const string AnisotropySlotName = "Anisotropy"; +// public const string PositionSlotName = "Vertex Position"; +// public const string PositionSlotDisplayName = "Vertex Position"; +// public const string VertexNormalSlotName = "Vertex Normal"; +// public const string VertexTangentSlotName = "Vertex Tangent"; +// public const string SpecularAAScreenSpaceVarianceSlotName = "SpecularAAScreenSpaceVariance"; +// public const string SpecularAAThresholdSlotName = "SpecularAAThreshold"; +// public const string RefractionIndexSlotName = "RefractionIndex"; +// public const string RefractionColorSlotName = "RefractionColor"; +// public const string RefractionColorSlotDisplayName = "Transmittance Color"; +// public const string RefractionDistanceSlotName = "RefractionDistance"; +// public const string RefractionDistanceSlotDisplayName = "Transmittance Absorption Distance"; +// public const string DistortionSlotName = "Distortion"; +// public const string DistortionSlotDisplayName = "Distortion Vector"; +// public const string DistortionBlurSlotName = "DistortionBlur"; +// public const string SpecularOcclusionSlotName = "SpecularOcclusion"; +// public const string AlphaClipThresholdShadowSlotName = "AlphaClipThresholdShadow"; +// public const string BakedGISlotName = "Baked GI"; +// public const string BakedBackGISlotName = "Baked Back GI"; +// public const string DepthOffsetSlotName = "DepthOffset"; + +// public const int PositionSlotId = 0; +// public const int AlbedoSlotId = 1; +// public const int NormalSlotId = 2; +// public const int BentNormalSlotId = 3; +// public const int TangentSlotId = 4; +// public const int SubsurfaceMaskSlotId = 5; +// public const int ThicknessSlotId = 6; +// public const int DiffusionProfileHashSlotId = 7; +// public const int IridescenceMaskSlotId = 8; +// public const int IridescenceThicknessSlotId = 9; +// public const int SpecularColorSlotId = 10; +// public const int CoatMaskSlotId = 11; +// public const int MetallicSlotId = 12; +// public const int EmissionSlotId = 13; +// public const int SmoothnessSlotId = 14; +// public const int AmbientOcclusionSlotId = 15; +// public const int AlphaSlotId = 16; +// public const int AlphaThresholdSlotId = 17; +// public const int AlphaThresholdDepthPrepassSlotId = 18; +// public const int AlphaThresholdDepthPostpassSlotId = 19; +// public const int AnisotropySlotId = 20; +// public const int SpecularAAScreenSpaceVarianceSlotId = 21; +// public const int SpecularAAThresholdSlotId = 22; +// public const int RefractionIndexSlotId = 23; +// public const int RefractionColorSlotId = 24; +// public const int RefractionDistanceSlotId = 25; +// public const int DistortionSlotId = 26; +// public const int DistortionBlurSlotId = 27; +// public const int SpecularOcclusionSlotId = 28; +// public const int AlphaThresholdShadowSlotId = 29; +// public const int LightingSlotId = 30; +// public const int BackLightingSlotId = 31; +// public const int DepthOffsetSlotId = 32; +// public const int VertexNormalSlotID = 33; +// public const int VertexTangentSlotID = 34; + +// public enum MaterialType +// { +// Standard, +// SubsurfaceScattering, +// Anisotropy, +// Iridescence, +// SpecularColor, +// Translucent +// } + +// // Don't support Multiply +// public enum AlphaModeLit +// { +// Alpha, +// Premultiply, +// Additive, +// } + +// // Just for convenience of doing simple masks. We could run out of bits of course. +// [Flags] +// enum SlotMask +// { +// None = 0, +// Position = 1 << PositionSlotId, +// Albedo = 1 << AlbedoSlotId, +// Normal = 1 << NormalSlotId, +// BentNormal = 1 << BentNormalSlotId, +// Tangent = 1 << TangentSlotId, +// SubsurfaceMask = 1 << SubsurfaceMaskSlotId, +// Thickness = 1 << ThicknessSlotId, +// DiffusionProfile = 1 << DiffusionProfileHashSlotId, +// IridescenceMask = 1 << IridescenceMaskSlotId, +// IridescenceLayerThickness = 1 << IridescenceThicknessSlotId, +// Specular = 1 << SpecularColorSlotId, +// CoatMask = 1 << CoatMaskSlotId, +// Metallic = 1 << MetallicSlotId, +// Emission = 1 << EmissionSlotId, +// Smoothness = 1 << SmoothnessSlotId, +// Occlusion = 1 << AmbientOcclusionSlotId, +// Alpha = 1 << AlphaSlotId, +// AlphaThreshold = 1 << AlphaThresholdSlotId, +// AlphaThresholdDepthPrepass = 1 << AlphaThresholdDepthPrepassSlotId, +// AlphaThresholdDepthPostpass = 1 << AlphaThresholdDepthPostpassSlotId, +// Anisotropy = 1 << AnisotropySlotId, +// SpecularOcclusion = 1 << SpecularOcclusionSlotId, +// AlphaThresholdShadow = 1 << AlphaThresholdShadowSlotId, +// Lighting = 1 << LightingSlotId, +// BackLighting = 1 << BackLightingSlotId, +// DepthOffset = 1 << DepthOffsetSlotId, +// VertexNormal = 1 << VertexNormalSlotID, +// VertexTangent = 1 << VertexTangentSlotID +// } + +// const SlotMask StandardSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Metallic | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; +// const SlotMask SubsurfaceScatteringSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.SubsurfaceMask | SlotMask.Thickness | SlotMask.DiffusionProfile | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; +// const SlotMask AnisotropySlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.Tangent | SlotMask.Anisotropy | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Metallic | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; +// const SlotMask IridescenceSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.IridescenceMask | SlotMask.IridescenceLayerThickness | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Metallic | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; +// const SlotMask SpecularColorSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.Specular | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; +// const SlotMask TranslucentSlotMask = SlotMask.Position | SlotMask.Albedo | SlotMask.Normal | SlotMask.BentNormal | SlotMask.Thickness | SlotMask.DiffusionProfile | SlotMask.CoatMask | SlotMask.Emission | SlotMask.Smoothness | SlotMask.Occlusion | SlotMask.SpecularOcclusion | SlotMask.Alpha | SlotMask.AlphaThreshold | SlotMask.AlphaThresholdDepthPrepass | SlotMask.AlphaThresholdDepthPostpass | SlotMask.AlphaThresholdShadow | SlotMask.Lighting | SlotMask.DepthOffset | SlotMask.VertexNormal | SlotMask.VertexTangent; + +// // This could also be a simple array. For now, catch any mismatched data. +// SlotMask GetActiveSlotMask() +// { +// switch (materialType) +// { +// case MaterialType.Standard: +// return StandardSlotMask; + +// case MaterialType.SubsurfaceScattering: +// return SubsurfaceScatteringSlotMask; + +// case MaterialType.Anisotropy: +// return AnisotropySlotMask; + +// case MaterialType.Iridescence: +// return IridescenceSlotMask; + +// case MaterialType.SpecularColor: +// return SpecularColorSlotMask; + +// case MaterialType.Translucent: +// return TranslucentSlotMask; + +// default: +// return SlotMask.None; +// } +// } + +// bool MaterialTypeUsesSlotMask(SlotMask mask) +// { +// SlotMask activeMask = GetActiveSlotMask(); +// return (activeMask & mask) != 0; +// } + +// [SerializeField] +// bool m_RayTracing; + +// public ToggleData rayTracing +// { +// get { return new ToggleData(m_RayTracing); } +// set +// { +// if (m_RayTracing == value.isOn) +// return; + +// m_RayTracing = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// SurfaceType m_SurfaceType; + +// public SurfaceType surfaceType +// { +// get { return m_SurfaceType; } +// set +// { +// if (m_SurfaceType == value) +// return; + +// m_SurfaceType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// AlphaMode m_AlphaMode; + +// public AlphaMode alphaMode +// { +// get { return m_AlphaMode; } +// set +// { +// if (m_AlphaMode == value) +// return; + +// m_AlphaMode = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// HDRenderQueue.RenderQueueType m_RenderingPass = HDRenderQueue.RenderQueueType.Opaque; + +// public HDRenderQueue.RenderQueueType renderingPass +// { +// get { return m_RenderingPass; } +// set +// { +// if (m_RenderingPass == value) +// return; + +// m_RenderingPass = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_BlendPreserveSpecular = true; + +// public ToggleData blendPreserveSpecular +// { +// get { return new ToggleData(m_BlendPreserveSpecular); } +// set +// { +// if (m_BlendPreserveSpecular == value.isOn) +// return; +// m_BlendPreserveSpecular = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_TransparencyFog = true; + +// public ToggleData transparencyFog +// { +// get { return new ToggleData(m_TransparencyFog); } +// set +// { +// if (m_TransparencyFog == value.isOn) +// return; +// m_TransparencyFog = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField, Obsolete("Kept for data migration")] +// internal bool m_DrawBeforeRefraction; + +// [SerializeField] +// ScreenSpaceRefraction.RefractionModel m_RefractionModel; + +// public ScreenSpaceRefraction.RefractionModel refractionModel +// { +// get { return m_RefractionModel; } +// set +// { +// if (m_RefractionModel == value) +// return; + +// m_RefractionModel = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_Distortion; + +// public ToggleData distortion +// { +// get { return new ToggleData(m_Distortion); } +// set +// { +// if (m_Distortion == value.isOn) +// return; +// m_Distortion = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// DistortionMode m_DistortionMode; + +// public DistortionMode distortionMode +// { +// get { return m_DistortionMode; } +// set +// { +// if (m_DistortionMode == value) +// return; + +// m_DistortionMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_DistortionDepthTest = true; + +// public ToggleData distortionDepthTest +// { +// get { return new ToggleData(m_DistortionDepthTest); } +// set +// { +// if (m_DistortionDepthTest == value.isOn) +// return; +// m_DistortionDepthTest = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaTest; + +// public ToggleData alphaTest +// { +// get { return new ToggleData(m_AlphaTest); } +// set +// { +// if (m_AlphaTest == value.isOn) +// return; +// m_AlphaTest = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_AlphaTestDepthPrepass; + +// public ToggleData alphaTestDepthPrepass +// { +// get { return new ToggleData(m_AlphaTestDepthPrepass); } +// set +// { +// if (m_AlphaTestDepthPrepass == value.isOn) +// return; +// m_AlphaTestDepthPrepass = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_AlphaTestDepthPostpass; + +// public ToggleData alphaTestDepthPostpass +// { +// get { return new ToggleData(m_AlphaTestDepthPostpass); } +// set +// { +// if (m_AlphaTestDepthPostpass == value.isOn) +// return; +// m_AlphaTestDepthPostpass = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_TransparentWritesMotionVec; + +// public ToggleData transparentWritesMotionVec +// { +// get { return new ToggleData(m_TransparentWritesMotionVec); } +// set +// { +// if (m_TransparentWritesMotionVec == value.isOn) +// return; +// m_TransparentWritesMotionVec = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_AlphaTestShadow; + +// public ToggleData alphaTestShadow +// { +// get { return new ToggleData(m_AlphaTestShadow); } +// set +// { +// if (m_AlphaTestShadow == value.isOn) +// return; +// m_AlphaTestShadow = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_BackThenFrontRendering; + +// public ToggleData backThenFrontRendering +// { +// get { return new ToggleData(m_BackThenFrontRendering); } +// set +// { +// if (m_BackThenFrontRendering == value.isOn) +// return; +// m_BackThenFrontRendering = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_SortPriority; + +// public int sortPriority +// { +// get { return m_SortPriority; } +// set +// { +// if (m_SortPriority == value) +// return; +// m_SortPriority = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// DoubleSidedMode m_DoubleSidedMode; + +// public DoubleSidedMode doubleSidedMode +// { +// get { return m_DoubleSidedMode; } +// set +// { +// if (m_DoubleSidedMode == value) +// return; + +// m_DoubleSidedMode = value; +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// NormalDropOffSpace m_NormalDropOffSpace; +// public NormalDropOffSpace normalDropOffSpace +// { +// get { return m_NormalDropOffSpace; } +// set +// { +// if (m_NormalDropOffSpace == value) +// return; + +// m_NormalDropOffSpace = value; +// if (!IsSlotConnected(NormalSlotId)) +// updateNormalSlot = true; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } +// bool updateNormalSlot; + + +// [SerializeField] +// MaterialType m_MaterialType; + +// public MaterialType materialType +// { +// get { return m_MaterialType; } +// set +// { +// if (m_MaterialType == value) +// return; + +// m_MaterialType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_SSSTransmission = true; + +// public ToggleData sssTransmission +// { +// get { return new ToggleData(m_SSSTransmission); } +// set +// { +// m_SSSTransmission = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ReceiveDecals = true; + +// public ToggleData receiveDecals +// { +// get { return new ToggleData(m_ReceiveDecals); } +// set +// { +// if (m_ReceiveDecals == value.isOn) +// return; +// m_ReceiveDecals = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_ReceivesSSR = true; +// public ToggleData receiveSSR +// { +// get { return new ToggleData(m_ReceivesSSR); } +// set +// { +// if (m_ReceivesSSR == value.isOn) +// return; +// m_ReceivesSSR = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_ReceivesSSRTransparent = true; +// public ToggleData receiveSSRTransparent +// { +// get { return new ToggleData(m_ReceivesSSRTransparent); } +// set +// { +// if (m_ReceivesSSRTransparent == value.isOn) +// return; +// m_ReceivesSSRTransparent = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AddPrecomputedVelocity = false; + +// public ToggleData addPrecomputedVelocity +// { +// get { return new ToggleData(m_AddPrecomputedVelocity); } +// set +// { +// if (m_AddPrecomputedVelocity == value.isOn) +// return; +// m_AddPrecomputedVelocity = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_EnergyConservingSpecular = true; + +// public ToggleData energyConservingSpecular +// { +// get { return new ToggleData(m_EnergyConservingSpecular); } +// set +// { +// if (m_EnergyConservingSpecular == value.isOn) +// return; +// m_EnergyConservingSpecular = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SpecularAA; + +// public ToggleData specularAA +// { +// get { return new ToggleData(m_SpecularAA); } +// set +// { +// if (m_SpecularAA == value.isOn) +// return; +// m_SpecularAA = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// float m_SpecularAAScreenSpaceVariance; + +// public float specularAAScreenSpaceVariance +// { +// get { return m_SpecularAAScreenSpaceVariance; } +// set +// { +// if (m_SpecularAAScreenSpaceVariance == value) +// return; +// m_SpecularAAScreenSpaceVariance = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// float m_SpecularAAThreshold; + +// public float specularAAThreshold +// { +// get { return m_SpecularAAThreshold; } +// set +// { +// if (m_SpecularAAThreshold == value) +// return; +// m_SpecularAAThreshold = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// SpecularOcclusionMode m_SpecularOcclusionMode; + +// public SpecularOcclusionMode specularOcclusionMode +// { +// get { return m_SpecularOcclusionMode; } +// set +// { +// if (m_SpecularOcclusionMode == value) +// return; + +// m_SpecularOcclusionMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// int m_DiffusionProfile; + +// public int diffusionProfile +// { +// get { return m_DiffusionProfile; } +// set +// { +// if (m_DiffusionProfile == value) +// return; + +// m_DiffusionProfile = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_overrideBakedGI; + +// public ToggleData overrideBakedGI +// { +// get { return new ToggleData(m_overrideBakedGI); } +// set +// { +// if (m_overrideBakedGI == value.isOn) +// return; +// m_overrideBakedGI = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_depthOffset; + +// public ToggleData depthOffset +// { +// get { return new ToggleData(m_depthOffset); } +// set +// { +// if (m_depthOffset == value.isOn) +// return; +// m_depthOffset = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ZWrite = false; +// public ToggleData zWrite +// { +// get { return new ToggleData(m_ZWrite); } +// set +// { +// if (m_ZWrite == value.isOn) +// return; + +// m_ZWrite = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; +// public TransparentCullMode transparentCullMode +// { +// get => m_transparentCullMode; +// set +// { +// if (m_transparentCullMode == value) +// return; + +// m_transparentCullMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// CompareFunction m_ZTest = CompareFunction.LessEqual; +// public CompareFunction zTest +// { +// get => m_ZTest; +// set +// { +// if (m_ZTest == value) +// return; + +// m_ZTest = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SupportLodCrossFade; + +// public ToggleData supportLodCrossFade +// { +// get { return new ToggleData(m_SupportLodCrossFade); } +// set +// { +// if (m_SupportLodCrossFade == value.isOn) +// return; +// m_SupportLodCrossFade = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Node); +// } +// } + +// [SerializeField] +// bool m_DOTSInstancing = false; + +// public ToggleData dotsInstancing +// { +// get { return new ToggleData(m_DOTSInstancing); } +// set +// { +// if (m_DOTSInstancing == value.isOn) +// return; + +// m_DOTSInstancing = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaToMask = false; + +// public ToggleData alphaToMask +// { +// get { return new ToggleData(m_AlphaToMask); } +// set +// { +// if (m_AlphaToMask == value.isOn) +// return; + +// m_AlphaToMask = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + + + +// [SerializeField] +// int m_MaterialNeedsUpdateHash = 0; + +// int ComputeMaterialNeedsUpdateHash() +// { +// int hash = 0; + +// hash |= (alphaTest.isOn ? 0 : 1) << 0; +// hash |= (alphaTestShadow.isOn ? 0 : 1) << 1; +// hash |= (receiveSSR.isOn ? 0 : 1) << 2; +// hash |= (receiveSSRTransparent.isOn ? 0 : 1) << 3; +// hash |= (RequiresSplitLighting() ? 0 : 1) << 4; + +// return hash; +// } + +// [SerializeField] private string m_ShaderGUIOverride; +// public string ShaderGUIOverride +// { +// get => m_ShaderGUIOverride; +// set => m_ShaderGUIOverride = value; +// } + +// [SerializeField] private bool m_OverrideEnabled; +// public bool OverrideEnabled +// { +// get => m_OverrideEnabled; +// set => m_OverrideEnabled = value; +// } + +// public HDLitMasterNode() +// { +// UpdateNodeAfterDeserialization(); +// } + +// public override string documentationURL +// { +// get { return null; } +// } + +// public bool HasRefraction() +// { +// return (surfaceType == SurfaceType.Transparent && renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && refractionModel != ScreenSpaceRefraction.RefractionModel.None); +// } + +// public bool HasDistortion() +// { +// return (surfaceType == SurfaceType.Transparent && distortion.isOn); +// } + +// public sealed override void UpdateNodeAfterDeserialization() +// { +// base.UpdateNodeAfterDeserialization(); +// name = "Lit Master"; + +// List validSlots = new List(); +// if (MaterialTypeUsesSlotMask(SlotMask.Position)) +// { +// AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(PositionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.VertexNormal)) +// { +// AddSlot(new NormalMaterialSlot(VertexNormalSlotID, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexNormalSlotID); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.VertexTangent)) +// { +// AddSlot(new TangentMaterialSlot(VertexTangentSlotID, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexTangentSlotID); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Albedo)) +// { +// AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoDisplaySlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(AlbedoSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Normal)) +// { +// var coordSpace = CoordinateSpace.Tangent; +// if (updateNormalSlot) +// { +// RemoveSlot(NormalSlotId); +// switch (m_NormalDropOffSpace) +// { +// case NormalDropOffSpace.Tangent: +// coordSpace = CoordinateSpace.Tangent; +// break; +// case NormalDropOffSpace.World: +// coordSpace = CoordinateSpace.World; +// break; +// case NormalDropOffSpace.Object: +// coordSpace = CoordinateSpace.Object; +// break; +// } +// updateNormalSlot = false; +// } +// AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, coordSpace, ShaderStageCapability.Fragment)); +// validSlots.Add(NormalSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.BentNormal)) +// { +// AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(BentNormalSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Tangent)) +// { +// AddSlot(new TangentMaterialSlot(TangentSlotId, TangentSlotName, TangentSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(TangentSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Anisotropy)) +// { +// AddSlot(new Vector1MaterialSlot(AnisotropySlotId, AnisotropySlotName, AnisotropySlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AnisotropySlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.SubsurfaceMask)) +// { +// AddSlot(new Vector1MaterialSlot(SubsurfaceMaskSlotId, SubsurfaceMaskSlotName, SubsurfaceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SubsurfaceMaskSlotId); +// } +// if ((MaterialTypeUsesSlotMask(SlotMask.Thickness) && (sssTransmission.isOn || materialType == MaterialType.Translucent)) || HasRefraction()) +// { +// AddSlot(new Vector1MaterialSlot(ThicknessSlotId, ThicknessSlotName, ThicknessSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(ThicknessSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.DiffusionProfile)) +// { +// AddSlot(new DiffusionProfileInputMaterialSlot(DiffusionProfileHashSlotId, DiffusionProfileHashSlotDisplayName, DiffusionProfileHashSlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(DiffusionProfileHashSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.IridescenceMask)) +// { +// AddSlot(new Vector1MaterialSlot(IridescenceMaskSlotId, IridescenceMaskSlotName, IridescenceMaskSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(IridescenceMaskSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.IridescenceLayerThickness)) +// { +// AddSlot(new Vector1MaterialSlot(IridescenceThicknessSlotId, IridescenceThicknessSlotDisplayName, IridescenceThicknessSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(IridescenceThicknessSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Specular)) +// { +// AddSlot(new ColorRGBMaterialSlot(SpecularColorSlotId, SpecularColorDisplaySlotName, SpecularColorSlotName, SlotType.Input, Color.white, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularColorSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.CoatMask)) +// { +// AddSlot(new Vector1MaterialSlot(CoatMaskSlotId, CoatMaskSlotName, CoatMaskSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(CoatMaskSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Metallic)) +// { +// AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(MetallicSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Smoothness)) +// { +// AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(SmoothnessSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Occlusion)) +// { +// AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionDisplaySlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AmbientOcclusionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.SpecularOcclusion) && specularOcclusionMode == SpecularOcclusionMode.Custom) +// { +// AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularOcclusionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Emission)) +// { +// AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); +// validSlots.Add(EmissionSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Alpha)) +// { +// AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaThreshold) && alphaTest.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaThresholdSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaThresholdDepthPrepass) && surfaceType == SurfaceType.Transparent && alphaTest.isOn && alphaTestDepthPrepass.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaThresholdDepthPrepassSlotId, AlphaClipThresholdDepthPrepassSlotName, AlphaClipThresholdDepthPrepassSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaThresholdDepthPrepassSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaThresholdDepthPostpass) && surfaceType == SurfaceType.Transparent && alphaTest.isOn && alphaTestDepthPostpass.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaThresholdDepthPostpassSlotId, AlphaClipThresholdDepthPostpassSlotName, AlphaClipThresholdDepthPostpassSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaThresholdDepthPostpassSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.AlphaThresholdShadow) && alphaTest.isOn && alphaTestShadow.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaThresholdShadowSlotId, AlphaClipThresholdShadowSlotName, AlphaClipThresholdShadowSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaThresholdShadowSlotId); +// } +// if (specularAA.isOn) +// { +// AddSlot(new Vector1MaterialSlot(SpecularAAScreenSpaceVarianceSlotId, SpecularAAScreenSpaceVarianceSlotName, SpecularAAScreenSpaceVarianceSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularAAScreenSpaceVarianceSlotId); + +// AddSlot(new Vector1MaterialSlot(SpecularAAThresholdSlotId, SpecularAAThresholdSlotName, SpecularAAThresholdSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularAAThresholdSlotId); +// } +// if (HasRefraction()) +// { +// AddSlot(new Vector1MaterialSlot(RefractionIndexSlotId, RefractionIndexSlotName, RefractionIndexSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(RefractionIndexSlotId); + +// AddSlot(new ColorRGBMaterialSlot(RefractionColorSlotId, RefractionColorSlotDisplayName, RefractionColorSlotName, SlotType.Input, Color.white, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(RefractionColorSlotId); + +// AddSlot(new Vector1MaterialSlot(RefractionDistanceSlotId, RefractionDistanceSlotDisplayName, RefractionDistanceSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(RefractionDistanceSlotId); +// } +// if (HasDistortion()) +// { +// AddSlot(new Vector2MaterialSlot(DistortionSlotId, DistortionSlotDisplayName, DistortionSlotName, SlotType.Input, new Vector2(2.0f, -1.0f), ShaderStageCapability.Fragment)); +// validSlots.Add(DistortionSlotId); + +// AddSlot(new Vector1MaterialSlot(DistortionBlurSlotId, DistortionBlurSlotName, DistortionBlurSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(DistortionBlurSlotId); +// } +// if (MaterialTypeUsesSlotMask(SlotMask.Lighting) && overrideBakedGI.isOn) +// { +// AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(LightingSlotId); +// AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(BackLightingSlotId); +// } +// if (depthOffset.isOn) +// { +// AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(DepthOffsetSlotId); +// } + +// RemoveSlotsNameNotMatching(validSlots, true); +// } + +// public VisualElement CreateSettingsElement() +// { +// return new HDLitSettingsView(this); +// } + +// public string renderQueueTag +// { +// get +// { +// if(renderingPass == HDRenderQueue.RenderQueueType.Unknown) +// { +// switch(surfaceType) +// { +// case SurfaceType.Opaque: +// renderingPass = HDRenderQueue.RenderQueueType.Opaque; +// break; +// case SurfaceType.Transparent: +// #pragma warning disable CS0618 // Type or member is obsolete +// if (m_DrawBeforeRefraction) +// { +// m_DrawBeforeRefraction = false; +// #pragma warning restore CS0618 // Type or member is obsolete +// renderingPass = HDRenderQueue.RenderQueueType.PreRefraction; +// } +// else +// { +// renderingPass = HDRenderQueue.RenderQueueType.Transparent; +// } +// break; +// } +// } +// int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); +// return HDRenderQueue.GetShaderTagValue(queue); +// } +// } + +// public string renderTypeTag => HDRenderTypeTags.HDLitShader.ToString(); + +// public ConditionalField[] GetConditionalFields(PassDescriptor pass) +// { +// var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); +// var coatMaskSlot = FindSlot(CoatMaskSlotId); + +// // We need this to know if there are any Dots properties active +// // Ideally we do this another way but HDLit needs this for conditional pragmas +// var shaderProperties = new PropertyCollector(); +// owner.CollectShaderProperties(shaderProperties, GenerationMode.ForReals); +// bool hasDotsProperties = shaderProperties.GetDotsInstancingPropertiesCount(GenerationMode.ForReals) > 0; + +// return new ConditionalField[] +// { +// // Features +// new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || +// IsSlotConnected(VertexNormalSlotID) || +// IsSlotConnected(VertexTangentSlotID)), +// new ConditionalField(Fields.GraphPixel, true), +// new ConditionalField(Fields.LodCrossFade, supportLodCrossFade.isOn), + +// // Structs +// new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && +// !pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)), + +// // Dots +// new ConditionalField(HDFields.DotsInstancing, dotsInstancing.isOn), +// new ConditionalField(HDFields.DotsProperties, hasDotsProperties), + +// // Material +// new ConditionalField(HDFields.Anisotropy, materialType == MaterialType.Anisotropy), +// new ConditionalField(HDFields.Iridescence, materialType == MaterialType.Iridescence), +// new ConditionalField(HDFields.SpecularColor, materialType == MaterialType.SpecularColor), +// new ConditionalField(HDFields.Standard, materialType == MaterialType.Standard), +// new ConditionalField(HDFields.SubsurfaceScattering, materialType == MaterialType.SubsurfaceScattering && +// surfaceType != SurfaceType.Transparent), +// new ConditionalField(HDFields.Transmission, (materialType == MaterialType.SubsurfaceScattering && sssTransmission.isOn) || +// (materialType == MaterialType.Translucent)), +// new ConditionalField(HDFields.Translucent, materialType == MaterialType.Translucent), + +// // Surface Type +// new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), +// new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), + +// // Blend Mode +// new ConditionalField(Fields.BlendAdd, surfaceType != SurfaceType.Opaque && alphaMode == AlphaMode.Additive), +// new ConditionalField(Fields.BlendAlpha, surfaceType != SurfaceType.Opaque && alphaMode == AlphaMode.Alpha), +// new ConditionalField(Fields.BlendMultiply, surfaceType != SurfaceType.Opaque && alphaMode == AlphaMode.Multiply), +// new ConditionalField(Fields.BlendPremultiply, surfaceType != SurfaceType.Opaque && alphaMode == AlphaMode.Premultiply), + +// // Double Sided +// new ConditionalField(HDFields.DoubleSided, doubleSidedMode != DoubleSidedMode.Disabled), +// new ConditionalField(HDFields.DoubleSidedFlip, doubleSidedMode == DoubleSidedMode.FlippedNormals && +// !pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)), +// new ConditionalField(HDFields.DoubleSidedMirror, doubleSidedMode == DoubleSidedMode.MirroredNormals && +// !pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)), + +// // Specular Occlusion +// new ConditionalField(HDFields.SpecularOcclusionFromAO, specularOcclusionMode == SpecularOcclusionMode.FromAO), +// new ConditionalField(HDFields.SpecularOcclusionFromAOBentNormal, specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal), +// new ConditionalField(HDFields.SpecularOcclusionCustom, specularOcclusionMode == SpecularOcclusionMode.Custom), + +// //Distortion +// new ConditionalField(HDFields.DistortionDepthTest, distortionDepthTest.isOn), +// new ConditionalField(HDFields.DistortionAdd, distortionMode == DistortionMode.Add), +// new ConditionalField(HDFields.DistortionMultiply, distortionMode == DistortionMode.Multiply), +// new ConditionalField(HDFields.DistortionReplace, distortionMode == DistortionMode.Replace), +// new ConditionalField(HDFields.TransparentDistortion, surfaceType != SurfaceType.Opaque && distortion.isOn), + +// // Refraction +// new ConditionalField(HDFields.Refraction, HasRefraction()), +// new ConditionalField(HDFields.RefractionBox, HasRefraction() && refractionModel == ScreenSpaceRefraction.RefractionModel.Box), +// new ConditionalField(HDFields.RefractionSphere, HasRefraction() && refractionModel == ScreenSpaceRefraction.RefractionModel.Sphere), + +// //Normal Drop Off Space +// new ConditionalField(Fields.NormalDropOffOS, normalDropOffSpace == NormalDropOffSpace.Object), +// new ConditionalField(Fields.NormalDropOffTS, normalDropOffSpace == NormalDropOffSpace.Tangent), +// new ConditionalField(Fields.NormalDropOffWS, normalDropOffSpace == NormalDropOffSpace.World), + +// // Misc +// // We always generate the keyword ALPHATEST_ON +// new ConditionalField(Fields.AlphaTest, alphaTest.isOn && (pass.pixelPorts.Contains(AlphaThresholdSlotId) || pass.pixelPorts.Contains(AlphaThresholdShadowSlotId) || +// pass.pixelPorts.Contains(AlphaThresholdDepthPrepassSlotId) || pass.pixelPorts.Contains(AlphaThresholdDepthPostpassSlotId))), +// // All the DoAlphaXXX field drive the generation of which code to use for alpha test in the template +// // Do alpha test only if we aren't using the TestShadow one +// // Note: we always generate the code for DoAlphaTestXXX as it is then the keyword _ALPHATEST_ON that will define if it is enabled or not +// new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && (pass.pixelPorts.Contains(AlphaThresholdSlotId) && +// !(alphaTestShadow.isOn && pass.pixelPorts.Contains(AlphaThresholdShadowSlotId)))), +// new ConditionalField(HDFields.DoAlphaTestShadow, alphaTest.isOn && alphaTestShadow.isOn && pass.pixelPorts.Contains(AlphaThresholdShadowSlotId)), +// new ConditionalField(HDFields.DoAlphaTestPrepass, alphaTest.isOn && alphaTestDepthPrepass.isOn && pass.pixelPorts.Contains(AlphaThresholdDepthPrepassSlotId)), +// new ConditionalField(HDFields.DoAlphaTestPostpass, alphaTest.isOn && alphaTestDepthPostpass.isOn && pass.pixelPorts.Contains(AlphaThresholdDepthPostpassSlotId)), +// new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaThresholdSlotId) && alphaToMask.isOn), +// new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), +// new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), +// new ConditionalField(HDFields.TransparentWritesMotionVec, surfaceType != SurfaceType.Opaque && transparentWritesMotionVec.isOn), +// new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), +// new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), +// new ConditionalField(HDFields.DisableSSRTransparent, !receiveSSRTransparent.isOn), +// new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), +// new ConditionalField(HDFields.SpecularAA, specularAA.isOn && +// pass.pixelPorts.Contains(SpecularAAThresholdSlotId) && +// pass.pixelPorts.Contains(SpecularAAScreenSpaceVarianceSlotId)), +// new ConditionalField(HDFields.EnergyConservingSpecular, energyConservingSpecular.isOn), +// new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && +// pass.pixelPorts.Contains(BentNormalSlotId)), +// new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && +// (IsSlotConnected(AmbientOcclusionSlotId) || +// ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), +// new ConditionalField(HDFields.CoatMask, pass.pixelPorts.Contains(CoatMaskSlotId) && +// (IsSlotConnected(CoatMaskSlotId) || coatMaskSlot.value > 0.0f)), +// new ConditionalField(HDFields.Tangent, IsSlotConnected(TangentSlotId) && +// pass.pixelPorts.Contains(TangentSlotId)), +// new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && +// pass.pixelPorts.Contains(LightingSlotId)), +// new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && +// pass.pixelPorts.Contains(BackLightingSlotId)), +// new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), +// new ConditionalField(HDFields.TransparentBackFace, surfaceType != SurfaceType.Opaque && backThenFrontRendering.isOn), +// new ConditionalField(HDFields.TransparentDepthPrePass, surfaceType != SurfaceType.Opaque && alphaTestDepthPrepass.isOn), +// new ConditionalField(HDFields.TransparentDepthPostPass, surfaceType != SurfaceType.Opaque && alphaTestDepthPostpass.isOn), +// new ConditionalField(HDFields.RayTracing, rayTracing.isOn), +// }; +// } + +// public void ProcessPreviewMaterial(Material material) +// { +// // Fixup the material settings: +// material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); +// material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); +// material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); +// material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); +// material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); +// material.SetFloat(kZTestTransparent, (int)zTest); +// material.SetFloat(kTransparentCullMode, (int)transparentCullMode); +// material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); +// // No sorting priority for shader graph preview +// material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); + +// HDLitGUI.SetupMaterialKeywordsAndPass(material); +// } + +// public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); +// } + +// public bool RequiresSplitLighting() +// { +// return materialType == HDLitMasterNode.MaterialType.SubsurfaceScattering; +// } +// public override object saveContext +// { +// get +// { +// int hash = ComputeMaterialNeedsUpdateHash(); + +// bool needsUpdate = hash != m_MaterialNeedsUpdateHash; + +// if (needsUpdate) +// m_MaterialNeedsUpdateHash = hash; + +// return new HDSaveContext{ updateMaterials = needsUpdate }; +// } +// } + +// public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) +// { +// // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. +// // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 +// // The user will then need to explicitly disable emissive GI if it is not needed. +// // To be able to automatically disable emission based on the ShaderGraph config when emission is black, +// // we will need a more general way to communicate this to the engine (not directly tied to a material property). +// collector.AddShaderProperty(new ColorShaderProperty() +// { +// overrideReferenceName = "_EmissionColor", +// hidden = true, +// value = new Color(1.0f, 1.0f, 1.0f, 1.0f) +// }); +// // ShaderGraph only property used to send the RenderQueueType to the material +// collector.AddShaderProperty(new Vector1ShaderProperty +// { +// overrideReferenceName = "_RenderQueueType", +// hidden = true, +// value = (int)renderingPass, +// }); + +// //See SG-ADDITIONALVELOCITY-NOTE +// if (addPrecomputedVelocity.isOn) +// { +// collector.AddShaderProperty(new BooleanShaderProperty +// { +// value = true, +// hidden = true, +// overrideReferenceName = kAddPrecomputedVelocity, +// }); +// } + +// // Add all shader properties required by the inspector +// HDSubShaderUtilities.AddStencilShaderProperties(collector, RequiresSplitLighting(), receiveSSR.isOn, receiveSSRTransparent.isOn); +// HDSubShaderUtilities.AddBlendingStatesShaderProperties( +// collector, +// surfaceType, +// HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), +// sortPriority, +// alphaToMask.isOn, +// zWrite.isOn, +// transparentCullMode, +// zTest, +// backThenFrontRendering.isOn, +// transparencyFog.isOn +// ); +// HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, alphaTestShadow.isOn); +// HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); +// HDSubShaderUtilities.AddRayTracingProperty(collector, rayTracing.isOn); + +// base.CollectShaderProperties(collector, generationMode); +// } + +// public override void Setup() +// { +// base.Setup(); +// var hdPipelineAsset = HDRenderPipeline.currentAsset; + +// if (hdPipelineAsset == null) +// return; + +// var diffusionProfileSlot = FindSlot(DiffusionProfileHashSlotId); + +// if (diffusionProfileSlot == null) +// return; + +// if ((diffusionProfileSlot.diffusionProfile) != null && !hdPipelineAsset.diffusionProfileSettingsList.Any(d => d == diffusionProfileSlot.diffusionProfile)) +// { +// //owner.AddSetupError(tempId, $"Diffusion profile '{diffusionProfileSlot.diffusionProfile.name}' is not referenced in the current HDRP asset", ShaderCompilerMessageSeverity.Warning); +// } + +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs index ca9257ce7dd..f2471e4740e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs @@ -1,791 +1,791 @@ -using System; -using UnityEditor.UIElements; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Internal; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; - -namespace UnityEditor.Rendering.HighDefinition.Drawing -{ - class HDLitSettingsView : MasterNodeSettingsView - { - HDLitMasterNode m_Node; - - IntegerField m_SortPriorityField; - - Label CreateLabel(string text, int indentLevel) - { - string label = ""; - for (var i = 0; i < indentLevel; i++) - { - label += " "; - } - return new Label(label + text); - } - - public HDLitSettingsView(HDLitMasterNode node) : base(node) - { - m_Node = node; - PropertySheet ps = new PropertySheet(); - - int indentLevel = 0; - - ps.Add(new PropertyRow(CreateLabel("Ray Tracing (Preview)", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.rayTracing.isOn; - toggle.RegisterValueChangedCallback(ChangeRayTracingFlag); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => - { - row.Add(new EnumField(SurfaceType.Opaque), (field) => - { - field.value = m_Node.surfaceType; - field.RegisterValueChangedCallback(ChangeSurfaceType); - }); - }); - - ++indentLevel; - switch (m_Node.surfaceType) - { - case SurfaceType.Opaque: - ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => - { - var valueList = HDSubShaderUtilities.GetRenderingPassList(true, false); - - row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Opaque, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => - { - field.value = HDRenderQueue.GetOpaqueEquivalent(m_Node.renderingPass); - field.RegisterValueChangedCallback(ChangeRenderingPass); - }); - }); - break; - case SurfaceType.Transparent: - ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => - { - Enum defaultValue; - switch (m_Node.renderingPass) // Migration - { - default: //when deserializing without issue, we still need to init the default to something even if not used. - case HDRenderQueue.RenderQueueType.Transparent: - defaultValue = HDRenderQueue.TransparentRenderQueue.Default; - break; - case HDRenderQueue.RenderQueueType.PreRefraction: - defaultValue = HDRenderQueue.TransparentRenderQueue.BeforeRefraction; - break; - } - - var valueList = HDSubShaderUtilities.GetRenderingPassList(false, false); - - row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Transparent, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => - { - field.value = HDRenderQueue.GetTransparentEquivalent(m_Node.renderingPass); - field.RegisterValueChangedCallback(ChangeRenderingPass); - }); - }); - break; - default: - throw new ArgumentException("Unknown SurfaceType"); - } - --indentLevel; - - if (m_Node.surfaceType == SurfaceType.Transparent) - { - ++indentLevel; - - if (!m_Node.HasRefraction()) - { - ps.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => - { - row.Add(new EnumField(HDLitMasterNode.AlphaModeLit.Additive), (field) => - { - field.value = GetAlphaModeLit(m_Node.alphaMode); - field.RegisterValueChangedCallback(ChangeBlendMode); - }); - }); - - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Preserve Specular Lighting", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.blendPreserveSpecular.isOn; - toggle.OnToggleChanged(ChangeBlendPreserveSpecular); - }); - }); - --indentLevel; - } - - m_SortPriorityField = new IntegerField(); - ps.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => - { - row.Add(m_SortPriorityField, (field) => - { - field.value = m_Node.sortPriority; - field.RegisterValueChangedCallback(ChangeSortPriority); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transparencyFog.isOn; - toggle.OnToggleChanged(ChangeTransparencyFog); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Back Then Front Rendering", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.backThenFrontRendering.isOn; - toggle.OnToggleChanged(ChangeBackThenFrontRendering); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Transparent Depth Prepass", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTestDepthPrepass.isOn; - toggle.OnToggleChanged(ChangeAlphaTestPrepass); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Transparent Depth Postpass", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTestDepthPostpass.isOn; - toggle.OnToggleChanged(ChangeAlphaTestPostpass); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Transparent Writes Motion Vector", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transparentWritesMotionVec.isOn; - toggle.OnToggleChanged(ChangeTransparentWritesMotionVec); - }); - }); - - if (m_Node.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction) - { - ps.Add(new PropertyRow(CreateLabel("Refraction Model", indentLevel)), (row) => - { - row.Add(new EnumField(ScreenSpaceRefraction.RefractionModel.None), (field) => - { - field.value = m_Node.refractionModel; - field.RegisterValueChangedCallback(ChangeRefractionModel); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.distortion.isOn; - toggle.OnToggleChanged(ChangeDistortion); - }); - }); - - if (m_Node.distortion.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Distortion Blend Mode", indentLevel)), (row) => - { - row.Add(new EnumField(DistortionMode.Add), (field) => - { - field.value = m_Node.distortionMode; - field.RegisterValueChangedCallback(ChangeDistortionMode); - }); - }); - ps.Add(new PropertyRow(CreateLabel("Distortion Depth Test", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.distortionDepthTest.isOn; - toggle.OnToggleChanged(ChangeDistortionDepthTest); - }); - }); - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.zWrite.isOn; - toggle.OnToggleChanged(ChangeZWrite); - }); - }); - - if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) - { - ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.transparentCullMode), (e) => - { - e.value = m_Node.transparentCullMode; - e.RegisterValueChangedCallback(ChangeTransparentCullMode); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.zTest), (e) => - { - e.value = m_Node.zTest; - e.RegisterValueChangedCallback(ChangeZTest); - }); - }); - - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => - { - row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => - { - field.value = m_Node.doubleSidedMode; - field.RegisterValueChangedCallback(ChangeDoubleSidedMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Fragment Normal Space", indentLevel)), (row) => - { - row.Add(new EnumField(NormalDropOffSpace.Tangent), (field) => - { - field.value = m_Node.normalDropOffSpace; - field.RegisterValueChangedCallback(ChangeSpaceOfNormalDropOffMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTest.isOn; - toggle.OnToggleChanged(ChangeAlphaTest); - }); - }); - - if (m_Node.alphaTest.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Use Shadow Threshold", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTestShadow.isOn; - toggle.OnToggleChanged(ChangeAlphaTestShadow); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaToMask.isOn; - toggle.OnToggleChanged(ChangeAlphaToMask); - }); - }); - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Material Type", indentLevel)), (row) => - { - row.Add(new EnumField(HDLitMasterNode.MaterialType.Standard), (field) => - { - field.value = m_Node.materialType; - field.RegisterValueChangedCallback(ChangeMaterialType); - }); - }); - - ++indentLevel; - if (m_Node.materialType == HDLitMasterNode.MaterialType.SubsurfaceScattering) - { - ps.Add(new PropertyRow(CreateLabel("Transmission", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.sssTransmission.isOn; - toggle.OnToggleChanged(ChangeSSSTransmission); - }); - }); - } - - if (m_Node.materialType == HDLitMasterNode.MaterialType.SpecularColor) - { - ps.Add(new PropertyRow(CreateLabel("Energy Conserving Specular", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.energyConservingSpecular.isOn; - toggle.OnToggleChanged(ChangeEnergyConservingSpecular); - }); - }); - } - --indentLevel; - - ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveDecals.isOn; - toggle.OnToggleChanged(ChangeDecal); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - if (m_Node.surfaceType == SurfaceType.Transparent) - { - toggle.value = m_Node.receiveSSRTransparent.isOn; - toggle.OnToggleChanged(ChangeSSRTransparent); - } - else - { - toggle.value = m_Node.receiveSSR.isOn; - toggle.OnToggleChanged(ChangeSSR); - } - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.addPrecomputedVelocity.isOn; - toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); - }); - }); - - - ps.Add(new PropertyRow(CreateLabel("Geometric Specular AA", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.specularAA.isOn; - toggle.OnToggleChanged(ChangeSpecularAA); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => - { - row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => - { - field.value = m_Node.specularOcclusionMode; - field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.overrideBakedGI.isOn; - toggle.OnToggleChanged(ChangeoverrideBakedGI); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.depthOffset.isOn; - toggle.OnToggleChanged(ChangeDepthOffset); - }); - }); - ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.supportLodCrossFade.isOn; - toggle.OnToggleChanged(ChangeSupportLODCrossFade); - }); - }); - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeRayTracingFlag(ChangeEvent evt) - { - if (Equals(m_Node.rayTracing, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Ray Tracing Flag Change"); - ToggleData rt = m_Node.rayTracing; - rt.isOn = evt.newValue; - m_Node.rayTracing = rt; - } - - void ChangeSurfaceType(ChangeEvent evt) - { - if (Equals(m_Node.surfaceType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); - m_Node.surfaceType = (SurfaceType)evt.newValue; - - UpdateRenderingPassValue(m_Node.renderingPass); - } - - void ChangeDoubleSidedMode(ChangeEvent evt) - { - if (Equals(m_Node.doubleSidedMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); - m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; - } - - void ChangeSpaceOfNormalDropOffMode(ChangeEvent evt) - { - if (Equals(m_Node.normalDropOffSpace, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Normal Space Drop-Off Mode Change"); - m_Node.normalDropOffSpace = (NormalDropOffSpace)evt.newValue; - } - - void ChangeMaterialType(ChangeEvent evt) - { - if (Equals(m_Node.materialType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Material Type Change"); - m_Node.materialType = (HDLitMasterNode.MaterialType)evt.newValue; - } - - void ChangeSSSTransmission(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SSS Transmission Change"); - ToggleData td = m_Node.sssTransmission; - td.isOn = evt.newValue; - m_Node.sssTransmission = td; - } - - void ChangeBlendMode(ChangeEvent evt) - { - // Make sure the mapping is correct by handling each case. - - AlphaMode alphaMode = GetAlphaMode((HDLitMasterNode.AlphaModeLit)evt.newValue); - - if (Equals(m_Node.alphaMode, alphaMode)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); - m_Node.alphaMode = alphaMode; - } - - void ChangeRenderingPass(ChangeEvent evt) - { - switch (evt.newValue) - { - case HDRenderQueue.RenderQueueType.Overlay: - case HDRenderQueue.RenderQueueType.Unknown: - case HDRenderQueue.RenderQueueType.Background: - throw new ArgumentException("Unexpected kind of RenderQueue, was " + evt.newValue); - default: - break; - }; - UpdateRenderingPassValue(evt.newValue); - } - - void UpdateRenderingPassValue(HDRenderQueue.RenderQueueType newValue) - { - HDRenderQueue.RenderQueueType renderingPass; - switch (m_Node.surfaceType) - { - case SurfaceType.Opaque: - renderingPass = HDRenderQueue.GetOpaqueEquivalent(newValue); - break; - case SurfaceType.Transparent: - renderingPass = HDRenderQueue.GetTransparentEquivalent(newValue); - break; - default: - throw new ArgumentException("Unknown SurfaceType"); - } - - if (Equals(m_Node.renderingPass, renderingPass)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Rendering Pass Change"); - m_Node.renderingPass = renderingPass; - } - - void ChangeBlendPreserveSpecular(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); - ToggleData td = m_Node.blendPreserveSpecular; - td.isOn = evt.newValue; - m_Node.blendPreserveSpecular = td; - } - - void ChangeTransparencyFog(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); - ToggleData td = m_Node.transparencyFog; - td.isOn = evt.newValue; - m_Node.transparencyFog = td; - } - - void ChangeRefractionModel(ChangeEvent evt) - { - if (Equals(m_Node.refractionModel, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Refraction Model Change"); - m_Node.refractionModel = (ScreenSpaceRefraction.RefractionModel)evt.newValue; - } - - void ChangeDistortion(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Change"); - ToggleData td = m_Node.distortion; - td.isOn = evt.newValue; - m_Node.distortion = td; - } - - void ChangeDistortionMode(ChangeEvent evt) - { - if (Equals(m_Node.distortionMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Mode Change"); - m_Node.distortionMode = (DistortionMode)evt.newValue; - } - - void ChangeDistortionDepthTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Depth Test Change"); - ToggleData td = m_Node.distortionDepthTest; - td.isOn = evt.newValue; - m_Node.distortionDepthTest = td; - } - - void ChangeBackThenFrontRendering(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Back Then Front Rendering Change"); - ToggleData td = m_Node.backThenFrontRendering; - td.isOn = evt.newValue; - m_Node.backThenFrontRendering = td; - } - - void ChangeSortPriority(ChangeEvent evt) - { - m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - // Force the text to match. - m_SortPriorityField.value = m_Node.sortPriority; - if (Equals(m_Node.sortPriority, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); - } - - void ChangeAlphaTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); - ToggleData td = m_Node.alphaTest; - td.isOn = evt.newValue; - m_Node.alphaTest = td; - } - - void ChangeAlphaTestPrepass(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Prepass Change"); - ToggleData td = m_Node.alphaTestDepthPrepass; - td.isOn = evt.newValue; - m_Node.alphaTestDepthPrepass = td; - } - - void ChangeAlphaTestPostpass(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Postpass Change"); - ToggleData td = m_Node.alphaTestDepthPostpass; - td.isOn = evt.newValue; - m_Node.alphaTestDepthPostpass = td; - } - void ChangeTransparentWritesMotionVec(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Writes Motion Vector Change"); - ToggleData td = m_Node.transparentWritesMotionVec; - td.isOn = evt.newValue; - m_Node.transparentWritesMotionVec = td; - } - void ChangeAlphaTestShadow(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Shadow Change"); - ToggleData td = m_Node.alphaTestShadow; - td.isOn = evt.newValue; - m_Node.alphaTestShadow = td; - } - - void ChangeDecal(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Decal Change"); - ToggleData td = m_Node.receiveDecals; - td.isOn = evt.newValue; - m_Node.receiveDecals = td; - } - - void ChangeSSR(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); - ToggleData td = m_Node.receiveSSR; - td.isOn = evt.newValue; - m_Node.receiveSSR = td; - } - - void ChangeSSRTransparent(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); - ToggleData td = m_Node.receiveSSRTransparent; - td.isOn = evt.newValue; - m_Node.receiveSSRTransparent = td; - } - - void ChangeAddPrecomputedVelocity(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); - ToggleData td = m_Node.addPrecomputedVelocity; - td.isOn = evt.newValue; - m_Node.addPrecomputedVelocity = td; - } - - void ChangeSpecularAA(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Specular AA Change"); - ToggleData td = m_Node.specularAA; - td.isOn = evt.newValue; - m_Node.specularAA = td; - } - - void ChangeEnergyConservingSpecular(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Energy Conserving Specular Change"); - ToggleData td = m_Node.energyConservingSpecular; - td.isOn = evt.newValue; - m_Node.energyConservingSpecular = td; - } - - void ChangeSpecularOcclusionMode(ChangeEvent evt) - { - if (Equals(m_Node.specularOcclusionMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Specular Occlusion Mode Change"); - m_Node.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; - } - - void ChangeoverrideBakedGI(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); - ToggleData td = m_Node.overrideBakedGI; - td.isOn = evt.newValue; - m_Node.overrideBakedGI = td; - } - - void ChangeDepthOffset(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); - ToggleData td = m_Node.depthOffset; - td.isOn = evt.newValue; - m_Node.depthOffset = td; - } - - void ChangeSupportLODCrossFade(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); - ToggleData td = m_Node.supportLodCrossFade; - td.isOn = evt.newValue; - m_Node.supportLodCrossFade = td; - } - - void ChangeAlphaToMask(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); - ToggleData td = m_Node.alphaToMask; - td.isOn = evt.newValue; - m_Node.alphaToMask = td; - } - - void ChangeZWrite(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); - ToggleData td = m_Node.zWrite; - td.isOn = evt.newValue; - m_Node.zWrite = td; - } - - void ChangeTransparentCullMode(ChangeEvent evt) - { - if (Equals(m_Node.transparentCullMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); - m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; - } - - void ChangeZTest(ChangeEvent evt) - { - if (Equals(m_Node.zTest, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); - m_Node.zTest = (CompareFunction)evt.newValue; - } - - public AlphaMode GetAlphaMode(HDLitMasterNode.AlphaModeLit alphaModeLit) - { - switch (alphaModeLit) - { - case HDLitMasterNode.AlphaModeLit.Alpha: - return AlphaMode.Alpha; - case HDLitMasterNode.AlphaModeLit.Premultiply: - return AlphaMode.Premultiply; - case HDLitMasterNode.AlphaModeLit.Additive: - return AlphaMode.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaModeLit); - return AlphaMode.Alpha; - } - } - } - - public HDLitMasterNode.AlphaModeLit GetAlphaModeLit(AlphaMode alphaMode) - { - switch (alphaMode) - { - case AlphaMode.Alpha: - return HDLitMasterNode.AlphaModeLit.Alpha; - case AlphaMode.Premultiply: - return HDLitMasterNode.AlphaModeLit.Premultiply; - case AlphaMode.Additive: - return HDLitMasterNode.AlphaModeLit.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaMode); - return HDLitMasterNode.AlphaModeLit.Alpha; - } - } - } - } -} +// using System; +// using UnityEditor.UIElements; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEditor.Graphing.Util; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; + +// namespace UnityEditor.Rendering.HighDefinition.Drawing +// { +// class HDLitSettingsView : MasterNodeSettingsView +// { +// HDLitMasterNode m_Node; + +// IntegerField m_SortPriorityField; + +// Label CreateLabel(string text, int indentLevel) +// { +// string label = ""; +// for (var i = 0; i < indentLevel; i++) +// { +// label += " "; +// } +// return new Label(label + text); +// } + +// public HDLitSettingsView(HDLitMasterNode node) : base(node) +// { +// m_Node = node; +// PropertySheet ps = new PropertySheet(); + +// int indentLevel = 0; + +// ps.Add(new PropertyRow(CreateLabel("Ray Tracing (Preview)", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.rayTracing.isOn; +// toggle.RegisterValueChangedCallback(ChangeRayTracingFlag); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(SurfaceType.Opaque), (field) => +// { +// field.value = m_Node.surfaceType; +// field.RegisterValueChangedCallback(ChangeSurfaceType); +// }); +// }); + +// ++indentLevel; +// switch (m_Node.surfaceType) +// { +// case SurfaceType.Opaque: +// ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => +// { +// var valueList = HDSubShaderUtilities.GetRenderingPassList(true, false); + +// row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Opaque, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => +// { +// field.value = HDRenderQueue.GetOpaqueEquivalent(m_Node.renderingPass); +// field.RegisterValueChangedCallback(ChangeRenderingPass); +// }); +// }); +// break; +// case SurfaceType.Transparent: +// ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => +// { +// Enum defaultValue; +// switch (m_Node.renderingPass) // Migration +// { +// default: //when deserializing without issue, we still need to init the default to something even if not used. +// case HDRenderQueue.RenderQueueType.Transparent: +// defaultValue = HDRenderQueue.TransparentRenderQueue.Default; +// break; +// case HDRenderQueue.RenderQueueType.PreRefraction: +// defaultValue = HDRenderQueue.TransparentRenderQueue.BeforeRefraction; +// break; +// } + +// var valueList = HDSubShaderUtilities.GetRenderingPassList(false, false); + +// row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Transparent, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => +// { +// field.value = HDRenderQueue.GetTransparentEquivalent(m_Node.renderingPass); +// field.RegisterValueChangedCallback(ChangeRenderingPass); +// }); +// }); +// break; +// default: +// throw new ArgumentException("Unknown SurfaceType"); +// } +// --indentLevel; + +// if (m_Node.surfaceType == SurfaceType.Transparent) +// { +// ++indentLevel; + +// if (!m_Node.HasRefraction()) +// { +// ps.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(HDLitMasterNode.AlphaModeLit.Additive), (field) => +// { +// field.value = GetAlphaModeLit(m_Node.alphaMode); +// field.RegisterValueChangedCallback(ChangeBlendMode); +// }); +// }); + +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Preserve Specular Lighting", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.blendPreserveSpecular.isOn; +// toggle.OnToggleChanged(ChangeBlendPreserveSpecular); +// }); +// }); +// --indentLevel; +// } + +// m_SortPriorityField = new IntegerField(); +// ps.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => +// { +// row.Add(m_SortPriorityField, (field) => +// { +// field.value = m_Node.sortPriority; +// field.RegisterValueChangedCallback(ChangeSortPriority); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transparencyFog.isOn; +// toggle.OnToggleChanged(ChangeTransparencyFog); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Back Then Front Rendering", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.backThenFrontRendering.isOn; +// toggle.OnToggleChanged(ChangeBackThenFrontRendering); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Transparent Depth Prepass", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTestDepthPrepass.isOn; +// toggle.OnToggleChanged(ChangeAlphaTestPrepass); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Transparent Depth Postpass", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTestDepthPostpass.isOn; +// toggle.OnToggleChanged(ChangeAlphaTestPostpass); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Transparent Writes Motion Vector", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transparentWritesMotionVec.isOn; +// toggle.OnToggleChanged(ChangeTransparentWritesMotionVec); +// }); +// }); + +// if (m_Node.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction) +// { +// ps.Add(new PropertyRow(CreateLabel("Refraction Model", indentLevel)), (row) => +// { +// row.Add(new EnumField(ScreenSpaceRefraction.RefractionModel.None), (field) => +// { +// field.value = m_Node.refractionModel; +// field.RegisterValueChangedCallback(ChangeRefractionModel); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.distortion.isOn; +// toggle.OnToggleChanged(ChangeDistortion); +// }); +// }); + +// if (m_Node.distortion.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Distortion Blend Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(DistortionMode.Add), (field) => +// { +// field.value = m_Node.distortionMode; +// field.RegisterValueChangedCallback(ChangeDistortionMode); +// }); +// }); +// ps.Add(new PropertyRow(CreateLabel("Distortion Depth Test", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.distortionDepthTest.isOn; +// toggle.OnToggleChanged(ChangeDistortionDepthTest); +// }); +// }); +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.zWrite.isOn; +// toggle.OnToggleChanged(ChangeZWrite); +// }); +// }); + +// if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) +// { +// ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.transparentCullMode), (e) => +// { +// e.value = m_Node.transparentCullMode; +// e.RegisterValueChangedCallback(ChangeTransparentCullMode); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.zTest), (e) => +// { +// e.value = m_Node.zTest; +// e.RegisterValueChangedCallback(ChangeZTest); +// }); +// }); + +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => +// { +// row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => +// { +// field.value = m_Node.doubleSidedMode; +// field.RegisterValueChangedCallback(ChangeDoubleSidedMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Fragment Normal Space", indentLevel)), (row) => +// { +// row.Add(new EnumField(NormalDropOffSpace.Tangent), (field) => +// { +// field.value = m_Node.normalDropOffSpace; +// field.RegisterValueChangedCallback(ChangeSpaceOfNormalDropOffMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTest.isOn; +// toggle.OnToggleChanged(ChangeAlphaTest); +// }); +// }); + +// if (m_Node.alphaTest.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Use Shadow Threshold", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTestShadow.isOn; +// toggle.OnToggleChanged(ChangeAlphaTestShadow); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaToMask.isOn; +// toggle.OnToggleChanged(ChangeAlphaToMask); +// }); +// }); +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Material Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(HDLitMasterNode.MaterialType.Standard), (field) => +// { +// field.value = m_Node.materialType; +// field.RegisterValueChangedCallback(ChangeMaterialType); +// }); +// }); + +// ++indentLevel; +// if (m_Node.materialType == HDLitMasterNode.MaterialType.SubsurfaceScattering) +// { +// ps.Add(new PropertyRow(CreateLabel("Transmission", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.sssTransmission.isOn; +// toggle.OnToggleChanged(ChangeSSSTransmission); +// }); +// }); +// } + +// if (m_Node.materialType == HDLitMasterNode.MaterialType.SpecularColor) +// { +// ps.Add(new PropertyRow(CreateLabel("Energy Conserving Specular", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.energyConservingSpecular.isOn; +// toggle.OnToggleChanged(ChangeEnergyConservingSpecular); +// }); +// }); +// } +// --indentLevel; + +// ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveDecals.isOn; +// toggle.OnToggleChanged(ChangeDecal); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// if (m_Node.surfaceType == SurfaceType.Transparent) +// { +// toggle.value = m_Node.receiveSSRTransparent.isOn; +// toggle.OnToggleChanged(ChangeSSRTransparent); +// } +// else +// { +// toggle.value = m_Node.receiveSSR.isOn; +// toggle.OnToggleChanged(ChangeSSR); +// } +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.addPrecomputedVelocity.isOn; +// toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); +// }); +// }); + + +// ps.Add(new PropertyRow(CreateLabel("Geometric Specular AA", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.specularAA.isOn; +// toggle.OnToggleChanged(ChangeSpecularAA); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => +// { +// field.value = m_Node.specularOcclusionMode; +// field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.overrideBakedGI.isOn; +// toggle.OnToggleChanged(ChangeoverrideBakedGI); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.depthOffset.isOn; +// toggle.OnToggleChanged(ChangeDepthOffset); +// }); +// }); +// ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.supportLodCrossFade.isOn; +// toggle.OnToggleChanged(ChangeSupportLODCrossFade); +// }); +// }); + +// Add(ps); +// Add(GetShaderGUIOverridePropertySheet()); +// } + +// void ChangeRayTracingFlag(ChangeEvent evt) +// { +// if (Equals(m_Node.rayTracing, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Ray Tracing Flag Change"); +// ToggleData rt = m_Node.rayTracing; +// rt.isOn = evt.newValue; +// m_Node.rayTracing = rt; +// } + +// void ChangeSurfaceType(ChangeEvent evt) +// { +// if (Equals(m_Node.surfaceType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); +// m_Node.surfaceType = (SurfaceType)evt.newValue; + +// UpdateRenderingPassValue(m_Node.renderingPass); +// } + +// void ChangeDoubleSidedMode(ChangeEvent evt) +// { +// if (Equals(m_Node.doubleSidedMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); +// m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; +// } + +// void ChangeSpaceOfNormalDropOffMode(ChangeEvent evt) +// { +// if (Equals(m_Node.normalDropOffSpace, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Normal Space Drop-Off Mode Change"); +// m_Node.normalDropOffSpace = (NormalDropOffSpace)evt.newValue; +// } + +// void ChangeMaterialType(ChangeEvent evt) +// { +// if (Equals(m_Node.materialType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Material Type Change"); +// m_Node.materialType = (HDLitMasterNode.MaterialType)evt.newValue; +// } + +// void ChangeSSSTransmission(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SSS Transmission Change"); +// ToggleData td = m_Node.sssTransmission; +// td.isOn = evt.newValue; +// m_Node.sssTransmission = td; +// } + +// void ChangeBlendMode(ChangeEvent evt) +// { +// // Make sure the mapping is correct by handling each case. + +// AlphaMode alphaMode = GetAlphaMode((HDLitMasterNode.AlphaModeLit)evt.newValue); + +// if (Equals(m_Node.alphaMode, alphaMode)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); +// m_Node.alphaMode = alphaMode; +// } + +// void ChangeRenderingPass(ChangeEvent evt) +// { +// switch (evt.newValue) +// { +// case HDRenderQueue.RenderQueueType.Overlay: +// case HDRenderQueue.RenderQueueType.Unknown: +// case HDRenderQueue.RenderQueueType.Background: +// throw new ArgumentException("Unexpected kind of RenderQueue, was " + evt.newValue); +// default: +// break; +// }; +// UpdateRenderingPassValue(evt.newValue); +// } + +// void UpdateRenderingPassValue(HDRenderQueue.RenderQueueType newValue) +// { +// HDRenderQueue.RenderQueueType renderingPass; +// switch (m_Node.surfaceType) +// { +// case SurfaceType.Opaque: +// renderingPass = HDRenderQueue.GetOpaqueEquivalent(newValue); +// break; +// case SurfaceType.Transparent: +// renderingPass = HDRenderQueue.GetTransparentEquivalent(newValue); +// break; +// default: +// throw new ArgumentException("Unknown SurfaceType"); +// } + +// if (Equals(m_Node.renderingPass, renderingPass)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Rendering Pass Change"); +// m_Node.renderingPass = renderingPass; +// } + +// void ChangeBlendPreserveSpecular(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); +// ToggleData td = m_Node.blendPreserveSpecular; +// td.isOn = evt.newValue; +// m_Node.blendPreserveSpecular = td; +// } + +// void ChangeTransparencyFog(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); +// ToggleData td = m_Node.transparencyFog; +// td.isOn = evt.newValue; +// m_Node.transparencyFog = td; +// } + +// void ChangeRefractionModel(ChangeEvent evt) +// { +// if (Equals(m_Node.refractionModel, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Refraction Model Change"); +// m_Node.refractionModel = (ScreenSpaceRefraction.RefractionModel)evt.newValue; +// } + +// void ChangeDistortion(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Change"); +// ToggleData td = m_Node.distortion; +// td.isOn = evt.newValue; +// m_Node.distortion = td; +// } + +// void ChangeDistortionMode(ChangeEvent evt) +// { +// if (Equals(m_Node.distortionMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Mode Change"); +// m_Node.distortionMode = (DistortionMode)evt.newValue; +// } + +// void ChangeDistortionDepthTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Depth Test Change"); +// ToggleData td = m_Node.distortionDepthTest; +// td.isOn = evt.newValue; +// m_Node.distortionDepthTest = td; +// } + +// void ChangeBackThenFrontRendering(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Back Then Front Rendering Change"); +// ToggleData td = m_Node.backThenFrontRendering; +// td.isOn = evt.newValue; +// m_Node.backThenFrontRendering = td; +// } + +// void ChangeSortPriority(ChangeEvent evt) +// { +// m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); +// // Force the text to match. +// m_SortPriorityField.value = m_Node.sortPriority; +// if (Equals(m_Node.sortPriority, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); +// } + +// void ChangeAlphaTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); +// ToggleData td = m_Node.alphaTest; +// td.isOn = evt.newValue; +// m_Node.alphaTest = td; +// } + +// void ChangeAlphaTestPrepass(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Prepass Change"); +// ToggleData td = m_Node.alphaTestDepthPrepass; +// td.isOn = evt.newValue; +// m_Node.alphaTestDepthPrepass = td; +// } + +// void ChangeAlphaTestPostpass(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Depth Postpass Change"); +// ToggleData td = m_Node.alphaTestDepthPostpass; +// td.isOn = evt.newValue; +// m_Node.alphaTestDepthPostpass = td; +// } +// void ChangeTransparentWritesMotionVec(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Writes Motion Vector Change"); +// ToggleData td = m_Node.transparentWritesMotionVec; +// td.isOn = evt.newValue; +// m_Node.transparentWritesMotionVec = td; +// } +// void ChangeAlphaTestShadow(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Shadow Change"); +// ToggleData td = m_Node.alphaTestShadow; +// td.isOn = evt.newValue; +// m_Node.alphaTestShadow = td; +// } + +// void ChangeDecal(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Decal Change"); +// ToggleData td = m_Node.receiveDecals; +// td.isOn = evt.newValue; +// m_Node.receiveDecals = td; +// } + +// void ChangeSSR(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); +// ToggleData td = m_Node.receiveSSR; +// td.isOn = evt.newValue; +// m_Node.receiveSSR = td; +// } + +// void ChangeSSRTransparent(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SSR Change"); +// ToggleData td = m_Node.receiveSSRTransparent; +// td.isOn = evt.newValue; +// m_Node.receiveSSRTransparent = td; +// } + +// void ChangeAddPrecomputedVelocity(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); +// ToggleData td = m_Node.addPrecomputedVelocity; +// td.isOn = evt.newValue; +// m_Node.addPrecomputedVelocity = td; +// } + +// void ChangeSpecularAA(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Specular AA Change"); +// ToggleData td = m_Node.specularAA; +// td.isOn = evt.newValue; +// m_Node.specularAA = td; +// } + +// void ChangeEnergyConservingSpecular(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Energy Conserving Specular Change"); +// ToggleData td = m_Node.energyConservingSpecular; +// td.isOn = evt.newValue; +// m_Node.energyConservingSpecular = td; +// } + +// void ChangeSpecularOcclusionMode(ChangeEvent evt) +// { +// if (Equals(m_Node.specularOcclusionMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Specular Occlusion Mode Change"); +// m_Node.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; +// } + +// void ChangeoverrideBakedGI(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); +// ToggleData td = m_Node.overrideBakedGI; +// td.isOn = evt.newValue; +// m_Node.overrideBakedGI = td; +// } + +// void ChangeDepthOffset(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); +// ToggleData td = m_Node.depthOffset; +// td.isOn = evt.newValue; +// m_Node.depthOffset = td; +// } + +// void ChangeSupportLODCrossFade(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); +// ToggleData td = m_Node.supportLodCrossFade; +// td.isOn = evt.newValue; +// m_Node.supportLodCrossFade = td; +// } + +// void ChangeAlphaToMask(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); +// ToggleData td = m_Node.alphaToMask; +// td.isOn = evt.newValue; +// m_Node.alphaToMask = td; +// } + +// void ChangeZWrite(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); +// ToggleData td = m_Node.zWrite; +// td.isOn = evt.newValue; +// m_Node.zWrite = td; +// } + +// void ChangeTransparentCullMode(ChangeEvent evt) +// { +// if (Equals(m_Node.transparentCullMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); +// m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; +// } + +// void ChangeZTest(ChangeEvent evt) +// { +// if (Equals(m_Node.zTest, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); +// m_Node.zTest = (CompareFunction)evt.newValue; +// } + +// public AlphaMode GetAlphaMode(HDLitMasterNode.AlphaModeLit alphaModeLit) +// { +// switch (alphaModeLit) +// { +// case HDLitMasterNode.AlphaModeLit.Alpha: +// return AlphaMode.Alpha; +// case HDLitMasterNode.AlphaModeLit.Premultiply: +// return AlphaMode.Premultiply; +// case HDLitMasterNode.AlphaModeLit.Additive: +// return AlphaMode.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaModeLit); +// return AlphaMode.Alpha; +// } +// } +// } + +// public HDLitMasterNode.AlphaModeLit GetAlphaModeLit(AlphaMode alphaMode) +// { +// switch (alphaMode) +// { +// case AlphaMode.Alpha: +// return HDLitMasterNode.AlphaModeLit.Alpha; +// case AlphaMode.Premultiply: +// return HDLitMasterNode.AlphaModeLit.Premultiply; +// case AlphaMode.Additive: +// return HDLitMasterNode.AlphaModeLit.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaMode); +// return HDLitMasterNode.AlphaModeLit.Alpha; +// } +// } +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs index be81709a5a5..a65983c6234 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs @@ -1,890 +1,890 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class HDLitSubTarget : SubTarget - { - const string kAssetGuid = "caab952c840878340810cca27417971c"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; - - public HDLitSubTarget() - { - displayName = "Lit"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.HDLitGUI"); - context.AddSubShader(SubShaders.Lit); - context.AddSubShader(SubShaders.LitRaytracing); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Lit = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { LitPasses.ShadowCaster }, - { LitPasses.META }, - { LitPasses.SceneSelection }, - { LitPasses.DepthOnly }, - { LitPasses.GBuffer }, - { LitPasses.MotionVectors }, - { LitPasses.DistortionVectors, new FieldCondition(HDFields.TransparentDistortion, true) }, - { LitPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, - { LitPasses.TransparentDepthPrepass, new FieldCondition(HDFields.TransparentDepthPrePass, true) }, - { LitPasses.Forward }, - { LitPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, - { LitPasses.RayTracingPrepass, new FieldCondition(HDFields.RayTracing, true) }, - }, - }; - - public static SubShaderDescriptor LitRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { LitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class LitPasses - { - public static PassDescriptor GBuffer = new PassDescriptor() - { - // Definition - displayName = "GBuffer", - referenceName = "SHADERPASS_GBUFFER", - lightMode = "GBuffer", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.GBuffer, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = LitKeywords.GBuffer, - includes = LitIncludes.GBuffer, - }; - - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - pixelPorts = LitPortMasks.FragmentMeta, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentShadowCaster, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentSceneSelection, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor DepthOnly = new PassDescriptor() - { - // Definition - displayName = "DepthOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = LitKeywords.DepthMotionVectors, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = LitKeywords.DepthMotionVectors, - includes = LitIncludes.MotionVectors, - }; - - public static PassDescriptor DistortionVectors = new PassDescriptor() - { - // Definition - displayName = "DistortionVectors", - referenceName = "SHADERPASS_DISTORTION", - lightMode = "DistortionVectors", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDistortion, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.Distortion, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.Distortion, - }; - - public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPrepass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPrepass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentTransparentDepthPrepass, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.TransparentDepthPrePostPass, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.TransparentDepthPrepass, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor TransparentBackface = new PassDescriptor() - { - // Definition - displayName = "TransparentBackface", - referenceName = "SHADERPASS_FORWARD", - lightMode = "TransparentBackface", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentTransparentBackface, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentBackface, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = LitIncludes.Forward, - }; - - public static PassDescriptor Forward = new PassDescriptor() - { - // Definition - displayName = "Forward", - referenceName = "SHADERPASS_FORWARD", - lightMode = "Forward", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ForwardColorMask, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = LitIncludes.Forward, - }; - - public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPostpass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPostpass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentTransparentDepthPostpass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePostPass, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor RayTracingPrepass = new PassDescriptor() - { - // Definition - displayName = "RayTracingPrepass", - referenceName = "SHADERPASS_CONSTANT", - lightMode = "RayTracingPrepass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentRayTracingPrepass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.RayTracingPrepass, - pragmas = LitPragmas.RaytracingBasic, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.RayTracingPrepass, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingVisibility, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingPathTracing = new PassDescriptor() - { - //Definition - displayName = "PathTracingDXR", - referenceName = "SHADERPASS_PATH_TRACING", - lightMode = "PathTracingDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDefault, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingPathTracing, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingPathTracing }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - vertexPorts = LitPortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentDefault, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region PortMasks - static class LitPortMasks - { - public static int[] Vertex = new int[] - { - HDLitMasterNode.PositionSlotId, - HDLitMasterNode.VertexNormalSlotID, - HDLitMasterNode.VertexTangentSlotID, - }; - - public static int[] FragmentDefault = new int[] - { - HDLitMasterNode.AlbedoSlotId, - HDLitMasterNode.NormalSlotId, - HDLitMasterNode.BentNormalSlotId, - HDLitMasterNode.TangentSlotId, - HDLitMasterNode.SubsurfaceMaskSlotId, - HDLitMasterNode.ThicknessSlotId, - HDLitMasterNode.DiffusionProfileHashSlotId, - HDLitMasterNode.IridescenceMaskSlotId, - HDLitMasterNode.IridescenceThicknessSlotId, - HDLitMasterNode.SpecularColorSlotId, - HDLitMasterNode.CoatMaskSlotId, - HDLitMasterNode.MetallicSlotId, - HDLitMasterNode.EmissionSlotId, - HDLitMasterNode.SmoothnessSlotId, - HDLitMasterNode.AmbientOcclusionSlotId, - HDLitMasterNode.SpecularOcclusionSlotId, - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdSlotId, - HDLitMasterNode.AnisotropySlotId, - HDLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, - HDLitMasterNode.SpecularAAThresholdSlotId, - HDLitMasterNode.RefractionIndexSlotId, - HDLitMasterNode.RefractionColorSlotId, - HDLitMasterNode.RefractionDistanceSlotId, - HDLitMasterNode.LightingSlotId, - HDLitMasterNode.BackLightingSlotId, - HDLitMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentMeta = new int[] - { - HDLitMasterNode.AlbedoSlotId, - HDLitMasterNode.NormalSlotId, - HDLitMasterNode.BentNormalSlotId, - HDLitMasterNode.TangentSlotId, - HDLitMasterNode.SubsurfaceMaskSlotId, - HDLitMasterNode.ThicknessSlotId, - HDLitMasterNode.DiffusionProfileHashSlotId, - HDLitMasterNode.IridescenceMaskSlotId, - HDLitMasterNode.IridescenceThicknessSlotId, - HDLitMasterNode.SpecularColorSlotId, - HDLitMasterNode.CoatMaskSlotId, - HDLitMasterNode.MetallicSlotId, - HDLitMasterNode.EmissionSlotId, - HDLitMasterNode.SmoothnessSlotId, - HDLitMasterNode.AmbientOcclusionSlotId, - HDLitMasterNode.SpecularOcclusionSlotId, - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdSlotId, - HDLitMasterNode.AnisotropySlotId, - HDLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, - HDLitMasterNode.SpecularAAThresholdSlotId, - HDLitMasterNode.RefractionIndexSlotId, - HDLitMasterNode.RefractionColorSlotId, - HDLitMasterNode.RefractionDistanceSlotId, - }; - - public static int[] FragmentShadowCaster = new int[] - { - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdSlotId, - HDLitMasterNode.AlphaThresholdShadowSlotId, - HDLitMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentSceneSelection = new int[] - { - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdSlotId, - HDLitMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentDepthMotionVectors = new int[] - { - HDLitMasterNode.NormalSlotId, - HDLitMasterNode.SmoothnessSlotId, - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdSlotId, - HDLitMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentDistortion = new int[] - { - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdSlotId, - HDLitMasterNode.DistortionSlotId, - HDLitMasterNode.DistortionBlurSlotId, - }; - - public static int[] FragmentTransparentDepthPrepass = new int[] - { - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdDepthPrepassSlotId, - HDLitMasterNode.DepthOffsetSlotId, - HDLitMasterNode.NormalSlotId, - HDLitMasterNode.SmoothnessSlotId, - }; - - public static int[] FragmentTransparentBackface = new int[] - { - HDLitMasterNode.AlbedoSlotId, - HDLitMasterNode.NormalSlotId, - HDLitMasterNode.BentNormalSlotId, - HDLitMasterNode.TangentSlotId, - HDLitMasterNode.SubsurfaceMaskSlotId, - HDLitMasterNode.ThicknessSlotId, - HDLitMasterNode.DiffusionProfileHashSlotId, - HDLitMasterNode.IridescenceMaskSlotId, - HDLitMasterNode.IridescenceThicknessSlotId, - HDLitMasterNode.SpecularColorSlotId, - HDLitMasterNode.CoatMaskSlotId, - HDLitMasterNode.MetallicSlotId, - HDLitMasterNode.EmissionSlotId, - HDLitMasterNode.SmoothnessSlotId, - HDLitMasterNode.AmbientOcclusionSlotId, - HDLitMasterNode.SpecularOcclusionSlotId, - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdSlotId, - HDLitMasterNode.AnisotropySlotId, - HDLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, - HDLitMasterNode.SpecularAAThresholdSlotId, - HDLitMasterNode.RefractionIndexSlotId, - HDLitMasterNode.RefractionColorSlotId, - HDLitMasterNode.RefractionDistanceSlotId, - HDLitMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentTransparentDepthPostpass = new int[] - { - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdDepthPostpassSlotId, - HDLitMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentRayTracingPrepass = new int[] - { - HDLitMasterNode.AlphaSlotId, - HDLitMasterNode.AlphaThresholdSlotId, - HDLitMasterNode.DepthOffsetSlotId, - }; - } -#endregion - -#region RenderStates - static class LitRenderStates - { - public static RenderStateCollection GBuffer = new RenderStateCollection - { - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZTest(CoreRenderStates.Uniforms.zTestGBuffer) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskGBuffer, - Ref = CoreRenderStates.Uniforms.stencilRefGBuffer, - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection Distortion = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, - { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, - { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, - { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, - Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection TransparentDepthPrePostPass = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.Zero) }, - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, - Ref = CoreRenderStates.Uniforms.stencilRefDepth, - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection RayTracingPrepass = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.Zero) }, - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - // Note: we use default ZTest LEqual so if the object have already been render in depth prepass, it will re-render to tag stencil - }; - } -#endregion - -#region Pragmas - static class LitPragmas - { - public static PragmaCollection RaytracingBasic = new PragmaCollection - { - { Pragma.Target(ShaderModel.Target45) }, - { Pragma.Vertex("Vert") }, - { Pragma.Fragment("Frag") }, - { Pragma.OnlyRenderers(new Platform[] {Platform.D3D11}) }, - }; - } -#endregion - -#region Defines - static class LitDefines - { - public static DefineCollection RaytracingForwardIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingVisibility = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingPathTracing = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - }; - } -#endregion - -#region Keywords - static class LitKeywords - { - public static KeywordCollection GBuffer = new KeywordCollection - { - { CoreKeywords.HDBase }, - { CoreKeywordDescriptors.DebugDisplay }, - { CoreKeywords.Lightmaps }, - { CoreKeywordDescriptors.ShadowsShadowmask }, - { CoreKeywordDescriptors.LightLayers }, - { CoreKeywordDescriptors.Decals }, - }; - - public static KeywordCollection DepthMotionVectors = new KeywordCollection - { - { CoreKeywords.HDBase }, - { CoreKeywordDescriptors.WriteMsaaDepth }, - { CoreKeywordDescriptors.WriteNormalBuffer }, - { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, - }; - } -#endregion - -#region Includes - static class LitIncludes - { - const string kLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; - const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"; - const string kPassConstant = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl"; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class HDLitSubTarget : SubTarget +// { +// const string kAssetGuid = "caab952c840878340810cca27417971c"; +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; + +// public HDLitSubTarget() +// { +// displayName = "Lit"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.HDLitGUI"); +// context.AddSubShader(SubShaders.Lit); +// context.AddSubShader(SubShaders.LitRaytracing); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Lit = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { LitPasses.ShadowCaster }, +// { LitPasses.META }, +// { LitPasses.SceneSelection }, +// { LitPasses.DepthOnly }, +// { LitPasses.GBuffer }, +// { LitPasses.MotionVectors }, +// { LitPasses.DistortionVectors, new FieldCondition(HDFields.TransparentDistortion, true) }, +// { LitPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, +// { LitPasses.TransparentDepthPrepass, new FieldCondition(HDFields.TransparentDepthPrePass, true) }, +// { LitPasses.Forward }, +// { LitPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, +// { LitPasses.RayTracingPrepass, new FieldCondition(HDFields.RayTracing, true) }, +// }, +// }; + +// public static SubShaderDescriptor LitRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { LitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class LitPasses +// { +// public static PassDescriptor GBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBuffer", +// referenceName = "SHADERPASS_GBUFFER", +// lightMode = "GBuffer", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = LitRenderStates.GBuffer, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = LitKeywords.GBuffer, +// includes = LitIncludes.GBuffer, +// }; + +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// pixelPorts = LitPortMasks.FragmentMeta, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentShadowCaster, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentSceneSelection, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = LitKeywords.DepthMotionVectors, +// includes = LitIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = LitKeywords.DepthMotionVectors, +// includes = LitIncludes.MotionVectors, +// }; + +// public static PassDescriptor DistortionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "DistortionVectors", +// referenceName = "SHADERPASS_DISTORTION", +// lightMode = "DistortionVectors", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDistortion, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = LitRenderStates.Distortion, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.Distortion, +// }; + +// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPrepass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPrepass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentTransparentDepthPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = LitRenderStates.TransparentDepthPrePostPass, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.TransparentDepthPrepass, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.DepthOnly, +// }; + +// public static PassDescriptor TransparentBackface = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentBackface", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "TransparentBackface", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentTransparentBackface, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentBackface, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = LitIncludes.Forward, +// }; + +// public static PassDescriptor Forward = new PassDescriptor() +// { +// // Definition +// displayName = "Forward", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "Forward", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ForwardColorMask, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = LitIncludes.Forward, +// }; + +// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPostpass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPostpass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentTransparentDepthPostpass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePostPass, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.DepthOnly, +// }; + +// public static PassDescriptor RayTracingPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "RayTracingPrepass", +// referenceName = "SHADERPASS_CONSTANT", +// lightMode = "RayTracingPrepass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentRayTracingPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = LitRenderStates.RayTracingPrepass, +// pragmas = LitPragmas.RaytracingBasic, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.RayTracingPrepass, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingVisibility, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingPathTracing = new PassDescriptor() +// { +// //Definition +// displayName = "PathTracingDXR", +// referenceName = "SHADERPASS_PATH_TRACING", +// lightMode = "PathTracingDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDefault, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingPathTracing, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingPathTracing }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// vertexPorts = LitPortMasks.Vertex, +// pixelPorts = LitPortMasks.FragmentDefault, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region PortMasks +// static class LitPortMasks +// { +// public static int[] Vertex = new int[] +// { +// HDLitMasterNode.PositionSlotId, +// HDLitMasterNode.VertexNormalSlotID, +// HDLitMasterNode.VertexTangentSlotID, +// }; + +// public static int[] FragmentDefault = new int[] +// { +// HDLitMasterNode.AlbedoSlotId, +// HDLitMasterNode.NormalSlotId, +// HDLitMasterNode.BentNormalSlotId, +// HDLitMasterNode.TangentSlotId, +// HDLitMasterNode.SubsurfaceMaskSlotId, +// HDLitMasterNode.ThicknessSlotId, +// HDLitMasterNode.DiffusionProfileHashSlotId, +// HDLitMasterNode.IridescenceMaskSlotId, +// HDLitMasterNode.IridescenceThicknessSlotId, +// HDLitMasterNode.SpecularColorSlotId, +// HDLitMasterNode.CoatMaskSlotId, +// HDLitMasterNode.MetallicSlotId, +// HDLitMasterNode.EmissionSlotId, +// HDLitMasterNode.SmoothnessSlotId, +// HDLitMasterNode.AmbientOcclusionSlotId, +// HDLitMasterNode.SpecularOcclusionSlotId, +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdSlotId, +// HDLitMasterNode.AnisotropySlotId, +// HDLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// HDLitMasterNode.SpecularAAThresholdSlotId, +// HDLitMasterNode.RefractionIndexSlotId, +// HDLitMasterNode.RefractionColorSlotId, +// HDLitMasterNode.RefractionDistanceSlotId, +// HDLitMasterNode.LightingSlotId, +// HDLitMasterNode.BackLightingSlotId, +// HDLitMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentMeta = new int[] +// { +// HDLitMasterNode.AlbedoSlotId, +// HDLitMasterNode.NormalSlotId, +// HDLitMasterNode.BentNormalSlotId, +// HDLitMasterNode.TangentSlotId, +// HDLitMasterNode.SubsurfaceMaskSlotId, +// HDLitMasterNode.ThicknessSlotId, +// HDLitMasterNode.DiffusionProfileHashSlotId, +// HDLitMasterNode.IridescenceMaskSlotId, +// HDLitMasterNode.IridescenceThicknessSlotId, +// HDLitMasterNode.SpecularColorSlotId, +// HDLitMasterNode.CoatMaskSlotId, +// HDLitMasterNode.MetallicSlotId, +// HDLitMasterNode.EmissionSlotId, +// HDLitMasterNode.SmoothnessSlotId, +// HDLitMasterNode.AmbientOcclusionSlotId, +// HDLitMasterNode.SpecularOcclusionSlotId, +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdSlotId, +// HDLitMasterNode.AnisotropySlotId, +// HDLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// HDLitMasterNode.SpecularAAThresholdSlotId, +// HDLitMasterNode.RefractionIndexSlotId, +// HDLitMasterNode.RefractionColorSlotId, +// HDLitMasterNode.RefractionDistanceSlotId, +// }; + +// public static int[] FragmentShadowCaster = new int[] +// { +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdSlotId, +// HDLitMasterNode.AlphaThresholdShadowSlotId, +// HDLitMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentSceneSelection = new int[] +// { +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdSlotId, +// HDLitMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentDepthMotionVectors = new int[] +// { +// HDLitMasterNode.NormalSlotId, +// HDLitMasterNode.SmoothnessSlotId, +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdSlotId, +// HDLitMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentDistortion = new int[] +// { +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdSlotId, +// HDLitMasterNode.DistortionSlotId, +// HDLitMasterNode.DistortionBlurSlotId, +// }; + +// public static int[] FragmentTransparentDepthPrepass = new int[] +// { +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdDepthPrepassSlotId, +// HDLitMasterNode.DepthOffsetSlotId, +// HDLitMasterNode.NormalSlotId, +// HDLitMasterNode.SmoothnessSlotId, +// }; + +// public static int[] FragmentTransparentBackface = new int[] +// { +// HDLitMasterNode.AlbedoSlotId, +// HDLitMasterNode.NormalSlotId, +// HDLitMasterNode.BentNormalSlotId, +// HDLitMasterNode.TangentSlotId, +// HDLitMasterNode.SubsurfaceMaskSlotId, +// HDLitMasterNode.ThicknessSlotId, +// HDLitMasterNode.DiffusionProfileHashSlotId, +// HDLitMasterNode.IridescenceMaskSlotId, +// HDLitMasterNode.IridescenceThicknessSlotId, +// HDLitMasterNode.SpecularColorSlotId, +// HDLitMasterNode.CoatMaskSlotId, +// HDLitMasterNode.MetallicSlotId, +// HDLitMasterNode.EmissionSlotId, +// HDLitMasterNode.SmoothnessSlotId, +// HDLitMasterNode.AmbientOcclusionSlotId, +// HDLitMasterNode.SpecularOcclusionSlotId, +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdSlotId, +// HDLitMasterNode.AnisotropySlotId, +// HDLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// HDLitMasterNode.SpecularAAThresholdSlotId, +// HDLitMasterNode.RefractionIndexSlotId, +// HDLitMasterNode.RefractionColorSlotId, +// HDLitMasterNode.RefractionDistanceSlotId, +// HDLitMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentTransparentDepthPostpass = new int[] +// { +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdDepthPostpassSlotId, +// HDLitMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentRayTracingPrepass = new int[] +// { +// HDLitMasterNode.AlphaSlotId, +// HDLitMasterNode.AlphaThresholdSlotId, +// HDLitMasterNode.DepthOffsetSlotId, +// }; +// } +// #endregion + +// #region RenderStates +// static class LitRenderStates +// { +// public static RenderStateCollection GBuffer = new RenderStateCollection +// { +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZTest(CoreRenderStates.Uniforms.zTestGBuffer) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskGBuffer, +// Ref = CoreRenderStates.Uniforms.stencilRefGBuffer, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection Distortion = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, +// { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, +// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, +// { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, +// { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, +// Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection TransparentDepthPrePostPass = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.Zero) }, +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, +// Ref = CoreRenderStates.Uniforms.stencilRefDepth, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection RayTracingPrepass = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.Zero) }, +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// // Note: we use default ZTest LEqual so if the object have already been render in depth prepass, it will re-render to tag stencil +// }; +// } +// #endregion + +// #region Pragmas +// static class LitPragmas +// { +// public static PragmaCollection RaytracingBasic = new PragmaCollection +// { +// { Pragma.Target(ShaderModel.Target45) }, +// { Pragma.Vertex("Vert") }, +// { Pragma.Fragment("Frag") }, +// { Pragma.OnlyRenderers(new Platform[] {Platform.D3D11}) }, +// }; +// } +// #endregion + +// #region Defines +// static class LitDefines +// { +// public static DefineCollection RaytracingForwardIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingVisibility = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingPathTracing = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// }; +// } +// #endregion + +// #region Keywords +// static class LitKeywords +// { +// public static KeywordCollection GBuffer = new KeywordCollection +// { +// { CoreKeywords.HDBase }, +// { CoreKeywordDescriptors.DebugDisplay }, +// { CoreKeywords.Lightmaps }, +// { CoreKeywordDescriptors.ShadowsShadowmask }, +// { CoreKeywordDescriptors.LightLayers }, +// { CoreKeywordDescriptors.Decals }, +// }; + +// public static KeywordCollection DepthMotionVectors = new KeywordCollection +// { +// { CoreKeywords.HDBase }, +// { CoreKeywordDescriptors.WriteMsaaDepth }, +// { CoreKeywordDescriptors.WriteNormalBuffer }, +// { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, +// }; +// } +// #endregion + +// #region Includes +// static class LitIncludes +// { +// const string kLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; +// const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"; +// const string kPassConstant = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl"; - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection GBuffer = new IncludeCollection - { - { Common }, - { kPassGBuffer, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection RayTracingPrepass = new IncludeCollection - { - { Common }, - { kPassConstant, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Forward = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { CoreIncludes.kLit, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Distortion = new IncludeCollection - { - { Common }, - { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection GBuffer = new IncludeCollection +// { +// { Common }, +// { kPassGBuffer, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection RayTracingPrepass = new IncludeCollection +// { +// { Common }, +// { kPassConstant, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Forward = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { CoreIncludes.kLit, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Distortion = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template index a6d63a9da3b..76095460a5d 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template @@ -145,7 +145,7 @@ Pass // however specularOcclusion can come from the graph, so need to be init here so it can be override. surfaceData.specularOcclusion = 1.0; - $SurfaceDescription.Albedo: surfaceData.baseColor = surfaceDescription.Albedo; + $SurfaceDescription.BaseColor: surfaceData.baseColor = surfaceDescription.BaseColor; $SurfaceDescription.Smoothness: surfaceData.perceptualSmoothness = surfaceDescription.Smoothness; $SurfaceDescription.Occlusion: surfaceData.ambientOcclusion = surfaceDescription.Occlusion; $SurfaceDescription.SpecularOcclusion: surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion; @@ -241,8 +241,11 @@ Pass #if HAVE_DECALS if (_EnableDecals) { + float alpha = 1.0; + $SurfaceDescription.Alpha: alpha = surfaceDescription.Alpha; + // Both uses and modifies 'surfaceData.normalWS'. - DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, surfaceDescription.Alpha); + DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, alpha); ApplyDecalToSurfaceData(decalSurfaceData, surfaceData); } #endif @@ -298,13 +301,16 @@ Pass SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); + float alpha = 1; + $SurfaceDescription.Alpha: alpha = surfaceDescription.Alpha; + // Perform alpha test very early to save performance (a killed pixel will not sample textures) // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. #ifdef _ALPHATEST_ON - $DoAlphaTest: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold); - $DoAlphaTestPrepass: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdDepthPrepass); - $DoAlphaTestPostpass: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdDepthPostpass); - $DoAlphaTestShadow: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow); + $DoAlphaTest: GENERIC_ALPHA_TEST(alpha, surfaceDescription.AlphaClipThreshold); + $DoAlphaTestPrepass: GENERIC_ALPHA_TEST(alpha, surfaceDescription.AlphaClipThresholdDepthPrepass); + $DoAlphaTestPostpass: GENERIC_ALPHA_TEST(alpha, surfaceDescription.AlphaClipThresholdDepthPostpass); + $DoAlphaTestShadow: GENERIC_ALPHA_TEST(alpha, surfaceDescription.AlphaClipThresholdShadow); #endif $DepthOffset: ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); @@ -314,7 +320,7 @@ Pass // Builtin Data // For back lighting we use the oposite vertex normal - InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData); + InitBuiltinData(posInput, alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData); #ifdef _ALPHATEST_ON // Used for sharpening by alpha to mask diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/PBR/ShaderGraph/PBRSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/PBR/ShaderGraph/PBRSubTarget.cs index 151239b87c5..cbdce158894 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/PBR/ShaderGraph/PBRSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/PBR/ShaderGraph/PBRSubTarget.cs @@ -1,465 +1,465 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class PBRSubTarget : SubTarget - { - const string kAssetGuid = "c01e45594b63bd8419839b581ee0f601"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/PBR/ShaderGraph/PBRPass.template"; - - public PBRSubTarget() - { - displayName = "PBR"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.HDPBRLitGUI"); - context.AddSubShader(SubShaders.PBR); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor PBR = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - renderTypeOverride = HDRenderTypeTags.HDLitShader.ToString(), - generatesPreview = true, - passes = new PassCollection - { - { PBRPasses.ShadowCaster }, - { PBRPasses.META }, - { PBRPasses.SceneSelection }, - { PBRPasses.DepthOnly, new FieldCondition(Fields.SurfaceOpaque, true) }, - { PBRPasses.GBuffer, new FieldCondition(Fields.SurfaceOpaque, true) }, - { PBRPasses.MotionVectors, new FieldCondition(Fields.SurfaceOpaque, true) }, - { PBRPasses.Forward }, - }, - }; - } -#endregion - -#region Passes - static class PBRPasses - { - public static PassDescriptor GBuffer = new PassDescriptor() - { - // Definition - displayName = "GBuffer", - referenceName = "SHADERPASS_GBUFFER", - lightMode = "GBuffer", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = PBRPortMasks.Vertex, - pixelPorts = PBRPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = PBRRenderStates.GBuffer, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = PBRKeywords.GBuffer, - includes = PBRIncludes.GBuffer, - }; - - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - pixelPorts = PBRPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = PBRKeywords.LodFadeCrossfade, - includes = PBRIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = PBRPortMasks.Vertex, - pixelPorts = PBRPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = PBRRenderStates.ShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = PBRKeywords.LodFadeCrossfade, - includes = PBRIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = PBRPortMasks.Vertex, - pixelPorts = PBRPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = PBRRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = PBRKeywords.LodFadeCrossfade, - includes = PBRIncludes.DepthOnly, - }; - - public static PassDescriptor DepthOnly = new PassDescriptor() - { - // Definition - displayName = "DepthOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = PBRPortMasks.Vertex, - pixelPorts = PBRPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = PBRRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = PBRKeywords.DepthMotionVectors, - includes = PBRIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = PBRPortMasks.Vertex, - pixelPorts = PBRPortMasks.FragmentDepthMotionVectors, - - // Fields - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.PositionRWS, - fieldDependencies = CoreFieldDependencies.Default, - - // Conditional State - renderStates = PBRRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = PBRKeywords.DepthMotionVectors, - includes = PBRIncludes.MotionVectors, - }; - - public static PassDescriptor Forward = new PassDescriptor() - { - // Definition - displayName = "Forward", - referenceName = "SHADERPASS_FORWARD", - lightMode = "Forward", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = PBRPortMasks.Vertex, - pixelPorts = PBRPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = PBRRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = PBRKeywords.Forward, - includes = PBRIncludes.Forward, - }; - } -#endregion - -#region PortMasks - static class PBRPortMasks - { - public static int[] Vertex = new int[] - { - PBRMasterNode.PositionSlotId, - PBRMasterNode.VertNormalSlotId, - PBRMasterNode.VertTangentSlotId, - }; - - public static int[] FragmentDefault = new int[] - { - PBRMasterNode.AlbedoSlotId, - PBRMasterNode.NormalSlotId, - PBRMasterNode.MetallicSlotId, - PBRMasterNode.SpecularSlotId, - PBRMasterNode.EmissionSlotId, - PBRMasterNode.SmoothnessSlotId, - PBRMasterNode.OcclusionSlotId, - PBRMasterNode.AlphaSlotId, - PBRMasterNode.AlphaThresholdSlotId, - }; - - public static int[] FragmentOnlyAlpha = new int[] - { - PBRMasterNode.AlphaSlotId, - PBRMasterNode.AlphaThresholdSlotId, - }; - - public static int[] FragmentDepthMotionVectors = new int[] - { - PBRMasterNode.NormalSlotId, - PBRMasterNode.SmoothnessSlotId, - PBRMasterNode.AlphaSlotId, - PBRMasterNode.AlphaThresholdSlotId, - }; - } -#endregion - -#region RenderStates - static class PBRRenderStates - { - public static RenderStateCollection GBuffer = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.ZTest(CoreRenderStates.Uniforms.zTestGBuffer) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = $"{ 0 | (int)StencilUsage.RequiresDeferredLighting | (int)StencilUsage.SubsurfaceScattering | (int)StencilUsage.TraceReflectionRay}", - Ref = $"{0 | (int)StencilUsage.RequiresDeferredLighting | (int)StencilUsage.TraceReflectionRay}", - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection ShadowCaster = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.Blend(Blend.One, Blend.Zero) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ColorMask("ColorMask 0") }, - }; - - public static RenderStateCollection SceneSelection = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.ZWrite(ZWrite.On), new FieldCondition(Fields.SurfaceOpaque, true) }, - { RenderState.ZWrite(ZWrite.Off), new FieldCondition(Fields.SurfaceTransparent, true) }, - { RenderState.ColorMask("ColorMask 0") }, - }; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class PBRSubTarget : SubTarget +// { +// const string kAssetGuid = "c01e45594b63bd8419839b581ee0f601"; +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/PBR/ShaderGraph/PBRPass.template"; + +// public PBRSubTarget() +// { +// displayName = "PBR"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.HDPBRLitGUI"); +// context.AddSubShader(SubShaders.PBR); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor PBR = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// renderTypeOverride = HDRenderTypeTags.HDLitShader.ToString(), +// generatesPreview = true, +// passes = new PassCollection +// { +// { PBRPasses.ShadowCaster }, +// { PBRPasses.META }, +// { PBRPasses.SceneSelection }, +// { PBRPasses.DepthOnly, new FieldCondition(Fields.SurfaceOpaque, true) }, +// { PBRPasses.GBuffer, new FieldCondition(Fields.SurfaceOpaque, true) }, +// { PBRPasses.MotionVectors, new FieldCondition(Fields.SurfaceOpaque, true) }, +// { PBRPasses.Forward }, +// }, +// }; +// } +// #endregion + +// #region Passes +// static class PBRPasses +// { +// public static PassDescriptor GBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBuffer", +// referenceName = "SHADERPASS_GBUFFER", +// lightMode = "GBuffer", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = PBRPortMasks.Vertex, +// pixelPorts = PBRPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = PBRRenderStates.GBuffer, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = PBRKeywords.GBuffer, +// includes = PBRIncludes.GBuffer, +// }; + +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// pixelPorts = PBRPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = PBRKeywords.LodFadeCrossfade, +// includes = PBRIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = PBRPortMasks.Vertex, +// pixelPorts = PBRPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = PBRRenderStates.ShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = PBRKeywords.LodFadeCrossfade, +// includes = PBRIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = PBRPortMasks.Vertex, +// pixelPorts = PBRPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = PBRRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = PBRKeywords.LodFadeCrossfade, +// includes = PBRIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = PBRPortMasks.Vertex, +// pixelPorts = PBRPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = PBRRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = PBRKeywords.DepthMotionVectors, +// includes = PBRIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = PBRPortMasks.Vertex, +// pixelPorts = PBRPortMasks.FragmentDepthMotionVectors, + +// // Fields +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.PositionRWS, +// fieldDependencies = CoreFieldDependencies.Default, + +// // Conditional State +// renderStates = PBRRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = PBRKeywords.DepthMotionVectors, +// includes = PBRIncludes.MotionVectors, +// }; + +// public static PassDescriptor Forward = new PassDescriptor() +// { +// // Definition +// displayName = "Forward", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "Forward", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = PBRPortMasks.Vertex, +// pixelPorts = PBRPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = PBRRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = PBRKeywords.Forward, +// includes = PBRIncludes.Forward, +// }; +// } +// #endregion + +// #region PortMasks +// static class PBRPortMasks +// { +// public static int[] Vertex = new int[] +// { +// PBRMasterNode.PositionSlotId, +// PBRMasterNode.VertNormalSlotId, +// PBRMasterNode.VertTangentSlotId, +// }; + +// public static int[] FragmentDefault = new int[] +// { +// PBRMasterNode.AlbedoSlotId, +// PBRMasterNode.NormalSlotId, +// PBRMasterNode.MetallicSlotId, +// PBRMasterNode.SpecularSlotId, +// PBRMasterNode.EmissionSlotId, +// PBRMasterNode.SmoothnessSlotId, +// PBRMasterNode.OcclusionSlotId, +// PBRMasterNode.AlphaSlotId, +// PBRMasterNode.AlphaThresholdSlotId, +// }; + +// public static int[] FragmentOnlyAlpha = new int[] +// { +// PBRMasterNode.AlphaSlotId, +// PBRMasterNode.AlphaThresholdSlotId, +// }; + +// public static int[] FragmentDepthMotionVectors = new int[] +// { +// PBRMasterNode.NormalSlotId, +// PBRMasterNode.SmoothnessSlotId, +// PBRMasterNode.AlphaSlotId, +// PBRMasterNode.AlphaThresholdSlotId, +// }; +// } +// #endregion + +// #region RenderStates +// static class PBRRenderStates +// { +// public static RenderStateCollection GBuffer = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.ZTest(CoreRenderStates.Uniforms.zTestGBuffer) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = $"{ 0 | (int)StencilUsage.RequiresDeferredLighting | (int)StencilUsage.SubsurfaceScattering | (int)StencilUsage.TraceReflectionRay}", +// Ref = $"{0 | (int)StencilUsage.RequiresDeferredLighting | (int)StencilUsage.TraceReflectionRay}", +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection ShadowCaster = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.Blend(Blend.One, Blend.Zero) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ColorMask("ColorMask 0") }, +// }; + +// public static RenderStateCollection SceneSelection = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.ZWrite(ZWrite.On), new FieldCondition(Fields.SurfaceOpaque, true) }, +// { RenderState.ZWrite(ZWrite.Off), new FieldCondition(Fields.SurfaceTransparent, true) }, +// { RenderState.ColorMask("ColorMask 0") }, +// }; - public static RenderStateCollection DepthOnly = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = $"{ 0 | (int)StencilUsage.TraceReflectionRay}", - Ref = $"{0 | (int)StencilUsage.TraceReflectionRay}", - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection MotionVectors = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = $"{0 | (int)StencilUsage.TraceReflectionRay | (int)StencilUsage.ObjectMotionVector}", - Ref = $"{ 0 | (int)StencilUsage.TraceReflectionRay | (int)StencilUsage.ObjectMotionVector}", - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection Forward = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(Fields.SurfaceOpaque, true) }, - { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { - new FieldCondition(Fields.SurfaceTransparent, true), - new FieldCondition(Fields.BlendAlpha, true) } }, - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition[] { - new FieldCondition(Fields.SurfaceTransparent, true), - new FieldCondition(Fields.BlendAdd, true) } }, - { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { - new FieldCondition(Fields.SurfaceTransparent, true), - new FieldCondition(Fields.BlendPremultiply, true) } }, - { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { - new FieldCondition(Fields.SurfaceTransparent, true), - new FieldCondition(Fields.BlendMultiply, true) } }, - - { RenderState.ZTest(ZTest.Equal), new FieldCondition[] { - new FieldCondition(Fields.SurfaceOpaque, true), - new FieldCondition(Fields.AlphaTest, true) } }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = $"{(int)StencilUsage.RequiresDeferredLighting | (int)StencilUsage.SubsurfaceScattering}", - Ref = $"{(int)StencilUsage.Clear}", - Comp = "Always", - Pass = "Replace", - }) }, - }; - } -#endregion - -#region Keywords - static class PBRKeywords - { - public static KeywordCollection GBuffer = new KeywordCollection - { - { CoreKeywordDescriptors.LodFadeCrossfade }, - { CoreKeywordDescriptors.DebugDisplay }, - { CoreKeywords.Lightmaps }, - { CoreKeywordDescriptors.ShadowsShadowmask }, - { CoreKeywordDescriptors.LightLayers }, - { CoreKeywordDescriptors.Decals }, - { CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) }, - }; - - public static KeywordCollection LodFadeCrossfade = new KeywordCollection - { - { CoreKeywordDescriptors.LodFadeCrossfade }, - { CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) }, - }; - - public static KeywordCollection DepthMotionVectors = new KeywordCollection - { - { CoreKeywordDescriptors.WriteMsaaDepth }, - { CoreKeywordDescriptors.WriteNormalBuffer }, - { CoreKeywordDescriptors.LodFadeCrossfade }, - { CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) }, - }; - - public static KeywordCollection Forward = new KeywordCollection - { - { CoreKeywordDescriptors.LodFadeCrossfade }, - { CoreKeywordDescriptors.DebugDisplay }, - { CoreKeywords.Lightmaps }, - { CoreKeywordDescriptors.ShadowsShadowmask }, - { CoreKeywordDescriptors.Decals }, - { CoreKeywordDescriptors.Shadow }, - { CoreKeywordDescriptors.LightList, new FieldCondition(Fields.SurfaceOpaque, true) }, - { CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) }, - }; - } -#endregion - -#region Includes - static class PBRIncludes - { - // These are duplicated from HDLitSubTarget - // We avoid moving these to CoreIncludes because this SubTarget will be removed with Stacks - - const string kLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; - const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"; - - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection GBuffer = new IncludeCollection - { - { Common }, - { kPassGBuffer, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Forward = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { CoreIncludes.kLit, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// public static RenderStateCollection DepthOnly = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = $"{ 0 | (int)StencilUsage.TraceReflectionRay}", +// Ref = $"{0 | (int)StencilUsage.TraceReflectionRay}", +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection MotionVectors = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = $"{0 | (int)StencilUsage.TraceReflectionRay | (int)StencilUsage.ObjectMotionVector}", +// Ref = $"{ 0 | (int)StencilUsage.TraceReflectionRay | (int)StencilUsage.ObjectMotionVector}", +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection Forward = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(Fields.SurfaceOpaque, true) }, +// { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceTransparent, true), +// new FieldCondition(Fields.BlendAlpha, true) } }, +// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceTransparent, true), +// new FieldCondition(Fields.BlendAdd, true) } }, +// { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceTransparent, true), +// new FieldCondition(Fields.BlendPremultiply, true) } }, +// { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceTransparent, true), +// new FieldCondition(Fields.BlendMultiply, true) } }, + +// { RenderState.ZTest(ZTest.Equal), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceOpaque, true), +// new FieldCondition(Fields.AlphaTest, true) } }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = $"{(int)StencilUsage.RequiresDeferredLighting | (int)StencilUsage.SubsurfaceScattering}", +// Ref = $"{(int)StencilUsage.Clear}", +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Keywords +// static class PBRKeywords +// { +// public static KeywordCollection GBuffer = new KeywordCollection +// { +// { CoreKeywordDescriptors.LodFadeCrossfade }, +// { CoreKeywordDescriptors.DebugDisplay }, +// { CoreKeywords.Lightmaps }, +// { CoreKeywordDescriptors.ShadowsShadowmask }, +// { CoreKeywordDescriptors.LightLayers }, +// { CoreKeywordDescriptors.Decals }, +// { CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) }, +// }; + +// public static KeywordCollection LodFadeCrossfade = new KeywordCollection +// { +// { CoreKeywordDescriptors.LodFadeCrossfade }, +// { CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) }, +// }; + +// public static KeywordCollection DepthMotionVectors = new KeywordCollection +// { +// { CoreKeywordDescriptors.WriteMsaaDepth }, +// { CoreKeywordDescriptors.WriteNormalBuffer }, +// { CoreKeywordDescriptors.LodFadeCrossfade }, +// { CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) }, +// }; + +// public static KeywordCollection Forward = new KeywordCollection +// { +// { CoreKeywordDescriptors.LodFadeCrossfade }, +// { CoreKeywordDescriptors.DebugDisplay }, +// { CoreKeywords.Lightmaps }, +// { CoreKeywordDescriptors.ShadowsShadowmask }, +// { CoreKeywordDescriptors.Decals }, +// { CoreKeywordDescriptors.Shadow }, +// { CoreKeywordDescriptors.LightList, new FieldCondition(Fields.SurfaceOpaque, true) }, +// { CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true) }, +// }; +// } +// #endregion + +// #region Includes +// static class PBRIncludes +// { +// // These are duplicated from HDLitSubTarget +// // We avoid moving these to CoreIncludes because this SubTarget will be removed with Stacks + +// const string kLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; +// const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"; + +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection GBuffer = new IncludeCollection +// { +// { Common }, +// { kPassGBuffer, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Forward = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { CoreIncludes.kLit, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/CreateStackLitShaderGraph.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/CreateStackLitShaderGraph.cs deleted file mode 100644 index daab72d9ff3..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/CreateStackLitShaderGraph.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition -{ - static class CreateStackLitShaderGraph - { - [MenuItem("Assets/Create/Shader/HDRP/StackLit Graph", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new StackLitMasterNode()); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/CreateStackLitShaderGraph.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/CreateStackLitShaderGraph.cs.meta deleted file mode 100644 index 4832c26dabc..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/CreateStackLitShaderGraph.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 93591f944368c1d48b18a4e485bdda70 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/HDStackLitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/HDStackLitSubTarget.cs index aa7c2e32818..3e47d557390 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/HDStackLitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/HDStackLitSubTarget.cs @@ -1,656 +1,656 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class HDStackLitSubTarget : SubTarget - { - const string kAssetGuid = "5f7ba34a143e67647b202a662748dae3"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; - - public HDStackLitSubTarget() - { - displayName = "StackLit"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.StackLitGUI"); - context.AddSubShader(SubShaders.StackLit); - context.AddSubShader(SubShaders.StackLitRaytracing); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor StackLit = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { StackLitPasses.ShadowCaster }, - { StackLitPasses.META }, - { StackLitPasses.SceneSelection }, - { StackLitPasses.DepthForwardOnly }, - { StackLitPasses.MotionVectors }, - { StackLitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, - { StackLitPasses.ForwardOnly }, - }, - }; - - public static SubShaderDescriptor StackLitRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { StackLitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { StackLitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { StackLitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { StackLitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { StackLitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class StackLitPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - pixelPorts = StackLitPortMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.VertexPosition, - pixelPorts = StackLitPortMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = StackLitRenderStates.ShadowCaster, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayerEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // // Code path for WRITE_NORMAL_BUFFER - // See StackLit.hlsl:ConvertSurfaceDataToNormalData() - // which ShaderPassDepthOnly uses: we need to add proper interpolators dependencies depending on WRITE_NORMAL_BUFFER. - // In our case WRITE_NORMAL_BUFFER is always enabled here. - // Also, we need to add PixelShaderSlots dependencies for everything potentially used there. - // See AddPixelShaderSlotsForWriteNormalBufferPasses() - - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = StackLitIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = StackLitIncludes.MotionVectors, - }; - - public static PassDescriptor Distortion = new PassDescriptor() - { - // Definition - displayName = "DistortionVectors", - referenceName = "SHADERPASS_DISTORTION", - lightMode = "DistortionVectors", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentDistortion, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = StackLitRenderStates.Distortion, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.Distortion, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = StackLitIncludes.ForwardOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - vertexPorts = StackLitPortMasks.Vertex, - pixelPorts = StackLitPortMasks.FragmentForward, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region PortMasks - static class StackLitPortMasks - { - public static int[] Vertex = new int[] - { - StackLitMasterNode.PositionSlotId, - StackLitMasterNode.VertexNormalSlotId, - StackLitMasterNode.VertexTangentSlotId - }; - - public static int[] VertexPosition = new int[] - { - StackLitMasterNode.PositionSlotId, - }; - - public static int[] FragmentMETA = new int[] - { - StackLitMasterNode.BaseColorSlotId, - StackLitMasterNode.NormalSlotId, - StackLitMasterNode.BentNormalSlotId, - StackLitMasterNode.TangentSlotId, - StackLitMasterNode.SubsurfaceMaskSlotId, - StackLitMasterNode.ThicknessSlotId, - StackLitMasterNode.DiffusionProfileHashSlotId, - StackLitMasterNode.IridescenceMaskSlotId, - StackLitMasterNode.IridescenceThicknessSlotId, - StackLitMasterNode.IridescenceCoatFixupTIRSlotId, - StackLitMasterNode.IridescenceCoatFixupTIRClampSlotId, - StackLitMasterNode.SpecularColorSlotId, - StackLitMasterNode.DielectricIorSlotId, - StackLitMasterNode.MetallicSlotId, - StackLitMasterNode.EmissionSlotId, - StackLitMasterNode.SmoothnessASlotId, - StackLitMasterNode.SmoothnessBSlotId, - StackLitMasterNode.AmbientOcclusionSlotId, - StackLitMasterNode.AlphaSlotId, - StackLitMasterNode.AlphaClipThresholdSlotId, - StackLitMasterNode.AnisotropyASlotId, - StackLitMasterNode.AnisotropyBSlotId, - StackLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, - StackLitMasterNode.SpecularAAThresholdSlotId, - StackLitMasterNode.CoatSmoothnessSlotId, - StackLitMasterNode.CoatIorSlotId, - StackLitMasterNode.CoatThicknessSlotId, - StackLitMasterNode.CoatExtinctionSlotId, - StackLitMasterNode.CoatNormalSlotId, - StackLitMasterNode.CoatMaskSlotId, - StackLitMasterNode.LobeMixSlotId, - StackLitMasterNode.HazinessSlotId, - StackLitMasterNode.HazeExtentSlotId, - StackLitMasterNode.HazyGlossMaxDielectricF0SlotId, - StackLitMasterNode.SpecularOcclusionSlotId, - StackLitMasterNode.SOFixupVisibilityRatioThresholdSlotId, - StackLitMasterNode.SOFixupStrengthFactorSlotId, - StackLitMasterNode.SOFixupMaxAddedRoughnessSlotId, - }; - - public static int[] FragmentAlphaDepth = new int[] - { - StackLitMasterNode.AlphaSlotId, - StackLitMasterNode.AlphaClipThresholdSlotId, - StackLitMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentDepthMotionVectors = new int[] - { - StackLitMasterNode.AlphaSlotId, - StackLitMasterNode.AlphaClipThresholdSlotId, - StackLitMasterNode.DepthOffsetSlotId, - // StackLitMasterNode.coat - StackLitMasterNode.CoatSmoothnessSlotId, - StackLitMasterNode.CoatNormalSlotId, - // !StackLitMasterNode.coat - StackLitMasterNode.NormalSlotId, - StackLitMasterNode.LobeMixSlotId, - StackLitMasterNode.SmoothnessASlotId, - StackLitMasterNode.SmoothnessBSlotId, - // StackLitMasterNode.geometricSpecularAA - StackLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, - StackLitMasterNode.SpecularAAThresholdSlotId, - }; - - public static int[] FragmentDistortion = new int[] - { - StackLitMasterNode.AlphaSlotId, - StackLitMasterNode.AlphaClipThresholdSlotId, - StackLitMasterNode.DistortionSlotId, - StackLitMasterNode.DistortionBlurSlotId, - StackLitMasterNode.DepthOffsetSlotId, - }; - - public static int[] FragmentForward = new int[] - { - StackLitMasterNode.BaseColorSlotId, - StackLitMasterNode.NormalSlotId, - StackLitMasterNode.BentNormalSlotId, - StackLitMasterNode.TangentSlotId, - StackLitMasterNode.SubsurfaceMaskSlotId, - StackLitMasterNode.ThicknessSlotId, - StackLitMasterNode.DiffusionProfileHashSlotId, - StackLitMasterNode.IridescenceMaskSlotId, - StackLitMasterNode.IridescenceThicknessSlotId, - StackLitMasterNode.IridescenceCoatFixupTIRSlotId, - StackLitMasterNode.IridescenceCoatFixupTIRClampSlotId, - StackLitMasterNode.SpecularColorSlotId, - StackLitMasterNode.DielectricIorSlotId, - StackLitMasterNode.MetallicSlotId, - StackLitMasterNode.EmissionSlotId, - StackLitMasterNode.SmoothnessASlotId, - StackLitMasterNode.SmoothnessBSlotId, - StackLitMasterNode.AmbientOcclusionSlotId, - StackLitMasterNode.AlphaSlotId, - StackLitMasterNode.AlphaClipThresholdSlotId, - StackLitMasterNode.AnisotropyASlotId, - StackLitMasterNode.AnisotropyBSlotId, - StackLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, - StackLitMasterNode.SpecularAAThresholdSlotId, - StackLitMasterNode.CoatSmoothnessSlotId, - StackLitMasterNode.CoatIorSlotId, - StackLitMasterNode.CoatThicknessSlotId, - StackLitMasterNode.CoatExtinctionSlotId, - StackLitMasterNode.CoatNormalSlotId, - StackLitMasterNode.CoatMaskSlotId, - StackLitMasterNode.LobeMixSlotId, - StackLitMasterNode.HazinessSlotId, - StackLitMasterNode.HazeExtentSlotId, - StackLitMasterNode.HazyGlossMaxDielectricF0SlotId, - StackLitMasterNode.SpecularOcclusionSlotId, - StackLitMasterNode.SOFixupVisibilityRatioThresholdSlotId, - StackLitMasterNode.SOFixupStrengthFactorSlotId, - StackLitMasterNode.SOFixupMaxAddedRoughnessSlotId, - StackLitMasterNode.LightingSlotId, - StackLitMasterNode.BackLightingSlotId, - StackLitMasterNode.DepthOffsetSlotId, - }; - } -#endregion - -#region RenderStates - static class StackLitRenderStates - { - public static RenderStateCollection ShadowCaster = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.Zero) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ZClip(CoreRenderStates.Uniforms.zClip) }, - { RenderState.ColorMask("ColorMask 0") }, - }; - - public static RenderStateCollection Distortion = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, - { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, - { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, - { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = $"{(int)StencilUsage.DistortionVectors}", - Ref = $"{(int)StencilUsage.DistortionVectors}", - Comp = "Always", - Pass = "Replace", - }) }, - }; - } -#endregion - -#region Defines - static class StackLitDefines - { - public static DefineCollection RaytracingForwardIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - }; - } -#endregion - -#region Pragmas - static class StackLitPragmas - { - public static PragmaCollection DotsInstancedInV2OnlyRenderingLayer = new PragmaCollection - { - { CorePragmas.Basic }, - { Pragma.MultiCompileInstancing }, - { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, - #if ENABLE_HYBRID_RENDERER_V2 - { Pragma.DOTSInstancing }, - { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, - #endif - }; - - public static PragmaCollection DotsInstancedInV2OnlyRenderingLayerEditorSync = new PragmaCollection - { - { CorePragmas.Basic }, - { Pragma.MultiCompileInstancing }, - { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, - { Pragma.EditorSyncCompilation }, - #if ENABLE_HYBRID_RENDERER_V2 - { Pragma.DOTSInstancing }, - { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, - #endif - }; - } -#endregion - -#region Includes - static class StackLitIncludes - { - const string kSpecularOcclusionDef = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/SphericalCapPivot/SpecularOcclusionDef.hlsl"; - const string kStackLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitDecalData.hlsl"; - - public static IncludeCollection Common = new IncludeCollection - { - { kSpecularOcclusionDef, IncludeLocation.Pregraph }, - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kStackLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Distortion = new IncludeCollection - { - { Common }, - { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { kSpecularOcclusionDef, IncludeLocation.Pregraph }, - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kStackLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class HDStackLitSubTarget : SubTarget +// { +// const string kAssetGuid = "5f7ba34a143e67647b202a662748dae3"; +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; + +// public HDStackLitSubTarget() +// { +// displayName = "StackLit"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.StackLitGUI"); +// context.AddSubShader(SubShaders.StackLit); +// context.AddSubShader(SubShaders.StackLitRaytracing); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor StackLit = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { StackLitPasses.ShadowCaster }, +// { StackLitPasses.META }, +// { StackLitPasses.SceneSelection }, +// { StackLitPasses.DepthForwardOnly }, +// { StackLitPasses.MotionVectors }, +// { StackLitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, +// { StackLitPasses.ForwardOnly }, +// }, +// }; + +// public static SubShaderDescriptor StackLitRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { StackLitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { StackLitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { StackLitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { StackLitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { StackLitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class StackLitPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// pixelPorts = StackLitPortMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.VertexPosition, +// pixelPorts = StackLitPortMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = StackLitRenderStates.ShadowCaster, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.SceneSelection, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayerEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // // Code path for WRITE_NORMAL_BUFFER +// // See StackLit.hlsl:ConvertSurfaceDataToNormalData() +// // which ShaderPassDepthOnly uses: we need to add proper interpolators dependencies depending on WRITE_NORMAL_BUFFER. +// // In our case WRITE_NORMAL_BUFFER is always enabled here. +// // Also, we need to add PixelShaderSlots dependencies for everything potentially used there. +// // See AddPixelShaderSlotsForWriteNormalBufferPasses() + +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = StackLitIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = StackLitIncludes.MotionVectors, +// }; + +// public static PassDescriptor Distortion = new PassDescriptor() +// { +// // Definition +// displayName = "DistortionVectors", +// referenceName = "SHADERPASS_DISTORTION", +// lightMode = "DistortionVectors", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentDistortion, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = StackLitRenderStates.Distortion, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.Distortion, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = StackLitIncludes.ForwardOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// vertexPorts = StackLitPortMasks.Vertex, +// pixelPorts = StackLitPortMasks.FragmentForward, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region PortMasks +// static class StackLitPortMasks +// { +// public static int[] Vertex = new int[] +// { +// StackLitMasterNode.PositionSlotId, +// StackLitMasterNode.VertexNormalSlotId, +// StackLitMasterNode.VertexTangentSlotId +// }; + +// public static int[] VertexPosition = new int[] +// { +// StackLitMasterNode.PositionSlotId, +// }; + +// public static int[] FragmentMETA = new int[] +// { +// StackLitMasterNode.BaseColorSlotId, +// StackLitMasterNode.NormalSlotId, +// StackLitMasterNode.BentNormalSlotId, +// StackLitMasterNode.TangentSlotId, +// StackLitMasterNode.SubsurfaceMaskSlotId, +// StackLitMasterNode.ThicknessSlotId, +// StackLitMasterNode.DiffusionProfileHashSlotId, +// StackLitMasterNode.IridescenceMaskSlotId, +// StackLitMasterNode.IridescenceThicknessSlotId, +// StackLitMasterNode.IridescenceCoatFixupTIRSlotId, +// StackLitMasterNode.IridescenceCoatFixupTIRClampSlotId, +// StackLitMasterNode.SpecularColorSlotId, +// StackLitMasterNode.DielectricIorSlotId, +// StackLitMasterNode.MetallicSlotId, +// StackLitMasterNode.EmissionSlotId, +// StackLitMasterNode.SmoothnessASlotId, +// StackLitMasterNode.SmoothnessBSlotId, +// StackLitMasterNode.AmbientOcclusionSlotId, +// StackLitMasterNode.AlphaSlotId, +// StackLitMasterNode.AlphaClipThresholdSlotId, +// StackLitMasterNode.AnisotropyASlotId, +// StackLitMasterNode.AnisotropyBSlotId, +// StackLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// StackLitMasterNode.SpecularAAThresholdSlotId, +// StackLitMasterNode.CoatSmoothnessSlotId, +// StackLitMasterNode.CoatIorSlotId, +// StackLitMasterNode.CoatThicknessSlotId, +// StackLitMasterNode.CoatExtinctionSlotId, +// StackLitMasterNode.CoatNormalSlotId, +// StackLitMasterNode.CoatMaskSlotId, +// StackLitMasterNode.LobeMixSlotId, +// StackLitMasterNode.HazinessSlotId, +// StackLitMasterNode.HazeExtentSlotId, +// StackLitMasterNode.HazyGlossMaxDielectricF0SlotId, +// StackLitMasterNode.SpecularOcclusionSlotId, +// StackLitMasterNode.SOFixupVisibilityRatioThresholdSlotId, +// StackLitMasterNode.SOFixupStrengthFactorSlotId, +// StackLitMasterNode.SOFixupMaxAddedRoughnessSlotId, +// }; + +// public static int[] FragmentAlphaDepth = new int[] +// { +// StackLitMasterNode.AlphaSlotId, +// StackLitMasterNode.AlphaClipThresholdSlotId, +// StackLitMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentDepthMotionVectors = new int[] +// { +// StackLitMasterNode.AlphaSlotId, +// StackLitMasterNode.AlphaClipThresholdSlotId, +// StackLitMasterNode.DepthOffsetSlotId, +// // StackLitMasterNode.coat +// StackLitMasterNode.CoatSmoothnessSlotId, +// StackLitMasterNode.CoatNormalSlotId, +// // !StackLitMasterNode.coat +// StackLitMasterNode.NormalSlotId, +// StackLitMasterNode.LobeMixSlotId, +// StackLitMasterNode.SmoothnessASlotId, +// StackLitMasterNode.SmoothnessBSlotId, +// // StackLitMasterNode.geometricSpecularAA +// StackLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// StackLitMasterNode.SpecularAAThresholdSlotId, +// }; + +// public static int[] FragmentDistortion = new int[] +// { +// StackLitMasterNode.AlphaSlotId, +// StackLitMasterNode.AlphaClipThresholdSlotId, +// StackLitMasterNode.DistortionSlotId, +// StackLitMasterNode.DistortionBlurSlotId, +// StackLitMasterNode.DepthOffsetSlotId, +// }; + +// public static int[] FragmentForward = new int[] +// { +// StackLitMasterNode.BaseColorSlotId, +// StackLitMasterNode.NormalSlotId, +// StackLitMasterNode.BentNormalSlotId, +// StackLitMasterNode.TangentSlotId, +// StackLitMasterNode.SubsurfaceMaskSlotId, +// StackLitMasterNode.ThicknessSlotId, +// StackLitMasterNode.DiffusionProfileHashSlotId, +// StackLitMasterNode.IridescenceMaskSlotId, +// StackLitMasterNode.IridescenceThicknessSlotId, +// StackLitMasterNode.IridescenceCoatFixupTIRSlotId, +// StackLitMasterNode.IridescenceCoatFixupTIRClampSlotId, +// StackLitMasterNode.SpecularColorSlotId, +// StackLitMasterNode.DielectricIorSlotId, +// StackLitMasterNode.MetallicSlotId, +// StackLitMasterNode.EmissionSlotId, +// StackLitMasterNode.SmoothnessASlotId, +// StackLitMasterNode.SmoothnessBSlotId, +// StackLitMasterNode.AmbientOcclusionSlotId, +// StackLitMasterNode.AlphaSlotId, +// StackLitMasterNode.AlphaClipThresholdSlotId, +// StackLitMasterNode.AnisotropyASlotId, +// StackLitMasterNode.AnisotropyBSlotId, +// StackLitMasterNode.SpecularAAScreenSpaceVarianceSlotId, +// StackLitMasterNode.SpecularAAThresholdSlotId, +// StackLitMasterNode.CoatSmoothnessSlotId, +// StackLitMasterNode.CoatIorSlotId, +// StackLitMasterNode.CoatThicknessSlotId, +// StackLitMasterNode.CoatExtinctionSlotId, +// StackLitMasterNode.CoatNormalSlotId, +// StackLitMasterNode.CoatMaskSlotId, +// StackLitMasterNode.LobeMixSlotId, +// StackLitMasterNode.HazinessSlotId, +// StackLitMasterNode.HazeExtentSlotId, +// StackLitMasterNode.HazyGlossMaxDielectricF0SlotId, +// StackLitMasterNode.SpecularOcclusionSlotId, +// StackLitMasterNode.SOFixupVisibilityRatioThresholdSlotId, +// StackLitMasterNode.SOFixupStrengthFactorSlotId, +// StackLitMasterNode.SOFixupMaxAddedRoughnessSlotId, +// StackLitMasterNode.LightingSlotId, +// StackLitMasterNode.BackLightingSlotId, +// StackLitMasterNode.DepthOffsetSlotId, +// }; +// } +// #endregion + +// #region RenderStates +// static class StackLitRenderStates +// { +// public static RenderStateCollection ShadowCaster = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.Zero) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ZClip(CoreRenderStates.Uniforms.zClip) }, +// { RenderState.ColorMask("ColorMask 0") }, +// }; + +// public static RenderStateCollection Distortion = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, +// { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, +// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, +// { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, +// { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = $"{(int)StencilUsage.DistortionVectors}", +// Ref = $"{(int)StencilUsage.DistortionVectors}", +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Defines +// static class StackLitDefines +// { +// public static DefineCollection RaytracingForwardIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// }; +// } +// #endregion + +// #region Pragmas +// static class StackLitPragmas +// { +// public static PragmaCollection DotsInstancedInV2OnlyRenderingLayer = new PragmaCollection +// { +// { CorePragmas.Basic }, +// { Pragma.MultiCompileInstancing }, +// { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, +// #if ENABLE_HYBRID_RENDERER_V2 +// { Pragma.DOTSInstancing }, +// { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, +// #endif +// }; + +// public static PragmaCollection DotsInstancedInV2OnlyRenderingLayerEditorSync = new PragmaCollection +// { +// { CorePragmas.Basic }, +// { Pragma.MultiCompileInstancing }, +// { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, +// { Pragma.EditorSyncCompilation }, +// #if ENABLE_HYBRID_RENDERER_V2 +// { Pragma.DOTSInstancing }, +// { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, +// #endif +// }; +// } +// #endregion + +// #region Includes +// static class StackLitIncludes +// { +// const string kSpecularOcclusionDef = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/SphericalCapPivot/SpecularOcclusionDef.hlsl"; +// const string kStackLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitDecalData.hlsl"; + +// public static IncludeCollection Common = new IncludeCollection +// { +// { kSpecularOcclusionDef, IncludeLocation.Pregraph }, +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kStackLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Distortion = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { kSpecularOcclusionDef, IncludeLocation.Pregraph }, +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kStackLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitMasterNode.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitMasterNode.cs index 9a56ff07d28..1930ca137cf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitMasterNode.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitMasterNode.cs @@ -1,1769 +1,1769 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Rendering.HighDefinition.Drawing; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph.Drawing.Inspector; -using UnityEditor.ShaderGraph.Internal; -using UnityEngine.Rendering; -using UnityEditor.Rendering.HighDefinition.ShaderGraph; - -// Include material common properties names -using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; - -//TODOTODO: -// clamp in shader code the ranged() properties -// or let inputs (eg mask?) follow invalid values ? Lit does that (let them free running). -namespace UnityEditor.Rendering.HighDefinition -{ - [Serializable] - [Title("Master", "StackLit (HDRP)")] - [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.StackLitMasterNode")] - [FormerName("UnityEditor.ShaderGraph.StackLitMasterNode")] - class StackLitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string PositionSlotName = "Vertex Position"; - public const string PositionSlotDisplayName = "Vertex Position"; - - public const string BaseColorSlotName = "BaseColor"; - - public const string NormalSlotName = "Normal"; - public const string BentNormalSlotName = "BentNormal"; - public const string TangentSlotName = "Tangent"; - - public const string SubsurfaceMaskSlotName = "SubsurfaceMask"; - public const string ThicknessSlotName = "Thickness"; - public const string DiffusionProfileHashSlotName = "DiffusionProfileHash"; - public const string DiffusionProfileHashSlotDisplayName = "Diffusion Profile"; - - public const string IridescenceMaskSlotName = "IridescenceMask"; - public const string IridescenceThicknessSlotName = "IridescenceThickness"; - public const string IridescenceThicknessSlotDisplayName = "Iridescence Layer Thickness"; - public const string IridescenceCoatFixupTIRSlotName = "IridescenceCoatFixupTIR"; - public const string IridescenceCoatFixupTIRClampSlotName = "IridescenceCoatFixupTIRClamp"; - - public const string SpecularColorSlotName = "SpecularColor"; - public const string MetallicSlotName = "Metallic"; - public const string DielectricIorSlotName = "DielectricIor"; - - public const string EmissionSlotName = "Emission"; - public const string SmoothnessASlotName = "SmoothnessA"; - public const string SmoothnessBSlotName = "SmoothnessB"; - public const string AmbientOcclusionSlotName = "AmbientOcclusion"; - public const string AlphaSlotName = "Alpha"; - public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; - public const string AnisotropyASlotName = "AnisotropyA"; - public const string AnisotropyBSlotName = "AnisotropyB"; - public const string SpecularAAScreenSpaceVarianceSlotName = "SpecularAAScreenSpaceVariance"; - public const string SpecularAAThresholdSlotName = "SpecularAAThreshold"; - public const string DistortionSlotName = "Distortion"; - public const string DistortionSlotDisplayName = "Distortion Vector"; - public const string DistortionBlurSlotName = "DistortionBlur"; - - public const string CoatSmoothnessSlotName = "CoatSmoothness"; - public const string CoatIorSlotName = "CoatIor"; - public const string CoatThicknessSlotName = "CoatThickness"; - public const string CoatExtinctionSlotName = "CoatExtinction"; - public const string CoatNormalSlotName = "CoatNormal"; - public const string CoatMaskSlotName = "CoatMask"; - - public const string LobeMixSlotName = "LobeMix"; - public const string HazinessSlotName = "Haziness"; - public const string HazeExtentSlotName = "HazeExtent"; - public const string HazyGlossMaxDielectricF0SlotName = "HazyGlossMaxDielectricF0"; // only valid if above option enabled and we have a basecolor + metallic input parametrization - - public const string BakedGISlotName = "BakedGI"; - public const string BakedBackGISlotName = "BakedBackGI"; - - // TODO: we would ideally need one value per lobe - public const string SpecularOcclusionSlotName = "SpecularOcclusion"; - - public const string SOFixupVisibilityRatioThresholdSlotName = "SOConeFixupVisibilityThreshold"; - public const string SOFixupStrengthFactorSlotName = "SOConeFixupStrength"; - public const string SOFixupMaxAddedRoughnessSlotName = "SOConeFixupMaxAddedRoughness"; - - public const string DepthOffsetSlotName = "DepthOffset"; - - public const string VertexNormalSlotName = "Vertex Normal"; - public const string VertexTangentSlotName = "Vertex Tangent"; - - public const int PositionSlotId = 0; - public const int BaseColorSlotId = 1; - public const int NormalSlotId = 2; - public const int BentNormalSlotId = 3; - public const int TangentSlotId = 4; - public const int SubsurfaceMaskSlotId = 5; - public const int ThicknessSlotId = 6; - public const int DiffusionProfileHashSlotId = 7; - public const int IridescenceMaskSlotId = 8; - public const int IridescenceThicknessSlotId = 9; - public const int SpecularColorSlotId = 10; - public const int DielectricIorSlotId = 11; - public const int MetallicSlotId = 12; - public const int EmissionSlotId = 13; - public const int SmoothnessASlotId = 14; - public const int SmoothnessBSlotId = 15; - public const int AmbientOcclusionSlotId = 16; - public const int AlphaSlotId = 17; - public const int AlphaClipThresholdSlotId = 18; - public const int AnisotropyASlotId = 19; - public const int AnisotropyBSlotId = 20; - public const int SpecularAAScreenSpaceVarianceSlotId = 21; - public const int SpecularAAThresholdSlotId = 22; - public const int DistortionSlotId = 23; - public const int DistortionBlurSlotId = 24; - - public const int CoatSmoothnessSlotId = 25; - public const int CoatIorSlotId = 26; - public const int CoatThicknessSlotId = 27; - public const int CoatExtinctionSlotId = 28; - public const int CoatNormalSlotId = 29; - - public const int LobeMixSlotId = 30; - public const int HazinessSlotId = 31; - public const int HazeExtentSlotId = 32; - public const int HazyGlossMaxDielectricF0SlotId = 33; - - public const int LightingSlotId = 34; - public const int BackLightingSlotId = 35; - - public const int SOFixupVisibilityRatioThresholdSlotId = 36; - public const int SOFixupStrengthFactorSlotId = 37; - public const int SOFixupMaxAddedRoughnessSlotId = 38; - - public const int CoatMaskSlotId = 39; - public const int IridescenceCoatFixupTIRSlotId = 40; - public const int IridescenceCoatFixupTIRClampSlotId = 41; - - public const int DepthOffsetSlotId = 42; - - public const int VertexNormalSlotId = 44; - public const int VertexTangentSlotId = 45; - - // TODO: we would ideally need one value per lobe - public const int SpecularOcclusionSlotId = 43; // for custom (external) SO replacing data based SO (which normally comes from some func of DataBasedSOMode(dataAO, optional bent normal)) - - // In StackLit.hlsl engine side - //public enum BaseParametrization - //public enum DualSpecularLobeParametrization - - // Available options for computing Vs (specular occlusion) based on: - // - // baked diffuse visibility (aka "data based AO") orientation - // (ie baked visibility cone (aka "bent visibility cone") orientation) - // := { normal aligned (default bentnormal value), bent normal } - // X - // baked diffuse visibility solid angle inference algo from baked visibility scalar - // (ie baked visibility cone aperture angle or solid angle) - // := { uniform (solid angle measure), cos weighted (projected solid angle measure with cone oriented with normal), - // cos properly weighted wrt bentnormal (projected solid angle measure with cone oriented with bent normal) } - // X - // Vs (aka specular occlusion) calculation algo from baked diffuse values above and BSDF lobe properties - // := {triACE - not tuned to account for bent normal, cone BSDF proxy intersection with bent cone, precise SPTD BSDF proxy lobe integration against the bent cone} } - // - // Note that in Lit SSAO is used with triACE as a clamp value to combine it with the calculations done with the baked AO, - // by doing a min(VsFromTriACE+SSAO, VsFromBakedVisibility). - // (See in particular Lit.hlsl:PostEvaluateBSDF(), MaterialEvaluation.hlsl:GetScreenSpaceAmbientOcclusionMultibounce(), - // where the handed bsdfData.specularOcclusion is data based (baked texture). - // - // In StackLit, we allow control of the SSAO based SO and also the data based one. - // - // Of the algos described above, we can narrow to these combined options: - // { Off, NoBentNormalTriACE, *ConeCone, *SPTD }, where * is any combination of using the normal or the bentnormal with any of 3 choices to interpret the AO - // measure for the cone aperture. - // - // See also _DebugSpecularOcclusion. - public enum SpecularOcclusionBaseMode - { - Off = 0, - DirectFromAO = 1, // TriACE - ConeConeFromBentAO = 2, - SPTDIntegrationOfBentAO = 3, - Custom = 4, - // Custom user port input: For now, we will only have one input used for all lobes and only for data-based SO - // (TODO: Normally would need a custom input per lobe. - // Main rationale is that roughness can change IBL fetch direction and not only BSDF lobe width, and interface normal changes shading reference frame - // hence it also changes the directional relation between the visibility cone and the BSDF lobe.) - } - - public enum SpecularOcclusionBaseModeSimple - { - Off = 0, - DirectFromAO = 1, // TriACE - SPTDIntegrationOfBentAO = 3, - Custom = 4, - } - - public enum SpecularOcclusionAOConeSize - { - UniformAO, - CosWeightedAO, - CosWeightedBentCorrectAO - } - - // This is in case SSAO-based SO method requires it (the SSAO we have doesn't provide a direction) - public enum SpecularOcclusionAOConeDir - { - GeomNormal, - BentNormal, - ShadingNormal - } - - // SO Bent cone fixup is only for methods using visibility cone and only for the data based SO: - public enum SpecularOcclusionConeFixupMethod - { - Off, - BoostBSDFRoughness, - TiltDirectionToGeomNormal, - BoostAndTilt, - } - - // Don't support Multiply - public enum AlphaModeLit - { - Alpha, - Premultiply, - Additive, - } - - - // Common surface config: - // - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - AlphaMode m_AlphaMode; - - public AlphaMode alphaMode - { - get { return m_AlphaMode; } - set - { - if (m_AlphaMode == value) - return; - - m_AlphaMode = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_BlendPreserveSpecular = true; - - public ToggleData blendPreserveSpecular - { - get { return new ToggleData(m_BlendPreserveSpecular); } - set - { - if (m_BlendPreserveSpecular == value.isOn) - return; - m_BlendPreserveSpecular = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_TransparencyFog = true; - - public ToggleData transparencyFog - { - get { return new ToggleData(m_TransparencyFog); } - set - { - if (m_TransparencyFog == value.isOn) - return; - m_TransparencyFog = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_Distortion; - - public ToggleData distortion - { - get { return new ToggleData(m_Distortion); } - set - { - if (m_Distortion == value.isOn) - return; - m_Distortion = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - DistortionMode m_DistortionMode; - - public DistortionMode distortionMode - { - get { return m_DistortionMode; } - set - { - if (m_DistortionMode == value) - return; - - m_DistortionMode = value; - UpdateNodeAfterDeserialization(); // TODOTODO: no need, ModificationScope.Graph is enough? - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_DistortionDepthTest = true; - - public ToggleData distortionDepthTest - { - get { return new ToggleData(m_DistortionDepthTest); } - set - { - if (m_DistortionDepthTest == value.isOn) - return; - m_DistortionDepthTest = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaTest; - - public ToggleData alphaTest - { - get { return new ToggleData(m_AlphaTest); } - set - { - if (m_AlphaTest == value.isOn) - return; - m_AlphaTest = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } +// using System; +// using System.Linq; +// using System.Collections.Generic; +// using UnityEditor.Rendering.HighDefinition.Drawing; +// using UnityEditor.Graphing; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph.Drawing.Inspector; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEngine.Rendering; +// using UnityEditor.Rendering.HighDefinition.ShaderGraph; + +// // Include material common properties names +// using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; + +// //TODOTODO: +// // clamp in shader code the ranged() properties +// // or let inputs (eg mask?) follow invalid values ? Lit does that (let them free running). +// namespace UnityEditor.Rendering.HighDefinition +// { +// [Serializable] +// [Title("Master", "StackLit (HDRP)")] +// [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.StackLitMasterNode")] +// [FormerName("UnityEditor.ShaderGraph.StackLitMasterNode")] +// class StackLitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent +// { +// public const string PositionSlotName = "Vertex Position"; +// public const string PositionSlotDisplayName = "Vertex Position"; + +// public const string BaseColorSlotName = "BaseColor"; + +// public const string NormalSlotName = "Normal"; +// public const string BentNormalSlotName = "BentNormal"; +// public const string TangentSlotName = "Tangent"; + +// public const string SubsurfaceMaskSlotName = "SubsurfaceMask"; +// public const string ThicknessSlotName = "Thickness"; +// public const string DiffusionProfileHashSlotName = "DiffusionProfileHash"; +// public const string DiffusionProfileHashSlotDisplayName = "Diffusion Profile"; + +// public const string IridescenceMaskSlotName = "IridescenceMask"; +// public const string IridescenceThicknessSlotName = "IridescenceThickness"; +// public const string IridescenceThicknessSlotDisplayName = "Iridescence Layer Thickness"; +// public const string IridescenceCoatFixupTIRSlotName = "IridescenceCoatFixupTIR"; +// public const string IridescenceCoatFixupTIRClampSlotName = "IridescenceCoatFixupTIRClamp"; + +// public const string SpecularColorSlotName = "SpecularColor"; +// public const string MetallicSlotName = "Metallic"; +// public const string DielectricIorSlotName = "DielectricIor"; + +// public const string EmissionSlotName = "Emission"; +// public const string SmoothnessASlotName = "SmoothnessA"; +// public const string SmoothnessBSlotName = "SmoothnessB"; +// public const string AmbientOcclusionSlotName = "AmbientOcclusion"; +// public const string AlphaSlotName = "Alpha"; +// public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; +// public const string AnisotropyASlotName = "AnisotropyA"; +// public const string AnisotropyBSlotName = "AnisotropyB"; +// public const string SpecularAAScreenSpaceVarianceSlotName = "SpecularAAScreenSpaceVariance"; +// public const string SpecularAAThresholdSlotName = "SpecularAAThreshold"; +// public const string DistortionSlotName = "Distortion"; +// public const string DistortionSlotDisplayName = "Distortion Vector"; +// public const string DistortionBlurSlotName = "DistortionBlur"; + +// public const string CoatSmoothnessSlotName = "CoatSmoothness"; +// public const string CoatIorSlotName = "CoatIor"; +// public const string CoatThicknessSlotName = "CoatThickness"; +// public const string CoatExtinctionSlotName = "CoatExtinction"; +// public const string CoatNormalSlotName = "CoatNormal"; +// public const string CoatMaskSlotName = "CoatMask"; + +// public const string LobeMixSlotName = "LobeMix"; +// public const string HazinessSlotName = "Haziness"; +// public const string HazeExtentSlotName = "HazeExtent"; +// public const string HazyGlossMaxDielectricF0SlotName = "HazyGlossMaxDielectricF0"; // only valid if above option enabled and we have a basecolor + metallic input parametrization + +// public const string BakedGISlotName = "BakedGI"; +// public const string BakedBackGISlotName = "BakedBackGI"; + +// // TODO: we would ideally need one value per lobe +// public const string SpecularOcclusionSlotName = "SpecularOcclusion"; + +// public const string SOFixupVisibilityRatioThresholdSlotName = "SOConeFixupVisibilityThreshold"; +// public const string SOFixupStrengthFactorSlotName = "SOConeFixupStrength"; +// public const string SOFixupMaxAddedRoughnessSlotName = "SOConeFixupMaxAddedRoughness"; + +// public const string DepthOffsetSlotName = "DepthOffset"; + +// public const string VertexNormalSlotName = "Vertex Normal"; +// public const string VertexTangentSlotName = "Vertex Tangent"; + +// public const int PositionSlotId = 0; +// public const int BaseColorSlotId = 1; +// public const int NormalSlotId = 2; +// public const int BentNormalSlotId = 3; +// public const int TangentSlotId = 4; +// public const int SubsurfaceMaskSlotId = 5; +// public const int ThicknessSlotId = 6; +// public const int DiffusionProfileHashSlotId = 7; +// public const int IridescenceMaskSlotId = 8; +// public const int IridescenceThicknessSlotId = 9; +// public const int SpecularColorSlotId = 10; +// public const int DielectricIorSlotId = 11; +// public const int MetallicSlotId = 12; +// public const int EmissionSlotId = 13; +// public const int SmoothnessASlotId = 14; +// public const int SmoothnessBSlotId = 15; +// public const int AmbientOcclusionSlotId = 16; +// public const int AlphaSlotId = 17; +// public const int AlphaClipThresholdSlotId = 18; +// public const int AnisotropyASlotId = 19; +// public const int AnisotropyBSlotId = 20; +// public const int SpecularAAScreenSpaceVarianceSlotId = 21; +// public const int SpecularAAThresholdSlotId = 22; +// public const int DistortionSlotId = 23; +// public const int DistortionBlurSlotId = 24; + +// public const int CoatSmoothnessSlotId = 25; +// public const int CoatIorSlotId = 26; +// public const int CoatThicknessSlotId = 27; +// public const int CoatExtinctionSlotId = 28; +// public const int CoatNormalSlotId = 29; + +// public const int LobeMixSlotId = 30; +// public const int HazinessSlotId = 31; +// public const int HazeExtentSlotId = 32; +// public const int HazyGlossMaxDielectricF0SlotId = 33; + +// public const int LightingSlotId = 34; +// public const int BackLightingSlotId = 35; + +// public const int SOFixupVisibilityRatioThresholdSlotId = 36; +// public const int SOFixupStrengthFactorSlotId = 37; +// public const int SOFixupMaxAddedRoughnessSlotId = 38; + +// public const int CoatMaskSlotId = 39; +// public const int IridescenceCoatFixupTIRSlotId = 40; +// public const int IridescenceCoatFixupTIRClampSlotId = 41; + +// public const int DepthOffsetSlotId = 42; + +// public const int VertexNormalSlotId = 44; +// public const int VertexTangentSlotId = 45; + +// // TODO: we would ideally need one value per lobe +// public const int SpecularOcclusionSlotId = 43; // for custom (external) SO replacing data based SO (which normally comes from some func of DataBasedSOMode(dataAO, optional bent normal)) + +// // In StackLit.hlsl engine side +// //public enum BaseParametrization +// //public enum DualSpecularLobeParametrization + +// // Available options for computing Vs (specular occlusion) based on: +// // +// // baked diffuse visibility (aka "data based AO") orientation +// // (ie baked visibility cone (aka "bent visibility cone") orientation) +// // := { normal aligned (default bentnormal value), bent normal } +// // X +// // baked diffuse visibility solid angle inference algo from baked visibility scalar +// // (ie baked visibility cone aperture angle or solid angle) +// // := { uniform (solid angle measure), cos weighted (projected solid angle measure with cone oriented with normal), +// // cos properly weighted wrt bentnormal (projected solid angle measure with cone oriented with bent normal) } +// // X +// // Vs (aka specular occlusion) calculation algo from baked diffuse values above and BSDF lobe properties +// // := {triACE - not tuned to account for bent normal, cone BSDF proxy intersection with bent cone, precise SPTD BSDF proxy lobe integration against the bent cone} } +// // +// // Note that in Lit SSAO is used with triACE as a clamp value to combine it with the calculations done with the baked AO, +// // by doing a min(VsFromTriACE+SSAO, VsFromBakedVisibility). +// // (See in particular Lit.hlsl:PostEvaluateBSDF(), MaterialEvaluation.hlsl:GetScreenSpaceAmbientOcclusionMultibounce(), +// // where the handed bsdfData.specularOcclusion is data based (baked texture). +// // +// // In StackLit, we allow control of the SSAO based SO and also the data based one. +// // +// // Of the algos described above, we can narrow to these combined options: +// // { Off, NoBentNormalTriACE, *ConeCone, *SPTD }, where * is any combination of using the normal or the bentnormal with any of 3 choices to interpret the AO +// // measure for the cone aperture. +// // +// // See also _DebugSpecularOcclusion. +// public enum SpecularOcclusionBaseMode +// { +// Off = 0, +// DirectFromAO = 1, // TriACE +// ConeConeFromBentAO = 2, +// SPTDIntegrationOfBentAO = 3, +// Custom = 4, +// // Custom user port input: For now, we will only have one input used for all lobes and only for data-based SO +// // (TODO: Normally would need a custom input per lobe. +// // Main rationale is that roughness can change IBL fetch direction and not only BSDF lobe width, and interface normal changes shading reference frame +// // hence it also changes the directional relation between the visibility cone and the BSDF lobe.) +// } + +// public enum SpecularOcclusionBaseModeSimple +// { +// Off = 0, +// DirectFromAO = 1, // TriACE +// SPTDIntegrationOfBentAO = 3, +// Custom = 4, +// } + +// public enum SpecularOcclusionAOConeSize +// { +// UniformAO, +// CosWeightedAO, +// CosWeightedBentCorrectAO +// } + +// // This is in case SSAO-based SO method requires it (the SSAO we have doesn't provide a direction) +// public enum SpecularOcclusionAOConeDir +// { +// GeomNormal, +// BentNormal, +// ShadingNormal +// } + +// // SO Bent cone fixup is only for methods using visibility cone and only for the data based SO: +// public enum SpecularOcclusionConeFixupMethod +// { +// Off, +// BoostBSDFRoughness, +// TiltDirectionToGeomNormal, +// BoostAndTilt, +// } + +// // Don't support Multiply +// public enum AlphaModeLit +// { +// Alpha, +// Premultiply, +// Additive, +// } + + +// // Common surface config: +// // +// [SerializeField] +// SurfaceType m_SurfaceType; + +// public SurfaceType surfaceType +// { +// get { return m_SurfaceType; } +// set +// { +// if (m_SurfaceType == value) +// return; + +// m_SurfaceType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// AlphaMode m_AlphaMode; + +// public AlphaMode alphaMode +// { +// get { return m_AlphaMode; } +// set +// { +// if (m_AlphaMode == value) +// return; + +// m_AlphaMode = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_BlendPreserveSpecular = true; + +// public ToggleData blendPreserveSpecular +// { +// get { return new ToggleData(m_BlendPreserveSpecular); } +// set +// { +// if (m_BlendPreserveSpecular == value.isOn) +// return; +// m_BlendPreserveSpecular = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_TransparencyFog = true; + +// public ToggleData transparencyFog +// { +// get { return new ToggleData(m_TransparencyFog); } +// set +// { +// if (m_TransparencyFog == value.isOn) +// return; +// m_TransparencyFog = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_Distortion; + +// public ToggleData distortion +// { +// get { return new ToggleData(m_Distortion); } +// set +// { +// if (m_Distortion == value.isOn) +// return; +// m_Distortion = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// DistortionMode m_DistortionMode; + +// public DistortionMode distortionMode +// { +// get { return m_DistortionMode; } +// set +// { +// if (m_DistortionMode == value) +// return; + +// m_DistortionMode = value; +// UpdateNodeAfterDeserialization(); // TODOTODO: no need, ModificationScope.Graph is enough? +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_DistortionDepthTest = true; + +// public ToggleData distortionDepthTest +// { +// get { return new ToggleData(m_DistortionDepthTest); } +// set +// { +// if (m_DistortionDepthTest == value.isOn) +// return; +// m_DistortionDepthTest = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaTest; + +// public ToggleData alphaTest +// { +// get { return new ToggleData(m_AlphaTest); } +// set +// { +// if (m_AlphaTest == value.isOn) +// return; +// m_AlphaTest = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } - [SerializeField] - bool m_AlphaToMask = false; - - public ToggleData alphaToMask - { - get { return new ToggleData(m_AlphaToMask); } - set - { - if (m_AlphaToMask == value.isOn) - return; - m_AlphaToMask = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_SortPriority; - - public int sortPriority - { - get { return m_SortPriority; } - set - { - if (m_SortPriority == value) - return; - m_SortPriority = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - DoubleSidedMode m_DoubleSidedMode; - - public DoubleSidedMode doubleSidedMode - { - get { return m_DoubleSidedMode; } - set - { - if (m_DoubleSidedMode == value) - return; - - m_DoubleSidedMode = value; - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - NormalDropOffSpace m_NormalDropOffSpace; - public NormalDropOffSpace normalDropOffSpace - { - get { return m_NormalDropOffSpace; } - set - { - if (m_NormalDropOffSpace == value) - return; - - m_NormalDropOffSpace = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - // Features: material surface input parametrizations - // - [SerializeField] - StackLit.BaseParametrization m_BaseParametrization; - - public StackLit.BaseParametrization baseParametrization - { - get { return m_BaseParametrization; } - set - { - if (m_BaseParametrization == value) - return; - - m_BaseParametrization = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_EnergyConservingSpecular = true; - - public ToggleData energyConservingSpecular - { - get { return new ToggleData(m_EnergyConservingSpecular); } - set - { - if (m_EnergyConservingSpecular == value.isOn) - return; - m_EnergyConservingSpecular = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - StackLit.DualSpecularLobeParametrization m_DualSpecularLobeParametrization; - - public StackLit.DualSpecularLobeParametrization dualSpecularLobeParametrization - { - get { return m_DualSpecularLobeParametrization; } - set - { - if (m_DualSpecularLobeParametrization == value) - return; - - m_DualSpecularLobeParametrization = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - // TODOTODO Change all to enable* ? - - // Features: "physical" material type enables - // - [SerializeField] - bool m_Anisotropy; - - public ToggleData anisotropy - { - get { return new ToggleData(m_Anisotropy); } - set - { - if (m_Anisotropy == value.isOn) - return; - m_Anisotropy = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_Coat; - - public ToggleData coat - { - get { return new ToggleData(m_Coat); } - set - { - if (m_Coat == value.isOn) - return; - m_Coat = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_CoatNormal; - - public ToggleData coatNormal - { - get { return new ToggleData(m_CoatNormal); } - set - { - if (m_CoatNormal == value.isOn) - return; - m_CoatNormal = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_DualSpecularLobe; - - public ToggleData dualSpecularLobe - { - get { return new ToggleData(m_DualSpecularLobe); } - set - { - if (m_DualSpecularLobe == value.isOn) - return; - m_DualSpecularLobe = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_CapHazinessWrtMetallic = true; - - public ToggleData capHazinessWrtMetallic - { - get { return new ToggleData(m_CapHazinessWrtMetallic); } - set - { - if (m_CapHazinessWrtMetallic == value.isOn) - return; - m_CapHazinessWrtMetallic = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_Iridescence; - - public ToggleData iridescence - { - get { return new ToggleData(m_Iridescence); } - set - { - if (m_Iridescence == value.isOn) - return; - m_Iridescence = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_SubsurfaceScattering; - - public ToggleData subsurfaceScattering - { - get { return new ToggleData(m_SubsurfaceScattering); } - set - { - if (m_SubsurfaceScattering == value.isOn) - return; - m_SubsurfaceScattering = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_Transmission; - - public ToggleData transmission - { - get { return new ToggleData(m_Transmission); } - set - { - if (m_Transmission == value.isOn) - return; - m_Transmission = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - // Features: other options - // - [SerializeField] - bool m_ReceiveDecals = true; - - public ToggleData receiveDecals - { - get { return new ToggleData(m_ReceiveDecals); } - set - { - if (m_ReceiveDecals == value.isOn) - return; - m_ReceiveDecals = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_ReceiveSSR = true; - - public ToggleData receiveSSR - { - get { return new ToggleData(m_ReceiveSSR); } - set - { - if (m_ReceiveSSR == value.isOn) - return; - m_ReceiveSSR = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AddPrecomputedVelocity = false; - - public ToggleData addPrecomputedVelocity - { - get { return new ToggleData(m_AddPrecomputedVelocity); } - set - { - if (m_AddPrecomputedVelocity == value.isOn) - return; - m_AddPrecomputedVelocity = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_GeometricSpecularAA; - - public ToggleData geometricSpecularAA - { - get { return new ToggleData(m_GeometricSpecularAA); } - set - { - if (m_GeometricSpecularAA == value.isOn) - return; - m_GeometricSpecularAA = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - //[SerializeField] - //bool m_SpecularOcclusion; // Main enable - // - //public ToggleData specularOcclusion - //{ - // get { return new ToggleData(m_SpecularOcclusion); } - // set - // { - // if (m_SpecularOcclusion == value.isOn) - // return; - // m_SpecularOcclusion = value.isOn; - // UpdateNodeAfterDeserialization(); - // Dirty(ModificationScope.Topological); - // } - //} - - [SerializeField] - SpecularOcclusionBaseMode m_ScreenSpaceSpecularOcclusionBaseMode = SpecularOcclusionBaseMode.DirectFromAO; - - public SpecularOcclusionBaseMode screenSpaceSpecularOcclusionBaseMode - { - get { return m_ScreenSpaceSpecularOcclusionBaseMode; } - set - { - if (m_ScreenSpaceSpecularOcclusionBaseMode == value) - return; - - m_ScreenSpaceSpecularOcclusionBaseMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - SpecularOcclusionBaseMode m_DataBasedSpecularOcclusionBaseMode; - - public SpecularOcclusionBaseMode dataBasedSpecularOcclusionBaseMode - { - get { return m_DataBasedSpecularOcclusionBaseMode; } - set - { - if (m_DataBasedSpecularOcclusionBaseMode == value) - return; - - m_DataBasedSpecularOcclusionBaseMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - SpecularOcclusionAOConeSize m_ScreenSpaceSpecularOcclusionAOConeSize; // This is still provided to tweak the effect of SSAO on the SO. - - public SpecularOcclusionAOConeSize screenSpaceSpecularOcclusionAOConeSize - { - get { return m_ScreenSpaceSpecularOcclusionAOConeSize; } - set - { - if (m_ScreenSpaceSpecularOcclusionAOConeSize == value) - return; - - m_ScreenSpaceSpecularOcclusionAOConeSize = value; - Dirty(ModificationScope.Graph); - } - } - - // See SpecularOcclusionAOConeDir for why we need this only for SSAO-based SO: - [SerializeField] - SpecularOcclusionAOConeDir m_ScreenSpaceSpecularOcclusionAOConeDir; - - public SpecularOcclusionAOConeDir screenSpaceSpecularOcclusionAOConeDir - { - get { return m_ScreenSpaceSpecularOcclusionAOConeDir; } - set - { - if (m_ScreenSpaceSpecularOcclusionAOConeDir == value) - return; - - m_ScreenSpaceSpecularOcclusionAOConeDir = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - SpecularOcclusionAOConeSize m_DataBasedSpecularOcclusionAOConeSize = SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO; // Only for SO methods using visibility cones (ie ConeCone and SPTD) - - public SpecularOcclusionAOConeSize dataBasedSpecularOcclusionAOConeSize - { - get { return m_DataBasedSpecularOcclusionAOConeSize; } - set - { - if (m_DataBasedSpecularOcclusionAOConeSize == value) - return; - - m_DataBasedSpecularOcclusionAOConeSize = value; - Dirty(ModificationScope.Graph); - } - } - - // TODO: this needs to be per lobe, less useful to have custom input. - //[SerializeField] - //bool m_SpecularOcclusionIsCustom; // allow custom input port for SO (replaces the data based one) - // - //public ToggleData specularOcclusionIsCustom - //{ - // get { return new ToggleData(m_SpecularOcclusionIsCustom); } - // set - // { - // if (m_SpecularOcclusionIsCustom == value.isOn) - // return; - // m_SpecularOcclusionIsCustom = value.isOn; - // UpdateNodeAfterDeserialization(); - // Dirty(ModificationScope.Topological); - // } - //} - - // SO Bent cone fixup is only for methods using visibility cone and only for the data based SO: - [SerializeField] - SpecularOcclusionConeFixupMethod m_SpecularOcclusionConeFixupMethod; - - public SpecularOcclusionConeFixupMethod specularOcclusionConeFixupMethod - { - get { return m_SpecularOcclusionConeFixupMethod; } - set - { - if (m_SpecularOcclusionConeFixupMethod == value) - return; - - m_SpecularOcclusionConeFixupMethod = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - // Features: Advanced options - // - [SerializeField] - bool m_AnisotropyForAreaLights = true; - - public ToggleData anisotropyForAreaLights - { - get { return new ToggleData(m_AnisotropyForAreaLights); } - set - { - if (m_AnisotropyForAreaLights == value.isOn) - return; - m_AnisotropyForAreaLights = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_RecomputeStackPerLight; - - public ToggleData recomputeStackPerLight - { - get { return new ToggleData(m_RecomputeStackPerLight); } - set - { - if (m_RecomputeStackPerLight == value.isOn) - return; - m_RecomputeStackPerLight = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_HonorPerLightMinRoughness; - - public ToggleData honorPerLightMinRoughness - { - get { return new ToggleData(m_HonorPerLightMinRoughness); } - set - { - if (m_HonorPerLightMinRoughness == value.isOn) - return; - m_HonorPerLightMinRoughness = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_ShadeBaseUsingRefractedAngles; - - public ToggleData shadeBaseUsingRefractedAngles - { - get { return new ToggleData(m_ShadeBaseUsingRefractedAngles); } - set - { - if (m_ShadeBaseUsingRefractedAngles == value.isOn) - return; - m_ShadeBaseUsingRefractedAngles = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_Debug; - - public ToggleData debug - { - get { return new ToggleData(m_Debug); } - set - { - if (m_Debug == value.isOn) - return; - m_Debug = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_DevMode; - - public ToggleData devMode - { - get { return new ToggleData(m_DevMode); } - set - { - if (m_DevMode == value.isOn) - return; - m_DevMode = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_overrideBakedGI; - - public ToggleData overrideBakedGI - { - get { return new ToggleData(m_overrideBakedGI); } - set - { - if (m_overrideBakedGI == value.isOn) - return; - m_overrideBakedGI = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_depthOffset; - - public ToggleData depthOffset - { - get { return new ToggleData(m_depthOffset); } - set - { - if (m_depthOffset == value.isOn) - return; - m_depthOffset = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ZWrite; - - public ToggleData zWrite - { - get { return new ToggleData(m_ZWrite); } - set - { - if (m_ZWrite == value.isOn) - return; - m_ZWrite = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; - public TransparentCullMode transparentCullMode - { - get => m_transparentCullMode; - set - { - if (m_transparentCullMode == value) - return; - - m_transparentCullMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - CompareFunction m_ZTest = CompareFunction.LessEqual; - public CompareFunction zTest - { - get => m_ZTest; - set - { - if (m_ZTest == value) - return; - - m_ZTest = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_SupportLodCrossFade; - - public ToggleData supportLodCrossFade - { - get { return new ToggleData(m_SupportLodCrossFade); } - set - { - if (m_SupportLodCrossFade == value.isOn) - return; - m_SupportLodCrossFade = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Node); - } - } - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_MaterialNeedsUpdateHash = 0; - - int ComputeMaterialNeedsUpdateHash() - { - int hash = 0; - - hash |= (alphaTest.isOn ? 0 : 1) << 0; - hash |= (receiveSSR.isOn ? 0 : 1) << 2; - hash |= (RequiresSplitLighting() ? 0 : 1) << 3; - - return hash; - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public StackLitMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - public override string documentationURL - { - get { return null; } - } - - public bool HasDistortion() - { - return (surfaceType == SurfaceType.Transparent && distortion.isOn); - } - - public static bool SpecularOcclusionModeUsesVisibilityCone(SpecularOcclusionBaseMode soMethod) - { - return (soMethod == SpecularOcclusionBaseMode.ConeConeFromBentAO - || soMethod == SpecularOcclusionBaseMode.SPTDIntegrationOfBentAO); - } - - public bool SpecularOcclusionUsesBentNormal() - { - return (SpecularOcclusionModeUsesVisibilityCone(dataBasedSpecularOcclusionBaseMode) - || (SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) - && screenSpaceSpecularOcclusionAOConeDir == SpecularOcclusionAOConeDir.BentNormal)); - } - - public bool DataBasedSpecularOcclusionIsCustom() - { - return dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Custom; - } - - public static bool SpecularOcclusionConeFixupMethodModifiesRoughness(SpecularOcclusionConeFixupMethod soConeFixupMethod) - { - return (soConeFixupMethod == SpecularOcclusionConeFixupMethod.BoostBSDFRoughness - || soConeFixupMethod == SpecularOcclusionConeFixupMethod.BoostAndTilt); - } - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "StackLit Master"; - - List validSlots = new List(); - - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(PositionSlotId); - - AddSlot(new NormalMaterialSlot(VertexNormalSlotId, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexNormalSlotId); - - AddSlot(new TangentMaterialSlot(VertexTangentSlotId, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexTangentSlotId); - - RemoveSlot(NormalSlotId); - var coordSpace = CoordinateSpace.Tangent; - switch (m_NormalDropOffSpace) - { - case NormalDropOffSpace.Tangent: - coordSpace = CoordinateSpace.Tangent; - break; - case NormalDropOffSpace.World: - coordSpace = CoordinateSpace.World; - break; - case NormalDropOffSpace.Object: - coordSpace = CoordinateSpace.Object; - break; - } - AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, coordSpace, ShaderStageCapability.Fragment)); - validSlots.Add(NormalSlotId); - - AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(BentNormalSlotId); - - AddSlot(new TangentMaterialSlot(TangentSlotId, TangentSlotName, TangentSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(TangentSlotId); - - AddSlot(new ColorRGBMaterialSlot(BaseColorSlotId, BaseColorSlotName, BaseColorSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(BaseColorSlotId); - - if (baseParametrization == StackLit.BaseParametrization.BaseMetallic) - { - AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(MetallicSlotId); - AddSlot(new Vector1MaterialSlot(DielectricIorSlotId, DielectricIorSlotName, DielectricIorSlotName, SlotType.Input, 1.5f, ShaderStageCapability.Fragment)); - validSlots.Add(DielectricIorSlotId); - } - else if (baseParametrization == StackLit.BaseParametrization.SpecularColor) - { - AddSlot(new ColorRGBMaterialSlot(SpecularColorSlotId, SpecularColorSlotName, SpecularColorSlotName, SlotType.Input, Color.white, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularColorSlotId); - } - - AddSlot(new Vector1MaterialSlot(SmoothnessASlotId, SmoothnessASlotName, SmoothnessASlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(SmoothnessASlotId); - - if (anisotropy.isOn) - { - AddSlot(new Vector1MaterialSlot(AnisotropyASlotId, AnisotropyASlotName, AnisotropyASlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AnisotropyASlotId); - } - - AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionSlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AmbientOcclusionSlotId); - - // TODO: we would ideally need one value per lobe - if (DataBasedSpecularOcclusionIsCustom()) - { - AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularOcclusionSlotId); - } - - if (SpecularOcclusionUsesBentNormal() && specularOcclusionConeFixupMethod != SpecularOcclusionConeFixupMethod.Off) - { - AddSlot(new Vector1MaterialSlot(SOFixupVisibilityRatioThresholdSlotId, SOFixupVisibilityRatioThresholdSlotName, SOFixupVisibilityRatioThresholdSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); - validSlots.Add(SOFixupVisibilityRatioThresholdSlotId); - AddSlot(new Vector1MaterialSlot(SOFixupStrengthFactorSlotId, SOFixupStrengthFactorSlotName, SOFixupStrengthFactorSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SOFixupStrengthFactorSlotId); - - if (SpecularOcclusionConeFixupMethodModifiesRoughness(specularOcclusionConeFixupMethod)) - { - AddSlot(new Vector1MaterialSlot(SOFixupMaxAddedRoughnessSlotId, SOFixupMaxAddedRoughnessSlotName, SOFixupMaxAddedRoughnessSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); - validSlots.Add(SOFixupMaxAddedRoughnessSlotId); - } - } - - if (coat.isOn) - { - AddSlot(new Vector1MaterialSlot(CoatSmoothnessSlotId, CoatSmoothnessSlotName, CoatSmoothnessSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(CoatSmoothnessSlotId); - AddSlot(new Vector1MaterialSlot(CoatIorSlotId, CoatIorSlotName, CoatIorSlotName, SlotType.Input, 1.4f, ShaderStageCapability.Fragment)); - validSlots.Add(CoatIorSlotId); - AddSlot(new Vector1MaterialSlot(CoatThicknessSlotId, CoatThicknessSlotName, CoatThicknessSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(CoatThicknessSlotId); - AddSlot(new ColorRGBMaterialSlot(CoatExtinctionSlotId, CoatExtinctionSlotName, CoatExtinctionSlotName, SlotType.Input, Color.white, ColorMode.HDR, ShaderStageCapability.Fragment)); - validSlots.Add(CoatExtinctionSlotId); - - if (coatNormal.isOn) - { - AddSlot(new NormalMaterialSlot(CoatNormalSlotId, CoatNormalSlotName, CoatNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); - validSlots.Add(CoatNormalSlotId); - } - - AddSlot(new Vector1MaterialSlot(CoatMaskSlotId, CoatMaskSlotName, CoatMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(CoatMaskSlotId); - } - - if (dualSpecularLobe.isOn) - { - if (dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.Direct) - { - AddSlot(new Vector1MaterialSlot(SmoothnessBSlotId, SmoothnessBSlotName, SmoothnessBSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(SmoothnessBSlotId); - AddSlot(new Vector1MaterialSlot(LobeMixSlotId, LobeMixSlotName, LobeMixSlotName, SlotType.Input, 0.3f, ShaderStageCapability.Fragment)); - validSlots.Add(LobeMixSlotId); - } - else if (dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss) - { - AddSlot(new Vector1MaterialSlot(HazinessSlotId, HazinessSlotName, HazinessSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); - validSlots.Add(HazinessSlotId); - AddSlot(new Vector1MaterialSlot(HazeExtentSlotId, HazeExtentSlotName, HazeExtentSlotName, SlotType.Input, 3.0f, ShaderStageCapability.Fragment)); - validSlots.Add(HazeExtentSlotId); - - if (capHazinessWrtMetallic.isOn && baseParametrization == StackLit.BaseParametrization.BaseMetallic) // the later should be an assert really - { - AddSlot(new Vector1MaterialSlot(HazyGlossMaxDielectricF0SlotId, HazyGlossMaxDielectricF0SlotName, HazyGlossMaxDielectricF0SlotName, SlotType.Input, 0.25f, ShaderStageCapability.Fragment)); - validSlots.Add(HazyGlossMaxDielectricF0SlotId); - } - } - - if (anisotropy.isOn) - { - AddSlot(new Vector1MaterialSlot(AnisotropyBSlotId, AnisotropyBSlotName, AnisotropyBSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AnisotropyBSlotId); - } - } - - if (iridescence.isOn) - { - AddSlot(new Vector1MaterialSlot(IridescenceMaskSlotId, IridescenceMaskSlotName, IridescenceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(IridescenceMaskSlotId); - AddSlot(new Vector1MaterialSlot(IridescenceThicknessSlotId, IridescenceThicknessSlotDisplayName, IridescenceThicknessSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(IridescenceThicknessSlotId); - if (coat.isOn) - { - AddSlot(new Vector1MaterialSlot(IridescenceCoatFixupTIRSlotId, IridescenceCoatFixupTIRSlotName, IridescenceCoatFixupTIRSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(IridescenceCoatFixupTIRSlotId); - AddSlot(new Vector1MaterialSlot(IridescenceCoatFixupTIRClampSlotId, IridescenceCoatFixupTIRClampSlotName, IridescenceCoatFixupTIRClampSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(IridescenceCoatFixupTIRClampSlotId); - } - } - - if (subsurfaceScattering.isOn) - { - AddSlot(new Vector1MaterialSlot(SubsurfaceMaskSlotId, SubsurfaceMaskSlotName, SubsurfaceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(SubsurfaceMaskSlotId); - } - - if (transmission.isOn) - { - AddSlot(new Vector1MaterialSlot(ThicknessSlotId, ThicknessSlotName, ThicknessSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(ThicknessSlotId); - } - - if (subsurfaceScattering.isOn || transmission.isOn) - { - AddSlot(new DiffusionProfileInputMaterialSlot(DiffusionProfileHashSlotId, DiffusionProfileHashSlotDisplayName, DiffusionProfileHashSlotName, ShaderStageCapability.Fragment)); - validSlots.Add(DiffusionProfileHashSlotId); - } - - AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaSlotId); - - if (alphaTest.isOn) - { - AddSlot(new Vector1MaterialSlot(AlphaClipThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaClipThresholdSlotId); - } - - AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); - validSlots.Add(EmissionSlotId); - - if (HasDistortion()) - { - AddSlot(new Vector2MaterialSlot(DistortionSlotId, DistortionSlotDisplayName, DistortionSlotName, SlotType.Input, new Vector2(2.0f, -1.0f), ShaderStageCapability.Fragment)); - validSlots.Add(DistortionSlotId); - - AddSlot(new Vector1MaterialSlot(DistortionBlurSlotId, DistortionBlurSlotName, DistortionBlurSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(DistortionBlurSlotId); - } - - if (geometricSpecularAA.isOn) - { - AddSlot(new Vector1MaterialSlot(SpecularAAScreenSpaceVarianceSlotId, SpecularAAScreenSpaceVarianceSlotName, SpecularAAScreenSpaceVarianceSlotName, SlotType.Input, 0.1f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularAAScreenSpaceVarianceSlotId); - - AddSlot(new Vector1MaterialSlot(SpecularAAThresholdSlotId, SpecularAAThresholdSlotName, SpecularAAThresholdSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); - validSlots.Add(SpecularAAThresholdSlotId); - } - - if (overrideBakedGI.isOn) - { - AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(LightingSlotId); - AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); - validSlots.Add(BackLightingSlotId); - } - - if (depthOffset.isOn) - { - AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - validSlots.Add(DepthOffsetSlotId); - } - - RemoveSlotsNameNotMatching(validSlots, true); - } - - public VisualElement CreateSettingsElement() - { - return new StackLitSettingsView(this); - } - - public string renderQueueTag - { - get - { - var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); - return HDRenderQueue.GetShaderTagValue(queue); - } - } - - public string renderTypeTag => HDRenderTypeTags.HDLitShader.ToString(); - - // Reference for GetConditionalFields - // ------------------------------------------- - // - // Properties (enables etc): - // - // ok+MFD -> material feature define: means we need a predicate, because we will transform it into a #define that match the material feature, shader_feature-defined, that the rest of the shader code uses. - // - // ok+MFD masterNode.baseParametrization --> even though we can just always transfer present fields (check with $SurfaceDescription.*) like specularcolor and metallic, - // we need to translate this into the _MATERIAL_FEATURE_SPECULAR_COLOR define. - // - // ok masterNode.energyConservingSpecular - // - // ~~~~ ok+MFD: these are almost all material features: - // masterNode.anisotropy - // masterNode.coat - // masterNode.coatNormal - // masterNode.dualSpecularLobe - // masterNode.dualSpecularLobeParametrization - // masterNode.capHazinessWrtMetallic -> not a material feature define, as such, we will create a combined predicate for the HazyGlossMaxDielectricF0 slot dependency - // instead of adding a #define in the template... - // masterNode.iridescence - // masterNode.subsurfaceScattering - // masterNode.transmission - // - // ~~~~ ...ok+MFD: these are all material features - // - // ok masterNode.receiveDecals - // ok masterNode.receiveSSR - // ok masterNode.geometricSpecularAA --> check, a way to combine predicates and/or exclude passes: TODOTODO What about WRITE_NORMAL_BUFFER passes ? (ie smoothness) - // ok masterNode.specularOcclusion --> no use for it though! see comments. - // - // ~~~~ ok+D: these require translation to defines also... - // - // masterNode.anisotropyForAreaLights - // masterNode.recomputeStackPerLight - // masterNode.shadeBaseUsingRefractedAngles - // masterNode.debug - - // Inputs: Most inputs don't need a specific predicate in addition to the "present field predicate", ie the $SurfaceDescription.*, - // but in some special cases we check connectivity to avoid processing the default value for nothing... - // (see specular occlusion with _MASKMAP and _BENTNORMALMAP in LitData, or _TANGENTMAP, _BENTNORMALMAP, etc. which act a bit like that - // although they also avoid sampling in that case, but default tiny texture map sampling isn't a big hit since they are all cached once - // a default "unityTexWhite" is sampled, it is cached for everyone defaulting to white...) - // - // ok+ means there's a specific additional predicate - // - // ok masterNode.BaseColorSlotId - // ok masterNode.NormalSlotId - // - // ok+ masterNode.BentNormalSlotId --> Dependency of the predicate on IsSlotConnected avoids processing even if the slots - // ok+ masterNode.TangentSlotId are always there so any pass that declares its use in PixelShaderSlots will have the field in SurfaceDescription, - // but it's not necessarily useful (if slot isnt connected, waste processing on potentially static expressions if - // shader compiler cant optimize...and even then, useless to have static override value for those.) - // - // TODOTODO: Note you could have the same argument for NormalSlot (which we dont exclude with a predicate). - // Also and anyways, the compiler is smart enough not to do the TS to WS matrix multiply on a (0,0,1) vector. - // - // ok+ masterNode.CoatNormalSlotId -> we already have a "material feature" coat normal map so can use that instead, although using that former, we assume the coat normal slot - // will be there, but it's ok, we can #ifdef the code on the material feature define, and use the $SurfaceDescription.CoatNormal predicate - // for the actual assignment, - // although for that one we could again - // use the "connected" condition like for tangent and bentnormal - // - // The following are all ok, no need beyond present field predicate, ie $SurfaceDescription.*, - // except special cases where noted - // - // ok masterNode.SubsurfaceMaskSlotId - // ok masterNode.ThicknessSlotId - // ok masterNode.DiffusionProfileHashSlotId - // ok masterNode.IridescenceMaskSlotId - // ok masterNode.IridescenceThicknessSlotId - // ok masterNode.SpecularColorSlotId - // ok masterNode.DielectricIorSlotId - // ok masterNode.MetallicSlotId - // ok masterNode.EmissionSlotId - // ok masterNode.SmoothnessASlotId - // ok masterNode.SmoothnessBSlotId - // ok+ masterNode.AmbientOcclusionSlotId -> defined a specific predicate, but not used, see StackLitData. - // ok masterNode.AlphaSlotId - // ok masterNode.AlphaClipThresholdSlotId - // ok masterNode.AnisotropyASlotId - // ok masterNode.AnisotropyBSlotId - // ok masterNode.SpecularAAScreenSpaceVarianceSlotId - // ok masterNode.SpecularAAThresholdSlotId - // ok masterNode.CoatSmoothnessSlotId - // ok masterNode.CoatIorSlotId - // ok masterNode.CoatThicknessSlotId - // ok masterNode.CoatExtinctionSlotId - // ok masterNode.LobeMixSlotId - // ok masterNode.HazinessSlotId - // ok masterNode.HazeExtentSlotId - // ok masterNode.HazyGlossMaxDielectricF0SlotId -> No need for a predicate, the needed predicate is the combined (capHazinessWrtMetallic + HazyGlossMaxDielectricF0) - // "leaking case": if the 2 are true, but we're not in metallic mode, the capHazinessWrtMetallic property is wrong, - // that means the master node is really misconfigured, spew an error, should never happen... - // If it happens, it's because we forgot UpdateNodeAfterDeserialization() call when modifying the capHazinessWrtMetallic or baseParametrization - // properties, maybe through debug etc. - // - // ok masterNode.DistortionSlotId -> Warning: peculiarly, instead of using $SurfaceDescription.Distortion and DistortionBlur, - // ok masterNode.DistortionBlurSlotId we do an #if (SHADERPASS == SHADERPASS_DISTORTION) in the template, instead of - // relying on other passed NOT to include the DistortionSlotId in their PixelShaderSlots!! - - // Other to deal with, and - // Common between Lit and StackLit: - // - // doubleSidedMode, alphaTest, receiveDecals, - // surfaceType, alphaMode, blendPreserveSpecular, transparencyFog, - // distortion, distortionMode, distortionDepthTest, - // sortPriority (int) - // geometricSpecularAA, energyConservingSpecular, specularOcclusion - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); - - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || - IsSlotConnected(VertexNormalSlotId) || - IsSlotConnected(VertexTangentSlotId)), - new ConditionalField(Fields.GraphPixel, true), - - // Surface Type - new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), - new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), - - // Structs - new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && - !pass.Equals(HDStackLitSubTarget.StackLitPasses.MotionVectors)), - - // Material - new ConditionalField(HDFields.Anisotropy, anisotropy.isOn), - new ConditionalField(HDFields.Coat, coat.isOn), - new ConditionalField(HDFields.CoatMask, coat.isOn && pass.pixelPorts.Contains(CoatMaskSlotId) && - (IsSlotConnected(CoatMaskSlotId) || - (FindSlot(CoatMaskSlotId).value != 0.0f && - FindSlot(CoatMaskSlotId).value != 1.0f))), - new ConditionalField(HDFields.CoatMaskZero, coat.isOn && pass.pixelPorts.Contains(CoatMaskSlotId) && - FindSlot(CoatMaskSlotId).value == 0.0f), - new ConditionalField(HDFields.CoatMaskOne, coat.isOn && pass.pixelPorts.Contains(CoatMaskSlotId) && - FindSlot(CoatMaskSlotId).value == 1.0f), - new ConditionalField(HDFields.CoatNormal, coatNormal.isOn && pass.pixelPorts.Contains(CoatNormalSlotId)), - new ConditionalField(HDFields.Iridescence, iridescence.isOn), - new ConditionalField(HDFields.SubsurfaceScattering, subsurfaceScattering.isOn && surfaceType != SurfaceType.Transparent), - new ConditionalField(HDFields.Transmission, transmission.isOn), - new ConditionalField(HDFields.DualSpecularLobe, dualSpecularLobe.isOn), - - // Normal Drop Off Space - new ConditionalField(Fields.NormalDropOffOS, normalDropOffSpace == NormalDropOffSpace.Object), - new ConditionalField(Fields.NormalDropOffTS, normalDropOffSpace == NormalDropOffSpace.Tangent), - new ConditionalField(Fields.NormalDropOffWS, normalDropOffSpace == NormalDropOffSpace.World), - - // Distortion - new ConditionalField(HDFields.DistortionDepthTest, distortionDepthTest.isOn), - new ConditionalField(HDFields.DistortionAdd, distortionMode == DistortionMode.Add), - new ConditionalField(HDFields.DistortionMultiply, distortionMode == DistortionMode.Multiply), - new ConditionalField(HDFields.DistortionReplace, distortionMode == DistortionMode.Replace), - new ConditionalField(HDFields.TransparentDistortion, surfaceType != SurfaceType.Opaque && distortion.isOn), - - // Base Parametrization - // Even though we can just always transfer the present (check with $SurfaceDescription.*) fields like specularcolor - // and metallic, we still need to know the baseParametrization in the template to translate into the - // _MATERIAL_FEATURE_SPECULAR_COLOR define: - new ConditionalField(HDFields.BaseParamSpecularColor, baseParametrization == StackLit.BaseParametrization.SpecularColor), - - // Dual Specular Lobe Parametrization - new ConditionalField(HDFields.HazyGloss, dualSpecularLobe.isOn && - dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss), - - // Misc - new ConditionalField(Fields.AlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), - new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), - new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && alphaToMask.isOn), - new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), - new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), - new ConditionalField(HDFields.EnergyConservingSpecular, energyConservingSpecular.isOn), - new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), - new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), - new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), - new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && - pass.pixelPorts.Contains(BentNormalSlotId)), - new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && - (IsSlotConnected(AmbientOcclusionSlotId) || - ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), - new ConditionalField(HDFields.Tangent, IsSlotConnected(TangentSlotId) && - pass.pixelPorts.Contains(TangentSlotId)), - new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && - pass.pixelPorts.Contains(LightingSlotId)), - new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && - pass.pixelPorts.Contains(BackLightingSlotId)), - new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), - // Option for baseParametrization == Metallic && DualSpecularLobeParametrization == HazyGloss: - // Again we assume masternode has HazyGlossMaxDielectricF0 which should always be the case - // if capHazinessWrtMetallic.isOn. - new ConditionalField(HDFields.CapHazinessIfNotMetallic, dualSpecularLobe.isOn && - dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss && - capHazinessWrtMetallic.isOn && baseParametrization == StackLit.BaseParametrization.BaseMetallic - && pass.pixelPorts.Contains(HazyGlossMaxDielectricF0SlotId)), - // Note here we combine an "enable"-like predicate and the $SurfaceDescription.(slotname) predicate - // into a single $GeometricSpecularAA pedicate. - // - // ($SurfaceDescription.* predicates are useful to make sure the field is present in the struct in the template. - // The field will be present if both the master node and pass have the slotid, see this set intersection we make - // in GenerateSurfaceDescriptionStruct(), with HDSubShaderUtilities.FindMaterialSlotsOnNode().) - // - // Normally, since the feature enable adds the required slots, only the $SurfaceDescription.* would be required, - // but some passes might not need it and not declare the PixelShaderSlot, or, inversely, the pass might not - // declare it as a way to avoid it. - // - // IE this has also the side effect to disable geometricSpecularAA - even if "on" - for passes that don't explicitly - // advertise these slots(eg for a general feature, with separate "enable" and "field present" predicates, the - // template could take a default value and process it anyway if a feature is "on"). - // - // (Note we can achieve the same results in the template on just single predicates by making defines out of them, - // and using #if defined() && etc) - new ConditionalField(HDFields.GeometricSpecularAA, geometricSpecularAA.isOn && - pass.pixelPorts.Contains(SpecularAAThresholdSlotId) && - pass.pixelPorts.Contains(SpecularAAScreenSpaceVarianceSlotId)), - new ConditionalField(HDFields.SpecularAA, geometricSpecularAA.isOn && - pass.pixelPorts.Contains(SpecularAAThresholdSlotId) && - pass.pixelPorts.Contains(SpecularAAScreenSpaceVarianceSlotId)), - new ConditionalField(HDFields.SpecularOcclusion, screenSpaceSpecularOcclusionBaseMode != SpecularOcclusionBaseMode.Off || - dataBasedSpecularOcclusionBaseMode != SpecularOcclusionBaseMode.Off), - - // Advanced - new ConditionalField(HDFields.AnisotropyForAreaLights, anisotropyForAreaLights.isOn), - new ConditionalField(HDFields.RecomputeStackPerLight, recomputeStackPerLight.isOn), - new ConditionalField(HDFields.HonorPerLightMinRoughness, honorPerLightMinRoughness.isOn), - new ConditionalField(HDFields.ShadeBaseUsingRefractedAngles, shadeBaseUsingRefractedAngles.isOn), - new ConditionalField(HDFields.StackLitDebug, debug.isOn), - - // Screen Space Specular Occlusion Base Mode - new ConditionalField(HDFields.SSSpecularOcclusionBaseModeOff, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Off), - new ConditionalField(HDFields.SSSpecularOcclusionBaseModeDirectFromAO, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.DirectFromAO), - new ConditionalField(HDFields.SSSpecularOcclusionBaseModeConeConeFromBentAO, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.ConeConeFromBentAO), - new ConditionalField(HDFields.SSSpecularOcclusionBaseModeSPTDIntegrationOfBentAO, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.SPTDIntegrationOfBentAO), - new ConditionalField(HDFields.SSSpecularOcclusionBaseModeCustom, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Custom), - - // Screen Space Specular Occlusion AO Cone Size - new ConditionalField(HDFields.SSSpecularOcclusionAOConeSizeUniformAO, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && - screenSpaceSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.UniformAO), - new ConditionalField(HDFields.SSSpecularOcclusionAOConeSizeCosWeightedAO, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && - screenSpaceSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.CosWeightedAO), - new ConditionalField(HDFields.SSSpecularOcclusionAOConeSizeCosWeightedBentCorrectAO, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && - screenSpaceSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO), - - // Screen Space Specular Occlusion AO Cone Dir - new ConditionalField(HDFields.SSSpecularOcclusionAOConeDirGeomNormal, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && - screenSpaceSpecularOcclusionAOConeDir == SpecularOcclusionAOConeDir.GeomNormal), - new ConditionalField(HDFields.SSSpecularOcclusionAOConeDirBentNormal, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && - screenSpaceSpecularOcclusionAOConeDir == SpecularOcclusionAOConeDir.BentNormal), - new ConditionalField(HDFields.SSSpecularOcclusionAOConeDirShadingNormal, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && - screenSpaceSpecularOcclusionAOConeDir == SpecularOcclusionAOConeDir.ShadingNormal), - - // Data Based Specular Occlusion Base Mode - new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeOff, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Off), - new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeDirectFromAO, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.DirectFromAO), - new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeConeConeFromBentAO, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.ConeConeFromBentAO), - new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeSPTDIntegrationOfBentAO, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.SPTDIntegrationOfBentAO), - new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeCustom, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Custom), - - // Data Based Specular Occlusion AO Cone Size - new ConditionalField(HDFields.DataBasedSpecularOcclusionAOConeSizeUniformAO, SpecularOcclusionModeUsesVisibilityCone(dataBasedSpecularOcclusionBaseMode) && - dataBasedSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.UniformAO), - new ConditionalField(HDFields.DataBasedSpecularOcclusionAOConeSizeCosWeightedAO, SpecularOcclusionModeUsesVisibilityCone(dataBasedSpecularOcclusionBaseMode) && - dataBasedSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.CosWeightedAO), - new ConditionalField(HDFields.DataBasedSpecularOcclusionAOConeSizeCosWeightedBentCorrectAO, SpecularOcclusionModeUsesVisibilityCone(dataBasedSpecularOcclusionBaseMode) && - dataBasedSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO), - - // Specular Occlusion Cone Fixup Method - new ConditionalField(HDFields.SpecularOcclusionConeFixupMethodOff, SpecularOcclusionUsesBentNormal() && - specularOcclusionConeFixupMethod == SpecularOcclusionConeFixupMethod.Off), - new ConditionalField(HDFields.SpecularOcclusionConeFixupMethodBoostBSDFRoughness, SpecularOcclusionUsesBentNormal() && - specularOcclusionConeFixupMethod == SpecularOcclusionConeFixupMethod.BoostBSDFRoughness), - new ConditionalField(HDFields.SpecularOcclusionConeFixupMethodTiltDirectionToGeomNormal, SpecularOcclusionUsesBentNormal() && - specularOcclusionConeFixupMethod == SpecularOcclusionConeFixupMethod.TiltDirectionToGeomNormal), - new ConditionalField(HDFields.SpecularOcclusionConeFixupMethodBoostAndTilt, SpecularOcclusionUsesBentNormal() && - specularOcclusionConeFixupMethod == SpecularOcclusionConeFixupMethod.BoostAndTilt), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); - material.SetFloat(kDoubleSidedEnable, doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); - material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); - material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)zTest); - material.SetFloat(kTransparentCullMode, (int)transparentCullMode); - material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); - // No sorting priority for shader graph preview - var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); - - StackLitGUI.SetupMaterialKeywordsAndPass(material); - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public bool RequiresSplitLighting() - { - return subsurfaceScattering.isOn; - } - - public override object saveContext - { - get - { - int hash = ComputeMaterialNeedsUpdateHash(); - - bool needsUpdate = hash != m_MaterialNeedsUpdateHash; - - if (needsUpdate) - m_MaterialNeedsUpdateHash = hash; - - return new HDSaveContext{ updateMaterials = needsUpdate }; - } - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - if (debug.isOn) - { - // We have useful debug options in StackLit, so add them always, and let the UI editor (non shadergraph) handle displaying them - // since this is also the editor that controls the keyword switching for the debug mode. - collector.AddShaderProperty(new Vector4ShaderProperty() - { - overrideReferenceName = "_DebugEnvLobeMask", // xyz is environments lights lobe 0 1 2 Enable, w is Enable VLayering - displayName = "_DebugEnvLobeMask", - value = new Vector4(1.0f, 1.0f, 1.0f, 1.0f) - }); - collector.AddShaderProperty(new Vector4ShaderProperty() - { - overrideReferenceName = "_DebugLobeMask", // xyz is analytical dirac lights lobe 0 1 2 Enable", false), - displayName = "_DebugLobeMask", - value = new Vector4(1.0f, 1.0f, 1.0f, 1.0f) - }); - collector.AddShaderProperty(new Vector4ShaderProperty() - { - overrideReferenceName = "_DebugAniso", // x is Hack Enable, w is factor - displayName = "_DebugAniso", - value = new Vector4(1.0f, 0.0f, 0.0f, 1000.0f) - }); - // _DebugSpecularOcclusion: - // - // eg (2,2,1,2) : - // .x = SO method {0 = fromAO, 1 = conecone, 2 = SPTD}, - // .y = bentao algo {0 = uniform, cos, bent cos}, - // .z = use upper visible hemisphere clipping, - // .w = The last component of _DebugSpecularOcclusion controls debug visualization: - // -1 colors the object according to the SO algorithm used, - // and values from 1 to 4 controls what the lighting debug display mode will show when set to show "indirect specular occlusion": - // Since there's not one value in our case, - // 0 will show the object all red to indicate to choose one, 1-4 corresponds to showing - // 1 = coat SO, 2 = base lobe A SO, 3 = base lobe B SO, 4 = shows the result of sampling the SSAO texture (screenSpaceAmbientOcclusion). - collector.AddShaderProperty(new Vector4ShaderProperty() - { - overrideReferenceName = "_DebugSpecularOcclusion", - displayName = "_DebugSpecularOcclusion", - value = new Vector4(2.0f, 2.0f, 1.0f, 2.0f) - }); - } - - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (addPrecomputedVelocity.isOn) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, RequiresSplitLighting(), receiveSSR.isOn); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - surfaceType, - HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), - sortPriority, - alphaToMask.isOn, - zWrite.isOn, - transparentCullMode, - zTest, - false, - transparencyFog.isOn - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, false); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); - - base.CollectShaderProperties(collector, generationMode); - } - } -} +// [SerializeField] +// bool m_AlphaToMask = false; + +// public ToggleData alphaToMask +// { +// get { return new ToggleData(m_AlphaToMask); } +// set +// { +// if (m_AlphaToMask == value.isOn) +// return; +// m_AlphaToMask = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_SortPriority; + +// public int sortPriority +// { +// get { return m_SortPriority; } +// set +// { +// if (m_SortPriority == value) +// return; +// m_SortPriority = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// DoubleSidedMode m_DoubleSidedMode; + +// public DoubleSidedMode doubleSidedMode +// { +// get { return m_DoubleSidedMode; } +// set +// { +// if (m_DoubleSidedMode == value) +// return; + +// m_DoubleSidedMode = value; +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// NormalDropOffSpace m_NormalDropOffSpace; +// public NormalDropOffSpace normalDropOffSpace +// { +// get { return m_NormalDropOffSpace; } +// set +// { +// if (m_NormalDropOffSpace == value) +// return; + +// m_NormalDropOffSpace = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// // Features: material surface input parametrizations +// // +// [SerializeField] +// StackLit.BaseParametrization m_BaseParametrization; + +// public StackLit.BaseParametrization baseParametrization +// { +// get { return m_BaseParametrization; } +// set +// { +// if (m_BaseParametrization == value) +// return; + +// m_BaseParametrization = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_EnergyConservingSpecular = true; + +// public ToggleData energyConservingSpecular +// { +// get { return new ToggleData(m_EnergyConservingSpecular); } +// set +// { +// if (m_EnergyConservingSpecular == value.isOn) +// return; +// m_EnergyConservingSpecular = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// StackLit.DualSpecularLobeParametrization m_DualSpecularLobeParametrization; + +// public StackLit.DualSpecularLobeParametrization dualSpecularLobeParametrization +// { +// get { return m_DualSpecularLobeParametrization; } +// set +// { +// if (m_DualSpecularLobeParametrization == value) +// return; + +// m_DualSpecularLobeParametrization = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// // TODOTODO Change all to enable* ? + +// // Features: "physical" material type enables +// // +// [SerializeField] +// bool m_Anisotropy; + +// public ToggleData anisotropy +// { +// get { return new ToggleData(m_Anisotropy); } +// set +// { +// if (m_Anisotropy == value.isOn) +// return; +// m_Anisotropy = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_Coat; + +// public ToggleData coat +// { +// get { return new ToggleData(m_Coat); } +// set +// { +// if (m_Coat == value.isOn) +// return; +// m_Coat = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_CoatNormal; + +// public ToggleData coatNormal +// { +// get { return new ToggleData(m_CoatNormal); } +// set +// { +// if (m_CoatNormal == value.isOn) +// return; +// m_CoatNormal = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_DualSpecularLobe; + +// public ToggleData dualSpecularLobe +// { +// get { return new ToggleData(m_DualSpecularLobe); } +// set +// { +// if (m_DualSpecularLobe == value.isOn) +// return; +// m_DualSpecularLobe = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_CapHazinessWrtMetallic = true; + +// public ToggleData capHazinessWrtMetallic +// { +// get { return new ToggleData(m_CapHazinessWrtMetallic); } +// set +// { +// if (m_CapHazinessWrtMetallic == value.isOn) +// return; +// m_CapHazinessWrtMetallic = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_Iridescence; + +// public ToggleData iridescence +// { +// get { return new ToggleData(m_Iridescence); } +// set +// { +// if (m_Iridescence == value.isOn) +// return; +// m_Iridescence = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_SubsurfaceScattering; + +// public ToggleData subsurfaceScattering +// { +// get { return new ToggleData(m_SubsurfaceScattering); } +// set +// { +// if (m_SubsurfaceScattering == value.isOn) +// return; +// m_SubsurfaceScattering = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_Transmission; + +// public ToggleData transmission +// { +// get { return new ToggleData(m_Transmission); } +// set +// { +// if (m_Transmission == value.isOn) +// return; +// m_Transmission = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// // Features: other options +// // +// [SerializeField] +// bool m_ReceiveDecals = true; + +// public ToggleData receiveDecals +// { +// get { return new ToggleData(m_ReceiveDecals); } +// set +// { +// if (m_ReceiveDecals == value.isOn) +// return; +// m_ReceiveDecals = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_ReceiveSSR = true; + +// public ToggleData receiveSSR +// { +// get { return new ToggleData(m_ReceiveSSR); } +// set +// { +// if (m_ReceiveSSR == value.isOn) +// return; +// m_ReceiveSSR = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AddPrecomputedVelocity = false; + +// public ToggleData addPrecomputedVelocity +// { +// get { return new ToggleData(m_AddPrecomputedVelocity); } +// set +// { +// if (m_AddPrecomputedVelocity == value.isOn) +// return; +// m_AddPrecomputedVelocity = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_GeometricSpecularAA; + +// public ToggleData geometricSpecularAA +// { +// get { return new ToggleData(m_GeometricSpecularAA); } +// set +// { +// if (m_GeometricSpecularAA == value.isOn) +// return; +// m_GeometricSpecularAA = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// //[SerializeField] +// //bool m_SpecularOcclusion; // Main enable +// // +// //public ToggleData specularOcclusion +// //{ +// // get { return new ToggleData(m_SpecularOcclusion); } +// // set +// // { +// // if (m_SpecularOcclusion == value.isOn) +// // return; +// // m_SpecularOcclusion = value.isOn; +// // UpdateNodeAfterDeserialization(); +// // Dirty(ModificationScope.Topological); +// // } +// //} + +// [SerializeField] +// SpecularOcclusionBaseMode m_ScreenSpaceSpecularOcclusionBaseMode = SpecularOcclusionBaseMode.DirectFromAO; + +// public SpecularOcclusionBaseMode screenSpaceSpecularOcclusionBaseMode +// { +// get { return m_ScreenSpaceSpecularOcclusionBaseMode; } +// set +// { +// if (m_ScreenSpaceSpecularOcclusionBaseMode == value) +// return; + +// m_ScreenSpaceSpecularOcclusionBaseMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// SpecularOcclusionBaseMode m_DataBasedSpecularOcclusionBaseMode; + +// public SpecularOcclusionBaseMode dataBasedSpecularOcclusionBaseMode +// { +// get { return m_DataBasedSpecularOcclusionBaseMode; } +// set +// { +// if (m_DataBasedSpecularOcclusionBaseMode == value) +// return; + +// m_DataBasedSpecularOcclusionBaseMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// SpecularOcclusionAOConeSize m_ScreenSpaceSpecularOcclusionAOConeSize; // This is still provided to tweak the effect of SSAO on the SO. + +// public SpecularOcclusionAOConeSize screenSpaceSpecularOcclusionAOConeSize +// { +// get { return m_ScreenSpaceSpecularOcclusionAOConeSize; } +// set +// { +// if (m_ScreenSpaceSpecularOcclusionAOConeSize == value) +// return; + +// m_ScreenSpaceSpecularOcclusionAOConeSize = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// // See SpecularOcclusionAOConeDir for why we need this only for SSAO-based SO: +// [SerializeField] +// SpecularOcclusionAOConeDir m_ScreenSpaceSpecularOcclusionAOConeDir; + +// public SpecularOcclusionAOConeDir screenSpaceSpecularOcclusionAOConeDir +// { +// get { return m_ScreenSpaceSpecularOcclusionAOConeDir; } +// set +// { +// if (m_ScreenSpaceSpecularOcclusionAOConeDir == value) +// return; + +// m_ScreenSpaceSpecularOcclusionAOConeDir = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// SpecularOcclusionAOConeSize m_DataBasedSpecularOcclusionAOConeSize = SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO; // Only for SO methods using visibility cones (ie ConeCone and SPTD) + +// public SpecularOcclusionAOConeSize dataBasedSpecularOcclusionAOConeSize +// { +// get { return m_DataBasedSpecularOcclusionAOConeSize; } +// set +// { +// if (m_DataBasedSpecularOcclusionAOConeSize == value) +// return; + +// m_DataBasedSpecularOcclusionAOConeSize = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// // TODO: this needs to be per lobe, less useful to have custom input. +// //[SerializeField] +// //bool m_SpecularOcclusionIsCustom; // allow custom input port for SO (replaces the data based one) +// // +// //public ToggleData specularOcclusionIsCustom +// //{ +// // get { return new ToggleData(m_SpecularOcclusionIsCustom); } +// // set +// // { +// // if (m_SpecularOcclusionIsCustom == value.isOn) +// // return; +// // m_SpecularOcclusionIsCustom = value.isOn; +// // UpdateNodeAfterDeserialization(); +// // Dirty(ModificationScope.Topological); +// // } +// //} + +// // SO Bent cone fixup is only for methods using visibility cone and only for the data based SO: +// [SerializeField] +// SpecularOcclusionConeFixupMethod m_SpecularOcclusionConeFixupMethod; + +// public SpecularOcclusionConeFixupMethod specularOcclusionConeFixupMethod +// { +// get { return m_SpecularOcclusionConeFixupMethod; } +// set +// { +// if (m_SpecularOcclusionConeFixupMethod == value) +// return; + +// m_SpecularOcclusionConeFixupMethod = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// // Features: Advanced options +// // +// [SerializeField] +// bool m_AnisotropyForAreaLights = true; + +// public ToggleData anisotropyForAreaLights +// { +// get { return new ToggleData(m_AnisotropyForAreaLights); } +// set +// { +// if (m_AnisotropyForAreaLights == value.isOn) +// return; +// m_AnisotropyForAreaLights = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_RecomputeStackPerLight; + +// public ToggleData recomputeStackPerLight +// { +// get { return new ToggleData(m_RecomputeStackPerLight); } +// set +// { +// if (m_RecomputeStackPerLight == value.isOn) +// return; +// m_RecomputeStackPerLight = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_HonorPerLightMinRoughness; + +// public ToggleData honorPerLightMinRoughness +// { +// get { return new ToggleData(m_HonorPerLightMinRoughness); } +// set +// { +// if (m_HonorPerLightMinRoughness == value.isOn) +// return; +// m_HonorPerLightMinRoughness = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_ShadeBaseUsingRefractedAngles; + +// public ToggleData shadeBaseUsingRefractedAngles +// { +// get { return new ToggleData(m_ShadeBaseUsingRefractedAngles); } +// set +// { +// if (m_ShadeBaseUsingRefractedAngles == value.isOn) +// return; +// m_ShadeBaseUsingRefractedAngles = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_Debug; + +// public ToggleData debug +// { +// get { return new ToggleData(m_Debug); } +// set +// { +// if (m_Debug == value.isOn) +// return; +// m_Debug = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_DevMode; + +// public ToggleData devMode +// { +// get { return new ToggleData(m_DevMode); } +// set +// { +// if (m_DevMode == value.isOn) +// return; +// m_DevMode = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_overrideBakedGI; + +// public ToggleData overrideBakedGI +// { +// get { return new ToggleData(m_overrideBakedGI); } +// set +// { +// if (m_overrideBakedGI == value.isOn) +// return; +// m_overrideBakedGI = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_depthOffset; + +// public ToggleData depthOffset +// { +// get { return new ToggleData(m_depthOffset); } +// set +// { +// if (m_depthOffset == value.isOn) +// return; +// m_depthOffset = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ZWrite; + +// public ToggleData zWrite +// { +// get { return new ToggleData(m_ZWrite); } +// set +// { +// if (m_ZWrite == value.isOn) +// return; +// m_ZWrite = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; +// public TransparentCullMode transparentCullMode +// { +// get => m_transparentCullMode; +// set +// { +// if (m_transparentCullMode == value) +// return; + +// m_transparentCullMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// CompareFunction m_ZTest = CompareFunction.LessEqual; +// public CompareFunction zTest +// { +// get => m_ZTest; +// set +// { +// if (m_ZTest == value) +// return; + +// m_ZTest = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_SupportLodCrossFade; + +// public ToggleData supportLodCrossFade +// { +// get { return new ToggleData(m_SupportLodCrossFade); } +// set +// { +// if (m_SupportLodCrossFade == value.isOn) +// return; +// m_SupportLodCrossFade = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Node); +// } +// } +// [SerializeField] +// bool m_DOTSInstancing = false; + +// public ToggleData dotsInstancing +// { +// get { return new ToggleData(m_DOTSInstancing); } +// set +// { +// if (m_DOTSInstancing == value.isOn) +// return; + +// m_DOTSInstancing = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_MaterialNeedsUpdateHash = 0; + +// int ComputeMaterialNeedsUpdateHash() +// { +// int hash = 0; + +// hash |= (alphaTest.isOn ? 0 : 1) << 0; +// hash |= (receiveSSR.isOn ? 0 : 1) << 2; +// hash |= (RequiresSplitLighting() ? 0 : 1) << 3; + +// return hash; +// } + +// [SerializeField] private string m_ShaderGUIOverride; +// public string ShaderGUIOverride +// { +// get => m_ShaderGUIOverride; +// set => m_ShaderGUIOverride = value; +// } + +// [SerializeField] private bool m_OverrideEnabled; +// public bool OverrideEnabled +// { +// get => m_OverrideEnabled; +// set => m_OverrideEnabled = value; +// } + +// public StackLitMasterNode() +// { +// UpdateNodeAfterDeserialization(); +// } + +// public override string documentationURL +// { +// get { return null; } +// } + +// public bool HasDistortion() +// { +// return (surfaceType == SurfaceType.Transparent && distortion.isOn); +// } + +// public static bool SpecularOcclusionModeUsesVisibilityCone(SpecularOcclusionBaseMode soMethod) +// { +// return (soMethod == SpecularOcclusionBaseMode.ConeConeFromBentAO +// || soMethod == SpecularOcclusionBaseMode.SPTDIntegrationOfBentAO); +// } + +// public bool SpecularOcclusionUsesBentNormal() +// { +// return (SpecularOcclusionModeUsesVisibilityCone(dataBasedSpecularOcclusionBaseMode) +// || (SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) +// && screenSpaceSpecularOcclusionAOConeDir == SpecularOcclusionAOConeDir.BentNormal)); +// } + +// public bool DataBasedSpecularOcclusionIsCustom() +// { +// return dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Custom; +// } + +// public static bool SpecularOcclusionConeFixupMethodModifiesRoughness(SpecularOcclusionConeFixupMethod soConeFixupMethod) +// { +// return (soConeFixupMethod == SpecularOcclusionConeFixupMethod.BoostBSDFRoughness +// || soConeFixupMethod == SpecularOcclusionConeFixupMethod.BoostAndTilt); +// } + +// public sealed override void UpdateNodeAfterDeserialization() +// { +// base.UpdateNodeAfterDeserialization(); +// name = "StackLit Master"; + +// List validSlots = new List(); + +// AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(PositionSlotId); + +// AddSlot(new NormalMaterialSlot(VertexNormalSlotId, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexNormalSlotId); + +// AddSlot(new TangentMaterialSlot(VertexTangentSlotId, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexTangentSlotId); + +// RemoveSlot(NormalSlotId); +// var coordSpace = CoordinateSpace.Tangent; +// switch (m_NormalDropOffSpace) +// { +// case NormalDropOffSpace.Tangent: +// coordSpace = CoordinateSpace.Tangent; +// break; +// case NormalDropOffSpace.World: +// coordSpace = CoordinateSpace.World; +// break; +// case NormalDropOffSpace.Object: +// coordSpace = CoordinateSpace.Object; +// break; +// } +// AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, coordSpace, ShaderStageCapability.Fragment)); +// validSlots.Add(NormalSlotId); + +// AddSlot(new NormalMaterialSlot(BentNormalSlotId, BentNormalSlotName, BentNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(BentNormalSlotId); + +// AddSlot(new TangentMaterialSlot(TangentSlotId, TangentSlotName, TangentSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(TangentSlotId); + +// AddSlot(new ColorRGBMaterialSlot(BaseColorSlotId, BaseColorSlotName, BaseColorSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(BaseColorSlotId); + +// if (baseParametrization == StackLit.BaseParametrization.BaseMetallic) +// { +// AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(MetallicSlotId); +// AddSlot(new Vector1MaterialSlot(DielectricIorSlotId, DielectricIorSlotName, DielectricIorSlotName, SlotType.Input, 1.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(DielectricIorSlotId); +// } +// else if (baseParametrization == StackLit.BaseParametrization.SpecularColor) +// { +// AddSlot(new ColorRGBMaterialSlot(SpecularColorSlotId, SpecularColorSlotName, SpecularColorSlotName, SlotType.Input, Color.white, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularColorSlotId); +// } + +// AddSlot(new Vector1MaterialSlot(SmoothnessASlotId, SmoothnessASlotName, SmoothnessASlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(SmoothnessASlotId); + +// if (anisotropy.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AnisotropyASlotId, AnisotropyASlotName, AnisotropyASlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AnisotropyASlotId); +// } + +// AddSlot(new Vector1MaterialSlot(AmbientOcclusionSlotId, AmbientOcclusionSlotName, AmbientOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AmbientOcclusionSlotId); + +// // TODO: we would ideally need one value per lobe +// if (DataBasedSpecularOcclusionIsCustom()) +// { +// AddSlot(new Vector1MaterialSlot(SpecularOcclusionSlotId, SpecularOcclusionSlotName, SpecularOcclusionSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularOcclusionSlotId); +// } + +// if (SpecularOcclusionUsesBentNormal() && specularOcclusionConeFixupMethod != SpecularOcclusionConeFixupMethod.Off) +// { +// AddSlot(new Vector1MaterialSlot(SOFixupVisibilityRatioThresholdSlotId, SOFixupVisibilityRatioThresholdSlotName, SOFixupVisibilityRatioThresholdSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); +// validSlots.Add(SOFixupVisibilityRatioThresholdSlotId); +// AddSlot(new Vector1MaterialSlot(SOFixupStrengthFactorSlotId, SOFixupStrengthFactorSlotName, SOFixupStrengthFactorSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SOFixupStrengthFactorSlotId); + +// if (SpecularOcclusionConeFixupMethodModifiesRoughness(specularOcclusionConeFixupMethod)) +// { +// AddSlot(new Vector1MaterialSlot(SOFixupMaxAddedRoughnessSlotId, SOFixupMaxAddedRoughnessSlotName, SOFixupMaxAddedRoughnessSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); +// validSlots.Add(SOFixupMaxAddedRoughnessSlotId); +// } +// } + +// if (coat.isOn) +// { +// AddSlot(new Vector1MaterialSlot(CoatSmoothnessSlotId, CoatSmoothnessSlotName, CoatSmoothnessSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(CoatSmoothnessSlotId); +// AddSlot(new Vector1MaterialSlot(CoatIorSlotId, CoatIorSlotName, CoatIorSlotName, SlotType.Input, 1.4f, ShaderStageCapability.Fragment)); +// validSlots.Add(CoatIorSlotId); +// AddSlot(new Vector1MaterialSlot(CoatThicknessSlotId, CoatThicknessSlotName, CoatThicknessSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(CoatThicknessSlotId); +// AddSlot(new ColorRGBMaterialSlot(CoatExtinctionSlotId, CoatExtinctionSlotName, CoatExtinctionSlotName, SlotType.Input, Color.white, ColorMode.HDR, ShaderStageCapability.Fragment)); +// validSlots.Add(CoatExtinctionSlotId); + +// if (coatNormal.isOn) +// { +// AddSlot(new NormalMaterialSlot(CoatNormalSlotId, CoatNormalSlotName, CoatNormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment)); +// validSlots.Add(CoatNormalSlotId); +// } + +// AddSlot(new Vector1MaterialSlot(CoatMaskSlotId, CoatMaskSlotName, CoatMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(CoatMaskSlotId); +// } + +// if (dualSpecularLobe.isOn) +// { +// if (dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.Direct) +// { +// AddSlot(new Vector1MaterialSlot(SmoothnessBSlotId, SmoothnessBSlotName, SmoothnessBSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(SmoothnessBSlotId); +// AddSlot(new Vector1MaterialSlot(LobeMixSlotId, LobeMixSlotName, LobeMixSlotName, SlotType.Input, 0.3f, ShaderStageCapability.Fragment)); +// validSlots.Add(LobeMixSlotId); +// } +// else if (dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss) +// { +// AddSlot(new Vector1MaterialSlot(HazinessSlotId, HazinessSlotName, HazinessSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); +// validSlots.Add(HazinessSlotId); +// AddSlot(new Vector1MaterialSlot(HazeExtentSlotId, HazeExtentSlotName, HazeExtentSlotName, SlotType.Input, 3.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(HazeExtentSlotId); + +// if (capHazinessWrtMetallic.isOn && baseParametrization == StackLit.BaseParametrization.BaseMetallic) // the later should be an assert really +// { +// AddSlot(new Vector1MaterialSlot(HazyGlossMaxDielectricF0SlotId, HazyGlossMaxDielectricF0SlotName, HazyGlossMaxDielectricF0SlotName, SlotType.Input, 0.25f, ShaderStageCapability.Fragment)); +// validSlots.Add(HazyGlossMaxDielectricF0SlotId); +// } +// } + +// if (anisotropy.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AnisotropyBSlotId, AnisotropyBSlotName, AnisotropyBSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AnisotropyBSlotId); +// } +// } + +// if (iridescence.isOn) +// { +// AddSlot(new Vector1MaterialSlot(IridescenceMaskSlotId, IridescenceMaskSlotName, IridescenceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(IridescenceMaskSlotId); +// AddSlot(new Vector1MaterialSlot(IridescenceThicknessSlotId, IridescenceThicknessSlotDisplayName, IridescenceThicknessSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(IridescenceThicknessSlotId); +// if (coat.isOn) +// { +// AddSlot(new Vector1MaterialSlot(IridescenceCoatFixupTIRSlotId, IridescenceCoatFixupTIRSlotName, IridescenceCoatFixupTIRSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(IridescenceCoatFixupTIRSlotId); +// AddSlot(new Vector1MaterialSlot(IridescenceCoatFixupTIRClampSlotId, IridescenceCoatFixupTIRClampSlotName, IridescenceCoatFixupTIRClampSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(IridescenceCoatFixupTIRClampSlotId); +// } +// } + +// if (subsurfaceScattering.isOn) +// { +// AddSlot(new Vector1MaterialSlot(SubsurfaceMaskSlotId, SubsurfaceMaskSlotName, SubsurfaceMaskSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(SubsurfaceMaskSlotId); +// } + +// if (transmission.isOn) +// { +// AddSlot(new Vector1MaterialSlot(ThicknessSlotId, ThicknessSlotName, ThicknessSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(ThicknessSlotId); +// } + +// if (subsurfaceScattering.isOn || transmission.isOn) +// { +// AddSlot(new DiffusionProfileInputMaterialSlot(DiffusionProfileHashSlotId, DiffusionProfileHashSlotDisplayName, DiffusionProfileHashSlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(DiffusionProfileHashSlotId); +// } + +// AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaSlotId); + +// if (alphaTest.isOn) +// { +// AddSlot(new Vector1MaterialSlot(AlphaClipThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaClipThresholdSlotId); +// } + +// AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); +// validSlots.Add(EmissionSlotId); + +// if (HasDistortion()) +// { +// AddSlot(new Vector2MaterialSlot(DistortionSlotId, DistortionSlotDisplayName, DistortionSlotName, SlotType.Input, new Vector2(2.0f, -1.0f), ShaderStageCapability.Fragment)); +// validSlots.Add(DistortionSlotId); + +// AddSlot(new Vector1MaterialSlot(DistortionBlurSlotId, DistortionBlurSlotName, DistortionBlurSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(DistortionBlurSlotId); +// } + +// if (geometricSpecularAA.isOn) +// { +// AddSlot(new Vector1MaterialSlot(SpecularAAScreenSpaceVarianceSlotId, SpecularAAScreenSpaceVarianceSlotName, SpecularAAScreenSpaceVarianceSlotName, SlotType.Input, 0.1f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularAAScreenSpaceVarianceSlotId); + +// AddSlot(new Vector1MaterialSlot(SpecularAAThresholdSlotId, SpecularAAThresholdSlotName, SpecularAAThresholdSlotName, SlotType.Input, 0.2f, ShaderStageCapability.Fragment)); +// validSlots.Add(SpecularAAThresholdSlotId); +// } + +// if (overrideBakedGI.isOn) +// { +// AddSlot(new DefaultMaterialSlot(LightingSlotId, BakedGISlotName, BakedGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(LightingSlotId); +// AddSlot(new DefaultMaterialSlot(BackLightingSlotId, BakedBackGISlotName, BakedBackGISlotName, ShaderStageCapability.Fragment)); +// validSlots.Add(BackLightingSlotId); +// } + +// if (depthOffset.isOn) +// { +// AddSlot(new Vector1MaterialSlot(DepthOffsetSlotId, DepthOffsetSlotName, DepthOffsetSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(DepthOffsetSlotId); +// } + +// RemoveSlotsNameNotMatching(validSlots, true); +// } + +// public VisualElement CreateSettingsElement() +// { +// return new StackLitSettingsView(this); +// } + +// public string renderQueueTag +// { +// get +// { +// var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; +// int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); +// return HDRenderQueue.GetShaderTagValue(queue); +// } +// } + +// public string renderTypeTag => HDRenderTypeTags.HDLitShader.ToString(); + +// // Reference for GetConditionalFields +// // ------------------------------------------- +// // +// // Properties (enables etc): +// // +// // ok+MFD -> material feature define: means we need a predicate, because we will transform it into a #define that match the material feature, shader_feature-defined, that the rest of the shader code uses. +// // +// // ok+MFD masterNode.baseParametrization --> even though we can just always transfer present fields (check with $SurfaceDescription.*) like specularcolor and metallic, +// // we need to translate this into the _MATERIAL_FEATURE_SPECULAR_COLOR define. +// // +// // ok masterNode.energyConservingSpecular +// // +// // ~~~~ ok+MFD: these are almost all material features: +// // masterNode.anisotropy +// // masterNode.coat +// // masterNode.coatNormal +// // masterNode.dualSpecularLobe +// // masterNode.dualSpecularLobeParametrization +// // masterNode.capHazinessWrtMetallic -> not a material feature define, as such, we will create a combined predicate for the HazyGlossMaxDielectricF0 slot dependency +// // instead of adding a #define in the template... +// // masterNode.iridescence +// // masterNode.subsurfaceScattering +// // masterNode.transmission +// // +// // ~~~~ ...ok+MFD: these are all material features +// // +// // ok masterNode.receiveDecals +// // ok masterNode.receiveSSR +// // ok masterNode.geometricSpecularAA --> check, a way to combine predicates and/or exclude passes: TODOTODO What about WRITE_NORMAL_BUFFER passes ? (ie smoothness) +// // ok masterNode.specularOcclusion --> no use for it though! see comments. +// // +// // ~~~~ ok+D: these require translation to defines also... +// // +// // masterNode.anisotropyForAreaLights +// // masterNode.recomputeStackPerLight +// // masterNode.shadeBaseUsingRefractedAngles +// // masterNode.debug + +// // Inputs: Most inputs don't need a specific predicate in addition to the "present field predicate", ie the $SurfaceDescription.*, +// // but in some special cases we check connectivity to avoid processing the default value for nothing... +// // (see specular occlusion with _MASKMAP and _BENTNORMALMAP in LitData, or _TANGENTMAP, _BENTNORMALMAP, etc. which act a bit like that +// // although they also avoid sampling in that case, but default tiny texture map sampling isn't a big hit since they are all cached once +// // a default "unityTexWhite" is sampled, it is cached for everyone defaulting to white...) +// // +// // ok+ means there's a specific additional predicate +// // +// // ok masterNode.BaseColorSlotId +// // ok masterNode.NormalSlotId +// // +// // ok+ masterNode.BentNormalSlotId --> Dependency of the predicate on IsSlotConnected avoids processing even if the slots +// // ok+ masterNode.TangentSlotId are always there so any pass that declares its use in PixelShaderSlots will have the field in SurfaceDescription, +// // but it's not necessarily useful (if slot isnt connected, waste processing on potentially static expressions if +// // shader compiler cant optimize...and even then, useless to have static override value for those.) +// // +// // TODOTODO: Note you could have the same argument for NormalSlot (which we dont exclude with a predicate). +// // Also and anyways, the compiler is smart enough not to do the TS to WS matrix multiply on a (0,0,1) vector. +// // +// // ok+ masterNode.CoatNormalSlotId -> we already have a "material feature" coat normal map so can use that instead, although using that former, we assume the coat normal slot +// // will be there, but it's ok, we can #ifdef the code on the material feature define, and use the $SurfaceDescription.CoatNormal predicate +// // for the actual assignment, +// // although for that one we could again +// // use the "connected" condition like for tangent and bentnormal +// // +// // The following are all ok, no need beyond present field predicate, ie $SurfaceDescription.*, +// // except special cases where noted +// // +// // ok masterNode.SubsurfaceMaskSlotId +// // ok masterNode.ThicknessSlotId +// // ok masterNode.DiffusionProfileHashSlotId +// // ok masterNode.IridescenceMaskSlotId +// // ok masterNode.IridescenceThicknessSlotId +// // ok masterNode.SpecularColorSlotId +// // ok masterNode.DielectricIorSlotId +// // ok masterNode.MetallicSlotId +// // ok masterNode.EmissionSlotId +// // ok masterNode.SmoothnessASlotId +// // ok masterNode.SmoothnessBSlotId +// // ok+ masterNode.AmbientOcclusionSlotId -> defined a specific predicate, but not used, see StackLitData. +// // ok masterNode.AlphaSlotId +// // ok masterNode.AlphaClipThresholdSlotId +// // ok masterNode.AnisotropyASlotId +// // ok masterNode.AnisotropyBSlotId +// // ok masterNode.SpecularAAScreenSpaceVarianceSlotId +// // ok masterNode.SpecularAAThresholdSlotId +// // ok masterNode.CoatSmoothnessSlotId +// // ok masterNode.CoatIorSlotId +// // ok masterNode.CoatThicknessSlotId +// // ok masterNode.CoatExtinctionSlotId +// // ok masterNode.LobeMixSlotId +// // ok masterNode.HazinessSlotId +// // ok masterNode.HazeExtentSlotId +// // ok masterNode.HazyGlossMaxDielectricF0SlotId -> No need for a predicate, the needed predicate is the combined (capHazinessWrtMetallic + HazyGlossMaxDielectricF0) +// // "leaking case": if the 2 are true, but we're not in metallic mode, the capHazinessWrtMetallic property is wrong, +// // that means the master node is really misconfigured, spew an error, should never happen... +// // If it happens, it's because we forgot UpdateNodeAfterDeserialization() call when modifying the capHazinessWrtMetallic or baseParametrization +// // properties, maybe through debug etc. +// // +// // ok masterNode.DistortionSlotId -> Warning: peculiarly, instead of using $SurfaceDescription.Distortion and DistortionBlur, +// // ok masterNode.DistortionBlurSlotId we do an #if (SHADERPASS == SHADERPASS_DISTORTION) in the template, instead of +// // relying on other passed NOT to include the DistortionSlotId in their PixelShaderSlots!! + +// // Other to deal with, and +// // Common between Lit and StackLit: +// // +// // doubleSidedMode, alphaTest, receiveDecals, +// // surfaceType, alphaMode, blendPreserveSpecular, transparencyFog, +// // distortion, distortionMode, distortionDepthTest, +// // sortPriority (int) +// // geometricSpecularAA, energyConservingSpecular, specularOcclusion + +// public ConditionalField[] GetConditionalFields(PassDescriptor pass) +// { +// var ambientOcclusionSlot = FindSlot(AmbientOcclusionSlotId); + +// return new ConditionalField[] +// { +// // Features +// new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || +// IsSlotConnected(VertexNormalSlotId) || +// IsSlotConnected(VertexTangentSlotId)), +// new ConditionalField(Fields.GraphPixel, true), + +// // Surface Type +// new ConditionalField(Fields.SurfaceOpaque, surfaceType == SurfaceType.Opaque), +// new ConditionalField(Fields.SurfaceTransparent, surfaceType != SurfaceType.Opaque), + +// // Structs +// new ConditionalField(HDStructFields.FragInputs.IsFrontFace,doubleSidedMode != DoubleSidedMode.Disabled && +// !pass.Equals(HDStackLitSubTarget.StackLitPasses.MotionVectors)), + +// // Material +// new ConditionalField(HDFields.Anisotropy, anisotropy.isOn), +// new ConditionalField(HDFields.Coat, coat.isOn), +// new ConditionalField(HDFields.CoatMask, coat.isOn && pass.pixelPorts.Contains(CoatMaskSlotId) && +// (IsSlotConnected(CoatMaskSlotId) || +// (FindSlot(CoatMaskSlotId).value != 0.0f && +// FindSlot(CoatMaskSlotId).value != 1.0f))), +// new ConditionalField(HDFields.CoatMaskZero, coat.isOn && pass.pixelPorts.Contains(CoatMaskSlotId) && +// FindSlot(CoatMaskSlotId).value == 0.0f), +// new ConditionalField(HDFields.CoatMaskOne, coat.isOn && pass.pixelPorts.Contains(CoatMaskSlotId) && +// FindSlot(CoatMaskSlotId).value == 1.0f), +// new ConditionalField(HDFields.CoatNormal, coatNormal.isOn && pass.pixelPorts.Contains(CoatNormalSlotId)), +// new ConditionalField(HDFields.Iridescence, iridescence.isOn), +// new ConditionalField(HDFields.SubsurfaceScattering, subsurfaceScattering.isOn && surfaceType != SurfaceType.Transparent), +// new ConditionalField(HDFields.Transmission, transmission.isOn), +// new ConditionalField(HDFields.DualSpecularLobe, dualSpecularLobe.isOn), + +// // Normal Drop Off Space +// new ConditionalField(Fields.NormalDropOffOS, normalDropOffSpace == NormalDropOffSpace.Object), +// new ConditionalField(Fields.NormalDropOffTS, normalDropOffSpace == NormalDropOffSpace.Tangent), +// new ConditionalField(Fields.NormalDropOffWS, normalDropOffSpace == NormalDropOffSpace.World), + +// // Distortion +// new ConditionalField(HDFields.DistortionDepthTest, distortionDepthTest.isOn), +// new ConditionalField(HDFields.DistortionAdd, distortionMode == DistortionMode.Add), +// new ConditionalField(HDFields.DistortionMultiply, distortionMode == DistortionMode.Multiply), +// new ConditionalField(HDFields.DistortionReplace, distortionMode == DistortionMode.Replace), +// new ConditionalField(HDFields.TransparentDistortion, surfaceType != SurfaceType.Opaque && distortion.isOn), + +// // Base Parametrization +// // Even though we can just always transfer the present (check with $SurfaceDescription.*) fields like specularcolor +// // and metallic, we still need to know the baseParametrization in the template to translate into the +// // _MATERIAL_FEATURE_SPECULAR_COLOR define: +// new ConditionalField(HDFields.BaseParamSpecularColor, baseParametrization == StackLit.BaseParametrization.SpecularColor), + +// // Dual Specular Lobe Parametrization +// new ConditionalField(HDFields.HazyGloss, dualSpecularLobe.isOn && +// dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss), + +// // Misc +// new ConditionalField(Fields.AlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), +// new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId)), +// new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaClipThresholdSlotId) && alphaToMask.isOn), +// new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), +// new ConditionalField(HDFields.BlendPreserveSpecular, surfaceType != SurfaceType.Opaque && blendPreserveSpecular.isOn), +// new ConditionalField(HDFields.EnergyConservingSpecular, energyConservingSpecular.isOn), +// new ConditionalField(HDFields.DisableDecals, !receiveDecals.isOn), +// new ConditionalField(HDFields.DisableSSR, !receiveSSR.isOn), +// new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), +// new ConditionalField(HDFields.BentNormal, IsSlotConnected(BentNormalSlotId) && +// pass.pixelPorts.Contains(BentNormalSlotId)), +// new ConditionalField(HDFields.AmbientOcclusion, pass.pixelPorts.Contains(AmbientOcclusionSlotId) && +// (IsSlotConnected(AmbientOcclusionSlotId) || +// ambientOcclusionSlot.value != ambientOcclusionSlot.defaultValue)), +// new ConditionalField(HDFields.Tangent, IsSlotConnected(TangentSlotId) && +// pass.pixelPorts.Contains(TangentSlotId)), +// new ConditionalField(HDFields.LightingGI, IsSlotConnected(LightingSlotId) && +// pass.pixelPorts.Contains(LightingSlotId)), +// new ConditionalField(HDFields.BackLightingGI, IsSlotConnected(BackLightingSlotId) && +// pass.pixelPorts.Contains(BackLightingSlotId)), +// new ConditionalField(HDFields.DepthOffset, depthOffset.isOn && pass.pixelPorts.Contains(DepthOffsetSlotId)), +// // Option for baseParametrization == Metallic && DualSpecularLobeParametrization == HazyGloss: +// // Again we assume masternode has HazyGlossMaxDielectricF0 which should always be the case +// // if capHazinessWrtMetallic.isOn. +// new ConditionalField(HDFields.CapHazinessIfNotMetallic, dualSpecularLobe.isOn && +// dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss && +// capHazinessWrtMetallic.isOn && baseParametrization == StackLit.BaseParametrization.BaseMetallic +// && pass.pixelPorts.Contains(HazyGlossMaxDielectricF0SlotId)), +// // Note here we combine an "enable"-like predicate and the $SurfaceDescription.(slotname) predicate +// // into a single $GeometricSpecularAA pedicate. +// // +// // ($SurfaceDescription.* predicates are useful to make sure the field is present in the struct in the template. +// // The field will be present if both the master node and pass have the slotid, see this set intersection we make +// // in GenerateSurfaceDescriptionStruct(), with HDSubShaderUtilities.FindMaterialSlotsOnNode().) +// // +// // Normally, since the feature enable adds the required slots, only the $SurfaceDescription.* would be required, +// // but some passes might not need it and not declare the PixelShaderSlot, or, inversely, the pass might not +// // declare it as a way to avoid it. +// // +// // IE this has also the side effect to disable geometricSpecularAA - even if "on" - for passes that don't explicitly +// // advertise these slots(eg for a general feature, with separate "enable" and "field present" predicates, the +// // template could take a default value and process it anyway if a feature is "on"). +// // +// // (Note we can achieve the same results in the template on just single predicates by making defines out of them, +// // and using #if defined() && etc) +// new ConditionalField(HDFields.GeometricSpecularAA, geometricSpecularAA.isOn && +// pass.pixelPorts.Contains(SpecularAAThresholdSlotId) && +// pass.pixelPorts.Contains(SpecularAAScreenSpaceVarianceSlotId)), +// new ConditionalField(HDFields.SpecularAA, geometricSpecularAA.isOn && +// pass.pixelPorts.Contains(SpecularAAThresholdSlotId) && +// pass.pixelPorts.Contains(SpecularAAScreenSpaceVarianceSlotId)), +// new ConditionalField(HDFields.SpecularOcclusion, screenSpaceSpecularOcclusionBaseMode != SpecularOcclusionBaseMode.Off || +// dataBasedSpecularOcclusionBaseMode != SpecularOcclusionBaseMode.Off), + +// // Advanced +// new ConditionalField(HDFields.AnisotropyForAreaLights, anisotropyForAreaLights.isOn), +// new ConditionalField(HDFields.RecomputeStackPerLight, recomputeStackPerLight.isOn), +// new ConditionalField(HDFields.HonorPerLightMinRoughness, honorPerLightMinRoughness.isOn), +// new ConditionalField(HDFields.ShadeBaseUsingRefractedAngles, shadeBaseUsingRefractedAngles.isOn), +// new ConditionalField(HDFields.StackLitDebug, debug.isOn), + +// // Screen Space Specular Occlusion Base Mode +// new ConditionalField(HDFields.SSSpecularOcclusionBaseModeOff, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Off), +// new ConditionalField(HDFields.SSSpecularOcclusionBaseModeDirectFromAO, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.DirectFromAO), +// new ConditionalField(HDFields.SSSpecularOcclusionBaseModeConeConeFromBentAO, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.ConeConeFromBentAO), +// new ConditionalField(HDFields.SSSpecularOcclusionBaseModeSPTDIntegrationOfBentAO, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.SPTDIntegrationOfBentAO), +// new ConditionalField(HDFields.SSSpecularOcclusionBaseModeCustom, screenSpaceSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Custom), + +// // Screen Space Specular Occlusion AO Cone Size +// new ConditionalField(HDFields.SSSpecularOcclusionAOConeSizeUniformAO, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && +// screenSpaceSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.UniformAO), +// new ConditionalField(HDFields.SSSpecularOcclusionAOConeSizeCosWeightedAO, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && +// screenSpaceSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.CosWeightedAO), +// new ConditionalField(HDFields.SSSpecularOcclusionAOConeSizeCosWeightedBentCorrectAO, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && +// screenSpaceSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO), + +// // Screen Space Specular Occlusion AO Cone Dir +// new ConditionalField(HDFields.SSSpecularOcclusionAOConeDirGeomNormal, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && +// screenSpaceSpecularOcclusionAOConeDir == SpecularOcclusionAOConeDir.GeomNormal), +// new ConditionalField(HDFields.SSSpecularOcclusionAOConeDirBentNormal, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && +// screenSpaceSpecularOcclusionAOConeDir == SpecularOcclusionAOConeDir.BentNormal), +// new ConditionalField(HDFields.SSSpecularOcclusionAOConeDirShadingNormal, SpecularOcclusionModeUsesVisibilityCone(screenSpaceSpecularOcclusionBaseMode) && +// screenSpaceSpecularOcclusionAOConeDir == SpecularOcclusionAOConeDir.ShadingNormal), + +// // Data Based Specular Occlusion Base Mode +// new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeOff, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Off), +// new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeDirectFromAO, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.DirectFromAO), +// new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeConeConeFromBentAO, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.ConeConeFromBentAO), +// new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeSPTDIntegrationOfBentAO, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.SPTDIntegrationOfBentAO), +// new ConditionalField(HDFields.DataBasedSpecularOcclusionBaseModeCustom, dataBasedSpecularOcclusionBaseMode == SpecularOcclusionBaseMode.Custom), + +// // Data Based Specular Occlusion AO Cone Size +// new ConditionalField(HDFields.DataBasedSpecularOcclusionAOConeSizeUniformAO, SpecularOcclusionModeUsesVisibilityCone(dataBasedSpecularOcclusionBaseMode) && +// dataBasedSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.UniformAO), +// new ConditionalField(HDFields.DataBasedSpecularOcclusionAOConeSizeCosWeightedAO, SpecularOcclusionModeUsesVisibilityCone(dataBasedSpecularOcclusionBaseMode) && +// dataBasedSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.CosWeightedAO), +// new ConditionalField(HDFields.DataBasedSpecularOcclusionAOConeSizeCosWeightedBentCorrectAO, SpecularOcclusionModeUsesVisibilityCone(dataBasedSpecularOcclusionBaseMode) && +// dataBasedSpecularOcclusionAOConeSize == SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO), + +// // Specular Occlusion Cone Fixup Method +// new ConditionalField(HDFields.SpecularOcclusionConeFixupMethodOff, SpecularOcclusionUsesBentNormal() && +// specularOcclusionConeFixupMethod == SpecularOcclusionConeFixupMethod.Off), +// new ConditionalField(HDFields.SpecularOcclusionConeFixupMethodBoostBSDFRoughness, SpecularOcclusionUsesBentNormal() && +// specularOcclusionConeFixupMethod == SpecularOcclusionConeFixupMethod.BoostBSDFRoughness), +// new ConditionalField(HDFields.SpecularOcclusionConeFixupMethodTiltDirectionToGeomNormal, SpecularOcclusionUsesBentNormal() && +// specularOcclusionConeFixupMethod == SpecularOcclusionConeFixupMethod.TiltDirectionToGeomNormal), +// new ConditionalField(HDFields.SpecularOcclusionConeFixupMethodBoostAndTilt, SpecularOcclusionUsesBentNormal() && +// specularOcclusionConeFixupMethod == SpecularOcclusionConeFixupMethod.BoostAndTilt), +// }; +// } + +// public void ProcessPreviewMaterial(Material material) +// { +// // Fixup the material settings: +// material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); +// material.SetFloat(kDoubleSidedNormalMode, (int)doubleSidedMode); +// material.SetFloat(kDoubleSidedEnable, doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); +// material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); +// material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); +// material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); +// material.SetFloat(kZTestTransparent, (int)zTest); +// material.SetFloat(kTransparentCullMode, (int)transparentCullMode); +// material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); +// // No sorting priority for shader graph preview +// var renderingPass = surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; +// material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); + +// StackLitGUI.SetupMaterialKeywordsAndPass(material); +// } + +// public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); +// } + +// public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); +// } + +// public bool RequiresSplitLighting() +// { +// return subsurfaceScattering.isOn; +// } + +// public override object saveContext +// { +// get +// { +// int hash = ComputeMaterialNeedsUpdateHash(); + +// bool needsUpdate = hash != m_MaterialNeedsUpdateHash; + +// if (needsUpdate) +// m_MaterialNeedsUpdateHash = hash; + +// return new HDSaveContext{ updateMaterials = needsUpdate }; +// } +// } + +// public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) +// { +// if (debug.isOn) +// { +// // We have useful debug options in StackLit, so add them always, and let the UI editor (non shadergraph) handle displaying them +// // since this is also the editor that controls the keyword switching for the debug mode. +// collector.AddShaderProperty(new Vector4ShaderProperty() +// { +// overrideReferenceName = "_DebugEnvLobeMask", // xyz is environments lights lobe 0 1 2 Enable, w is Enable VLayering +// displayName = "_DebugEnvLobeMask", +// value = new Vector4(1.0f, 1.0f, 1.0f, 1.0f) +// }); +// collector.AddShaderProperty(new Vector4ShaderProperty() +// { +// overrideReferenceName = "_DebugLobeMask", // xyz is analytical dirac lights lobe 0 1 2 Enable", false), +// displayName = "_DebugLobeMask", +// value = new Vector4(1.0f, 1.0f, 1.0f, 1.0f) +// }); +// collector.AddShaderProperty(new Vector4ShaderProperty() +// { +// overrideReferenceName = "_DebugAniso", // x is Hack Enable, w is factor +// displayName = "_DebugAniso", +// value = new Vector4(1.0f, 0.0f, 0.0f, 1000.0f) +// }); +// // _DebugSpecularOcclusion: +// // +// // eg (2,2,1,2) : +// // .x = SO method {0 = fromAO, 1 = conecone, 2 = SPTD}, +// // .y = bentao algo {0 = uniform, cos, bent cos}, +// // .z = use upper visible hemisphere clipping, +// // .w = The last component of _DebugSpecularOcclusion controls debug visualization: +// // -1 colors the object according to the SO algorithm used, +// // and values from 1 to 4 controls what the lighting debug display mode will show when set to show "indirect specular occlusion": +// // Since there's not one value in our case, +// // 0 will show the object all red to indicate to choose one, 1-4 corresponds to showing +// // 1 = coat SO, 2 = base lobe A SO, 3 = base lobe B SO, 4 = shows the result of sampling the SSAO texture (screenSpaceAmbientOcclusion). +// collector.AddShaderProperty(new Vector4ShaderProperty() +// { +// overrideReferenceName = "_DebugSpecularOcclusion", +// displayName = "_DebugSpecularOcclusion", +// value = new Vector4(2.0f, 2.0f, 1.0f, 2.0f) +// }); +// } + +// // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. +// // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 +// // The user will then need to explicitly disable emissive GI if it is not needed. +// // To be able to automatically disable emission based on the ShaderGraph config when emission is black, +// // we will need a more general way to communicate this to the engine (not directly tied to a material property). +// collector.AddShaderProperty(new ColorShaderProperty() +// { +// overrideReferenceName = "_EmissionColor", +// hidden = true, +// value = new Color(1.0f, 1.0f, 1.0f, 1.0f) +// }); + +// //See SG-ADDITIONALVELOCITY-NOTE +// if (addPrecomputedVelocity.isOn) +// { +// collector.AddShaderProperty(new BooleanShaderProperty +// { +// value = true, +// hidden = true, +// overrideReferenceName = kAddPrecomputedVelocity, +// }); +// } + +// // Add all shader properties required by the inspector +// HDSubShaderUtilities.AddStencilShaderProperties(collector, RequiresSplitLighting(), receiveSSR.isOn); +// HDSubShaderUtilities.AddBlendingStatesShaderProperties( +// collector, +// surfaceType, +// HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), +// sortPriority, +// alphaToMask.isOn, +// zWrite.isOn, +// transparentCullMode, +// zTest, +// false, +// transparencyFog.isOn +// ); +// HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, false); +// HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSidedMode); + +// base.CollectShaderProperties(collector, generationMode); +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs index e95db02bf83..a0027fc0f2e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs @@ -1,1060 +1,1060 @@ -using System; -using UnityEditor.UIElements; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Internal; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEditor.Rendering.HighDefinition; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; - -namespace UnityEditor.Rendering.HighDefinition.Drawing -{ - class StackLitSettingsView : MasterNodeSettingsView - { - StackLitMasterNode m_Node; - - IntegerField m_SortPiorityField; - - Label CreateLabel(string text, int indentLevel) - { - string label = ""; - for (var i = 0; i < indentLevel; i++) - { - label += " "; - } - return new Label(label + text); - } - - public StackLitSettingsView(StackLitMasterNode node) : base(node) - { - m_Node = node; - PropertySheet ps = new PropertySheet(); - - int indentLevel = 0; - ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => - { - row.Add(new EnumField(SurfaceType.Opaque), (field) => - { - field.value = m_Node.surfaceType; - field.RegisterValueChangedCallback(ChangeSurfaceType); - }); - }); - - if (m_Node.surfaceType == SurfaceType.Transparent) - { - ++indentLevel; - - // No refraction in StackLit, always show this: - ps.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => - { - row.Add(new EnumField(StackLitMasterNode.AlphaModeLit.Additive), (field) => - { - field.value = GetAlphaModeLit(m_Node.alphaMode); - field.RegisterValueChangedCallback(ChangeBlendMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Blend Preserves Specular", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.blendPreserveSpecular.isOn; - toggle.OnToggleChanged(ChangeBlendPreserveSpecular); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Fog", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transparencyFog.isOn; - toggle.OnToggleChanged(ChangeTransparencyFog); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.distortion.isOn; - toggle.OnToggleChanged(ChangeDistortion); - }); - }); - - if (m_Node.distortion.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Distortion Blend Mode", indentLevel)), (row) => - { - row.Add(new EnumField(DistortionMode.Add), (field) => - { - field.value = m_Node.distortionMode; - field.RegisterValueChangedCallback(ChangeDistortionMode); - }); - }); - ps.Add(new PropertyRow(CreateLabel("Distortion Depth Test", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.distortionDepthTest.isOn; - toggle.OnToggleChanged(ChangeDistortionDepthTest); - }); - }); - --indentLevel; - } - - m_SortPiorityField = new IntegerField(); - ps.Add(new PropertyRow(CreateLabel("Sort Priority", indentLevel)), (row) => - { - row.Add(m_SortPiorityField, (field) => - { - field.value = m_Node.sortPriority; - field.RegisterValueChangedCallback(ChangeSortPriority); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.zWrite.isOn; - toggle.OnToggleChanged(ChangeZWrite); - }); - }); - - if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) - { - ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.transparentCullMode), (e) => - { - e.value = m_Node.transparentCullMode; - e.RegisterValueChangedCallback(ChangeTransparentCullMode); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.zTest), (e) => - { - e.value = m_Node.zTest; - e.RegisterValueChangedCallback(ChangeZTest); - }); - }); - - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTest.isOn; - toggle.OnToggleChanged(ChangeAlphaTest); - }); - }); - - if (m_Node.alphaTest.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaToMask.isOn; - toggle.OnToggleChanged(ChangeAlphaToMask); - }); - }); - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => - { - row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => - { - field.value = m_Node.doubleSidedMode; - field.RegisterValueChangedCallback(ChangeDoubleSidedMode); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Fragment Normal Space", indentLevel)), (row) => - { - row.Add(new EnumField(NormalDropOffSpace.Tangent), (field) => - { - field.value = m_Node.normalDropOffSpace; - field.RegisterValueChangedCallback(ChangeSpaceOfNormalDropOffMode); - }); - }); - - // Rest of UI looks like this: - // - // baseParametrization - // energyConservingSpecular - // - // anisotropy - // coat - // coatNormal - // dualSpecularLobe - // dualSpecularLobeParametrization - // capHazinessWrtMetallic - // iridescence - // subsurfaceScattering - // transmission - // - // receiveDecals - // receiveSSR - // addPrecomputedVelocity - // geometricSpecularAA - // specularOcclusion - // - // anisotropyForAreaLights - // recomputeStackPerLight - // shadeBaseUsingRefractedAngles - - // Base parametrization: - - ps.Add(new PropertyRow(CreateLabel("Base Color Parametrization", indentLevel)), (row) => - { - row.Add(new EnumField(StackLit.BaseParametrization.BaseMetallic), (field) => - { - field.value = m_Node.baseParametrization; - field.RegisterValueChangedCallback(ChangeBaseParametrization); - }); - }); - - if (m_Node.baseParametrization == StackLit.BaseParametrization.SpecularColor) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Energy Conserving Specular", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.energyConservingSpecular.isOn; - toggle.OnToggleChanged(ChangeEnergyConservingSpecular); - }); - }); - --indentLevel; - } - - // Material type enables: - ps.Add(new PropertyRow(CreateLabel("Material Core Features", indentLevel)), (row) => {} ); - ++indentLevel; - - ps.Add(new PropertyRow(CreateLabel("Anisotropy", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.anisotropy.isOn; - toggle.OnToggleChanged(ChangeAnisotropy); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Coat", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.coat.isOn; - toggle.OnToggleChanged(ChangeCoat); - }); - }); - - if (m_Node.coat.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Coat Normal", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.coatNormal.isOn; - toggle.OnToggleChanged(ChangeCoatNormal); - }); - }); - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Dual Specular Lobe", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.dualSpecularLobe.isOn; - toggle.OnToggleChanged(ChangeDualSpecularLobe); - }); - }); - - if (m_Node.dualSpecularLobe.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Dual SpecularLobe Parametrization", indentLevel)), (row) => - { - row.Add(new EnumField(StackLit.DualSpecularLobeParametrization.HazyGloss), (field) => - { - field.value = m_Node.dualSpecularLobeParametrization; - field.RegisterValueChangedCallback(ChangeDualSpecularLobeParametrization); - }); - }); - if ((m_Node.baseParametrization == StackLit.BaseParametrization.BaseMetallic) - && (m_Node.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss)) - { - ps.Add(new PropertyRow(CreateLabel("Cap Haziness For Non Metallic", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.capHazinessWrtMetallic.isOn; - toggle.OnToggleChanged(ChangeCapHazinessWrtMetallic); - }); - }); - } - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Iridescence", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.iridescence.isOn; - toggle.OnToggleChanged(ChangeIridescence); - }); - }); - - if (m_Node.surfaceType != SurfaceType.Transparent) - { - ps.Add(new PropertyRow(CreateLabel("Subsurface Scattering", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.subsurfaceScattering.isOn; - toggle.OnToggleChanged(ChangeSubsurfaceScattering); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Transmission", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transmission.isOn; - toggle.OnToggleChanged(ChangeTransmission); - }); - }); - --indentLevel; // ...Material type enables. - - ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveDecals.isOn; - toggle.OnToggleChanged(ChangeReceiveDecals); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.receiveSSR.isOn; - toggle.OnToggleChanged(ChangeReceiveSSR); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.addPrecomputedVelocity.isOn; - toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Geometric Specular AA", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.geometricSpecularAA.isOn; - toggle.OnToggleChanged(ChangeGeometricSpecularAA); - }); - }); - - //ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (main enable)", indentLevel)), (row) => - //{ - // row.Add(new Toggle(), (toggle) => - // { - // toggle.value = m_Node.specularOcclusion.isOn; - // toggle.OnToggleChanged(ChangeSpecularOcclusion); - // }); - //}); - - // SpecularOcclusion from SSAO - if (m_Node.devMode.isOn) - { - // Only in dev mode do we show controls for SO fed from SSAO: otherwise, we keep the default which is DirectFromAO - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (from SSAO)", indentLevel)), (row) => - { - row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionBaseMode.DirectFromAO), (field) => - { - field.value = m_Node.screenSpaceSpecularOcclusionBaseMode; - field.RegisterValueChangedCallback(ChangeScreenSpaceSpecularOcclusionBaseMode); - }); - - }); - if (StackLitMasterNode.SpecularOcclusionModeUsesVisibilityCone(m_Node.screenSpaceSpecularOcclusionBaseMode)) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (SS) AO Cone Weight", indentLevel)), (row) => - { - row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionAOConeSize.CosWeightedAO), (field) => - { - field.value = m_Node.screenSpaceSpecularOcclusionAOConeSize; - field.RegisterValueChangedCallback(ChangeScreenSpaceSpecularOcclusionAOConeSize); - }); - }); - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (SS) AO Cone Dir", indentLevel)), (row) => - { - row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionAOConeDir.ShadingNormal), (field) => - { - field.value = m_Node.screenSpaceSpecularOcclusionAOConeDir; - field.RegisterValueChangedCallback(ChangeScreenSpaceSpecularOcclusionAOConeDir); - }); - }); - --indentLevel; - } - } - - // SpecularOcclusion from input AO (baked or data-based SO) - { - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (from input AO)", indentLevel)), (row) => - { - if (m_Node.devMode.isOn) - { - row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionBaseMode.DirectFromAO), (field) => - { - field.value = m_Node.dataBasedSpecularOcclusionBaseMode; - field.RegisterValueChangedCallback(ChangeDataBasedSpecularOcclusionBaseMode); - }); - } - else - { - row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionBaseModeSimple.DirectFromAO), (field) => - { - // In non-dev mode, parse any enum value set to a method not shown in the simple UI as SPTD (highest quality) method: - StackLitMasterNode.SpecularOcclusionBaseModeSimple simpleUIEnumValue = - Enum.TryParse(m_Node.dataBasedSpecularOcclusionBaseMode.ToString(), out StackLitMasterNode.SpecularOcclusionBaseModeSimple parsedValue) ? - parsedValue : StackLitMasterNode.SpecularOcclusionBaseModeSimple.SPTDIntegrationOfBentAO; - field.value = simpleUIEnumValue; - field.RegisterValueChangedCallback(ChangeDataBasedSpecularOcclusionBaseModeSimpleUI); - }); - } - }); - if (StackLitMasterNode.SpecularOcclusionModeUsesVisibilityCone(m_Node.dataBasedSpecularOcclusionBaseMode)) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion AO Cone Weight", indentLevel)), (row) => - { - row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO), (field) => - { - field.value = m_Node.dataBasedSpecularOcclusionAOConeSize; - field.RegisterValueChangedCallback(ChangeDataBasedSpecularOcclusionAOConeSize); - }); - }); - --indentLevel; - } - } - - if (m_Node.SpecularOcclusionUsesBentNormal()) - { - if (m_Node.devMode.isOn) - { - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Bent Cone Fixup", indentLevel)), (row) => - { - row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionConeFixupMethod.Off), (field) => - { - field.value = m_Node.specularOcclusionConeFixupMethod; - field.RegisterValueChangedCallback(ChangeSpecularOcclusionConeFixupMethod); - }); - }); - } - else - { - // Just show a simple toggle when not in dev mode - ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Bent Cone Fixup", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.specularOcclusionConeFixupMethod != StackLitMasterNode.SpecularOcclusionConeFixupMethod.Off; - toggle.OnToggleChanged(ChangeSpecularOcclusionConeFixupMethodSimpleUI); - }); - }); - } - } - - ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.supportLodCrossFade.isOn; - toggle.OnToggleChanged(ChangeSupportLODCrossFade); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Advanced Options", indentLevel)), (row) => {} ); - ++indentLevel; - - ps.Add(new PropertyRow(CreateLabel("Anisotropy For Area Lights", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.anisotropyForAreaLights.isOn; - toggle.OnToggleChanged(ChangeAnisotropyForAreaLights); - }); - }); - - // Per Punctual/Directional Lights - { - ps.Add(new PropertyRow(CreateLabel("Per Punctual/Directional Lights:", indentLevel)), (row) => { }); - ++indentLevel; - - if (m_Node.coat.isOn) - { - ps.Add(new PropertyRow(CreateLabel("Base Layer Uses Refracted Angles", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.shadeBaseUsingRefractedAngles.isOn; - toggle.OnToggleChanged(ChangeShadeBaseUsingRefractedAngles); - }); - }); - } - if (m_Node.coat.isOn || m_Node.iridescence.isOn) - { - ps.Add(new PropertyRow(CreateLabel("Recompute Stack & Iridescence", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.recomputeStackPerLight.isOn; - toggle.OnToggleChanged(ChangeRecomputeStackPerLight); - }); - }); - } - ps.Add(new PropertyRow(CreateLabel("Honor Per Light Max Smoothness", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.honorPerLightMinRoughness.isOn; - toggle.OnToggleChanged(ChangeHonorPerLightMinRoughness); - }); - }); - - --indentLevel; - } // Per Punctual/Directional Lights - - // Uncomment to show the dev mode UI: - // - //ps.Add(new PropertyRow(CreateLabel("Enable Dev Mode", indentLevel)), (row) => - //{ - // row.Add(new Toggle(), (toggle) => - // { - // toggle.value = m_Node.devMode.isOn; - // toggle.OnToggleChanged(ChangeDevMode); - // }); - //}); - - if (m_Node.devMode.isOn) - { - ps.Add(new PropertyRow(CreateLabel("Show And Enable StackLit Debugs", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.debug.isOn; - toggle.OnToggleChanged(ChangeDebug); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.overrideBakedGI.isOn; - toggle.OnToggleChanged(ChangeoverrideBakedGI); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.depthOffset.isOn; - toggle.OnToggleChanged(ChangeDepthOffset); - }); - }); - - --indentLevel; //...Advanced options - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeSurfaceType(ChangeEvent evt) - { - if (Equals(m_Node.surfaceType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); - m_Node.surfaceType = (SurfaceType)evt.newValue; - } - - void ChangeDoubleSidedMode(ChangeEvent evt) - { - if (Equals(m_Node.doubleSidedMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); - m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; - } - - void ChangeSpaceOfNormalDropOffMode(ChangeEvent evt) - { - if (Equals(m_Node.normalDropOffSpace, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Normal Space Drop-Off Mode Change"); - m_Node.normalDropOffSpace = (NormalDropOffSpace)evt.newValue; - } - - void ChangeBaseParametrization(ChangeEvent evt) - { - if (Equals(m_Node.baseParametrization, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Base Parametrization Change"); - m_Node.baseParametrization = (StackLit.BaseParametrization)evt.newValue; - } - - void ChangeDualSpecularLobeParametrization(ChangeEvent evt) - { - if (Equals(m_Node.dualSpecularLobeParametrization, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Dual Specular Lobe Parametrization Change"); - m_Node.dualSpecularLobeParametrization = (StackLit.DualSpecularLobeParametrization)evt.newValue; - } - - void ChangeBlendMode(ChangeEvent evt) - { - // Make sure the mapping is correct by handling each case. - AlphaMode alphaMode = GetAlphaMode((StackLitMasterNode.AlphaModeLit)evt.newValue); - - if (Equals(m_Node.alphaMode, alphaMode)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); - m_Node.alphaMode = alphaMode; - } - - void ChangeBlendPreserveSpecular(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); - ToggleData td = m_Node.blendPreserveSpecular; - td.isOn = evt.newValue; - m_Node.blendPreserveSpecular = td; - } - - void ChangeTransparencyFog(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); - ToggleData td = m_Node.transparencyFog; - td.isOn = evt.newValue; - m_Node.transparencyFog = td; - } - - void ChangeDistortion(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Change"); - ToggleData td = m_Node.distortion; - td.isOn = evt.newValue; - m_Node.distortion = td; - } - - void ChangeDistortionMode(ChangeEvent evt) - { - if (Equals(m_Node.distortionMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Mode Change"); - m_Node.distortionMode = (DistortionMode)evt.newValue; - } - - void ChangeDistortionDepthTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Depth Test Change"); - ToggleData td = m_Node.distortionDepthTest; - td.isOn = evt.newValue; - m_Node.distortionDepthTest = td; - } - - void ChangeSortPriority(ChangeEvent evt) - { - m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - // Force the text to match. - m_SortPiorityField.value = m_Node.sortPriority; - if (Equals(m_Node.sortPriority, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); - } - - void ChangeAlphaTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); - ToggleData td = m_Node.alphaTest; - td.isOn = evt.newValue; - m_Node.alphaTest = td; - } - - void ChangeAlphaToMask(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); - ToggleData td = m_Node.alphaToMask; - td.isOn = evt.newValue; - m_Node.alphaToMask = td; - } - - void ChangeReceiveDecals(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Receive Decals Change"); - ToggleData td = m_Node.receiveDecals; - td.isOn = evt.newValue; - m_Node.receiveDecals = td; - } - - void ChangeReceiveSSR(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Receive SSR Change"); - ToggleData td = m_Node.receiveSSR; - td.isOn = evt.newValue; - m_Node.receiveSSR = td; - } - - void ChangeAddPrecomputedVelocity(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); - ToggleData td = m_Node.addPrecomputedVelocity; - td.isOn = evt.newValue; - m_Node.addPrecomputedVelocity = td; - } - - void ChangeGeometricSpecularAA(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Specular AA Change"); - ToggleData td = m_Node.geometricSpecularAA; - td.isOn = evt.newValue; - m_Node.geometricSpecularAA = td; - } - - void ChangeEnergyConservingSpecular(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Energy Conserving Specular Change"); - ToggleData td = m_Node.energyConservingSpecular; - td.isOn = evt.newValue; - m_Node.energyConservingSpecular = td; - } - - void ChangeAnisotropy(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Anisotropy Change"); - ToggleData td = m_Node.anisotropy; - td.isOn = evt.newValue; - m_Node.anisotropy = td; - } - - void ChangeCoat(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Coat Change"); - ToggleData td = m_Node.coat; - td.isOn = evt.newValue; - m_Node.coat = td; - } - - void ChangeCoatNormal(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Coat Normal Change"); - ToggleData td = m_Node.coatNormal; - td.isOn = evt.newValue; - m_Node.coatNormal = td; - } - - void ChangeDualSpecularLobe(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("DualSpecularLobe Change"); - ToggleData td = m_Node.dualSpecularLobe; - td.isOn = evt.newValue; - m_Node.dualSpecularLobe = td; - } - - void ChangeCapHazinessWrtMetallic(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("CapHazinessWrtMetallic Change"); - ToggleData td = m_Node.capHazinessWrtMetallic; - td.isOn = evt.newValue; - m_Node.capHazinessWrtMetallic = td; - } - - void ChangeIridescence(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Iridescence Change"); - ToggleData td = m_Node.iridescence; - td.isOn = evt.newValue; - m_Node.iridescence = td; - } - - void ChangeSubsurfaceScattering(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("SubsurfaceScattering Change"); - ToggleData td = m_Node.subsurfaceScattering; - td.isOn = evt.newValue; - m_Node.subsurfaceScattering = td; - } - - void ChangeTransmission(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transmission Change"); - ToggleData td = m_Node.transmission; - td.isOn = evt.newValue; - m_Node.transmission = td; - } - - //void ChangeSpecularOcclusion(ChangeEvent evt) - //{ - // m_Node.owner.owner.RegisterCompleteObjectUndo("SpecularOcclusion Change"); - // ToggleData td = m_Node.specularOcclusion; - // td.isOn = evt.newValue; - // m_Node.specularOcclusion = td; - //} - - void ChangeScreenSpaceSpecularOcclusionBaseMode(ChangeEvent evt) - { - if (Equals(m_Node.screenSpaceSpecularOcclusionBaseMode, evt.newValue)) - return; - - if (Equals(evt.newValue, StackLitMasterNode.SpecularOcclusionBaseMode.Custom)) - { - Debug.LogWarning("Custom input not supported for SSAO based specular occlusion."); - // Make sure the UI field doesn't switch and stays in synch with the master node property: - if (evt.currentTarget is EnumField enumField) - { - enumField.value = m_Node.screenSpaceSpecularOcclusionBaseMode; - } - return; - } - - m_Node.owner.owner.RegisterCompleteObjectUndo("ScreenSpaceSpecularOcclusionBaseMode Change"); - m_Node.screenSpaceSpecularOcclusionBaseMode = (StackLitMasterNode.SpecularOcclusionBaseMode)evt.newValue; - } - - void ChangeScreenSpaceSpecularOcclusionAOConeSize(ChangeEvent evt) - { - if (Equals(m_Node.screenSpaceSpecularOcclusionAOConeSize, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("ScreenSpaceSpecularOcclusionAOConeSize Change"); - m_Node.screenSpaceSpecularOcclusionAOConeSize = (StackLitMasterNode.SpecularOcclusionAOConeSize)evt.newValue; - } - - void ChangeScreenSpaceSpecularOcclusionAOConeDir(ChangeEvent evt) - { - if (Equals(m_Node.screenSpaceSpecularOcclusionAOConeDir, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("ScreenSpaceSpecularOcclusionAOConeDir Change"); - m_Node.screenSpaceSpecularOcclusionAOConeDir = (StackLitMasterNode.SpecularOcclusionAOConeDir)evt.newValue; - } - - void ChangeDataBasedSpecularOcclusionBaseMode(ChangeEvent evt) - { - if (Equals(m_Node.dataBasedSpecularOcclusionBaseMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("DataBasedSpecularOcclusionBaseMode Change"); - m_Node.dataBasedSpecularOcclusionBaseMode = (StackLitMasterNode.SpecularOcclusionBaseMode)evt.newValue; - } - - void ChangeDataBasedSpecularOcclusionBaseModeSimpleUI(ChangeEvent evt) - { - // StackLitMasterNode.SpecularOcclusionBaseModeSimple should always be a subset of StackLitMasterNode.SpecularOcclusionBaseMode: - if (Equals(m_Node.dataBasedSpecularOcclusionBaseMode, (StackLitMasterNode.SpecularOcclusionBaseMode) evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("DataBasedSpecularOcclusionBaseMode (simple UI) Change"); - m_Node.dataBasedSpecularOcclusionBaseMode = (StackLitMasterNode.SpecularOcclusionBaseMode)evt.newValue; - } - - void ChangeDataBasedSpecularOcclusionAOConeSize(ChangeEvent evt) - { - if (Equals(m_Node.dataBasedSpecularOcclusionAOConeSize, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("DataBasedSpecularOcclusionAOConeSize Change"); - m_Node.dataBasedSpecularOcclusionAOConeSize = (StackLitMasterNode.SpecularOcclusionAOConeSize)evt.newValue; - } - - void ChangeSpecularOcclusionConeFixupMethod(ChangeEvent evt) - { - if (Equals(m_Node.specularOcclusionConeFixupMethod, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("SpecularOcclusionConeFixupMethod Change"); - m_Node.specularOcclusionConeFixupMethod = (StackLitMasterNode.SpecularOcclusionConeFixupMethod)evt.newValue; - } - - void ChangeSpecularOcclusionConeFixupMethodSimpleUI(ChangeEvent evt) - { - if ( (evt.newValue == false && Equals(m_Node.specularOcclusionConeFixupMethod, StackLitMasterNode.SpecularOcclusionConeFixupMethod.Off)) - || (evt.newValue == true && Equals(m_Node.specularOcclusionConeFixupMethod, StackLitMasterNode.SpecularOcclusionConeFixupMethod.BoostAndTilt)) ) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("SpecularOcclusionConeFixupMethod Change"); - - m_Node.specularOcclusionConeFixupMethod = evt.newValue ? StackLitMasterNode.SpecularOcclusionConeFixupMethod.BoostAndTilt - : StackLitMasterNode.SpecularOcclusionConeFixupMethod.Off; - } - - void ChangeAnisotropyForAreaLights(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("AnisotropyForAreaLights Change"); - ToggleData td = m_Node.anisotropyForAreaLights; - td.isOn = evt.newValue; - m_Node.anisotropyForAreaLights = td; - } - - void ChangeoverrideBakedGI(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); - ToggleData td = m_Node.overrideBakedGI; - td.isOn = evt.newValue; - m_Node.overrideBakedGI = td; - } - - void ChangeRecomputeStackPerLight(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("RecomputeStackPerLight Change"); - ToggleData td = m_Node.recomputeStackPerLight; - td.isOn = evt.newValue; - m_Node.recomputeStackPerLight = td; - } - - void ChangeHonorPerLightMinRoughness(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("HonorPerLightMinRoughness Change"); - ToggleData td = m_Node.honorPerLightMinRoughness; - td.isOn = evt.newValue; - m_Node.honorPerLightMinRoughness = td; - } - - void ChangeShadeBaseUsingRefractedAngles(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("ShadeBaseUsingRefractedAngles Change"); - ToggleData td = m_Node.shadeBaseUsingRefractedAngles; - td.isOn = evt.newValue; - m_Node.shadeBaseUsingRefractedAngles = td; - } - - void ChangeDevMode(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("StackLit DevMode Change"); - ToggleData td = m_Node.devMode; - td.isOn = evt.newValue; - m_Node.devMode = td; - } - - void ChangeDebug(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("StackLit Debug Change"); - ToggleData td = m_Node.debug; - td.isOn = evt.newValue; - m_Node.debug = td; - } - - void ChangeDepthOffset(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); - ToggleData td = m_Node.depthOffset; - td.isOn = evt.newValue; - m_Node.depthOffset = td; - } - - void ChangeZWrite(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); - ToggleData td = m_Node.zWrite; - td.isOn = evt.newValue; - m_Node.zWrite = td; - } - - void ChangeTransparentCullMode(ChangeEvent evt) - { - if (Equals(m_Node.transparentCullMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); - m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; - } - - void ChangeZTest(ChangeEvent evt) - { - if (Equals(m_Node.zTest, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); - m_Node.zTest = (CompareFunction)evt.newValue; - } - - void ChangeSupportLODCrossFade(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); - ToggleData td = m_Node.supportLodCrossFade; - td.isOn = evt.newValue; - m_Node.supportLodCrossFade = td; - } - - public AlphaMode GetAlphaMode(StackLitMasterNode.AlphaModeLit alphaModeLit) - { - switch (alphaModeLit) - { - case StackLitMasterNode.AlphaModeLit.Alpha: - return AlphaMode.Alpha; - case StackLitMasterNode.AlphaModeLit.Premultiply: - return AlphaMode.Premultiply; - case StackLitMasterNode.AlphaModeLit.Additive: - return AlphaMode.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaModeLit); - return AlphaMode.Alpha; - } - - } - } - - public StackLitMasterNode.AlphaModeLit GetAlphaModeLit(AlphaMode alphaMode) - { - switch (alphaMode) - { - case AlphaMode.Alpha: - return StackLitMasterNode.AlphaModeLit.Alpha; - case AlphaMode.Premultiply: - return StackLitMasterNode.AlphaModeLit.Premultiply; - case AlphaMode.Additive: - return StackLitMasterNode.AlphaModeLit.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaMode); - return StackLitMasterNode.AlphaModeLit.Alpha; - } - } - } - } -} +// using System; +// using UnityEditor.UIElements; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEditor.Graphing.Util; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEditor.Rendering.HighDefinition; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; + +// namespace UnityEditor.Rendering.HighDefinition.Drawing +// { +// class StackLitSettingsView : MasterNodeSettingsView +// { +// StackLitMasterNode m_Node; + +// IntegerField m_SortPiorityField; + +// Label CreateLabel(string text, int indentLevel) +// { +// string label = ""; +// for (var i = 0; i < indentLevel; i++) +// { +// label += " "; +// } +// return new Label(label + text); +// } + +// public StackLitSettingsView(StackLitMasterNode node) : base(node) +// { +// m_Node = node; +// PropertySheet ps = new PropertySheet(); + +// int indentLevel = 0; +// ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(SurfaceType.Opaque), (field) => +// { +// field.value = m_Node.surfaceType; +// field.RegisterValueChangedCallback(ChangeSurfaceType); +// }); +// }); + +// if (m_Node.surfaceType == SurfaceType.Transparent) +// { +// ++indentLevel; + +// // No refraction in StackLit, always show this: +// ps.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(StackLitMasterNode.AlphaModeLit.Additive), (field) => +// { +// field.value = GetAlphaModeLit(m_Node.alphaMode); +// field.RegisterValueChangedCallback(ChangeBlendMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Blend Preserves Specular", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.blendPreserveSpecular.isOn; +// toggle.OnToggleChanged(ChangeBlendPreserveSpecular); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Fog", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transparencyFog.isOn; +// toggle.OnToggleChanged(ChangeTransparencyFog); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.distortion.isOn; +// toggle.OnToggleChanged(ChangeDistortion); +// }); +// }); + +// if (m_Node.distortion.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Distortion Blend Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(DistortionMode.Add), (field) => +// { +// field.value = m_Node.distortionMode; +// field.RegisterValueChangedCallback(ChangeDistortionMode); +// }); +// }); +// ps.Add(new PropertyRow(CreateLabel("Distortion Depth Test", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.distortionDepthTest.isOn; +// toggle.OnToggleChanged(ChangeDistortionDepthTest); +// }); +// }); +// --indentLevel; +// } + +// m_SortPiorityField = new IntegerField(); +// ps.Add(new PropertyRow(CreateLabel("Sort Priority", indentLevel)), (row) => +// { +// row.Add(m_SortPiorityField, (field) => +// { +// field.value = m_Node.sortPriority; +// field.RegisterValueChangedCallback(ChangeSortPriority); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.zWrite.isOn; +// toggle.OnToggleChanged(ChangeZWrite); +// }); +// }); + +// if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) +// { +// ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.transparentCullMode), (e) => +// { +// e.value = m_Node.transparentCullMode; +// e.RegisterValueChangedCallback(ChangeTransparentCullMode); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.zTest), (e) => +// { +// e.value = m_Node.zTest; +// e.RegisterValueChangedCallback(ChangeZTest); +// }); +// }); + +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTest.isOn; +// toggle.OnToggleChanged(ChangeAlphaTest); +// }); +// }); + +// if (m_Node.alphaTest.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaToMask.isOn; +// toggle.OnToggleChanged(ChangeAlphaToMask); +// }); +// }); +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => +// { +// row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => +// { +// field.value = m_Node.doubleSidedMode; +// field.RegisterValueChangedCallback(ChangeDoubleSidedMode); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Fragment Normal Space", indentLevel)), (row) => +// { +// row.Add(new EnumField(NormalDropOffSpace.Tangent), (field) => +// { +// field.value = m_Node.normalDropOffSpace; +// field.RegisterValueChangedCallback(ChangeSpaceOfNormalDropOffMode); +// }); +// }); + +// // Rest of UI looks like this: +// // +// // baseParametrization +// // energyConservingSpecular +// // +// // anisotropy +// // coat +// // coatNormal +// // dualSpecularLobe +// // dualSpecularLobeParametrization +// // capHazinessWrtMetallic +// // iridescence +// // subsurfaceScattering +// // transmission +// // +// // receiveDecals +// // receiveSSR +// // addPrecomputedVelocity +// // geometricSpecularAA +// // specularOcclusion +// // +// // anisotropyForAreaLights +// // recomputeStackPerLight +// // shadeBaseUsingRefractedAngles + +// // Base parametrization: + +// ps.Add(new PropertyRow(CreateLabel("Base Color Parametrization", indentLevel)), (row) => +// { +// row.Add(new EnumField(StackLit.BaseParametrization.BaseMetallic), (field) => +// { +// field.value = m_Node.baseParametrization; +// field.RegisterValueChangedCallback(ChangeBaseParametrization); +// }); +// }); + +// if (m_Node.baseParametrization == StackLit.BaseParametrization.SpecularColor) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Energy Conserving Specular", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.energyConservingSpecular.isOn; +// toggle.OnToggleChanged(ChangeEnergyConservingSpecular); +// }); +// }); +// --indentLevel; +// } + +// // Material type enables: +// ps.Add(new PropertyRow(CreateLabel("Material Core Features", indentLevel)), (row) => {} ); +// ++indentLevel; + +// ps.Add(new PropertyRow(CreateLabel("Anisotropy", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.anisotropy.isOn; +// toggle.OnToggleChanged(ChangeAnisotropy); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Coat", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.coat.isOn; +// toggle.OnToggleChanged(ChangeCoat); +// }); +// }); + +// if (m_Node.coat.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Coat Normal", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.coatNormal.isOn; +// toggle.OnToggleChanged(ChangeCoatNormal); +// }); +// }); +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Dual Specular Lobe", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.dualSpecularLobe.isOn; +// toggle.OnToggleChanged(ChangeDualSpecularLobe); +// }); +// }); + +// if (m_Node.dualSpecularLobe.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Dual SpecularLobe Parametrization", indentLevel)), (row) => +// { +// row.Add(new EnumField(StackLit.DualSpecularLobeParametrization.HazyGloss), (field) => +// { +// field.value = m_Node.dualSpecularLobeParametrization; +// field.RegisterValueChangedCallback(ChangeDualSpecularLobeParametrization); +// }); +// }); +// if ((m_Node.baseParametrization == StackLit.BaseParametrization.BaseMetallic) +// && (m_Node.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss)) +// { +// ps.Add(new PropertyRow(CreateLabel("Cap Haziness For Non Metallic", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.capHazinessWrtMetallic.isOn; +// toggle.OnToggleChanged(ChangeCapHazinessWrtMetallic); +// }); +// }); +// } +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Iridescence", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.iridescence.isOn; +// toggle.OnToggleChanged(ChangeIridescence); +// }); +// }); + +// if (m_Node.surfaceType != SurfaceType.Transparent) +// { +// ps.Add(new PropertyRow(CreateLabel("Subsurface Scattering", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.subsurfaceScattering.isOn; +// toggle.OnToggleChanged(ChangeSubsurfaceScattering); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Transmission", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transmission.isOn; +// toggle.OnToggleChanged(ChangeTransmission); +// }); +// }); +// --indentLevel; // ...Material type enables. + +// ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveDecals.isOn; +// toggle.OnToggleChanged(ChangeReceiveDecals); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.receiveSSR.isOn; +// toggle.OnToggleChanged(ChangeReceiveSSR); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.addPrecomputedVelocity.isOn; +// toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Geometric Specular AA", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.geometricSpecularAA.isOn; +// toggle.OnToggleChanged(ChangeGeometricSpecularAA); +// }); +// }); + +// //ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (main enable)", indentLevel)), (row) => +// //{ +// // row.Add(new Toggle(), (toggle) => +// // { +// // toggle.value = m_Node.specularOcclusion.isOn; +// // toggle.OnToggleChanged(ChangeSpecularOcclusion); +// // }); +// //}); + +// // SpecularOcclusion from SSAO +// if (m_Node.devMode.isOn) +// { +// // Only in dev mode do we show controls for SO fed from SSAO: otherwise, we keep the default which is DirectFromAO +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (from SSAO)", indentLevel)), (row) => +// { +// row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionBaseMode.DirectFromAO), (field) => +// { +// field.value = m_Node.screenSpaceSpecularOcclusionBaseMode; +// field.RegisterValueChangedCallback(ChangeScreenSpaceSpecularOcclusionBaseMode); +// }); + +// }); +// if (StackLitMasterNode.SpecularOcclusionModeUsesVisibilityCone(m_Node.screenSpaceSpecularOcclusionBaseMode)) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (SS) AO Cone Weight", indentLevel)), (row) => +// { +// row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionAOConeSize.CosWeightedAO), (field) => +// { +// field.value = m_Node.screenSpaceSpecularOcclusionAOConeSize; +// field.RegisterValueChangedCallback(ChangeScreenSpaceSpecularOcclusionAOConeSize); +// }); +// }); +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (SS) AO Cone Dir", indentLevel)), (row) => +// { +// row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionAOConeDir.ShadingNormal), (field) => +// { +// field.value = m_Node.screenSpaceSpecularOcclusionAOConeDir; +// field.RegisterValueChangedCallback(ChangeScreenSpaceSpecularOcclusionAOConeDir); +// }); +// }); +// --indentLevel; +// } +// } + +// // SpecularOcclusion from input AO (baked or data-based SO) +// { +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion (from input AO)", indentLevel)), (row) => +// { +// if (m_Node.devMode.isOn) +// { +// row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionBaseMode.DirectFromAO), (field) => +// { +// field.value = m_Node.dataBasedSpecularOcclusionBaseMode; +// field.RegisterValueChangedCallback(ChangeDataBasedSpecularOcclusionBaseMode); +// }); +// } +// else +// { +// row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionBaseModeSimple.DirectFromAO), (field) => +// { +// // In non-dev mode, parse any enum value set to a method not shown in the simple UI as SPTD (highest quality) method: +// StackLitMasterNode.SpecularOcclusionBaseModeSimple simpleUIEnumValue = +// Enum.TryParse(m_Node.dataBasedSpecularOcclusionBaseMode.ToString(), out StackLitMasterNode.SpecularOcclusionBaseModeSimple parsedValue) ? +// parsedValue : StackLitMasterNode.SpecularOcclusionBaseModeSimple.SPTDIntegrationOfBentAO; +// field.value = simpleUIEnumValue; +// field.RegisterValueChangedCallback(ChangeDataBasedSpecularOcclusionBaseModeSimpleUI); +// }); +// } +// }); +// if (StackLitMasterNode.SpecularOcclusionModeUsesVisibilityCone(m_Node.dataBasedSpecularOcclusionBaseMode)) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion AO Cone Weight", indentLevel)), (row) => +// { +// row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO), (field) => +// { +// field.value = m_Node.dataBasedSpecularOcclusionAOConeSize; +// field.RegisterValueChangedCallback(ChangeDataBasedSpecularOcclusionAOConeSize); +// }); +// }); +// --indentLevel; +// } +// } + +// if (m_Node.SpecularOcclusionUsesBentNormal()) +// { +// if (m_Node.devMode.isOn) +// { +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Bent Cone Fixup", indentLevel)), (row) => +// { +// row.Add(new EnumField(StackLitMasterNode.SpecularOcclusionConeFixupMethod.Off), (field) => +// { +// field.value = m_Node.specularOcclusionConeFixupMethod; +// field.RegisterValueChangedCallback(ChangeSpecularOcclusionConeFixupMethod); +// }); +// }); +// } +// else +// { +// // Just show a simple toggle when not in dev mode +// ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Bent Cone Fixup", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.specularOcclusionConeFixupMethod != StackLitMasterNode.SpecularOcclusionConeFixupMethod.Off; +// toggle.OnToggleChanged(ChangeSpecularOcclusionConeFixupMethodSimpleUI); +// }); +// }); +// } +// } + +// ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.supportLodCrossFade.isOn; +// toggle.OnToggleChanged(ChangeSupportLODCrossFade); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Advanced Options", indentLevel)), (row) => {} ); +// ++indentLevel; + +// ps.Add(new PropertyRow(CreateLabel("Anisotropy For Area Lights", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.anisotropyForAreaLights.isOn; +// toggle.OnToggleChanged(ChangeAnisotropyForAreaLights); +// }); +// }); + +// // Per Punctual/Directional Lights +// { +// ps.Add(new PropertyRow(CreateLabel("Per Punctual/Directional Lights:", indentLevel)), (row) => { }); +// ++indentLevel; + +// if (m_Node.coat.isOn) +// { +// ps.Add(new PropertyRow(CreateLabel("Base Layer Uses Refracted Angles", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.shadeBaseUsingRefractedAngles.isOn; +// toggle.OnToggleChanged(ChangeShadeBaseUsingRefractedAngles); +// }); +// }); +// } +// if (m_Node.coat.isOn || m_Node.iridescence.isOn) +// { +// ps.Add(new PropertyRow(CreateLabel("Recompute Stack & Iridescence", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.recomputeStackPerLight.isOn; +// toggle.OnToggleChanged(ChangeRecomputeStackPerLight); +// }); +// }); +// } +// ps.Add(new PropertyRow(CreateLabel("Honor Per Light Max Smoothness", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.honorPerLightMinRoughness.isOn; +// toggle.OnToggleChanged(ChangeHonorPerLightMinRoughness); +// }); +// }); + +// --indentLevel; +// } // Per Punctual/Directional Lights + +// // Uncomment to show the dev mode UI: +// // +// //ps.Add(new PropertyRow(CreateLabel("Enable Dev Mode", indentLevel)), (row) => +// //{ +// // row.Add(new Toggle(), (toggle) => +// // { +// // toggle.value = m_Node.devMode.isOn; +// // toggle.OnToggleChanged(ChangeDevMode); +// // }); +// //}); + +// if (m_Node.devMode.isOn) +// { +// ps.Add(new PropertyRow(CreateLabel("Show And Enable StackLit Debugs", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.debug.isOn; +// toggle.OnToggleChanged(ChangeDebug); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.overrideBakedGI.isOn; +// toggle.OnToggleChanged(ChangeoverrideBakedGI); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.depthOffset.isOn; +// toggle.OnToggleChanged(ChangeDepthOffset); +// }); +// }); + +// --indentLevel; //...Advanced options + +// Add(ps); +// Add(GetShaderGUIOverridePropertySheet()); +// } + +// void ChangeSurfaceType(ChangeEvent evt) +// { +// if (Equals(m_Node.surfaceType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); +// m_Node.surfaceType = (SurfaceType)evt.newValue; +// } + +// void ChangeDoubleSidedMode(ChangeEvent evt) +// { +// if (Equals(m_Node.doubleSidedMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Mode Change"); +// m_Node.doubleSidedMode = (DoubleSidedMode)evt.newValue; +// } + +// void ChangeSpaceOfNormalDropOffMode(ChangeEvent evt) +// { +// if (Equals(m_Node.normalDropOffSpace, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Normal Space Drop-Off Mode Change"); +// m_Node.normalDropOffSpace = (NormalDropOffSpace)evt.newValue; +// } + +// void ChangeBaseParametrization(ChangeEvent evt) +// { +// if (Equals(m_Node.baseParametrization, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Base Parametrization Change"); +// m_Node.baseParametrization = (StackLit.BaseParametrization)evt.newValue; +// } + +// void ChangeDualSpecularLobeParametrization(ChangeEvent evt) +// { +// if (Equals(m_Node.dualSpecularLobeParametrization, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Dual Specular Lobe Parametrization Change"); +// m_Node.dualSpecularLobeParametrization = (StackLit.DualSpecularLobeParametrization)evt.newValue; +// } + +// void ChangeBlendMode(ChangeEvent evt) +// { +// // Make sure the mapping is correct by handling each case. +// AlphaMode alphaMode = GetAlphaMode((StackLitMasterNode.AlphaModeLit)evt.newValue); + +// if (Equals(m_Node.alphaMode, alphaMode)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); +// m_Node.alphaMode = alphaMode; +// } + +// void ChangeBlendPreserveSpecular(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Blend Preserve Specular Change"); +// ToggleData td = m_Node.blendPreserveSpecular; +// td.isOn = evt.newValue; +// m_Node.blendPreserveSpecular = td; +// } + +// void ChangeTransparencyFog(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); +// ToggleData td = m_Node.transparencyFog; +// td.isOn = evt.newValue; +// m_Node.transparencyFog = td; +// } + +// void ChangeDistortion(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Change"); +// ToggleData td = m_Node.distortion; +// td.isOn = evt.newValue; +// m_Node.distortion = td; +// } + +// void ChangeDistortionMode(ChangeEvent evt) +// { +// if (Equals(m_Node.distortionMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Mode Change"); +// m_Node.distortionMode = (DistortionMode)evt.newValue; +// } + +// void ChangeDistortionDepthTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Depth Test Change"); +// ToggleData td = m_Node.distortionDepthTest; +// td.isOn = evt.newValue; +// m_Node.distortionDepthTest = td; +// } + +// void ChangeSortPriority(ChangeEvent evt) +// { +// m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); +// // Force the text to match. +// m_SortPiorityField.value = m_Node.sortPriority; +// if (Equals(m_Node.sortPriority, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); +// } + +// void ChangeAlphaTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); +// ToggleData td = m_Node.alphaTest; +// td.isOn = evt.newValue; +// m_Node.alphaTest = td; +// } + +// void ChangeAlphaToMask(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); +// ToggleData td = m_Node.alphaToMask; +// td.isOn = evt.newValue; +// m_Node.alphaToMask = td; +// } + +// void ChangeReceiveDecals(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Receive Decals Change"); +// ToggleData td = m_Node.receiveDecals; +// td.isOn = evt.newValue; +// m_Node.receiveDecals = td; +// } + +// void ChangeReceiveSSR(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Receive SSR Change"); +// ToggleData td = m_Node.receiveSSR; +// td.isOn = evt.newValue; +// m_Node.receiveSSR = td; +// } + +// void ChangeAddPrecomputedVelocity(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); +// ToggleData td = m_Node.addPrecomputedVelocity; +// td.isOn = evt.newValue; +// m_Node.addPrecomputedVelocity = td; +// } + +// void ChangeGeometricSpecularAA(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Specular AA Change"); +// ToggleData td = m_Node.geometricSpecularAA; +// td.isOn = evt.newValue; +// m_Node.geometricSpecularAA = td; +// } + +// void ChangeEnergyConservingSpecular(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Energy Conserving Specular Change"); +// ToggleData td = m_Node.energyConservingSpecular; +// td.isOn = evt.newValue; +// m_Node.energyConservingSpecular = td; +// } + +// void ChangeAnisotropy(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Anisotropy Change"); +// ToggleData td = m_Node.anisotropy; +// td.isOn = evt.newValue; +// m_Node.anisotropy = td; +// } + +// void ChangeCoat(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Coat Change"); +// ToggleData td = m_Node.coat; +// td.isOn = evt.newValue; +// m_Node.coat = td; +// } + +// void ChangeCoatNormal(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Coat Normal Change"); +// ToggleData td = m_Node.coatNormal; +// td.isOn = evt.newValue; +// m_Node.coatNormal = td; +// } + +// void ChangeDualSpecularLobe(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("DualSpecularLobe Change"); +// ToggleData td = m_Node.dualSpecularLobe; +// td.isOn = evt.newValue; +// m_Node.dualSpecularLobe = td; +// } + +// void ChangeCapHazinessWrtMetallic(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("CapHazinessWrtMetallic Change"); +// ToggleData td = m_Node.capHazinessWrtMetallic; +// td.isOn = evt.newValue; +// m_Node.capHazinessWrtMetallic = td; +// } + +// void ChangeIridescence(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Iridescence Change"); +// ToggleData td = m_Node.iridescence; +// td.isOn = evt.newValue; +// m_Node.iridescence = td; +// } + +// void ChangeSubsurfaceScattering(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("SubsurfaceScattering Change"); +// ToggleData td = m_Node.subsurfaceScattering; +// td.isOn = evt.newValue; +// m_Node.subsurfaceScattering = td; +// } + +// void ChangeTransmission(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transmission Change"); +// ToggleData td = m_Node.transmission; +// td.isOn = evt.newValue; +// m_Node.transmission = td; +// } + +// //void ChangeSpecularOcclusion(ChangeEvent evt) +// //{ +// // m_Node.owner.owner.RegisterCompleteObjectUndo("SpecularOcclusion Change"); +// // ToggleData td = m_Node.specularOcclusion; +// // td.isOn = evt.newValue; +// // m_Node.specularOcclusion = td; +// //} + +// void ChangeScreenSpaceSpecularOcclusionBaseMode(ChangeEvent evt) +// { +// if (Equals(m_Node.screenSpaceSpecularOcclusionBaseMode, evt.newValue)) +// return; + +// if (Equals(evt.newValue, StackLitMasterNode.SpecularOcclusionBaseMode.Custom)) +// { +// Debug.LogWarning("Custom input not supported for SSAO based specular occlusion."); +// // Make sure the UI field doesn't switch and stays in synch with the master node property: +// if (evt.currentTarget is EnumField enumField) +// { +// enumField.value = m_Node.screenSpaceSpecularOcclusionBaseMode; +// } +// return; +// } + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ScreenSpaceSpecularOcclusionBaseMode Change"); +// m_Node.screenSpaceSpecularOcclusionBaseMode = (StackLitMasterNode.SpecularOcclusionBaseMode)evt.newValue; +// } + +// void ChangeScreenSpaceSpecularOcclusionAOConeSize(ChangeEvent evt) +// { +// if (Equals(m_Node.screenSpaceSpecularOcclusionAOConeSize, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ScreenSpaceSpecularOcclusionAOConeSize Change"); +// m_Node.screenSpaceSpecularOcclusionAOConeSize = (StackLitMasterNode.SpecularOcclusionAOConeSize)evt.newValue; +// } + +// void ChangeScreenSpaceSpecularOcclusionAOConeDir(ChangeEvent evt) +// { +// if (Equals(m_Node.screenSpaceSpecularOcclusionAOConeDir, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ScreenSpaceSpecularOcclusionAOConeDir Change"); +// m_Node.screenSpaceSpecularOcclusionAOConeDir = (StackLitMasterNode.SpecularOcclusionAOConeDir)evt.newValue; +// } + +// void ChangeDataBasedSpecularOcclusionBaseMode(ChangeEvent evt) +// { +// if (Equals(m_Node.dataBasedSpecularOcclusionBaseMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("DataBasedSpecularOcclusionBaseMode Change"); +// m_Node.dataBasedSpecularOcclusionBaseMode = (StackLitMasterNode.SpecularOcclusionBaseMode)evt.newValue; +// } + +// void ChangeDataBasedSpecularOcclusionBaseModeSimpleUI(ChangeEvent evt) +// { +// // StackLitMasterNode.SpecularOcclusionBaseModeSimple should always be a subset of StackLitMasterNode.SpecularOcclusionBaseMode: +// if (Equals(m_Node.dataBasedSpecularOcclusionBaseMode, (StackLitMasterNode.SpecularOcclusionBaseMode) evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("DataBasedSpecularOcclusionBaseMode (simple UI) Change"); +// m_Node.dataBasedSpecularOcclusionBaseMode = (StackLitMasterNode.SpecularOcclusionBaseMode)evt.newValue; +// } + +// void ChangeDataBasedSpecularOcclusionAOConeSize(ChangeEvent evt) +// { +// if (Equals(m_Node.dataBasedSpecularOcclusionAOConeSize, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("DataBasedSpecularOcclusionAOConeSize Change"); +// m_Node.dataBasedSpecularOcclusionAOConeSize = (StackLitMasterNode.SpecularOcclusionAOConeSize)evt.newValue; +// } + +// void ChangeSpecularOcclusionConeFixupMethod(ChangeEvent evt) +// { +// if (Equals(m_Node.specularOcclusionConeFixupMethod, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("SpecularOcclusionConeFixupMethod Change"); +// m_Node.specularOcclusionConeFixupMethod = (StackLitMasterNode.SpecularOcclusionConeFixupMethod)evt.newValue; +// } + +// void ChangeSpecularOcclusionConeFixupMethodSimpleUI(ChangeEvent evt) +// { +// if ( (evt.newValue == false && Equals(m_Node.specularOcclusionConeFixupMethod, StackLitMasterNode.SpecularOcclusionConeFixupMethod.Off)) +// || (evt.newValue == true && Equals(m_Node.specularOcclusionConeFixupMethod, StackLitMasterNode.SpecularOcclusionConeFixupMethod.BoostAndTilt)) ) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("SpecularOcclusionConeFixupMethod Change"); + +// m_Node.specularOcclusionConeFixupMethod = evt.newValue ? StackLitMasterNode.SpecularOcclusionConeFixupMethod.BoostAndTilt +// : StackLitMasterNode.SpecularOcclusionConeFixupMethod.Off; +// } + +// void ChangeAnisotropyForAreaLights(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("AnisotropyForAreaLights Change"); +// ToggleData td = m_Node.anisotropyForAreaLights; +// td.isOn = evt.newValue; +// m_Node.anisotropyForAreaLights = td; +// } + +// void ChangeoverrideBakedGI(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("overrideBakedGI Change"); +// ToggleData td = m_Node.overrideBakedGI; +// td.isOn = evt.newValue; +// m_Node.overrideBakedGI = td; +// } + +// void ChangeRecomputeStackPerLight(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("RecomputeStackPerLight Change"); +// ToggleData td = m_Node.recomputeStackPerLight; +// td.isOn = evt.newValue; +// m_Node.recomputeStackPerLight = td; +// } + +// void ChangeHonorPerLightMinRoughness(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("HonorPerLightMinRoughness Change"); +// ToggleData td = m_Node.honorPerLightMinRoughness; +// td.isOn = evt.newValue; +// m_Node.honorPerLightMinRoughness = td; +// } + +// void ChangeShadeBaseUsingRefractedAngles(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("ShadeBaseUsingRefractedAngles Change"); +// ToggleData td = m_Node.shadeBaseUsingRefractedAngles; +// td.isOn = evt.newValue; +// m_Node.shadeBaseUsingRefractedAngles = td; +// } + +// void ChangeDevMode(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("StackLit DevMode Change"); +// ToggleData td = m_Node.devMode; +// td.isOn = evt.newValue; +// m_Node.devMode = td; +// } + +// void ChangeDebug(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("StackLit Debug Change"); +// ToggleData td = m_Node.debug; +// td.isOn = evt.newValue; +// m_Node.debug = td; +// } + +// void ChangeDepthOffset(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("DepthOffset Change"); +// ToggleData td = m_Node.depthOffset; +// td.isOn = evt.newValue; +// m_Node.depthOffset = td; +// } + +// void ChangeZWrite(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); +// ToggleData td = m_Node.zWrite; +// td.isOn = evt.newValue; +// m_Node.zWrite = td; +// } + +// void ChangeTransparentCullMode(ChangeEvent evt) +// { +// if (Equals(m_Node.transparentCullMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); +// m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; +// } + +// void ChangeZTest(ChangeEvent evt) +// { +// if (Equals(m_Node.zTest, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); +// m_Node.zTest = (CompareFunction)evt.newValue; +// } + +// void ChangeSupportLODCrossFade(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Support LOD CrossFade Change"); +// ToggleData td = m_Node.supportLodCrossFade; +// td.isOn = evt.newValue; +// m_Node.supportLodCrossFade = td; +// } + +// public AlphaMode GetAlphaMode(StackLitMasterNode.AlphaModeLit alphaModeLit) +// { +// switch (alphaModeLit) +// { +// case StackLitMasterNode.AlphaModeLit.Alpha: +// return AlphaMode.Alpha; +// case StackLitMasterNode.AlphaModeLit.Premultiply: +// return AlphaMode.Premultiply; +// case StackLitMasterNode.AlphaModeLit.Additive: +// return AlphaMode.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaModeLit); +// return AlphaMode.Alpha; +// } + +// } +// } + +// public StackLitMasterNode.AlphaModeLit GetAlphaModeLit(AlphaMode alphaMode) +// { +// switch (alphaMode) +// { +// case AlphaMode.Alpha: +// return StackLitMasterNode.AlphaModeLit.Alpha; +// case AlphaMode.Premultiply: +// return StackLitMasterNode.AlphaModeLit.Premultiply; +// case AlphaMode.Additive: +// return StackLitMasterNode.AlphaModeLit.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaMode); +// return StackLitMasterNode.AlphaModeLit.Alpha; +// } +// } +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/CreateHDUnlitShaderGraph.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/CreateHDUnlitShaderGraph.cs deleted file mode 100644 index adf10bd6f3e..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/CreateHDUnlitShaderGraph.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.IO; -using UnityEditor.ProjectWindowCallback; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition -{ - static class CreateHDUnlitShaderGraph - { - [MenuItem("Assets/Create/Shader/HDRP/Unlit Graph", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new HDUnlitMasterNode()); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/CreateHDUnlitShaderGraph.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/CreateHDUnlitShaderGraph.cs.meta deleted file mode 100644 index 21be91b3e72..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/CreateHDUnlitShaderGraph.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ba0ffd782e187fc4486b762f67621be6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitMasterNode.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitMasterNode.cs index 86cc022075e..99792087b1c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitMasterNode.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitMasterNode.cs @@ -1,590 +1,590 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Rendering.HighDefinition.Drawing; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph.Drawing.Inspector; -using UnityEditor.ShaderGraph.Internal; -using UnityEngine.Rendering; -using UnityEditor.Rendering.HighDefinition.ShaderGraph; - -// Include material common properties names -using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; - -namespace UnityEditor.Rendering.HighDefinition -{ - [Serializable] - [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.HDUnlitMasterNode")] - [Title("Master", "Unlit (HDRP)")] - class HDUnlitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string ColorSlotName = "Color"; - public const string AlphaSlotName = "Alpha"; - public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; - public const string DistortionSlotName = "Distortion"; - public const string DistortionSlotDisplayName = "Distortion Vector"; - public const string DistortionBlurSlotName = "DistortionBlur"; - public const string PositionSlotName = "Vertex Position"; - public const string PositionSlotDisplayName = "Vertex Position"; - public const string EmissionSlotName = "Emission"; - public const string VertexNormalSlotName = "Vertex Normal"; - public const string VertexTangentSlotName = "Vertex Tangent"; - public const string ShadowTintSlotName = "Shadow Tint"; - - public const int ColorSlotId = 0; - public const int AlphaSlotId = 7; - public const int AlphaThresholdSlotId = 8; - public const int PositionSlotId = 9; - public const int DistortionSlotId = 10; - public const int DistortionBlurSlotId = 11; - public const int EmissionSlotId = 12; - public const int VertexNormalSlotId = 13; - public const int VertexTangentSlotId = 14; - public const int ShadowTintSlotId = 15; - - // Don't support Multiply - public enum AlphaModeLit - { - Alpha, - Premultiply, - Additive, - } - - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - AlphaMode m_AlphaMode; - - public AlphaMode alphaMode - { - get { return m_AlphaMode; } - set - { - if (m_AlphaMode == value) - return; - - m_AlphaMode = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - HDRenderQueue.RenderQueueType m_RenderingPass = HDRenderQueue.RenderQueueType.Opaque; - - public HDRenderQueue.RenderQueueType renderingPass - { - get { return m_RenderingPass; } - set - { - if (m_RenderingPass == value) - return; - - m_RenderingPass = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_TransparencyFog = true; - - public ToggleData transparencyFog - { - get { return new ToggleData(m_TransparencyFog); } - set - { - if (m_TransparencyFog == value.isOn) - return; - m_TransparencyFog = value.isOn; - Dirty(ModificationScope.Graph); - } - } - -#pragma warning disable 649 - [SerializeField, Obsolete("Kept for data migration")] - internal bool m_DrawBeforeRefraction; -#pragma warning restore 649 - - [SerializeField] - bool m_Distortion; - - public ToggleData distortion - { - get { return new ToggleData(m_Distortion); } - set - { - if (m_Distortion == value.isOn) - return; - m_Distortion = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - DistortionMode m_DistortionMode; - - public DistortionMode distortionMode - { - get { return m_DistortionMode; } - set - { - if (m_DistortionMode == value) - return; - - m_DistortionMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_DistortionOnly = true; - - public ToggleData distortionOnly - { - get { return new ToggleData(m_DistortionOnly); } - set - { - if (m_DistortionOnly == value.isOn) - return; - m_DistortionOnly = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_DistortionDepthTest = true; - - public ToggleData distortionDepthTest - { - get { return new ToggleData(m_DistortionDepthTest); } - set - { - if (m_DistortionDepthTest == value.isOn) - return; - m_DistortionDepthTest = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AlphaTest; - - public ToggleData alphaTest - { - get { return new ToggleData(m_AlphaTest); } - set - { - if (m_AlphaTest == value.isOn) - return; - m_AlphaTest = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_AlphaToMask = false; - - public ToggleData alphaToMask - { - get { return new ToggleData(m_AlphaToMask); } - set - { - if (m_AlphaToMask == value.isOn) - return; - - m_AlphaToMask = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - int m_SortPriority; - - public int sortPriority - { - get { return m_SortPriority; } - set - { - if (m_SortPriority == value) - return; - m_SortPriority = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_DoubleSided; - - public ToggleData doubleSided - { - get { return new ToggleData(m_DoubleSided); } - set - { - if (m_DoubleSided == value.isOn) - return; - m_DoubleSided = value.isOn; - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_ZWrite = true; - - public ToggleData zWrite - { - get { return new ToggleData(m_ZWrite); } - set - { - if (m_ZWrite == value.isOn) - return; - m_ZWrite = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; - public TransparentCullMode transparentCullMode - { - get => m_transparentCullMode; - set - { - if (m_transparentCullMode == value) - return; - - m_transparentCullMode = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - CompareFunction m_ZTest = CompareFunction.LessEqual; - public CompareFunction zTest - { - get => m_ZTest; - set - { - if (m_ZTest == value) - return; - - m_ZTest = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AddPrecomputedVelocity = false; - - public ToggleData addPrecomputedVelocity - { - get { return new ToggleData(m_AddPrecomputedVelocity); } - set - { - if (m_AddPrecomputedVelocity == value.isOn) - return; - m_AddPrecomputedVelocity = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_EnableShadowMatte = false; - - public ToggleData enableShadowMatte - { - get { return new ToggleData(m_EnableShadowMatte); } - set - { - if (m_EnableShadowMatte == value.isOn) - return; - m_EnableShadowMatte = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public HDUnlitMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - public override string documentationURL => Documentation.GetPageLink("Master-Node-Unlit"); - - public bool HasDistortion() - { - return (surfaceType == SurfaceType.Transparent && distortion.isOn); - } - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Unlit Master"; - - List validSlots = new List(); - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(PositionSlotId); - AddSlot(new NormalMaterialSlot(VertexNormalSlotId, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexNormalSlotId); - AddSlot(new TangentMaterialSlot(VertexTangentSlotId, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - validSlots.Add(VertexTangentSlotId); - AddSlot(new ColorRGBMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - validSlots.Add(ColorSlotId); - AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaSlotId); - AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - validSlots.Add(AlphaThresholdSlotId); - AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); - validSlots.Add(EmissionSlotId); - - if (HasDistortion()) - { - AddSlot(new Vector2MaterialSlot(DistortionSlotId, DistortionSlotDisplayName, DistortionSlotName, SlotType.Input, new Vector2(0.0f, 0.0f), ShaderStageCapability.Fragment)); - validSlots.Add(DistortionSlotId); - - AddSlot(new Vector1MaterialSlot(DistortionBlurSlotId, DistortionBlurSlotName, DistortionBlurSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); - validSlots.Add(DistortionBlurSlotId); - } - - if (enableShadowMatte.isOn) - { - AddSlot(new ColorRGBAMaterialSlot(ShadowTintSlotId, ShadowTintSlotName, ShadowTintSlotName, SlotType.Input, Color.black, ShaderStageCapability.Fragment)); - validSlots.Add(ShadowTintSlotId); - } - - RemoveSlotsNameNotMatching(validSlots, true); - } - - public VisualElement CreateSettingsElement() - { - return new HDUnlitSettingsView(this); - } - - public string renderQueueTag - { - get - { - int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); - return HDRenderQueue.GetShaderTagValue(queue); - } - } - - public string renderTypeTag => HDRenderTypeTags.HDUnlitShader.ToString(); - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || - IsSlotConnected(VertexNormalSlotId) || - IsSlotConnected(VertexTangentSlotId)), - new ConditionalField(Fields.GraphPixel, true), - - // Distortion - new ConditionalField(HDFields.DistortionDepthTest, distortionDepthTest.isOn), - new ConditionalField(HDFields.DistortionAdd, distortionMode == DistortionMode.Add), - new ConditionalField(HDFields.DistortionMultiply, distortionMode == DistortionMode.Multiply), - new ConditionalField(HDFields.DistortionReplace, distortionMode == DistortionMode.Replace), - new ConditionalField(HDFields.TransparentDistortion, surfaceType != SurfaceType.Opaque && distortion.isOn), - - // Misc - new ConditionalField(Fields.AlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaThresholdSlotId)), - new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaThresholdSlotId)), - new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaThresholdSlotId) && alphaToMask.isOn), - new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), - new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), - new ConditionalField(HDFields.EnableShadowMatte, enableShadowMatte.isOn), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); - material.SetFloat(kDoubleSidedEnable, doubleSided.isOn ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); - material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); - material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)zTest); - material.SetFloat(kTransparentCullMode, (int)transparentCullMode); - material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); - // No sorting priority for shader graph preview - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); - - HDUnlitGUI.SetupMaterialKeywordsAndPass(material); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - var slotRequirements = validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - - return slotRequirements | (transparencyFog.isOn ? NeededCoordinateSpace.World : 0); - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - var slotRequirements = validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - return (enableShadowMatte.isOn ? 0 : slotRequirements); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - var slotRequirements = validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - return (enableShadowMatte.isOn ? 0 : slotRequirements); - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - // ShaderGraph only property used to send the RenderQueueType to the material - collector.AddShaderProperty(new Vector1ShaderProperty - { - overrideReferenceName = "_RenderQueueType", - hidden = true, - value = (int)renderingPass, - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (addPrecomputedVelocity.isOn) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - if (enableShadowMatte.isOn) - { - uint mantissa = ((uint)LightFeatureFlags.Punctual | (uint)LightFeatureFlags.Directional | (uint)LightFeatureFlags.Area) & 0x007FFFFFu; - uint exponent = 0b10000000u; // 0 as exponent - collector.AddShaderProperty(new Vector1ShaderProperty - { - hidden = true, - value = HDShadowUtils.Asfloat((exponent << 23) | mantissa), - overrideReferenceName = HDMaterialProperties.kShadowMatteFilter - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, false, false); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - surfaceType, - HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), - sortPriority, - alphaTest.isOn, - zWrite.isOn, - transparentCullMode, - zTest, - false, - transparencyFog.isOn - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, false); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSided.isOn ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled); - - base.CollectShaderProperties(collector, generationMode); - } - } -} +// using System; +// using System.Linq; +// using System.Collections.Generic; +// using UnityEditor.Rendering.HighDefinition.Drawing; +// using UnityEditor.Graphing; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph.Drawing.Inspector; +// using UnityEditor.ShaderGraph.Internal; +// using UnityEngine.Rendering; +// using UnityEditor.Rendering.HighDefinition.ShaderGraph; + +// // Include material common properties names +// using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; + +// namespace UnityEditor.Rendering.HighDefinition +// { +// [Serializable] +// [FormerName("UnityEditor.Experimental.Rendering.HDPipeline.HDUnlitMasterNode")] +// [Title("Master", "Unlit (HDRP)")] +// class HDUnlitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent +// { +// public const string ColorSlotName = "Color"; +// public const string AlphaSlotName = "Alpha"; +// public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; +// public const string DistortionSlotName = "Distortion"; +// public const string DistortionSlotDisplayName = "Distortion Vector"; +// public const string DistortionBlurSlotName = "DistortionBlur"; +// public const string PositionSlotName = "Vertex Position"; +// public const string PositionSlotDisplayName = "Vertex Position"; +// public const string EmissionSlotName = "Emission"; +// public const string VertexNormalSlotName = "Vertex Normal"; +// public const string VertexTangentSlotName = "Vertex Tangent"; +// public const string ShadowTintSlotName = "Shadow Tint"; + +// public const int ColorSlotId = 0; +// public const int AlphaSlotId = 7; +// public const int AlphaThresholdSlotId = 8; +// public const int PositionSlotId = 9; +// public const int DistortionSlotId = 10; +// public const int DistortionBlurSlotId = 11; +// public const int EmissionSlotId = 12; +// public const int VertexNormalSlotId = 13; +// public const int VertexTangentSlotId = 14; +// public const int ShadowTintSlotId = 15; + +// // Don't support Multiply +// public enum AlphaModeLit +// { +// Alpha, +// Premultiply, +// Additive, +// } + +// [SerializeField] +// SurfaceType m_SurfaceType; + +// public SurfaceType surfaceType +// { +// get { return m_SurfaceType; } +// set +// { +// if (m_SurfaceType == value) +// return; + +// m_SurfaceType = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// AlphaMode m_AlphaMode; + +// public AlphaMode alphaMode +// { +// get { return m_AlphaMode; } +// set +// { +// if (m_AlphaMode == value) +// return; + +// m_AlphaMode = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// HDRenderQueue.RenderQueueType m_RenderingPass = HDRenderQueue.RenderQueueType.Opaque; + +// public HDRenderQueue.RenderQueueType renderingPass +// { +// get { return m_RenderingPass; } +// set +// { +// if (m_RenderingPass == value) +// return; + +// m_RenderingPass = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_TransparencyFog = true; + +// public ToggleData transparencyFog +// { +// get { return new ToggleData(m_TransparencyFog); } +// set +// { +// if (m_TransparencyFog == value.isOn) +// return; +// m_TransparencyFog = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// #pragma warning disable 649 +// [SerializeField, Obsolete("Kept for data migration")] +// internal bool m_DrawBeforeRefraction; +// #pragma warning restore 649 + +// [SerializeField] +// bool m_Distortion; + +// public ToggleData distortion +// { +// get { return new ToggleData(m_Distortion); } +// set +// { +// if (m_Distortion == value.isOn) +// return; +// m_Distortion = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// DistortionMode m_DistortionMode; + +// public DistortionMode distortionMode +// { +// get { return m_DistortionMode; } +// set +// { +// if (m_DistortionMode == value) +// return; + +// m_DistortionMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_DistortionOnly = true; + +// public ToggleData distortionOnly +// { +// get { return new ToggleData(m_DistortionOnly); } +// set +// { +// if (m_DistortionOnly == value.isOn) +// return; +// m_DistortionOnly = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_DistortionDepthTest = true; + +// public ToggleData distortionDepthTest +// { +// get { return new ToggleData(m_DistortionDepthTest); } +// set +// { +// if (m_DistortionDepthTest == value.isOn) +// return; +// m_DistortionDepthTest = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AlphaTest; + +// public ToggleData alphaTest +// { +// get { return new ToggleData(m_AlphaTest); } +// set +// { +// if (m_AlphaTest == value.isOn) +// return; +// m_AlphaTest = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_AlphaToMask = false; + +// public ToggleData alphaToMask +// { +// get { return new ToggleData(m_AlphaToMask); } +// set +// { +// if (m_AlphaToMask == value.isOn) +// return; + +// m_AlphaToMask = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// int m_SortPriority; + +// public int sortPriority +// { +// get { return m_SortPriority; } +// set +// { +// if (m_SortPriority == value) +// return; +// m_SortPriority = value; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_DoubleSided; + +// public ToggleData doubleSided +// { +// get { return new ToggleData(m_DoubleSided); } +// set +// { +// if (m_DoubleSided == value.isOn) +// return; +// m_DoubleSided = value.isOn; +// Dirty(ModificationScope.Topological); +// } +// } + +// [SerializeField] +// bool m_ZWrite = true; + +// public ToggleData zWrite +// { +// get { return new ToggleData(m_ZWrite); } +// set +// { +// if (m_ZWrite == value.isOn) +// return; +// m_ZWrite = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// TransparentCullMode m_transparentCullMode = TransparentCullMode.Back; +// public TransparentCullMode transparentCullMode +// { +// get => m_transparentCullMode; +// set +// { +// if (m_transparentCullMode == value) +// return; + +// m_transparentCullMode = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// CompareFunction m_ZTest = CompareFunction.LessEqual; +// public CompareFunction zTest +// { +// get => m_ZTest; +// set +// { +// if (m_ZTest == value) +// return; + +// m_ZTest = value; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_AddPrecomputedVelocity = false; + +// public ToggleData addPrecomputedVelocity +// { +// get { return new ToggleData(m_AddPrecomputedVelocity); } +// set +// { +// if (m_AddPrecomputedVelocity == value.isOn) +// return; +// m_AddPrecomputedVelocity = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_EnableShadowMatte = false; + +// public ToggleData enableShadowMatte +// { +// get { return new ToggleData(m_EnableShadowMatte); } +// set +// { +// if (m_EnableShadowMatte == value.isOn) +// return; +// m_EnableShadowMatte = value.isOn; +// UpdateNodeAfterDeserialization(); +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] +// bool m_DOTSInstancing = false; + +// public ToggleData dotsInstancing +// { +// get { return new ToggleData(m_DOTSInstancing); } +// set +// { +// if (m_DOTSInstancing == value.isOn) +// return; + +// m_DOTSInstancing = value.isOn; +// Dirty(ModificationScope.Graph); +// } +// } + +// [SerializeField] private string m_ShaderGUIOverride; +// public string ShaderGUIOverride +// { +// get => m_ShaderGUIOverride; +// set => m_ShaderGUIOverride = value; +// } + +// [SerializeField] private bool m_OverrideEnabled; +// public bool OverrideEnabled +// { +// get => m_OverrideEnabled; +// set => m_OverrideEnabled = value; +// } + +// public HDUnlitMasterNode() +// { +// UpdateNodeAfterDeserialization(); +// } + +// public override string documentationURL => Documentation.GetPageLink("Master-Node-Unlit"); + +// public bool HasDistortion() +// { +// return (surfaceType == SurfaceType.Transparent && distortion.isOn); +// } + +// public sealed override void UpdateNodeAfterDeserialization() +// { +// base.UpdateNodeAfterDeserialization(); +// name = "Unlit Master"; + +// List validSlots = new List(); +// AddSlot(new PositionMaterialSlot(PositionSlotId, PositionSlotDisplayName, PositionSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(PositionSlotId); +// AddSlot(new NormalMaterialSlot(VertexNormalSlotId, VertexNormalSlotName, VertexNormalSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexNormalSlotId); +// AddSlot(new TangentMaterialSlot(VertexTangentSlotId, VertexTangentSlotName, VertexTangentSlotName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); +// validSlots.Add(VertexTangentSlotId); +// AddSlot(new ColorRGBMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); +// validSlots.Add(ColorSlotId); +// AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaSlotId); +// AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); +// validSlots.Add(AlphaThresholdSlotId); +// AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); +// validSlots.Add(EmissionSlotId); + +// if (HasDistortion()) +// { +// AddSlot(new Vector2MaterialSlot(DistortionSlotId, DistortionSlotDisplayName, DistortionSlotName, SlotType.Input, new Vector2(0.0f, 0.0f), ShaderStageCapability.Fragment)); +// validSlots.Add(DistortionSlotId); + +// AddSlot(new Vector1MaterialSlot(DistortionBlurSlotId, DistortionBlurSlotName, DistortionBlurSlotName, SlotType.Input, 1.0f, ShaderStageCapability.Fragment)); +// validSlots.Add(DistortionBlurSlotId); +// } + +// if (enableShadowMatte.isOn) +// { +// AddSlot(new ColorRGBAMaterialSlot(ShadowTintSlotId, ShadowTintSlotName, ShadowTintSlotName, SlotType.Input, Color.black, ShaderStageCapability.Fragment)); +// validSlots.Add(ShadowTintSlotId); +// } + +// RemoveSlotsNameNotMatching(validSlots, true); +// } + +// public VisualElement CreateSettingsElement() +// { +// return new HDUnlitSettingsView(this); +// } + +// public string renderQueueTag +// { +// get +// { +// int queue = HDRenderQueue.ChangeType(renderingPass, sortPriority, alphaTest.isOn); +// return HDRenderQueue.GetShaderTagValue(queue); +// } +// } + +// public string renderTypeTag => HDRenderTypeTags.HDUnlitShader.ToString(); + +// public ConditionalField[] GetConditionalFields(PassDescriptor pass) +// { +// return new ConditionalField[] +// { +// // Features +// new ConditionalField(Fields.GraphVertex, IsSlotConnected(PositionSlotId) || +// IsSlotConnected(VertexNormalSlotId) || +// IsSlotConnected(VertexTangentSlotId)), +// new ConditionalField(Fields.GraphPixel, true), + +// // Distortion +// new ConditionalField(HDFields.DistortionDepthTest, distortionDepthTest.isOn), +// new ConditionalField(HDFields.DistortionAdd, distortionMode == DistortionMode.Add), +// new ConditionalField(HDFields.DistortionMultiply, distortionMode == DistortionMode.Multiply), +// new ConditionalField(HDFields.DistortionReplace, distortionMode == DistortionMode.Replace), +// new ConditionalField(HDFields.TransparentDistortion, surfaceType != SurfaceType.Opaque && distortion.isOn), + +// // Misc +// new ConditionalField(Fields.AlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaThresholdSlotId)), +// new ConditionalField(HDFields.DoAlphaTest, alphaTest.isOn && pass.pixelPorts.Contains(AlphaThresholdSlotId)), +// new ConditionalField(Fields.AlphaToMask, alphaTest.isOn && pass.pixelPorts.Contains(AlphaThresholdSlotId) && alphaToMask.isOn), +// new ConditionalField(HDFields.AlphaFog, surfaceType != SurfaceType.Opaque && transparencyFog.isOn), +// new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), +// new ConditionalField(HDFields.EnableShadowMatte, enableShadowMatte.isOn), +// }; +// } + +// public void ProcessPreviewMaterial(Material material) +// { +// // Fixup the material settings: +// material.SetFloat(kSurfaceType, (int)(SurfaceType)surfaceType); +// material.SetFloat(kDoubleSidedEnable, doubleSided.isOn ? 1.0f : 0.0f); +// material.SetFloat(kAlphaCutoffEnabled, alphaTest.isOn ? 1 : 0); +// material.SetFloat(kBlendMode, (int)HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode)); +// material.SetFloat(kEnableFogOnTransparent, transparencyFog.isOn ? 1.0f : 0.0f); +// material.SetFloat(kZTestTransparent, (int)zTest); +// material.SetFloat(kTransparentCullMode, (int)transparentCullMode); +// material.SetFloat(kZWrite, zWrite.isOn ? 1.0f : 0.0f); +// // No sorting priority for shader graph preview +// material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: alphaTest.isOn); + +// HDUnlitGUI.SetupMaterialKeywordsAndPass(material); +// } + +// public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// var slotRequirements = validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); + +// return slotRequirements | (transparencyFog.isOn ? NeededCoordinateSpace.World : 0); +// } + +// public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// var slotRequirements = validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); +// return (enableShadowMatte.isOn ? 0 : slotRequirements); +// } + +// public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) +// { +// List slots = new List(); +// GetSlots(slots); + +// List validSlots = new List(); +// for (int i = 0; i < slots.Count; i++) +// { +// if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) +// continue; + +// validSlots.Add(slots[i]); +// } +// var slotRequirements = validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); +// return (enableShadowMatte.isOn ? 0 : slotRequirements); +// } + +// public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) +// { +// // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. +// // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 +// // The user will then need to explicitly disable emissive GI if it is not needed. +// // To be able to automatically disable emission based on the ShaderGraph config when emission is black, +// // we will need a more general way to communicate this to the engine (not directly tied to a material property). +// collector.AddShaderProperty(new ColorShaderProperty() +// { +// overrideReferenceName = "_EmissionColor", +// hidden = true, +// value = new Color(1.0f, 1.0f, 1.0f, 1.0f) +// }); + +// // ShaderGraph only property used to send the RenderQueueType to the material +// collector.AddShaderProperty(new Vector1ShaderProperty +// { +// overrideReferenceName = "_RenderQueueType", +// hidden = true, +// value = (int)renderingPass, +// }); + +// //See SG-ADDITIONALVELOCITY-NOTE +// if (addPrecomputedVelocity.isOn) +// { +// collector.AddShaderProperty(new BooleanShaderProperty +// { +// value = true, +// hidden = true, +// overrideReferenceName = kAddPrecomputedVelocity, +// }); +// } + +// if (enableShadowMatte.isOn) +// { +// uint mantissa = ((uint)LightFeatureFlags.Punctual | (uint)LightFeatureFlags.Directional | (uint)LightFeatureFlags.Area) & 0x007FFFFFu; +// uint exponent = 0b10000000u; // 0 as exponent +// collector.AddShaderProperty(new Vector1ShaderProperty +// { +// hidden = true, +// value = HDShadowUtils.Asfloat((exponent << 23) | mantissa), +// overrideReferenceName = HDMaterialProperties.kShadowMatteFilter +// }); +// } + +// // Add all shader properties required by the inspector +// HDSubShaderUtilities.AddStencilShaderProperties(collector, false, false); +// HDSubShaderUtilities.AddBlendingStatesShaderProperties( +// collector, +// surfaceType, +// HDSubShaderUtilities.ConvertAlphaModeToBlendMode(alphaMode), +// sortPriority, +// alphaTest.isOn, +// zWrite.isOn, +// transparentCullMode, +// zTest, +// false, +// transparencyFog.isOn +// ); +// HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, alphaTest.isOn, false); +// HDSubShaderUtilities.AddDoubleSidedProperty(collector, doubleSided.isOn ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled); + +// base.CollectShaderProperties(collector, generationMode); +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template index 3e24948e532..096eac81a5e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template @@ -100,7 +100,7 @@ Pass ZERO_INITIALIZE(SurfaceData, surfaceData); // copy across graph values, if defined - $SurfaceDescription.Color: surfaceData.color = surfaceDescription.Color; + $SurfaceDescription.BaseColor: surfaceData.color = surfaceDescription.BaseColor; #if defined(DEBUG_DISPLAY) if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) @@ -115,10 +115,15 @@ Pass SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); + half alpha = 1; + #if _SURFACE_TYPE_TRANSPARENT + alpha = surfaceDescription.Alpha; + #endif + // Perform alpha test very early to save performance (a killed pixel will not sample textures) // TODO: split graph evaluation to grab just alpha dependencies first? tricky. #ifdef _ALPHATEST_ON - $DoAlphaTest: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold); + $DoAlphaTest: GENERIC_ALPHA_TEST(alpha, surfaceDescription.AlphaClipThreshold); #endif BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); @@ -134,7 +139,7 @@ Pass shadow = dot(shadow3, float3(1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f)); float4 shadowColor = (1 - shadow)*surfaceDescription.ShadowTint.rgba; - float localAlpha = saturate(shadowColor.a + surfaceDescription.Alpha); + float localAlpha = saturate(shadowColor.a + alpha); // Keep the nested lerp // With no Color (bsdfData.color.rgb, bsdfData.color.a == 0.0f), just use ShadowColor*Color to avoid a ring of "white" around the shadow @@ -146,12 +151,12 @@ Pass #endif localAlpha = ApplyBlendMode(surfaceData.color, localAlpha).a; - surfaceDescription.Alpha = localAlpha; + alpha = localAlpha; #endif // Builtin Data ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; + builtinData.opacity = alpha; #ifdef _ALPHATEST_ON // Used for sharpening by alpha to mask diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs index ff53f62f509..e467111f016 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs @@ -1,461 +1,461 @@ -using System; -using UnityEditor.UIElements; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEditor.Rendering.HighDefinition; -using UnityEngine.Rendering.HighDefinition; -using UnityEngine.Rendering; - -namespace UnityEditor.Rendering.HighDefinition.Drawing -{ - class HDUnlitSettingsView : MasterNodeSettingsView - { - HDUnlitMasterNode m_Node; - - IntegerField m_SortPiorityField; - - Label CreateLabel(string text, int indentLevel) - { - string label = ""; - for (var i = 0; i < indentLevel; i++) - { - label += " "; - } - return new Label(label + text); - } - - public HDUnlitSettingsView(HDUnlitMasterNode node) : base(node) - { - m_Node = node; - PropertySheet ps = new PropertySheet(); - - int indentLevel = 0; - ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => - { - row.Add(new EnumField(SurfaceType.Opaque), (field) => - { - field.value = m_Node.surfaceType; - field.RegisterValueChangedCallback(ChangeSurfaceType); - }); - }); - - ++indentLevel; - switch (m_Node.surfaceType) - { - case SurfaceType.Opaque: - ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => - { - var valueList = HDSubShaderUtilities.GetRenderingPassList(true, true); - - row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Opaque, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => - { - field.value = HDRenderQueue.GetOpaqueEquivalent(m_Node.renderingPass); - field.RegisterValueChangedCallback(ChangeRenderingPass); - }); - }); - break; - case SurfaceType.Transparent: - ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => - { - Enum defaultValue; - switch (m_Node.renderingPass) // Migration - { - default: //when deserializing without issue, we still need to init the default to something even if not used. - case HDRenderQueue.RenderQueueType.Transparent: - defaultValue = HDRenderQueue.TransparentRenderQueue.Default; - break; - case HDRenderQueue.RenderQueueType.PreRefraction: - defaultValue = HDRenderQueue.TransparentRenderQueue.BeforeRefraction; - break; - } - - var valueList = HDSubShaderUtilities.GetRenderingPassList(false, true); - - row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Transparent, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => - { - field.value = HDRenderQueue.GetTransparentEquivalent(m_Node.renderingPass); - field.RegisterValueChangedCallback(ChangeRenderingPass); - }); - }); - break; - default: - throw new ArgumentException("Unknown SurfaceType"); - } - --indentLevel; - - if (m_Node.surfaceType == SurfaceType.Transparent) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => - { - row.Add(new EnumField(HDUnlitMasterNode.AlphaModeLit.Additive), (field) => - { - field.value = GetAlphaModeLit(m_Node.alphaMode); - field.RegisterValueChangedCallback(ChangeBlendMode); - }); - }); - - m_SortPiorityField = new IntegerField(); - ps.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => - { - row.Add(m_SortPiorityField, (field) => - { - field.value = m_Node.sortPriority; - field.RegisterValueChangedCallback(ChangeSortPriority); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.transparencyFog.isOn; - toggle.OnToggleChanged(ChangeTransparencyFog); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.distortion.isOn; - toggle.OnToggleChanged(ChangeDistortion); - }); - }); - - if (m_Node.distortion.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Distortion Blend Mode", indentLevel)), (row) => - { - row.Add(new EnumField(DistortionMode.Add), (field) => - { - field.value = m_Node.distortionMode; - field.RegisterValueChangedCallback(ChangeDistortionMode); - }); - }); - ps.Add(new PropertyRow(CreateLabel("Distortion Only", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.distortionOnly.isOn; - toggle.OnToggleChanged(ChangeDistortionOnly); - }); - }); - ps.Add(new PropertyRow(CreateLabel("Distortion Depth Test", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.distortionDepthTest.isOn; - toggle.OnToggleChanged(ChangeDistortionDepthTest); - }); - }); - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.zWrite.isOn; - toggle.OnToggleChanged(ChangeZWrite); - }); - }); - - if (!m_Node.doubleSided.isOn) - { - ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.transparentCullMode), (e) => - { - e.value = m_Node.transparentCullMode; - e.RegisterValueChangedCallback(ChangeTransparentCullMode); - }); - }); - } - - ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => - { - row.Add(new EnumField(m_Node.zTest), (e) => - { - e.value = m_Node.zTest; - e.RegisterValueChangedCallback(ChangeZTest); - }); - }); - - --indentLevel; - } - - ps.Add(new PropertyRow(new Label("Double-Sided")), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.doubleSided.isOn; - toggle.OnToggleChanged(ChangeDoubleSided); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTest.isOn; - toggle.OnToggleChanged(ChangeAlphaTest); - }); - }); - - if (m_Node.alphaTest.isOn) - { - ++indentLevel; - ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaToMask.isOn; - toggle.OnToggleChanged(ChangeAlphaToMask); - }); - }); - --indentLevel; - } - - ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.addPrecomputedVelocity.isOn; - toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); - }); - }); - - ps.Add(new PropertyRow(CreateLabel("Shadow Matte", indentLevel)), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.enableShadowMatte.isOn; - toggle.OnToggleChanged(ChangeEnableShadowMatte); - }); - }); - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeSurfaceType(ChangeEvent evt) - { - if (Equals(m_Node.surfaceType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); - m_Node.surfaceType = (SurfaceType)evt.newValue; - - UpdateRenderingPassValue(m_Node.renderingPass); - } - - void ChangeDoubleSided(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Change"); - ToggleData td = m_Node.doubleSided; - td.isOn = evt.newValue; - m_Node.doubleSided = td; - } - - void ChangeBlendMode(ChangeEvent evt) - { - // Make sure the mapping is correct by handling each case. - - AlphaMode alphaMode = GetAlphaMode((HDUnlitMasterNode.AlphaModeLit)evt.newValue); - - if (Equals(m_Node.alphaMode, alphaMode)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); - m_Node.alphaMode = alphaMode; - } - - void ChangeTransparencyFog(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); - ToggleData td = m_Node.transparencyFog; - td.isOn = evt.newValue; - m_Node.transparencyFog = td; - } - - void ChangeRenderingPass(ChangeEvent evt) - { - switch (evt.newValue) - { - case HDRenderQueue.RenderQueueType.Overlay: - case HDRenderQueue.RenderQueueType.Unknown: - case HDRenderQueue.RenderQueueType.Background: - throw new ArgumentException("Unexpected kind of RenderQueue, was " + evt.newValue); - default: - break; - }; - UpdateRenderingPassValue(evt.newValue); - } - - void UpdateRenderingPassValue(HDRenderQueue.RenderQueueType newValue) - { - HDRenderQueue.RenderQueueType renderingPass; - switch (m_Node.surfaceType) - { - case SurfaceType.Opaque: - renderingPass = HDRenderQueue.GetOpaqueEquivalent(newValue); - break; - case SurfaceType.Transparent: - renderingPass = HDRenderQueue.GetTransparentEquivalent(newValue); - break; - default: - throw new ArgumentException("Unknown SurfaceType"); - } - - if (Equals(m_Node.renderingPass, renderingPass)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Rendering Pass Change"); - m_Node.renderingPass = renderingPass; - } - - void ChangeDistortion(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Change"); - ToggleData td = m_Node.distortion; - td.isOn = evt.newValue; - m_Node.distortion = td; - } - - void ChangeDistortionMode(ChangeEvent evt) - { - if (Equals(m_Node.distortionMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Mode Change"); - m_Node.distortionMode = (DistortionMode)evt.newValue; - } - - void ChangeDistortionOnly(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Only Change"); - ToggleData td = m_Node.distortionOnly; - td.isOn = evt.newValue; - m_Node.distortionDepthTest = td; - } - - void ChangeDistortionDepthTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Depth Test Change"); - ToggleData td = m_Node.distortionDepthTest; - td.isOn = evt.newValue; - m_Node.distortionDepthTest = td; - } - - void ChangeSortPriority(ChangeEvent evt) - { - m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - // Force the text to match. - m_SortPiorityField.value = m_Node.sortPriority; - if (Equals(m_Node.sortPriority, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); - } - - void ChangeAlphaTest(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); - ToggleData td = m_Node.alphaTest; - td.isOn = evt.newValue; - m_Node.alphaTest = td; - } - - void ChangeAlphaToMask(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); - ToggleData td = m_Node.alphaToMask; - td.isOn = evt.newValue; - m_Node.alphaToMask = td; - } - - void ChangeAddPrecomputedVelocity(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); - ToggleData td = m_Node.addPrecomputedVelocity; - td.isOn = evt.newValue; - m_Node.addPrecomputedVelocity = td; - } - - void ChangeEnableShadowMatte(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Shadow Matte"); - ToggleData td = m_Node.enableShadowMatte; - td.isOn = evt.newValue; - m_Node.enableShadowMatte = td; - } - - void ChangeZWrite(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); - ToggleData td = m_Node.zWrite; - td.isOn = evt.newValue; - m_Node.zWrite = td; - } - - void ChangeTransparentCullMode(ChangeEvent evt) - { - if (Equals(m_Node.transparentCullMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); - m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; - } - - void ChangeZTest(ChangeEvent evt) - { - if (Equals(m_Node.zTest, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); - m_Node.zTest = (CompareFunction)evt.newValue; - } - - public AlphaMode GetAlphaMode(HDUnlitMasterNode.AlphaModeLit alphaModeLit) - { - switch (alphaModeLit) - { - case HDUnlitMasterNode.AlphaModeLit.Alpha: - return AlphaMode.Alpha; - case HDUnlitMasterNode.AlphaModeLit.Premultiply: - return AlphaMode.Premultiply; - case HDUnlitMasterNode.AlphaModeLit.Additive: - return AlphaMode.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaModeLit); - return AlphaMode.Alpha; - } - } - } - - public HDUnlitMasterNode.AlphaModeLit GetAlphaModeLit(AlphaMode alphaMode) - { - switch (alphaMode) - { - case AlphaMode.Alpha: - return HDUnlitMasterNode.AlphaModeLit.Alpha; - case AlphaMode.Premultiply: - return HDUnlitMasterNode.AlphaModeLit.Premultiply; - case AlphaMode.Additive: - return HDUnlitMasterNode.AlphaModeLit.Additive; - default: - { - Debug.LogWarning("Not supported: " + alphaMode); - return HDUnlitMasterNode.AlphaModeLit.Alpha; - } - } - } - } -} +// using System; +// using UnityEditor.UIElements; +// using UnityEngine; +// using UnityEngine.UIElements; +// using UnityEditor.Graphing.Util; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Drawing; +// using UnityEditor.ShaderGraph.Drawing.Controls; +// using UnityEditor.Rendering.HighDefinition; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEngine.Rendering; + +// namespace UnityEditor.Rendering.HighDefinition.Drawing +// { +// class HDUnlitSettingsView : MasterNodeSettingsView +// { +// HDUnlitMasterNode m_Node; + +// IntegerField m_SortPiorityField; + +// Label CreateLabel(string text, int indentLevel) +// { +// string label = ""; +// for (var i = 0; i < indentLevel; i++) +// { +// label += " "; +// } +// return new Label(label + text); +// } + +// public HDUnlitSettingsView(HDUnlitMasterNode node) : base(node) +// { +// m_Node = node; +// PropertySheet ps = new PropertySheet(); + +// int indentLevel = 0; +// ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(SurfaceType.Opaque), (field) => +// { +// field.value = m_Node.surfaceType; +// field.RegisterValueChangedCallback(ChangeSurfaceType); +// }); +// }); + +// ++indentLevel; +// switch (m_Node.surfaceType) +// { +// case SurfaceType.Opaque: +// ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => +// { +// var valueList = HDSubShaderUtilities.GetRenderingPassList(true, true); + +// row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Opaque, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => +// { +// field.value = HDRenderQueue.GetOpaqueEquivalent(m_Node.renderingPass); +// field.RegisterValueChangedCallback(ChangeRenderingPass); +// }); +// }); +// break; +// case SurfaceType.Transparent: +// ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => +// { +// Enum defaultValue; +// switch (m_Node.renderingPass) // Migration +// { +// default: //when deserializing without issue, we still need to init the default to something even if not used. +// case HDRenderQueue.RenderQueueType.Transparent: +// defaultValue = HDRenderQueue.TransparentRenderQueue.Default; +// break; +// case HDRenderQueue.RenderQueueType.PreRefraction: +// defaultValue = HDRenderQueue.TransparentRenderQueue.BeforeRefraction; +// break; +// } + +// var valueList = HDSubShaderUtilities.GetRenderingPassList(false, true); + +// row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Transparent, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => +// { +// field.value = HDRenderQueue.GetTransparentEquivalent(m_Node.renderingPass); +// field.RegisterValueChangedCallback(ChangeRenderingPass); +// }); +// }); +// break; +// default: +// throw new ArgumentException("Unknown SurfaceType"); +// } +// --indentLevel; + +// if (m_Node.surfaceType == SurfaceType.Transparent) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(HDUnlitMasterNode.AlphaModeLit.Additive), (field) => +// { +// field.value = GetAlphaModeLit(m_Node.alphaMode); +// field.RegisterValueChangedCallback(ChangeBlendMode); +// }); +// }); + +// m_SortPiorityField = new IntegerField(); +// ps.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => +// { +// row.Add(m_SortPiorityField, (field) => +// { +// field.value = m_Node.sortPriority; +// field.RegisterValueChangedCallback(ChangeSortPriority); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.transparencyFog.isOn; +// toggle.OnToggleChanged(ChangeTransparencyFog); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.distortion.isOn; +// toggle.OnToggleChanged(ChangeDistortion); +// }); +// }); + +// if (m_Node.distortion.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Distortion Blend Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(DistortionMode.Add), (field) => +// { +// field.value = m_Node.distortionMode; +// field.RegisterValueChangedCallback(ChangeDistortionMode); +// }); +// }); +// ps.Add(new PropertyRow(CreateLabel("Distortion Only", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.distortionOnly.isOn; +// toggle.OnToggleChanged(ChangeDistortionOnly); +// }); +// }); +// ps.Add(new PropertyRow(CreateLabel("Distortion Depth Test", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.distortionDepthTest.isOn; +// toggle.OnToggleChanged(ChangeDistortionDepthTest); +// }); +// }); +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.zWrite.isOn; +// toggle.OnToggleChanged(ChangeZWrite); +// }); +// }); + +// if (!m_Node.doubleSided.isOn) +// { +// ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.transparentCullMode), (e) => +// { +// e.value = m_Node.transparentCullMode; +// e.RegisterValueChangedCallback(ChangeTransparentCullMode); +// }); +// }); +// } + +// ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => +// { +// row.Add(new EnumField(m_Node.zTest), (e) => +// { +// e.value = m_Node.zTest; +// e.RegisterValueChangedCallback(ChangeZTest); +// }); +// }); + +// --indentLevel; +// } + +// ps.Add(new PropertyRow(new Label("Double-Sided")), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.doubleSided.isOn; +// toggle.OnToggleChanged(ChangeDoubleSided); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaTest.isOn; +// toggle.OnToggleChanged(ChangeAlphaTest); +// }); +// }); + +// if (m_Node.alphaTest.isOn) +// { +// ++indentLevel; +// ps.Add(new PropertyRow(CreateLabel("Alpha to Mask", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.alphaToMask.isOn; +// toggle.OnToggleChanged(ChangeAlphaToMask); +// }); +// }); +// --indentLevel; +// } + +// ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.addPrecomputedVelocity.isOn; +// toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); +// }); +// }); + +// ps.Add(new PropertyRow(CreateLabel("Shadow Matte", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (toggle) => +// { +// toggle.value = m_Node.enableShadowMatte.isOn; +// toggle.OnToggleChanged(ChangeEnableShadowMatte); +// }); +// }); + +// Add(ps); +// Add(GetShaderGUIOverridePropertySheet()); +// } + +// void ChangeSurfaceType(ChangeEvent evt) +// { +// if (Equals(m_Node.surfaceType, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Type Change"); +// m_Node.surfaceType = (SurfaceType)evt.newValue; + +// UpdateRenderingPassValue(m_Node.renderingPass); +// } + +// void ChangeDoubleSided(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Double-Sided Change"); +// ToggleData td = m_Node.doubleSided; +// td.isOn = evt.newValue; +// m_Node.doubleSided = td; +// } + +// void ChangeBlendMode(ChangeEvent evt) +// { +// // Make sure the mapping is correct by handling each case. + +// AlphaMode alphaMode = GetAlphaMode((HDUnlitMasterNode.AlphaModeLit)evt.newValue); + +// if (Equals(m_Node.alphaMode, alphaMode)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); +// m_Node.alphaMode = alphaMode; +// } + +// void ChangeTransparencyFog(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparency Fog Change"); +// ToggleData td = m_Node.transparencyFog; +// td.isOn = evt.newValue; +// m_Node.transparencyFog = td; +// } + +// void ChangeRenderingPass(ChangeEvent evt) +// { +// switch (evt.newValue) +// { +// case HDRenderQueue.RenderQueueType.Overlay: +// case HDRenderQueue.RenderQueueType.Unknown: +// case HDRenderQueue.RenderQueueType.Background: +// throw new ArgumentException("Unexpected kind of RenderQueue, was " + evt.newValue); +// default: +// break; +// }; +// UpdateRenderingPassValue(evt.newValue); +// } + +// void UpdateRenderingPassValue(HDRenderQueue.RenderQueueType newValue) +// { +// HDRenderQueue.RenderQueueType renderingPass; +// switch (m_Node.surfaceType) +// { +// case SurfaceType.Opaque: +// renderingPass = HDRenderQueue.GetOpaqueEquivalent(newValue); +// break; +// case SurfaceType.Transparent: +// renderingPass = HDRenderQueue.GetTransparentEquivalent(newValue); +// break; +// default: +// throw new ArgumentException("Unknown SurfaceType"); +// } + +// if (Equals(m_Node.renderingPass, renderingPass)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Rendering Pass Change"); +// m_Node.renderingPass = renderingPass; +// } + +// void ChangeDistortion(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Change"); +// ToggleData td = m_Node.distortion; +// td.isOn = evt.newValue; +// m_Node.distortion = td; +// } + +// void ChangeDistortionMode(ChangeEvent evt) +// { +// if (Equals(m_Node.distortionMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Mode Change"); +// m_Node.distortionMode = (DistortionMode)evt.newValue; +// } + +// void ChangeDistortionOnly(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Only Change"); +// ToggleData td = m_Node.distortionOnly; +// td.isOn = evt.newValue; +// m_Node.distortionDepthTest = td; +// } + +// void ChangeDistortionDepthTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Distortion Depth Test Change"); +// ToggleData td = m_Node.distortionDepthTest; +// td.isOn = evt.newValue; +// m_Node.distortionDepthTest = td; +// } + +// void ChangeSortPriority(ChangeEvent evt) +// { +// m_Node.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); +// // Force the text to match. +// m_SortPiorityField.value = m_Node.sortPriority; +// if (Equals(m_Node.sortPriority, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Sort Priority Change"); +// } + +// void ChangeAlphaTest(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Test Change"); +// ToggleData td = m_Node.alphaTest; +// td.isOn = evt.newValue; +// m_Node.alphaTest = td; +// } + +// void ChangeAlphaToMask(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha to Mask Change"); +// ToggleData td = m_Node.alphaToMask; +// td.isOn = evt.newValue; +// m_Node.alphaToMask = td; +// } + +// void ChangeAddPrecomputedVelocity(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Add Precomputed Velocity"); +// ToggleData td = m_Node.addPrecomputedVelocity; +// td.isOn = evt.newValue; +// m_Node.addPrecomputedVelocity = td; +// } + +// void ChangeEnableShadowMatte(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("Shadow Matte"); +// ToggleData td = m_Node.enableShadowMatte; +// td.isOn = evt.newValue; +// m_Node.enableShadowMatte = td; +// } + +// void ChangeZWrite(ChangeEvent evt) +// { +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZWrite Change"); +// ToggleData td = m_Node.zWrite; +// td.isOn = evt.newValue; +// m_Node.zWrite = td; +// } + +// void ChangeTransparentCullMode(ChangeEvent evt) +// { +// if (Equals(m_Node.transparentCullMode, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("Transparent Cull Mode Change"); +// m_Node.transparentCullMode = (TransparentCullMode)evt.newValue; +// } + +// void ChangeZTest(ChangeEvent evt) +// { +// if (Equals(m_Node.zTest, evt.newValue)) +// return; + +// m_Node.owner.owner.RegisterCompleteObjectUndo("ZTest Change"); +// m_Node.zTest = (CompareFunction)evt.newValue; +// } + +// public AlphaMode GetAlphaMode(HDUnlitMasterNode.AlphaModeLit alphaModeLit) +// { +// switch (alphaModeLit) +// { +// case HDUnlitMasterNode.AlphaModeLit.Alpha: +// return AlphaMode.Alpha; +// case HDUnlitMasterNode.AlphaModeLit.Premultiply: +// return AlphaMode.Premultiply; +// case HDUnlitMasterNode.AlphaModeLit.Additive: +// return AlphaMode.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaModeLit); +// return AlphaMode.Alpha; +// } +// } +// } + +// public HDUnlitMasterNode.AlphaModeLit GetAlphaModeLit(AlphaMode alphaMode) +// { +// switch (alphaMode) +// { +// case AlphaMode.Alpha: +// return HDUnlitMasterNode.AlphaModeLit.Alpha; +// case AlphaMode.Premultiply: +// return HDUnlitMasterNode.AlphaModeLit.Premultiply; +// case AlphaMode.Additive: +// return HDUnlitMasterNode.AlphaModeLit.Additive; +// default: +// { +// Debug.LogWarning("Not supported: " + alphaMode); +// return HDUnlitMasterNode.AlphaModeLit.Alpha; +// } +// } +// } +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs index 64fdfb7b6f0..46d518d9215 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs @@ -1,565 +1,565 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class HDUnlitSubTarget : SubTarget - { - const string kAssetGuid = "4516595d40fa52047a77940183dc8e74"; - - // Why do the raytracing passes use the template for the pipeline agnostic Unlit master node? - // This should be resolved so we can delete the second pass template - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template"; - static string raytracingPassTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/UnlitPass.template"; - - public HDUnlitSubTarget() - { - displayName = "Unlit"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.HDUnlitGUI"); - context.AddSubShader(SubShaders.Unlit); - context.AddSubShader(SubShaders.UnlitRaytracing); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Unlit = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { UnlitPasses.ShadowCaster }, - { UnlitPasses.META }, - { UnlitPasses.SceneSelection }, - { UnlitPasses.DepthForwardOnly }, - { UnlitPasses.MotionVectors }, - { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, - { UnlitPasses.ForwardOnly }, - }, - }; - - public static SubShaderDescriptor UnlitRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { UnlitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - static class UnlitPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - pixelPorts = UnlitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ CoreRequiredFields.Meta, HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = UnlitIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.DepthForwardOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = UnlitKeywords.DepthMotionVectors, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ CoreRequiredFields.PositionRWS, HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = UnlitKeywords.DepthMotionVectors, - includes = UnlitIncludes.MotionVectors, - }; - - public static PassDescriptor Distortion = new PassDescriptor() - { - // Definition - displayName = "DistortionVectors", - referenceName = "SHADERPASS_DISTORTION", - lightMode = "DistortionVectors", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentDistortion, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.Distortion, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = UnlitIncludes.Distortion, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD_UNLIT", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = UnlitKeywords.Forward, - includes = UnlitIncludes.ForwardOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = raytracingPassTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = raytracingPassTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = raytracingPassTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = raytracingPassTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingPathTracing = new PassDescriptor() - { - //Definition - displayName = "PathTracingDXR", - referenceName = "SHADERPASS_PATH_TRACING", - lightMode = "PathTracingDXR", - useInPreview = false, - - // Template - passTemplatePath = raytracingPassTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingPathTracing }, - }; - } -#endregion - -#region PortMasks - static class UnlitPortMasks - { - public static int[] Vertex = new int[] - { - HDUnlitMasterNode.PositionSlotId, - HDUnlitMasterNode.VertexNormalSlotId, - HDUnlitMasterNode.VertexTangentSlotId, - }; - - public static int[] FragmentDefault = new int[] - { - HDUnlitMasterNode.ColorSlotId, - HDUnlitMasterNode.AlphaSlotId, - HDUnlitMasterNode.AlphaThresholdSlotId, - HDUnlitMasterNode.EmissionSlotId, - }; - - public static int[] FragmentOnlyAlpha = new int[] - { - HDUnlitMasterNode.AlphaSlotId, - HDUnlitMasterNode.AlphaThresholdSlotId, - }; - - public static int[] FragmentDistortion = new int[] - { - HDUnlitMasterNode.AlphaSlotId, - HDUnlitMasterNode.AlphaThresholdSlotId, - HDUnlitMasterNode.DistortionSlotId, - HDUnlitMasterNode.DistortionBlurSlotId, - }; - - public static int[] FragmentForward = new int[] - { - HDUnlitMasterNode.ColorSlotId, - HDUnlitMasterNode.AlphaSlotId, - HDUnlitMasterNode.AlphaThresholdSlotId, - HDUnlitMasterNode.EmissionSlotId, - HDUnlitMasterNode.ShadowTintSlotId, - }; - } -#endregion - -#region RenderStates - static class UnlitRenderStates - { - public static RenderStateCollection SceneSelection = new RenderStateCollection - { - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ColorMask("ColorMask 0") }, - }; - - // Caution: When using MSAA we have normal and depth buffer bind. - // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT - // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask - // - When MSAA: disable target 1 (normal buffer) - // - When no MSAA: disable target 0 (normal buffer) and 1 (unused) - public static RenderStateCollection DepthForwardOnly = new RenderStateCollection - { - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ColorMask("ColorMask [_ColorMaskNormal]") }, - { RenderState.ColorMask("ColorMask 0 1") }, - { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, - Ref = CoreRenderStates.Uniforms.stencilRefDepth, - Comp = "Always", - Pass = "Replace", - }) }, - }; - - // Caution: When using MSAA we have motion vector, normal and depth buffer bind. - // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT - // This is not a problem in no MSAA mode as there is no buffer bind - public static RenderStateCollection MotionVectors = new RenderStateCollection - { - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1") }, - { RenderState.ColorMask("ColorMask 0 2") }, - { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, - Ref = CoreRenderStates.Uniforms.stencilRefMV, - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection Distortion = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, - { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, - { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, - { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, - Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, - Comp = "Always", - Pass = "Replace", - }) }, - }; - } -#endregion - -#region Keywords - static class UnlitKeywords - { - public static KeywordCollection DepthMotionVectors = new KeywordCollection - { - { CoreKeywords.HDBase }, - { CoreKeywordDescriptors.WriteMsaaDepth }, - { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, - }; - - public static KeywordCollection Forward = new KeywordCollection - { - { CoreKeywords.HDBase }, - { CoreKeywordDescriptors.DebugDisplay }, - }; - } -#endregion - -#region Includes - static class UnlitIncludes - { - const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class HDUnlitSubTarget : SubTarget +// { +// const string kAssetGuid = "4516595d40fa52047a77940183dc8e74"; + +// // Why do the raytracing passes use the template for the pipeline agnostic Unlit master node? +// // This should be resolved so we can delete the second pass template +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template"; +// static string raytracingPassTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/UnlitPass.template"; + +// public HDUnlitSubTarget() +// { +// displayName = "Unlit"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.HDUnlitGUI"); +// context.AddSubShader(SubShaders.Unlit); +// context.AddSubShader(SubShaders.UnlitRaytracing); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Unlit = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { UnlitPasses.ShadowCaster }, +// { UnlitPasses.META }, +// { UnlitPasses.SceneSelection }, +// { UnlitPasses.DepthForwardOnly }, +// { UnlitPasses.MotionVectors }, +// { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, +// { UnlitPasses.ForwardOnly }, +// }, +// }; + +// public static SubShaderDescriptor UnlitRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { UnlitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// static class UnlitPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// pixelPorts = UnlitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ CoreRequiredFields.Meta, HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = UnlitIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.DepthForwardOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = UnlitKeywords.DepthMotionVectors, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ CoreRequiredFields.PositionRWS, HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = UnlitKeywords.DepthMotionVectors, +// includes = UnlitIncludes.MotionVectors, +// }; + +// public static PassDescriptor Distortion = new PassDescriptor() +// { +// // Definition +// displayName = "DistortionVectors", +// referenceName = "SHADERPASS_DISTORTION", +// lightMode = "DistortionVectors", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentDistortion, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.Distortion, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = UnlitIncludes.Distortion, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD_UNLIT", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = UnlitKeywords.Forward, +// includes = UnlitIncludes.ForwardOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = raytracingPassTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = raytracingPassTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = raytracingPassTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = raytracingPassTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingPathTracing = new PassDescriptor() +// { +// //Definition +// displayName = "PathTracingDXR", +// referenceName = "SHADERPASS_PATH_TRACING", +// lightMode = "PathTracingDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = raytracingPassTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingPathTracing }, +// }; +// } +// #endregion + +// #region PortMasks +// static class UnlitPortMasks +// { +// public static int[] Vertex = new int[] +// { +// HDUnlitMasterNode.PositionSlotId, +// HDUnlitMasterNode.VertexNormalSlotId, +// HDUnlitMasterNode.VertexTangentSlotId, +// }; + +// public static int[] FragmentDefault = new int[] +// { +// HDUnlitMasterNode.ColorSlotId, +// HDUnlitMasterNode.AlphaSlotId, +// HDUnlitMasterNode.AlphaThresholdSlotId, +// HDUnlitMasterNode.EmissionSlotId, +// }; + +// public static int[] FragmentOnlyAlpha = new int[] +// { +// HDUnlitMasterNode.AlphaSlotId, +// HDUnlitMasterNode.AlphaThresholdSlotId, +// }; + +// public static int[] FragmentDistortion = new int[] +// { +// HDUnlitMasterNode.AlphaSlotId, +// HDUnlitMasterNode.AlphaThresholdSlotId, +// HDUnlitMasterNode.DistortionSlotId, +// HDUnlitMasterNode.DistortionBlurSlotId, +// }; + +// public static int[] FragmentForward = new int[] +// { +// HDUnlitMasterNode.ColorSlotId, +// HDUnlitMasterNode.AlphaSlotId, +// HDUnlitMasterNode.AlphaThresholdSlotId, +// HDUnlitMasterNode.EmissionSlotId, +// HDUnlitMasterNode.ShadowTintSlotId, +// }; +// } +// #endregion + +// #region RenderStates +// static class UnlitRenderStates +// { +// public static RenderStateCollection SceneSelection = new RenderStateCollection +// { +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ColorMask("ColorMask 0") }, +// }; + +// // Caution: When using MSAA we have normal and depth buffer bind. +// // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT +// // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask +// // - When MSAA: disable target 1 (normal buffer) +// // - When no MSAA: disable target 0 (normal buffer) and 1 (unused) +// public static RenderStateCollection DepthForwardOnly = new RenderStateCollection +// { +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ColorMask("ColorMask [_ColorMaskNormal]") }, +// { RenderState.ColorMask("ColorMask 0 1") }, +// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, +// Ref = CoreRenderStates.Uniforms.stencilRefDepth, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// // Caution: When using MSAA we have motion vector, normal and depth buffer bind. +// // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT +// // This is not a problem in no MSAA mode as there is no buffer bind +// public static RenderStateCollection MotionVectors = new RenderStateCollection +// { +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1") }, +// { RenderState.ColorMask("ColorMask 0 2") }, +// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, +// Ref = CoreRenderStates.Uniforms.stencilRefMV, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection Distortion = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, +// { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, +// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, +// { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, +// { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, +// Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Keywords +// static class UnlitKeywords +// { +// public static KeywordCollection DepthMotionVectors = new KeywordCollection +// { +// { CoreKeywords.HDBase }, +// { CoreKeywordDescriptors.WriteMsaaDepth }, +// { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, +// }; + +// public static KeywordCollection Forward = new KeywordCollection +// { +// { CoreKeywords.HDBase }, +// { CoreKeywordDescriptors.DebugDisplay }, +// }; +// } +// #endregion + +// #region Includes +// static class UnlitIncludes +// { +// const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; - public static IncludeCollection Meta = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Distortion = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kCommonLighting, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kShadowContext, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { kPassForwardUnlit, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// public static IncludeCollection Meta = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Distortion = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kCommonLighting, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kShadowContext, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { kPassForwardUnlit, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitSubTarget.cs index cda904e70d2..eb1794f9c22 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitSubTarget.cs @@ -1,354 +1,354 @@ -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - sealed class UnlitSubTarget : SubTarget - { - const string kAssetGuid = "625d75e9f0cb52546993731fe9ceeb47"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/UnlitPass.template"; - - public UnlitSubTarget() - { - displayName = "Unlit"; - } - - public override void Setup(ref TargetSetupContext context) - { - context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.SetDefaultShaderGUI("Rendering.HighDefinition.UnlitUI"); - context.AddSubShader(SubShaders.Unlit); - } - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Unlit = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - renderTypeOverride = HDRenderTypeTags.HDUnlitShader.ToString(), - generatesPreview = true, - passes = new PassCollection - { - { UnlitPasses.ShadowCaster }, - { UnlitPasses.META }, - { UnlitPasses.SceneSelection }, - { UnlitPasses.DepthForwardOnly, new FieldCondition(Fields.SurfaceOpaque, true) }, - { UnlitPasses.MotionVectors, new FieldCondition(Fields.SurfaceOpaque, true) }, - { UnlitPasses.ForwardOnly }, - }, - }; - } -#endregion - -#region Passes - static class UnlitPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - pixelPorts = UnlitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - includes = UnlitIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.ShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.DepthForwardOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.WriteMsaaDepth, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.PositionRWS, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.WriteMsaaDepth, - includes = UnlitIncludes.MotionVectors, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD_UNLIT", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.DebugDisplay, - includes = UnlitIncludes.ForwardOnly, - }; - } -#endregion - -#region PortMasks - static class UnlitPortMasks - { - public static int[] Vertex = new int[] - { - UnlitMasterNode.PositionSlotId, - UnlitMasterNode.VertNormalSlotId, - UnlitMasterNode.VertTangentSlotId, - }; - - public static int[] FragmentDefault = new int[] - { - UnlitMasterNode.ColorSlotId, - UnlitMasterNode.AlphaSlotId, - UnlitMasterNode.AlphaThresholdSlotId, - }; - - public static int[] FragmentOnlyAlpha = new int[] - { - UnlitMasterNode.AlphaSlotId, - UnlitMasterNode.AlphaThresholdSlotId, - }; - } -#endregion - -#region RenderStates - static class UnlitRenderStates - { - public static RenderStateCollection ShadowCaster = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ColorMask("ColorMask 0") }, - }; - - public static RenderStateCollection SceneSelection = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.ZWrite(ZWrite.On), new FieldCondition(Fields.SurfaceOpaque, true) }, - { RenderState.ZWrite(ZWrite.Off), new FieldCondition(Fields.SurfaceTransparent, true) }, - { RenderState.ColorMask("ColorMask 0") }, - }; - - // Caution: When using MSAA we have normal and depth buffer bind. - // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT - // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask - // - When MSAA: disable target 1 (normal buffer) - // - When no MSAA: disable target 0 (normal buffer) and 1 (unused) - public static RenderStateCollection DepthForwardOnly = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.ZWrite(ZWrite.On), new FieldCondition(Fields.SurfaceOpaque, true) }, - { RenderState.ZWrite(ZWrite.Off), new FieldCondition(Fields.SurfaceTransparent, true) }, - { RenderState.ColorMask("ColorMask [_ColorMaskNormal]") }, - { RenderState.ColorMask("ColorMask 0 1") }, - }; - - // Caution: When using MSAA we have motion vector, normal and depth buffer bind. - // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT - // This is not a problem in no MSAA mode as there is no buffer bind - public static RenderStateCollection MotionVectors = new RenderStateCollection - { - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1") }, - { RenderState.ColorMask("ColorMask 0 2") }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = $"{(int)StencilUsage.ObjectMotionVector}", - Ref = $"{(int)StencilUsage.ObjectMotionVector}", - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection Forward = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(Fields.SurfaceOpaque, true) }, - { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { - new FieldCondition(Fields.SurfaceTransparent, true), - new FieldCondition(Fields.BlendAlpha, true) } }, - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition[] { - new FieldCondition(Fields.SurfaceTransparent, true), - new FieldCondition(Fields.BlendAdd, true) } }, - { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { - new FieldCondition(Fields.SurfaceTransparent, true), - new FieldCondition(Fields.BlendPremultiply, true) } }, - { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { - new FieldCondition(Fields.SurfaceTransparent, true), - new FieldCondition(Fields.BlendMultiply, true) } }, - - { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, - { RenderState.ZWrite(ZWrite.On), new FieldCondition(Fields.SurfaceOpaque, true) }, - { RenderState.ZWrite(ZWrite.Off), new FieldCondition(Fields.SurfaceTransparent, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = $"{(int)StencilUsage.RequiresDeferredLighting | (int)StencilUsage.SubsurfaceScattering}", - Ref = $"{(int)StencilUsage.Clear}", - Comp = "Always", - Pass = "Replace", - }) }, - }; - } -#endregion - -#region Includes - static class UnlitIncludes - { - // These are duplicated from HDUnlitSubTarget - // We avoid moving these to CoreIncludes because this SubTarget will be removed with Stacks - - const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// sealed class UnlitSubTarget : SubTarget +// { +// const string kAssetGuid = "625d75e9f0cb52546993731fe9ceeb47"; +// static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/UnlitPass.template"; + +// public UnlitSubTarget() +// { +// displayName = "Unlit"; +// } + +// public override void Setup(ref TargetSetupContext context) +// { +// context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); +// context.SetDefaultShaderGUI("Rendering.HighDefinition.UnlitUI"); +// context.AddSubShader(SubShaders.Unlit); +// } + +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Unlit = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// renderTypeOverride = HDRenderTypeTags.HDUnlitShader.ToString(), +// generatesPreview = true, +// passes = new PassCollection +// { +// { UnlitPasses.ShadowCaster }, +// { UnlitPasses.META }, +// { UnlitPasses.SceneSelection }, +// { UnlitPasses.DepthForwardOnly, new FieldCondition(Fields.SurfaceOpaque, true) }, +// { UnlitPasses.MotionVectors, new FieldCondition(Fields.SurfaceOpaque, true) }, +// { UnlitPasses.ForwardOnly }, +// }, +// }; +// } +// #endregion + +// #region Passes +// static class UnlitPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// pixelPorts = UnlitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// includes = UnlitIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.ShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.DepthForwardOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.WriteMsaaDepth, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.PositionRWS, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.WriteMsaaDepth, +// includes = UnlitIncludes.MotionVectors, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD_UNLIT", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// vertexPorts = UnlitPortMasks.Vertex, +// pixelPorts = UnlitPortMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.DebugDisplay, +// includes = UnlitIncludes.ForwardOnly, +// }; +// } +// #endregion + +// #region PortMasks +// static class UnlitPortMasks +// { +// public static int[] Vertex = new int[] +// { +// UnlitMasterNode.PositionSlotId, +// UnlitMasterNode.VertNormalSlotId, +// UnlitMasterNode.VertTangentSlotId, +// }; + +// public static int[] FragmentDefault = new int[] +// { +// UnlitMasterNode.ColorSlotId, +// UnlitMasterNode.AlphaSlotId, +// UnlitMasterNode.AlphaThresholdSlotId, +// }; + +// public static int[] FragmentOnlyAlpha = new int[] +// { +// UnlitMasterNode.AlphaSlotId, +// UnlitMasterNode.AlphaThresholdSlotId, +// }; +// } +// #endregion + +// #region RenderStates +// static class UnlitRenderStates +// { +// public static RenderStateCollection ShadowCaster = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ColorMask("ColorMask 0") }, +// }; + +// public static RenderStateCollection SceneSelection = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.ZWrite(ZWrite.On), new FieldCondition(Fields.SurfaceOpaque, true) }, +// { RenderState.ZWrite(ZWrite.Off), new FieldCondition(Fields.SurfaceTransparent, true) }, +// { RenderState.ColorMask("ColorMask 0") }, +// }; + +// // Caution: When using MSAA we have normal and depth buffer bind. +// // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT +// // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask +// // - When MSAA: disable target 1 (normal buffer) +// // - When no MSAA: disable target 0 (normal buffer) and 1 (unused) +// public static RenderStateCollection DepthForwardOnly = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.ZWrite(ZWrite.On), new FieldCondition(Fields.SurfaceOpaque, true) }, +// { RenderState.ZWrite(ZWrite.Off), new FieldCondition(Fields.SurfaceTransparent, true) }, +// { RenderState.ColorMask("ColorMask [_ColorMaskNormal]") }, +// { RenderState.ColorMask("ColorMask 0 1") }, +// }; + +// // Caution: When using MSAA we have motion vector, normal and depth buffer bind. +// // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT +// // This is not a problem in no MSAA mode as there is no buffer bind +// public static RenderStateCollection MotionVectors = new RenderStateCollection +// { +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1") }, +// { RenderState.ColorMask("ColorMask 0 2") }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = $"{(int)StencilUsage.ObjectMotionVector}", +// Ref = $"{(int)StencilUsage.ObjectMotionVector}", +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection Forward = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(Fields.SurfaceOpaque, true) }, +// { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceTransparent, true), +// new FieldCondition(Fields.BlendAlpha, true) } }, +// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceTransparent, true), +// new FieldCondition(Fields.BlendAdd, true) } }, +// { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceTransparent, true), +// new FieldCondition(Fields.BlendPremultiply, true) } }, +// { RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha), new FieldCondition[] { +// new FieldCondition(Fields.SurfaceTransparent, true), +// new FieldCondition(Fields.BlendMultiply, true) } }, + +// { RenderState.Cull(Cull.Off), new FieldCondition(Fields.DoubleSided, true) }, +// { RenderState.ZWrite(ZWrite.On), new FieldCondition(Fields.SurfaceOpaque, true) }, +// { RenderState.ZWrite(ZWrite.Off), new FieldCondition(Fields.SurfaceTransparent, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = $"{(int)StencilUsage.RequiresDeferredLighting | (int)StencilUsage.SubsurfaceScattering}", +// Ref = $"{(int)StencilUsage.Clear}", +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Includes +// static class UnlitIncludes +// { +// // These are duplicated from HDUnlitSubTarget +// // We avoid moving these to CoreIncludes because this SubTarget will be removed with Stacks + +// const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; - public static IncludeCollection Meta = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kCommonLighting, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kShadowContext, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { kPassForwardUnlit, IncludeLocation.Postgraph }, - }; - } -#endregion - } -} +// public static IncludeCollection Meta = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kCommonLighting, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kShadowContext, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { kPassForwardUnlit, IncludeLocation.Postgraph }, +// }; +// } +// #endregion +// } +// } diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDShaderUtils.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDShaderUtils.cs index cfcfa5dd4fa..1ead30a51f6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDShaderUtils.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDShaderUtils.cs @@ -48,18 +48,6 @@ internal enum ShaderID "HDRP/AxF", }; - // exposed shadergraph, for reference while searching the ShaderID - static readonly Type[] s_MasterNodes = - { - typeof(HDUnlitMasterNode), - typeof(HDLitMasterNode), - typeof(HairMasterNode), - typeof(FabricMasterNode), - typeof(StackLitMasterNode), - typeof(DecalMasterNode), - typeof(EyeMasterNode), - }; - // list of methods for resetting keywords delegate void MaterialResetter(Material material); static Dictionary k_MaterialResetters = new Dictionary() @@ -133,8 +121,9 @@ internal static bool IsHDRPShader(Shader shader, bool upgradable = false) if (shader.IsShaderGraph()) { - var outputNodeType = GraphUtil.GetOutputNodeType(AssetDatabase.GetAssetPath(shader)); - return s_MasterNodes.Contains(outputNodeType); + // TODO: All Shader Graphs are now HDRP shaders + // TODO: Need to calculate this from Targets? + return true; } else if (upgradable) return s_ShaderPaths.Contains(shader.name); @@ -149,15 +138,17 @@ internal static bool IsUnlitHDRPShader(Shader shader) if (shader.IsShaderGraph()) { - string shaderPath = AssetDatabase.GetAssetPath(shader); - switch (GraphUtil.GetOutputNodeType(shaderPath).Name) - { - case nameof(HDUnlitMasterNode): - case nameof(UnlitMasterNode): - return true; - default: - return false; - } + // TODO: Calculate this from metadata + return true; + // string shaderPath = AssetDatabase.GetAssetPath(shader); + // switch (GraphUtil.GetOutputNodeType(shaderPath).Name) + // { + // case nameof(HDUnlitMasterNode): + // case nameof(UnlitMasterNode): + // return true; + // default: + // return false; + // } } else return shader.name == "HDRP/Unlit"; @@ -175,27 +166,18 @@ internal static string GetShaderPath(ShaderID id) return s_ShaderPaths[index]; } - internal static Type GetShaderMasterNodeType(ShaderID id) - { - int index = (int)id - (int)ShaderID.Count_Standard; - if (index < 0 && index >= (int)ShaderID.Count_ShaderGraph) - { - Debug.LogError("Trying to access HDRP shader path out of bounds"); - return null; - } - - return s_MasterNodes[index]; - } - internal static ShaderID GetShaderEnumFromShader(Shader shader) { if (shader.IsShaderGraph()) { - var type = GraphUtil.GetOutputNodeType(AssetDatabase.GetAssetPath(shader)); - var index = Array.FindIndex(s_MasterNodes, m => m == type); - if (index == -1) - throw new ArgumentException("Unknown shader"); - return (ShaderID)(index + ShaderID.Count_Standard); + return ShaderID.SG_Unlit; + + // TODO: Calculate this from metadata + // var type = GraphUtil.GetOutputNodeType(AssetDatabase.GetAssetPath(shader)); + // var index = Array.FindIndex(s_MasterNodes, m => m == type); + // if (index == -1) + // throw new ArgumentException("Unknown shader"); + // return (ShaderID)(index + ShaderID.Count_Standard); } else { diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs new file mode 100644 index 00000000000..11fe5e21131 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs @@ -0,0 +1,71 @@ +using UnityEngine; +using UnityEditor.ShaderGraph.Internal; +using UnityEditor.ShaderGraph; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + internal static class HDBlockFields + { + [GenerateBlocks] + public struct SurfaceDescription + { + public static string name = "SurfaceDescription"; + + // -------------------------------------------------- + // Unlit + + public static BlockFieldDescriptor Distortion = new BlockFieldDescriptor(SurfaceDescription.name, "Distortion", "SURFACEDESCRIPTION_DISTORTION", + new Vector2Control(Vector2.zero), ShaderStage.Fragment); // TODO: Lit is Vector2(2.0f, -1.0f) + public static BlockFieldDescriptor DistortionBlur = new BlockFieldDescriptor(SurfaceDescription.name, "DistortionBlur", "SURFACEDESCRIPTION_DISTORTIONBLUR", + new FloatControl(1.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor ShadowTint = new BlockFieldDescriptor(SurfaceDescription.name, "ShadowTint", "SURFACEDESCRIPTION_SHADOWTINT", + new ColorRGBAControl(Color.black), ShaderStage.Fragment); + + // -------------------------------------------------- + // Lit + + public static BlockFieldDescriptor BentNormal = new BlockFieldDescriptor(SurfaceDescription.name, "BentNormal", "SURFACEDESCRIPTION_BENTNORMAL", + new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment); + public static BlockFieldDescriptor Tangent = new BlockFieldDescriptor(SurfaceDescription.name, "Tangent", "SURFACEDESCRIPTION_TANGENT", + new TangentControl(CoordinateSpace.Tangent), ShaderStage.Fragment); + public static BlockFieldDescriptor Anisotropy = new BlockFieldDescriptor(SurfaceDescription.name, "Anisotropy", "SURFACEDESCRIPTION_ANISOTROPY", + new FloatControl(0.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor SubsurfaceMask = new BlockFieldDescriptor(SurfaceDescription.name, "SubsurfaceMask", "SURFACEDESCRIPTION_SUBSURFACEMASK", + new FloatControl(1.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor Thickness = new BlockFieldDescriptor(SurfaceDescription.name, "Thickness", "SURFACEDESCRIPTION_THICKNESS", + new FloatControl(1.0f), ShaderStage.Fragment); + public static CustomSlotBlockFieldDescriptor DiffusionProfileHash = new CustomSlotBlockFieldDescriptor(SurfaceDescription.name, "DiffusionProfileHash", "SURFACEDESCRIPTION_DIFFUSIONPROFILEHASH", + new DiffusionProfileInputMaterialSlot(0, "DiffusionProfile", "DiffusionProfileHash", ShaderStageCapability.Fragment)); + public static BlockFieldDescriptor IridescenceMask = new BlockFieldDescriptor(SurfaceDescription.name, "IridescenceMask", "SURFACEDESCRIPTION_IRIDESCENCEMASK", + new FloatControl(0.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor IridescenceThickness = new BlockFieldDescriptor(SurfaceDescription.name, "IridescenceThickness", "SURFACEDESCRIPTION_IRIDESCENCETHICKNESS", + new FloatControl(0.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor CoatMask = new BlockFieldDescriptor(SurfaceDescription.name, "CoatMask", "SURFACEDESCRIPTION_COATMASK", + new FloatControl(0.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor SpecularOcclusion = new BlockFieldDescriptor(SurfaceDescription.name, "SpecularOcclusion", "SURFACEDESCRIPTION_SPECULAROCCLUSION", + new FloatControl(1.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor AlphaClipThresholdDepthPrepass = new BlockFieldDescriptor(SurfaceDescription.name, "AlphaClipThresholdDepthPrepass", "SURFACEDESCRIPTION_ALPHACLIPTHRESHOLDDEPTHPREPASS", + new FloatControl(0.5f), ShaderStage.Fragment); + public static BlockFieldDescriptor AlphaClipThresholdDepthPostpass = new BlockFieldDescriptor(SurfaceDescription.name, "AlphaClipThresholdDepthPostpass", "SURFACEDESCRIPTION_ALPHACLIPTHRESHOLDDEPTHPOSTPASS", + new FloatControl(0.5f), ShaderStage.Fragment); + public static BlockFieldDescriptor AlphaClipThresholdShadow = new BlockFieldDescriptor(SurfaceDescription.name, "AlphaClipThresholdShadow", "SURFACEDESCRIPTION_ALPHACLIPTHRESHOLDSHADOW", + new FloatControl(0.5f), ShaderStage.Fragment); + public static BlockFieldDescriptor SpecularAAScreenSpaceVariance = new BlockFieldDescriptor(SurfaceDescription.name, "SpecularAAScreenSpaceVariance", "SURFACEDESCRIPTION_SPECULARAASCEENSPACEVARIANCE", + new FloatControl(0.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor SpecularAAThreshold = new BlockFieldDescriptor(SurfaceDescription.name, "SpecularAAThreshold", "SURFACEDESCRIPTION_SPECULARAATHRESHOLD", + new FloatControl(0.0f), ShaderStage.Fragment); + public static CustomSlotBlockFieldDescriptor BakedGI = new CustomSlotBlockFieldDescriptor(SurfaceDescription.name, "BakedGI", "SURFACEDESCRIPTION_BAKEDGI", + new DefaultMaterialSlot(0, "BakedGI", "BakedGI", ShaderStageCapability.Fragment)); + public static CustomSlotBlockFieldDescriptor BakedBackGI = new CustomSlotBlockFieldDescriptor(SurfaceDescription.name, "BakedBackGI", "SURFACEDESCRIPTION_BAKEDBACKGI", + new DefaultMaterialSlot(0, "BakedBackGI", "BakedBackGI", ShaderStageCapability.Fragment)); + public static BlockFieldDescriptor DepthOffset = new BlockFieldDescriptor(SurfaceDescription.name, "DepthOffset", "SURFACEDESCRIPTION_DEPTHOFFSET", + new FloatControl(0.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor RefractionIndex = new BlockFieldDescriptor(SurfaceDescription.name, "RefractionIndex", "SURFACEDESCRIPTION_REFRACTIONINDEX", + new FloatControl(1.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor RefractionColor = new BlockFieldDescriptor(SurfaceDescription.name, "RefractionColor", "SURFACEDESCRIPTION_REFRACTIONCOLOR", + new ColorControl(Color.white, false), ShaderStage.Fragment); + public static BlockFieldDescriptor RefractionDistance = new BlockFieldDescriptor(SurfaceDescription.name, "RefractionDistance", "SURFACEDESCRIPTION_REFRACTIONDISTANCE", + new FloatControl(1.0f), ShaderStage.Fragment); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/CreateHairShaderGraph.cs.meta b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/CreateHairShaderGraph.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs.meta index 4a9701cdc83..f2c91704e2c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/CreateHairShaderGraph.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDBlockFields.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f8cd1630249e23445be1ed78d1b524dd +guid: 55b3aee4ed078d942b20b4a453e266e8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDMeshTargetSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDMeshTargetSettingsView.cs new file mode 100644 index 00000000000..4bb8ad87b0f --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDMeshTargetSettingsView.cs @@ -0,0 +1,445 @@ +// using System; +// using System.Collections.Generic; +// using System.Linq; +// using UnityEngine; +// using UnityEngine.Rendering; +// using UnityEngine.Rendering.HighDefinition; +// using UnityEditor.ShaderGraph; +// using UnityEditor.ShaderGraph.Internal; +// using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; + +// using UnityEditor.UIElements; +// using UnityEngine.UIElements; +// using UnityEditor.Graphing; +// using UnityEditor.Graphing.Util; +// using UnityEditor.ShaderGraph.Drawing; + +// namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +// { +// class HDMeshTargetSettingsView : VisualElement +// { +// HDMeshTarget target; +// Action onChange; +// int indentLevel; + +// public HDMeshTargetSettingsView(HDMeshTarget target, Action onChange) +// { +// // Set data +// name = "hdMeshSettings"; +// this.target = target; +// this.onChange = onChange; +// indentLevel = 0; + +// // Main +// DoSurfaceType(0); +// RenderingPass(1); + +// if(target.surfaceType == SurfaceType.Transparent) +// { +// // Render State +// BlendingMode(1); +// DepthTest(1); +// DepthWrite(1); +// if(target.doubleSidedMode != DoubleSidedMode.Disabled) +// { +// CullMode(1); +// } +// SortingPriority(1); + +// // Misc +// ReceiveFog(1); + +// // Distortion +// DoDistortion(1); +// if(target.distortion) +// { +// DistortionBlendMode(2); +// DistortionOnly(2); +// DistortionDepthTest(2); +// } +// } + +// // Misc +// DoubleSided(0); +// AlphaClipping(0); +// AddPrecomputedVelocity(0); +// ShadowMatte(0); +// } + +// #region Properties +// void DoSurfaceType(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => +// { +// row.Add(new EnumField(SurfaceType.Opaque), (field) => +// { +// field.value = target.surfaceType; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.surfaceType, evt.newValue)) +// return; + +// target.surfaceType = (SurfaceType)evt.newValue; +// UpdateRenderingPassValue(target.renderingPass); +// onChange(); +// }); +// }); +// }); +// } + +// void RenderingPass(int indentLevel) +// { +// switch (target.surfaceType) +// { +// case SurfaceType.Opaque: +// this.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => +// { +// var valueList = HDSubShaderUtilities.GetRenderingPassList(true, true); +// row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Opaque, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => +// { +// var value = HDRenderQueue.GetOpaqueEquivalent(target.renderingPass); +// field.value = value; +// field.RegisterValueChangedCallback(evt => { +// if(ChangeRenderingPass(value)) +// { +// onChange(); +// } +// }); +// }); +// }); +// break; +// case SurfaceType.Transparent: +// this.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => +// { +// Enum defaultValue; +// switch (target.renderingPass) // Migration +// { +// default: //when deserializing without issue, we still need to init the default to something even if not used. +// case HDRenderQueue.RenderQueueType.Transparent: +// defaultValue = HDRenderQueue.TransparentRenderQueue.Default; +// break; +// case HDRenderQueue.RenderQueueType.PreRefraction: +// defaultValue = HDRenderQueue.TransparentRenderQueue.BeforeRefraction; +// break; +// } + +// var valueList = HDSubShaderUtilities.GetRenderingPassList(false, true); +// row.Add(new PopupField(valueList, HDRenderQueue.RenderQueueType.Transparent, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => +// { +// var value = HDRenderQueue.GetTransparentEquivalent(target.renderingPass); +// field.value = value; +// field.RegisterValueChangedCallback(evt => { +// if(ChangeRenderingPass(value)) +// { +// onChange(); +// } +// }); +// }); +// }); +// break; +// default: +// throw new ArgumentException("Unknown SurfaceType"); +// } +// } + +// void BlendingMode(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(AlphaMode.Alpha), (field) => +// { +// field.value = target.alphaMode; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.alphaMode, evt.newValue)) +// return; + +// target.alphaMode = (AlphaMode)evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void SortingPriority(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => +// { +// row.Add(new IntegerField(), (field) => +// { +// field.value = target.sortPriority; +// field.RegisterValueChangedCallback(evt => { +// var value = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); +// if (Equals(target.sortPriority, value)) +// return; + +// target.sortPriority = value; +// onChange(); +// }); +// }); +// }); +// } + +// void ReceiveFog(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (field) => +// { +// field.value = target.transparencyFog; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.transparencyFog, evt.newValue)) +// return; + +// target.transparencyFog = evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void DoDistortion(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (field) => +// { +// field.value = target.distortion; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.distortion, evt.newValue)) +// return; + +// target.distortion = evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void DistortionBlendMode(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Distortion Blend Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(DistortionMode.Add), (field) => +// { +// field.value = target.distortionMode; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.distortionMode, evt.newValue)) +// return; + +// target.distortionMode = (DistortionMode)evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void DistortionOnly(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Distortion Only", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (field) => +// { +// field.value = target.distortionOnly; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.distortionOnly, evt.newValue)) +// return; + +// target.distortionOnly = evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void DistortionDepthTest(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Distortion Depth Test", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (field) => +// { +// field.value = target.distortionDepthTest; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.distortionDepthTest, evt.newValue)) +// return; + +// target.distortionDepthTest = evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void DepthTest(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => +// { +// row.Add(new EnumField(target.zTest), (field) => +// { +// field.value = target.zTest; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.zTest, evt.newValue)) +// return; + +// target.zTest = (CompareFunction)evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void DepthWrite(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (field) => +// { +// field.value = target.zWrite; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.zWrite, evt.newValue)) +// return; + +// target.zWrite = evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void CullMode(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => +// { +// row.Add(new EnumField(target.transparentCullMode), (field) => +// { +// field.value = target.transparentCullMode; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.transparentCullMode, evt.newValue)) +// return; + +// target.transparentCullMode = (TransparentCullMode)evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void DoubleSided(int indentLevel) +// { +// this.Add(new PropertyRow(new Label("Double-Sided Mode")), (row) => +// { +// row.Add(new EnumField(target.doubleSidedMode), (field) => +// { +// field.value = target.doubleSidedMode; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.doubleSidedMode, evt.newValue)) +// return; + +// target.doubleSidedMode = (DoubleSidedMode)evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void AlphaClipping(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (field) => +// { +// field.value = target.alphaTest; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.alphaTest, evt.newValue)) +// return; + +// target.alphaTest = evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void AddPrecomputedVelocity(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (field) => +// { +// field.value = target.addPrecomputedVelocity; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.addPrecomputedVelocity, evt.newValue)) +// return; + +// target.addPrecomputedVelocity = evt.newValue; +// onChange(); +// }); +// }); +// }); +// } + +// void ShadowMatte(int indentLevel) +// { +// this.Add(new PropertyRow(CreateLabel("Shadow Matte", indentLevel)), (row) => +// { +// row.Add(new Toggle(), (field) => +// { +// field.value = target.enableShadowMatte; +// field.RegisterValueChangedCallback(evt => { +// if (Equals(target.enableShadowMatte, evt.newValue)) +// return; + +// target.enableShadowMatte = evt.newValue; +// onChange(); +// }); +// }); +// }); +// } +// #endregion + +// #region Helpers +// Label CreateLabel(string text, int indentLevel) +// { +// string label = ""; +// for (var i = 0; i < indentLevel; i++) +// { +// label += " "; +// } +// return new Label(label + text); +// } + +// bool ChangeRenderingPass(HDRenderQueue.RenderQueueType value) +// { +// switch (value) +// { +// case HDRenderQueue.RenderQueueType.Overlay: +// case HDRenderQueue.RenderQueueType.Unknown: +// case HDRenderQueue.RenderQueueType.Background: +// throw new ArgumentException("Unexpected kind of RenderQueue, was " + value); +// default: +// break; +// }; +// return UpdateRenderingPassValue(value); +// } + +// bool UpdateRenderingPassValue(HDRenderQueue.RenderQueueType value) +// { +// switch (target.surfaceType) +// { +// case SurfaceType.Opaque: +// value = HDRenderQueue.GetOpaqueEquivalent(value); +// break; +// case SurfaceType.Transparent: +// value = HDRenderQueue.GetTransparentEquivalent(value); +// break; +// default: +// throw new ArgumentException("Unknown SurfaceType"); +// } + +// if (Equals(target.renderingPass, value)) +// return false; + +// target.renderingPass = value; +// return true; +// } +// #endregion +// } +// } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs.meta b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDMeshTargetSettingsView.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDMeshTargetSettingsView.cs.meta index ea5232a74da..58a17974cf1 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/CreateEyeShaderGraph.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDMeshTargetSettingsView.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1c420b007c865ea46acf39ca5a4a0044 +guid: df34290c9d9d6764184eed2c00357706 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs index 54228829450..984a369c45c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs @@ -8,6 +8,7 @@ using UnityEditor.ShaderGraph.Internal; using UnityEngine.Rendering.HighDefinition; using UnityEngine.Rendering; +using UnityEditor.Rendering.HighDefinition.ShaderGraph; using ShaderPass = UnityEditor.ShaderGraph.PassDescriptor; // Include material common properties names @@ -212,23 +213,6 @@ public static string RenderQueueName(HDRenderQueue.RenderQueueType value) return result; } - public static BlendMode ConvertAlphaModeToBlendMode(AlphaMode alphaMode) - { - switch (alphaMode) - { - case AlphaMode.Additive: - return BlendMode.Additive; - case AlphaMode.Alpha: - return BlendMode.Alpha; - case AlphaMode.Premultiply: - return BlendMode.Premultiply; - case AlphaMode.Multiply: // In case of multiply we fall back to alpha - return BlendMode.Alpha; - default: - throw new System.Exception("Unknown AlphaMode: " + alphaMode + ": can't convert to BlendMode."); - } - } - public static DoubleSidedNormalMode ConvertDoubleSidedModeToDoubleSidedNormalMode(DoubleSidedMode shaderGraphMode) { switch (shaderGraphMode) diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs index 1ad6541e5f7..9af130526b2 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs @@ -1,72 +1,163 @@ using System; using System.Collections.Generic; using System.Linq; +using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; +using UnityEngine.UIElements; +using UnityEditor.Graphing; using UnityEditor.ShaderGraph; +using UnityEditor.UIElements; namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { + enum DoubleSidedMode + { + Disabled, + Enabled, + FlippedNormals, + MirroredNormals, + } + sealed class HDTarget : Target { + // Constants const string kAssetGuid = "61d9843d4027e3e4a924953135f76f3c"; + + // SubTarget List m_SubTargets; + List m_SubTargetNames; + int activeSubTargetIndex => m_SubTargets.IndexOf(m_ActiveSubTarget); + + // View + PopupField m_SubTargetField; + TextField m_CustomGUIField; + + // TODO: Remove when Peter's serialization lands + [SerializeField] + SerializationHelper.JSONSerializedElement m_SerializedSubTarget; + + [SerializeField] SubTarget m_ActiveSubTarget; + [SerializeField] + string m_CustomEditorGUI; + public HDTarget() { displayName = "HDRP"; - m_SubTargets = TargetUtils.GetSubTargetsOfType(); + m_SubTargets = TargetUtils.GetSubTargets(this); + m_SubTargetNames = m_SubTargets.Select(x => x.displayName).ToList(); } public static string sharedTemplateDirectory => $"{HDUtils.GetHDRenderPipelinePath()}Editor/ShaderGraph/Templates"; - public override void Setup(ref TargetSetupContext context) + public override bool IsActive() { - // Currently we infer the active SubTarget based on the MasterNode type - void SetActiveSubTargetIndex(IMasterNode masterNode) - { - Type activeSubTargetType; - if(!s_SubTargetMap.TryGetValue(masterNode.GetType(), out activeSubTargetType)) - return; + if(m_ActiveSubTarget == null) + return false; - m_ActiveSubTarget = m_SubTargets.FirstOrDefault(x => x.GetType() == activeSubTargetType); - } - + bool isHDRenderPipeline = GraphicsSettings.currentRenderPipeline is HDRenderPipelineAsset; + return isHDRenderPipeline && m_ActiveSubTarget.IsActive(); + } + + public override void Setup(ref TargetSetupContext context) + { // Setup the Target context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); + // Process SubTargets + TargetUtils.ProcessSubTargetList(ref m_ActiveSubTarget, ref m_SubTargets); + if(m_ActiveSubTarget == null) + return; + // Setup the active SubTarget - SetActiveSubTargetIndex(context.masterNode); m_ActiveSubTarget.Setup(ref context); + + // Override EditorGUI + if(!string.IsNullOrEmpty(m_CustomEditorGUI)) + { + context.SetDefaultShaderGUI(m_CustomEditorGUI); + } + } + + public override void GetFields(ref TargetFieldContext context) + { } - public override bool IsValid(IMasterNode masterNode) + public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - // Currently we infer the validity based on SubTarget mapping - return s_SubTargetMap.TryGetValue(masterNode.GetType(), out _); } - public override bool IsPipelineCompatible(RenderPipelineAsset currentPipeline) + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange) + { + if(m_ActiveSubTarget == null) + return; + + // Core properties + m_SubTargetField = new PopupField(m_SubTargetNames, activeSubTargetIndex); + context.AddProperty("Material", m_SubTargetField, (evt) => + { + if (Equals(activeSubTargetIndex, m_SubTargetField.index)) + return; + + m_ActiveSubTarget = m_SubTargets[m_SubTargetField.index]; + onChange(); + }); + + // SubTarget properties + m_ActiveSubTarget.GetPropertiesGUI(ref context, onChange); + + // Custom Editor GUI + m_CustomGUIField = new TextField("") { value = m_CustomEditorGUI }; + m_CustomGUIField.RegisterCallback(s => + { + if (Equals(m_CustomEditorGUI, m_CustomGUIField.value)) + return; + + m_CustomEditorGUI = m_CustomGUIField.value; + onChange(); + }); + context.AddProperty("Custom Editor GUI", m_CustomGUIField, (evt) => {}); + } + + public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { - return currentPipeline is HDRenderPipelineAsset; } - // Currently we need to map SubTarget type to IMasterNode type - // We do this here to avoid bleeding this into the SubTarget API - static Dictionary s_SubTargetMap = new Dictionary() + // TODO: Remove this +#region Serialization + public void OnBeforeSerialize() { - { typeof(PBRMasterNode), typeof(PBRSubTarget) }, - { typeof(UnlitMasterNode), typeof(UnlitSubTarget) }, - { typeof(HDLitMasterNode), typeof(HDLitSubTarget) }, - { typeof(HDUnlitMasterNode), typeof(HDUnlitSubTarget) }, - { typeof(DecalMasterNode), typeof(HDDecalSubTarget) }, - { typeof(EyeMasterNode), typeof(HDEyeSubTarget) }, - { typeof(FabricMasterNode), typeof(HDFabricSubTarget) }, - { typeof(HairMasterNode), typeof(HDHairSubTarget) }, - { typeof(StackLitMasterNode), typeof(HDStackLitSubTarget) }, + if(m_ActiveSubTarget == null) + return; + + m_SerializedSubTarget = SerializationHelper.Serialize(m_ActiveSubTarget); + } + + public void OnAfterDeserialize() + { + if(m_ActiveSubTarget == null) + return; + + // Deserialize the SubTarget + m_ActiveSubTarget = SerializationHelper.Deserialize(m_SerializedSubTarget, GraphUtil.GetLegacyTypeRemapping()); + m_ActiveSubTarget.target = this; + } +#endregion + } + +#region BlockMasks + static class CoreBlockMasks + { + public static BlockFieldDescriptor[] Vertex = new BlockFieldDescriptor[] + { + BlockFields.VertexDescription.Position, + BlockFields.VertexDescription.Normal, + BlockFields.VertexDescription.Tangent, }; } +#endregion #region StructCollections static class CoreStructCollections diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteLitShaderGraph.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteLitShaderGraph.cs deleted file mode 100644 index ec4ef448b95..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteLitShaderGraph.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Experimental.Rendering.Universal -{ - class CreateSpriteLitShaderGraph - { - [MenuItem("Assets/Create/Shader/2D Renderer/Sprite Lit Graph (Experimental)", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new SpriteLitMasterNode()); - } - } -} diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteLitShaderGraph.cs.meta b/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteLitShaderGraph.cs.meta deleted file mode 100644 index eb74b7ff219..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteLitShaderGraph.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fd5bf26faac23425db7917a29fb41dce -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteUnlitShaderGraph.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteUnlitShaderGraph.cs deleted file mode 100644 index 3c6ae78d347..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteUnlitShaderGraph.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEditor.ShaderGraph; - -namespace UnityEditor.Experimental.Rendering.Universal -{ - class CreateSpriteUnlitShaderGraph - { - [MenuItem("Assets/Create/Shader/2D Renderer/Sprite Unlit Graph (Experimental)", false, 208)] - public static void CreateMaterialGraph() - { - GraphUtil.CreateNewGraph(new SpriteUnlitMasterNode()); - } - } -} diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteUnlitShaderGraph.cs.meta b/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteUnlitShaderGraph.cs.meta deleted file mode 100644 index 19d786ab397..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks/CreateSpriteUnlitShaderGraph.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c705bcf9da993314fb781d5341f7c25a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/LightingMetaPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/LightingMetaPass.hlsl index 254778a3223..d5a92431cb8 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/LightingMetaPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/LightingMetaPass.hlsl @@ -23,7 +23,7 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET #endif MetaInput metaInput = (MetaInput)0; - metaInput.Albedo = surfaceDescription.Albedo; + metaInput.Albedo = surfaceDescription.BaseColor; metaInput.Emission = surfaceDescription.Emission; return MetaFragment(metaInput); diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBR2DPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBR2DPass.hlsl index 44f72799948..2ee42719f0d 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBR2DPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBR2DPass.hlsl @@ -20,6 +20,11 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold); #endif - half4 color = half4(surfaceDescription.Albedo, surfaceDescription.Alpha); + half alpha = 1; + #if _SURFACE_TYPE_TRANSPARENT + alpha = surfaceDescription.Alpha; + #endif + + half4 color = half4(surfaceDescription.BaseColor, alpha); return color; } diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl index 9ac3b77b6fb..2c08a56790b 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBRForwardPass.hlsl @@ -56,7 +56,7 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET #endif InputData inputData; - BuildInputData(unpacked, surfaceDescription.Normal, inputData); + BuildInputData(unpacked, surfaceDescription.NormalTS, inputData); #ifdef _SPECULAR_SETUP float3 specular = surfaceDescription.Specular; @@ -66,15 +66,20 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET float metallic = surfaceDescription.Metallic; #endif + half alpha = 1; + #if _SURFACE_TYPE_TRANSPARENT + alpha = surfaceDescription.Alpha; + #endif + half4 color = UniversalFragmentPBR( inputData, - surfaceDescription.Albedo, + surfaceDescription.BaseColor, metallic, specular, surfaceDescription.Smoothness, surfaceDescription.Occlusion, surfaceDescription.Emission, - surfaceDescription.Alpha); + alpha); color.rgb = MixFog(color.rgb, inputData.fogCoord); return color; diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteForwardPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteForwardPass.hlsl index 1a5be4f5870..9353b6b43eb 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteForwardPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteForwardPass.hlsl @@ -22,10 +22,10 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET #if ETC1_EXTERNAL_ALPHA float4 alpha = SAMPLE_TEXTURE2D(_AlphaTex, sampler_AlphaTex, unpacked.texCoord0.xy); - surfaceDescription.Color.a = lerp (surfaceDescription.Color.a, alpha.r, _EnableAlphaTexture); + surfaceDescription.Alpha = lerp (surfaceDescription.Alpha, alpha.r, _EnableAlphaTexture); #endif - surfaceDescription.Color *= unpacked.color; - - return surfaceDescription.Color; + half4 color = half4(surfaceDescription.BaseColor, surfaceDescription.Alpha); + color *= unpacked.color; + return color; } diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteLitPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteLitPass.hlsl index 42a5bc1a793..4556a3dc37b 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteLitPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteLitPass.hlsl @@ -40,10 +40,11 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET #if ETC1_EXTERNAL_ALPHA float4 alpha = SAMPLE_TEXTURE2D(_AlphaTex, sampler_AlphaTex, unpacked.texCoord0.xy); - surfaceDescription.Color.a = lerp (surfaceDescription.Color.a, alpha.r, _EnableAlphaTexture); + surfaceDescription.Alpha = lerp (surfaceDescription.Alpha, alpha.r, _EnableAlphaTexture); #endif - surfaceDescription.Color *= unpacked.color; + half4 color = half4(surfaceDescription.BaseColor, surfaceDescription.Alpha); + color *= unpacked.color; - return CombinedShapeLightShared(surfaceDescription.Color, surfaceDescription.Mask, unpacked.screenPosition.xy / unpacked.screenPosition.w); + return CombinedShapeLightShared(color, surfaceDescription.SpriteMask, unpacked.screenPosition.xy / unpacked.screenPosition.w); } diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteNormalPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteNormalPass.hlsl index 8c20b94df2b..0ca097010cc 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteNormalPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteNormalPass.hlsl @@ -17,5 +17,6 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET float crossSign = (unpacked.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale(); float3 bitangent = crossSign * cross(unpacked.normalWS.xyz, unpacked.tangentWS.xyz); - return NormalsRenderingShared(surfaceDescription.Color, surfaceDescription.Normal, unpacked.tangentWS.xyz, bitangent, unpacked.normalWS); + half4 color = half4(surfaceDescription.BaseColor, surfaceDescription.Alpha); + return NormalsRenderingShared(color, surfaceDescription.NormalTS, unpacked.tangentWS.xyz, bitangent, unpacked.normalWS); } diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteUnlitPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteUnlitPass.hlsl index 46638915efd..820898d6bf2 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteUnlitPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SpriteUnlitPass.hlsl @@ -23,10 +23,10 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET #if ETC1_EXTERNAL_ALPHA float4 alpha = SAMPLE_TEXTURE2D(_AlphaTex, sampler_AlphaTex, unpacked.texCoord0.xy); - surfaceDescription.Color.a = lerp (surfaceDescription.Color.a, alpha.r, _EnableAlphaTexture); + surfaceDescription.Alpha = lerp (surfaceDescription.Alpha, alpha.r, _EnableAlphaTexture); #endif - surfaceDescription.Color *= unpacked.color * _RendererColor; - - return surfaceDescription.Color; + half4 color = half4(surfaceDescription.BaseColor, surfaceDescription.Alpha); + color *= unpacked.color * _RendererColor; + return color; } diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl index c5716e3b4df..409fbff86f8 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/UnlitPass.hlsl @@ -19,9 +19,14 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold); #endif + half alpha = 1; + #if _SURFACE_TYPE_TRANSPARENT + alpha = surfaceDescription.Alpha; + #endif + #ifdef _ALPHAPREMULTIPLY_ON - surfaceDescription.Color *= surfaceDescription.Alpha; + surfaceDescription.BaseColor *= surfaceDescription.Alpha; #endif - return half4(surfaceDescription.Color, surfaceDescription.Alpha); + return half4(surfaceDescription.BaseColor, alpha); } diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl index d770e432c8a..fdde7ba906a 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl @@ -14,14 +14,14 @@ Varyings BuildVaryings(Attributes input) // Evaluate Vertex Graph VertexDescriptionInputs vertexDescriptionInputs = BuildVertexDescriptionInputs(input); VertexDescription vertexDescription = VertexDescriptionFunction(vertexDescriptionInputs); - + // Assign modified vertex attributes - input.positionOS = vertexDescription.VertexPosition; + input.positionOS = vertexDescription.Position; #if defined(VARYINGS_NEED_NORMAL_WS) - input.normalOS = vertexDescription.VertexNormal; + input.normalOS = vertexDescription.Normal; #endif //FEATURES_GRAPH_NORMAL #if defined(VARYINGS_NEED_TANGENT_WS) - input.tangentOS.xyz = vertexDescription.VertexTangent.xyz; + input.tangentOS.xyz = vertexDescription.Tangent.xyz; #endif //FEATURES GRAPH TANGENT #endif //FEATURES_GRAPH_VERTEX diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes.meta b/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes.meta deleted file mode 100644 index ca53b9a0b0a..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d2026810a59da7a44a66430043ecf480 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteLitMasterNode.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteLitMasterNode.cs deleted file mode 100644 index 721c6db5858..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteLitMasterNode.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Graphing; -using UnityEngine; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Internal; -using UnityEngine.UIElements; - -namespace UnityEditor.Experimental.Rendering.Universal -{ - [Serializable] - [Title("Master", "Sprite Lit (Experimental)")] - [FormerName("UnityEditor.Experimental.Rendering.LWRP.SpriteLitMasterNode")] - class SpriteLitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string PositionName = "Vertex Position"; - public const string NormalName = "Vertex Normal"; - public const string TangentName = "Vertex Tangent"; - public const string ColorSlotName = "Color"; - public const string MaskSlotName = "Mask"; - public const string NormalSlotName = "Normal"; - - public const int PositionSlotId = 9; - public const int ColorSlotId = 0; - public const int MaskSlotId = 1; - public const int NormalSlotId = 2; - public const int VertNormalSlotId = 10; - public const int VertTangentSlotId = 11; - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public SpriteLitMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Sprite Lit Master"; - - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionName, PositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new NormalMaterialSlot(VertNormalSlotId, NormalName, NormalName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new TangentMaterialSlot(VertTangentSlotId, TangentName, TangentName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new ColorRGBAMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.white, ShaderStageCapability.Fragment)); - AddSlot(new ColorRGBAMaterialSlot(MaskSlotId, MaskSlotName, MaskSlotName, SlotType.Input, Color.white, ShaderStageCapability.Fragment)); - AddSlot(new Vector3MaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, new Vector3(0.0f, 0.0f, 1.0f), ShaderStageCapability.Fragment)); - - RemoveSlotsNameNotMatching( - new[] - { - PositionSlotId, - VertNormalSlotId, - VertTangentSlotId, - ColorSlotId, - MaskSlotId, - NormalSlotId, - }); - } - - public VisualElement CreateSettingsElement() - { - return new SpriteSettingsView(this); - } - - public string renderQueueTag => $"{RenderQueue.Transparent}"; - public string renderTypeTag => $"{RenderType.Transparent}"; - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PBRMasterNode.PositionSlotId) || - IsSlotConnected(PBRMasterNode.VertNormalSlotId) || - IsSlotConnected(PBRMasterNode.VertTangentSlotId)), - new ConditionalField(Fields.GraphPixel, true), - - // Surface Type - new ConditionalField(Fields.SurfaceTransparent, true), - - // Blend Mode - new ConditionalField(Fields.BlendAlpha, true), - - // Culling - new ConditionalField(Fields.DoubleSided, true), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - } -} diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteLitMasterNode.cs.meta b/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteLitMasterNode.cs.meta deleted file mode 100644 index df5e88add29..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteLitMasterNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 28a14e6c1f93e424e9ea6a1c938d5d58 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteSettingsView.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteSettingsView.cs deleted file mode 100644 index 61815c589da..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteSettingsView.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Drawing; - -namespace UnityEditor.Experimental.Rendering.Universal -{ - class SpriteSettingsView : MasterNodeSettingsView - { - public SpriteSettingsView(AbstractMaterialNode node) : base(node) - { - Add(GetShaderGUIOverridePropertySheet()); - } - } -} diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteSettingsView.cs.meta b/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteSettingsView.cs.meta deleted file mode 100644 index 53ad68a7dfb..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteSettingsView.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 80b080eab50bfbe4e80c04b9e39eb969 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteUnlitMasterNode.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteUnlitMasterNode.cs deleted file mode 100644 index 6e0a0f02931..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteUnlitMasterNode.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Graphing; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEditor.ShaderGraph; -using UnityEditor.ShaderGraph.Internal; - -namespace UnityEditor.Experimental.Rendering.Universal -{ - [Serializable] - [Title("Master", "Sprite Unlit (Experimental)")] - [FormerName("UnityEditor.Experimental.Rendering.LWRP.SpriteUnlitMasterNode")] - class SpriteUnlitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string PositionName = "Vertex Position"; - public const string NormalName = "Vertex Normal"; - public const string TangentName = "Vertex Tangent"; - public const string ColorSlotName = "Color"; - - - public const int PositionSlotId = 9; - public const int ColorSlotId = 0; - public const int VertNormalSlotId = 10; - public const int VertTangentSlotId = 11; - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public SpriteUnlitMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Sprite Unlit Master"; - - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionName, PositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new NormalMaterialSlot(VertNormalSlotId, NormalName, NormalName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new TangentMaterialSlot(VertTangentSlotId, TangentName, TangentName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new ColorRGBAMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.white, ShaderStageCapability.Fragment)); - - RemoveSlotsNameNotMatching( - new[] - { - PositionSlotId, - VertNormalSlotId, - VertTangentSlotId, - ColorSlotId, - }); - } - - public VisualElement CreateSettingsElement() - { - return new SpriteSettingsView(this); - } - - public string renderQueueTag => $"{RenderQueue.Transparent}"; - public string renderTypeTag => $"{RenderType.Transparent}"; - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PBRMasterNode.PositionSlotId) || - IsSlotConnected(PBRMasterNode.VertNormalSlotId) || - IsSlotConnected(PBRMasterNode.VertTangentSlotId)), - new ConditionalField(Fields.GraphPixel, true), - - // Surface Type - new ConditionalField(Fields.SurfaceTransparent, true), - - // Blend Mode - new ConditionalField(Fields.BlendAlpha, true), - - // Culling - new ConditionalField(Fields.DoubleSided, true), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - } -} diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteUnlitMasterNode.cs.meta b/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteUnlitMasterNode.cs.meta deleted file mode 100644 index 07315cc0f02..00000000000 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/MasterNodes/SpriteUnlitMasterNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b98f1695965a77f449e8877343eaecce -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs index 3447c6fc365..6f1fe842023 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs @@ -1,8 +1,11 @@ using System; using System.Linq; using System.Collections.Generic; +using UnityEngine; using UnityEditor.ShaderGraph; using UnityEngine.Rendering; +using UnityEditor.UIElements; +using UnityEngine.UIElements; namespace UnityEditor.Rendering.Universal.ShaderGraph { @@ -10,17 +13,135 @@ sealed class UniversalLitSubTarget : SubTarget { const string kAssetGuid = "d6c78107b64145745805d963de80cc17"; + [SerializeField] + WorkflowMode m_WorkflowMode = WorkflowMode.Metallic; + + [SerializeField] + NormalDropOffSpace m_NormalDropOffSpace = NormalDropOffSpace.Tangent; + public UniversalLitSubTarget() { displayName = "Lit"; } + public WorkflowMode workflowMode + { + get => m_WorkflowMode; + set => m_WorkflowMode = value; + } + + public NormalDropOffSpace normalDropOffSpace + { + get => m_NormalDropOffSpace; + set => m_NormalDropOffSpace = value; + } + + public override bool IsActive() => true; + public override void Setup(ref TargetSetupContext context) { context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); context.SetDefaultShaderGUI("ShaderGraph.PBRMasterGUI"); // TODO: This should be owned by URP - context.AddSubShader(SubShaders.Lit); - context.AddSubShader(SubShaders.LitDOTS); + + // Process SubShaders + SubShaderDescriptor[] subShaders = { SubShaders.Lit, SubShaders.LitDOTS }; + for(int i = 0; i < subShaders.Length; i++) + { + // Update Render State + subShaders[i].renderType = target.renderType; + subShaders[i].renderQueue = target.renderQueue; + + // Add + context.AddSubShader(subShaders[i]); + } + } + + public override void GetFields(ref TargetFieldContext context) + { + // Surface Type & Blend Mode + // These must be set per SubTarget as Sprite SubTargets override them + context.AddField(Fields.SurfaceOpaque, target.surfaceType == SurfaceType.Opaque); + context.AddField(Fields.SurfaceTransparent, target.surfaceType != SurfaceType.Opaque); + context.AddField(Fields.BlendAdd, target.surfaceType != SurfaceType.Opaque && target.alphaMode == AlphaMode.Additive); + context.AddField(Fields.BlendAlpha, target.surfaceType != SurfaceType.Opaque && target.alphaMode == AlphaMode.Alpha); + context.AddField(Fields.BlendMultiply, target.surfaceType != SurfaceType.Opaque && target.alphaMode == AlphaMode.Multiply); + context.AddField(Fields.BlendPremultiply, target.surfaceType != SurfaceType.Opaque && target.alphaMode == AlphaMode.Premultiply); + + // Lit + context.AddField(Fields.NormalDropOffOS, normalDropOffSpace == NormalDropOffSpace.Object); + context.AddField(Fields.NormalDropOffTS, normalDropOffSpace == NormalDropOffSpace.Tangent); + context.AddField(Fields.NormalDropOffWS, normalDropOffSpace == NormalDropOffSpace.World); + context.AddField(Fields.SpecularSetup, workflowMode == WorkflowMode.Specular); + context.AddField(Fields.Normal, context.blocks.Contains(BlockFields.SurfaceDescription.NormalTS)); + } + + public override void GetActiveBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(BlockFields.SurfaceDescription.Smoothness); + context.AddBlock(BlockFields.SurfaceDescription.NormalTS); + context.AddBlock(BlockFields.SurfaceDescription.Emission); + context.AddBlock(BlockFields.SurfaceDescription.Occlusion); + context.AddBlock(BlockFields.SurfaceDescription.Specular, workflowMode == WorkflowMode.Specular); + context.AddBlock(BlockFields.SurfaceDescription.Metallic, workflowMode == WorkflowMode.Metallic); + context.AddBlock(BlockFields.SurfaceDescription.Alpha, target.surfaceType == SurfaceType.Transparent || target.alphaClip); + context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, target.alphaClip); + } + + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange) + { + context.AddProperty("Workflow", new EnumField(WorkflowMode.Metallic) { value = workflowMode }, (evt) => + { + if (Equals(workflowMode, evt.newValue)) + return; + + workflowMode = (WorkflowMode)evt.newValue; + onChange(); + }); + + context.AddProperty("Surface", new EnumField(SurfaceType.Opaque) { value = target.surfaceType }, (evt) => + { + if (Equals(target.surfaceType, evt.newValue)) + return; + + target.surfaceType = (SurfaceType)evt.newValue; + onChange(); + }); + + context.AddProperty("Blend", new EnumField(AlphaMode.Alpha) { value = target.alphaMode }, target.surfaceType == SurfaceType.Transparent, (evt) => + { + if (Equals(target.alphaMode, evt.newValue)) + return; + + target.alphaMode = (AlphaMode)evt.newValue; + onChange(); + }); + + context.AddProperty("Alpha Clip", new Toggle() { value = target.alphaClip }, (evt) => + { + if (Equals(target.alphaClip, evt.newValue)) + return; + + target.alphaClip = evt.newValue; + onChange(); + }); + + context.AddProperty("Two Sided", new Toggle() { value = target.twoSided }, (evt) => + { + if (Equals(target.twoSided, evt.newValue)) + return; + + target.twoSided = evt.newValue; + onChange(); + }); + + context.AddProperty("Fragment Normal Space", new EnumField(NormalDropOffSpace.Tangent) { value = normalDropOffSpace }, (evt) => + { + if (Equals(normalDropOffSpace, evt.newValue)) + return; + + normalDropOffSpace = (NormalDropOffSpace)evt.newValue; + onChange(); + }); } #region SubShader @@ -90,8 +211,8 @@ static class LitPasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = CorePortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentLit, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = LitBlockMasks.FragmentLit, // Fields structs = CoreStructCollections.Default, @@ -117,8 +238,8 @@ static class LitPasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = CorePortMasks.Vertex, - pixelPorts = LitPortMasks.FragmentMeta, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = LitBlockMasks.FragmentMeta, // Fields structs = CoreStructCollections.Default, @@ -143,8 +264,8 @@ static class LitPasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = CorePortMasks.Vertex, - pixelPorts = LitPortMasks.Fragment2D, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = CoreBlockMasks.FragmentColorAlpha, // Fields structs = CoreStructCollections.Default, @@ -159,34 +280,27 @@ static class LitPasses #endregion #region PortMasks - static class LitPortMasks + static class LitBlockMasks { - public static int[] FragmentLit = new int[] - { - PBRMasterNode.AlbedoSlotId, - PBRMasterNode.NormalSlotId, - PBRMasterNode.EmissionSlotId, - PBRMasterNode.MetallicSlotId, - PBRMasterNode.SpecularSlotId, - PBRMasterNode.SmoothnessSlotId, - PBRMasterNode.OcclusionSlotId, - PBRMasterNode.AlphaSlotId, - PBRMasterNode.AlphaThresholdSlotId, - }; - - public static int[] FragmentMeta = new int[] + public static BlockFieldDescriptor[] FragmentLit = new BlockFieldDescriptor[] { - PBRMasterNode.AlbedoSlotId, - PBRMasterNode.EmissionSlotId, - PBRMasterNode.AlphaSlotId, - PBRMasterNode.AlphaThresholdSlotId, + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Specular, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, }; - public static int[] Fragment2D = new int[] + public static BlockFieldDescriptor[] FragmentMeta = new BlockFieldDescriptor[] { - PBRMasterNode.AlbedoSlotId, - PBRMasterNode.AlphaSlotId, - PBRMasterNode.AlphaThresholdSlotId + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, }; } #endregion diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSpriteLitSubTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSpriteLitSubTarget.cs index 546f6bab43c..bda36605689 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSpriteLitSubTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSpriteLitSubTarget.cs @@ -11,18 +11,45 @@ sealed class UniversalSpriteLitSubTarget : SubTarget { const string kAssetGuid = "ea1514729d7120344b27dcd67fbf34de"; + public UniversalSpriteLitSubTarget() + { + displayName = "Sprite Lit"; + } + + public override bool IsActive() => true; + public override void Setup(ref TargetSetupContext context) { context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); context.AddSubShader(SubShaders.SpriteLit); } + public override void GetFields(ref TargetFieldContext context) + { + // Surface Type & Blend Mode + context.AddField(Fields.SurfaceTransparent); + context.AddField(Fields.BlendAlpha); + } + + public override void GetActiveBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(BlockFields.SurfaceDescription.SpriteMask); + context.AddBlock(BlockFields.SurfaceDescription.NormalTS); + context.AddBlock(BlockFields.SurfaceDescription.Alpha); + } + + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange) + { + } + #region SubShader static class SubShaders { public static SubShaderDescriptor SpriteLit = new SubShaderDescriptor() { pipelineTag = UniversalTarget.kPipelineTag, + renderType = $"{RenderType.Transparent}", + renderQueue = $"{UnityEditor.ShaderGraph.RenderQueue.Transparent}", generatesPreview = true, passes = new PassCollection { @@ -50,8 +77,8 @@ static class SpriteLitPasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = SpriteLitPortMasks.Vertex, - pixelPorts = SpriteLitPortMasks.FragmentLit, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = SpriteLitBlockMasks.FragmentLit, // Fields structs = CoreStructCollections.Default, @@ -78,8 +105,8 @@ static class SpriteLitPasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = SpriteLitPortMasks.Vertex, - pixelPorts = SpriteLitPortMasks.FragmentForwardNormal, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = SpriteLitBlockMasks.FragmentForwardNormal, // Fields structs = CoreStructCollections.Default, @@ -105,8 +132,8 @@ static class SpriteLitPasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = SpriteLitPortMasks.Vertex, - pixelPorts = SpriteLitPortMasks.FragmentForwardNormal, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = SpriteLitBlockMasks.FragmentForwardNormal, // Fields structs = CoreStructCollections.Default, @@ -123,25 +150,20 @@ static class SpriteLitPasses #endregion #region PortMasks - static class SpriteLitPortMasks + static class SpriteLitBlockMasks { - public static int[] Vertex = new int[] - { - SpriteLitMasterNode.PositionSlotId, - SpriteLitMasterNode.VertNormalSlotId, - SpriteLitMasterNode.VertTangentSlotId, - }; - - public static int[] FragmentLit = new int[] + public static BlockFieldDescriptor[] FragmentLit = new BlockFieldDescriptor[] { - SpriteLitMasterNode.ColorSlotId, - SpriteLitMasterNode.MaskSlotId, + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.SpriteMask, }; - public static int[] FragmentForwardNormal = new int[] + public static BlockFieldDescriptor[] FragmentForwardNormal = new BlockFieldDescriptor[] { - SpriteLitMasterNode.ColorSlotId, - SpriteLitMasterNode.NormalSlotId, + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.NormalTS, }; } #endregion diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSpriteUnlitSubTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSpriteUnlitSubTarget.cs index 7bd3d1677c2..e824b529b51 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSpriteUnlitSubTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSpriteUnlitSubTarget.cs @@ -11,18 +11,44 @@ sealed class UniversalSpriteUnlitSubTarget : SubTarget { const string kAssetGuid = "ed7c0aacec26e9646b45c96fb318e5a3"; + public UniversalSpriteUnlitSubTarget() + { + displayName = "Sprite Unlit"; + } + + public override bool IsActive() => true; + public override void Setup(ref TargetSetupContext context) { context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); context.AddSubShader(SubShaders.SpriteUnlit); } + public override void GetFields(ref TargetFieldContext context) + { + // Surface Type & Blend Mode + context.AddField(Fields.SurfaceTransparent); + context.AddField(Fields.BlendAlpha); + } + + public override void GetActiveBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(BlockFields.SurfaceDescription.SpriteMask); + context.AddBlock(BlockFields.SurfaceDescription.Alpha); + } + + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange) + { + } + #region SubShader static class SubShaders { public static SubShaderDescriptor SpriteUnlit = new SubShaderDescriptor() { pipelineTag = UniversalTarget.kPipelineTag, + renderType = $"{RenderType.Transparent}", + renderQueue = $"{UnityEditor.ShaderGraph.RenderQueue.Transparent}", generatesPreview = true, passes = new PassCollection { @@ -46,8 +72,8 @@ static class SpriteUnlitPasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = SpriteUnlitPortMasks.Vertex, - pixelPorts = SpriteUnlitPortMasks.Fragment, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = SpriteUnlitBlockMasks.Fragment, // Fields structs = CoreStructCollections.Default, @@ -64,18 +90,12 @@ static class SpriteUnlitPasses #endregion #region PortMasks - static class SpriteUnlitPortMasks + static class SpriteUnlitBlockMasks { - public static int[] Vertex = new int[] - { - SpriteUnlitMasterNode.PositionSlotId, - SpriteUnlitMasterNode.VertNormalSlotId, - SpriteUnlitMasterNode.VertTangentSlotId - }; - - public static int[] Fragment = new int[] + public static BlockFieldDescriptor[] Fragment = new BlockFieldDescriptor[] { - SpriteUnlitMasterNode.ColorSlotId, + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Alpha, }; } #endregion diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs index 5c30bf89d26..d3f81873051 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs @@ -1,67 +1,251 @@ using System; using System.Linq; using System.Collections.Generic; -using UnityEditor.ShaderGraph; +using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; +using UnityEngine.UIElements; +using UnityEditor.ShaderGraph; using UnityEditor.Experimental.Rendering.Universal; +using UnityEditor.Graphing; +using UnityEditor.UIElements; namespace UnityEditor.Rendering.Universal.ShaderGraph { - sealed class UniversalTarget : Target + public enum MaterialType + { + Lit, + Unlit, + SpriteLit, + SpriteUnlit, + } + + public enum WorkflowMode + { + Specular, + Metallic, + } + + enum SurfaceType + { + Opaque, + Transparent, + } + + enum AlphaMode { + Alpha, + Premultiply, + Additive, + Multiply, + } + + sealed class UniversalTarget : Target, ISerializationCallbackReceiver + { + // Constants const string kAssetGuid = "8c72f47fdde33b14a9340e325ce56f4d"; + public const string kPipelineTag = "UniversalPipeline"; + + // SubTarget List m_SubTargets; + List m_SubTargetNames; + int activeSubTargetIndex => m_SubTargets.IndexOf(m_ActiveSubTarget); + + // View + PopupField m_SubTargetField; + TextField m_CustomGUIField; + + // TODO: Remove when Peter's serialization lands + [SerializeField] + SerializationHelper.JSONSerializedElement m_SerializedSubTarget; + + [SerializeField] SubTarget m_ActiveSubTarget; + [SerializeField] + SurfaceType m_SurfaceType = SurfaceType.Opaque; + + [SerializeField] + AlphaMode m_AlphaMode = AlphaMode.Alpha; + + [SerializeField] + bool m_TwoSided = false; + + [SerializeField] + bool m_AlphaClip = false; + + [SerializeField] + bool m_AddPrecomputedVelocity = false; + + [SerializeField] + string m_CustomEditorGUI; + public UniversalTarget() { displayName = "Universal"; - m_SubTargets = TargetUtils.GetSubTargetsOfType(); + m_SubTargets = TargetUtils.GetSubTargets(this); + m_SubTargetNames = m_SubTargets.Select(x => x.displayName).ToList(); } - public const string kPipelineTag = "UniversalPipeline"; - - public override void Setup(ref TargetSetupContext context) + public string renderType { - // Currently we infer the active SubTarget based on the MasterNode type - void SetActiveSubTargetIndex(IMasterNode masterNode) + get { - Type activeSubTargetType; - if(!s_SubTargetMap.TryGetValue(masterNode.GetType(), out activeSubTargetType)) - return; + if(surfaceType == SurfaceType.Transparent) + return $"{RenderType.Transparent}"; + else + return $"{RenderType.Opaque}"; + } + } - m_ActiveSubTarget = m_SubTargets.FirstOrDefault(x => x.GetType() == activeSubTargetType); + public string renderQueue + { + get + { + if(surfaceType == SurfaceType.Transparent) + return $"{UnityEditor.ShaderGraph.RenderQueue.Transparent}"; + else if(alphaClip) + return $"{UnityEditor.ShaderGraph.RenderQueue.AlphaTest}"; + else + return $"{UnityEditor.ShaderGraph.RenderQueue.Geometry}"; } - + } + + public SubTarget activeSubTarget + { + get => m_ActiveSubTarget; + set => m_ActiveSubTarget = value; + } + + public SurfaceType surfaceType + { + get => m_SurfaceType; + set => m_SurfaceType = value; + } + + public AlphaMode alphaMode + { + get => m_AlphaMode; + set => m_AlphaMode = value; + } + + public bool twoSided + { + get => m_TwoSided; + set => m_TwoSided = value; + } + + public bool alphaClip + { + get => m_AlphaClip; + set => m_AlphaClip = value; + } + + public bool addPrecomputedVelocity + { + get => m_AddPrecomputedVelocity; + set => m_AddPrecomputedVelocity = value; + } + + public string customEditorGUI + { + get => m_CustomEditorGUI; + set => m_CustomEditorGUI = value; + } + + public override bool IsActive() + { + bool isUniversalRenderPipeline = GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset; + return isUniversalRenderPipeline && activeSubTarget.IsActive(); + } + + public override void Setup(ref TargetSetupContext context) + { // Setup the Target context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); // Setup the active SubTarget - SetActiveSubTargetIndex(context.masterNode); + TargetUtils.ProcessSubTargetList(ref m_ActiveSubTarget, ref m_SubTargets); m_ActiveSubTarget.Setup(ref context); + + // Override EditorGUI + if(!string.IsNullOrEmpty(m_CustomEditorGUI)) + { + context.SetDefaultShaderGUI(m_CustomEditorGUI); + } + } + + public override void GetFields(ref TargetFieldContext context) + { + // Core fields + context.AddField(Fields.GraphVertex, context.blocks.Contains(BlockFields.VertexDescription.Position) || + context.blocks.Contains(BlockFields.VertexDescription.Normal) || + context.blocks.Contains(BlockFields.VertexDescription.Tangent)); + context.AddField(Fields.GraphPixel); + context.AddField(Fields.AlphaClip, alphaClip); + context.AddField(Fields.VelocityPrecomputed, addPrecomputedVelocity); + context.AddField(Fields.DoubleSided, twoSided); + + // SubTarget fields + m_ActiveSubTarget.GetFields(ref context); } - public override bool IsValid(IMasterNode masterNode) + public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - // Currently we infer the validity based on SubTarget mapping - return s_SubTargetMap.TryGetValue(masterNode.GetType(), out _); + // Core blocks + context.AddBlock(BlockFields.VertexDescription.Position); + context.AddBlock(BlockFields.VertexDescription.Normal); + context.AddBlock(BlockFields.VertexDescription.Tangent); + context.AddBlock(BlockFields.SurfaceDescription.BaseColor); + + // SubTarget blocks + m_ActiveSubTarget.GetActiveBlocks(ref context); } - public override bool IsPipelineCompatible(RenderPipelineAsset currentPipeline) + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange) { - return currentPipeline is UniversalRenderPipelineAsset; + // Core properties + m_SubTargetField = new PopupField(m_SubTargetNames, activeSubTargetIndex); + context.AddProperty("Material", m_SubTargetField, (evt) => + { + if (Equals(activeSubTargetIndex, m_SubTargetField.index)) + return; + + m_ActiveSubTarget = m_SubTargets[m_SubTargetField.index]; + onChange(); + }); + + // SubTarget properties + m_ActiveSubTarget.GetPropertiesGUI(ref context, onChange); + + // Custom Editor GUI + // Requires FocusOutEvent + m_CustomGUIField = new TextField("") { value = customEditorGUI }; + m_CustomGUIField.RegisterCallback(s => + { + if (Equals(customEditorGUI, m_CustomGUIField.value)) + return; + + customEditorGUI = m_CustomGUIField.value; + onChange(); + }); + context.AddProperty("Custom Editor GUI", m_CustomGUIField, (evt) => {}); } - // Currently we need to map SubTarget type to IMasterNode type - // We do this here to avoid bleeding this into the SubTarget API - static Dictionary s_SubTargetMap = new Dictionary() + // TODO: Remove this +#region Serialization + public void OnBeforeSerialize() { - { typeof(PBRMasterNode), typeof(UniversalLitSubTarget) }, - { typeof(UnlitMasterNode), typeof(UniversalUnlitSubTarget) }, - { typeof(SpriteLitMasterNode), typeof(UniversalSpriteLitSubTarget) }, - { typeof(SpriteUnlitMasterNode), typeof(UniversalSpriteUnlitSubTarget) }, - }; + m_SerializedSubTarget = SerializationHelper.Serialize(m_ActiveSubTarget); + } + + public void OnAfterDeserialize() + { + // Deserialize the SubTarget + m_ActiveSubTarget = SerializationHelper.Deserialize(m_SerializedSubTarget, GraphUtil.GetLegacyTypeRemapping()); + m_ActiveSubTarget.target = this; + } +#endregion } #region Passes @@ -80,8 +264,8 @@ static class CorePasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = CorePortMasks.Vertex, - pixelPorts = CorePortMasks.FragmentAlphaOnly, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = CoreBlockMasks.FragmentAlphaOnly, // Fields structs = CoreStructCollections.Default, @@ -105,8 +289,8 @@ static class CorePasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = CorePortMasks.Vertex, - pixelPorts = CorePortMasks.FragmentAlphaOnly, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = CoreBlockMasks.FragmentAlphaOnly, // Fields structs = CoreStructCollections.Default, @@ -122,19 +306,26 @@ static class CorePasses #endregion #region PortMasks - class CorePortMasks + class CoreBlockMasks { - public static int[] Vertex = new int[] + public static BlockFieldDescriptor[] Vertex = new BlockFieldDescriptor[] + { + BlockFields.VertexDescription.Position, + BlockFields.VertexDescription.Normal, + BlockFields.VertexDescription.Tangent, + }; + + public static BlockFieldDescriptor[] FragmentAlphaOnly = new BlockFieldDescriptor[] { - PBRMasterNode.PositionSlotId, - PBRMasterNode.VertNormalSlotId, - PBRMasterNode.VertTangentSlotId, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, }; - public static int[] FragmentAlphaOnly = new int[] + public static BlockFieldDescriptor[] FragmentColorAlpha = new BlockFieldDescriptor[] { - PBRMasterNode.AlphaSlotId, - PBRMasterNode.AlphaThresholdSlotId, + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, }; } #endregion diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs index 20ef55cd7ff..2d68c354e83 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs @@ -1,8 +1,11 @@ using System; using System.Linq; using System.Collections.Generic; +using UnityEngine; using UnityEditor.ShaderGraph; using UnityEngine.Rendering; +using UnityEditor.UIElements; +using UnityEngine.UIElements; namespace UnityEditor.Rendering.Universal.ShaderGraph { @@ -15,11 +18,80 @@ public UniversalUnlitSubTarget() displayName = "Unlit"; } + public override bool IsActive() => true; + public override void Setup(ref TargetSetupContext context) { context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(kAssetGuid)); - context.AddSubShader(SubShaders.Unlit); - context.AddSubShader(SubShaders.UnlitDOTS); + + // Process SubShaders + SubShaderDescriptor[] subShaders = { SubShaders.Unlit, SubShaders.UnlitDOTS }; + for(int i = 0; i < subShaders.Length; i++) + { + // Update Render State + subShaders[i].renderType = target.renderType; + subShaders[i].renderQueue = target.renderQueue; + + // Add + context.AddSubShader(subShaders[i]); + } + } + + public override void GetFields(ref TargetFieldContext context) + { + // Surface Type & Blend Mode + // These must be set per SubTarget as Sprite SubTargets override them + context.AddField(Fields.SurfaceOpaque, target.surfaceType == SurfaceType.Opaque); + context.AddField(Fields.SurfaceTransparent, target.surfaceType != SurfaceType.Opaque); + context.AddField(Fields.BlendAdd, target.surfaceType != SurfaceType.Opaque && target.alphaMode == AlphaMode.Additive); + context.AddField(Fields.BlendAlpha, target.surfaceType != SurfaceType.Opaque && target.alphaMode == AlphaMode.Alpha); + context.AddField(Fields.BlendMultiply, target.surfaceType != SurfaceType.Opaque && target.alphaMode == AlphaMode.Multiply); + context.AddField(Fields.BlendPremultiply, target.surfaceType != SurfaceType.Opaque && target.alphaMode == AlphaMode.Premultiply); + } + + public override void GetActiveBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(BlockFields.SurfaceDescription.Alpha, target.surfaceType == SurfaceType.Transparent || target.alphaClip); + context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, target.alphaClip); + } + + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange) + { + context.AddProperty("Surface", new EnumField(SurfaceType.Opaque) { value = target.surfaceType }, (evt) => + { + if (Equals(target.surfaceType, evt.newValue)) + return; + + target.surfaceType = (SurfaceType)evt.newValue; + onChange(); + }); + + context.AddProperty("Blend", new EnumField(AlphaMode.Alpha) { value = target.alphaMode }, target.surfaceType == SurfaceType.Transparent, (evt) => + { + if (Equals(target.alphaMode, evt.newValue)) + return; + + target.alphaMode = (AlphaMode)evt.newValue; + onChange(); + }); + + context.AddProperty("Alpha Clip", new Toggle() { value = target.alphaClip }, (evt) => + { + if (Equals(target.alphaClip, evt.newValue)) + return; + + target.alphaClip = evt.newValue; + onChange(); + }); + + context.AddProperty("Two Sided", new Toggle() { value = target.twoSided }, (evt) => + { + if (Equals(target.twoSided, evt.newValue)) + return; + + target.twoSided = evt.newValue; + onChange(); + }); } #region SubShader @@ -80,8 +152,8 @@ static class UnlitPasses sharedTemplateDirectory = GenerationUtils.GetDefaultSharedTemplateDirectory(), // Port Mask - vertexPorts = UnlitPortMasks.Vertex, - pixelPorts = UnlitPortMasks.Fragment, + vertexBlocks = CoreBlockMasks.Vertex, + pixelBlocks = CoreBlockMasks.FragmentColorAlpha, // Fields structs = CoreStructCollections.Default, @@ -96,25 +168,6 @@ static class UnlitPasses } #endregion -#region PortMask - static class UnlitPortMasks - { - public static int[] Vertex = new int[] - { - UnlitMasterNode.PositionSlotId, - UnlitMasterNode.VertNormalSlotId, - UnlitMasterNode.VertTangentSlotId, - }; - - public static int[] Fragment = new int[] - { - UnlitMasterNode.ColorSlotId, - UnlitMasterNode.AlphaSlotId, - UnlitMasterNode.AlphaThresholdSlotId, - }; - } -#endregion - #region Keywords static class UnlitKeywords { diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalBlockMasks.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalBlockMasks.cs new file mode 100644 index 00000000000..020f5e39b58 --- /dev/null +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalBlockMasks.cs @@ -0,0 +1,82 @@ +using UnityEditor.ShaderGraph; + +namespace UnityEditor.Rendering.Universal.ShaderGraph +{ + static class UniversalBlockMasks + { + public static class Vertex + { + public static BlockFieldDescriptor[] Default = new BlockFieldDescriptor[] + { + BlockFields.VertexDescription.Position, + BlockFields.VertexDescription.Normal, + BlockFields.VertexDescription.Tangent, + }; + } + + public static class Pixel + { + public static BlockFieldDescriptor[] LitForward = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Specular, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + }; + + public static BlockFieldDescriptor[] LitAlphaOnly = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + }; + + public static BlockFieldDescriptor[] LitMeta = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + }; + + public static BlockFieldDescriptor[] Unlit = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + }; + + public static BlockFieldDescriptor[] SpriteLit = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.SpriteMask, + BlockFields.SurfaceDescription.Alpha, + }; + + public static BlockFieldDescriptor[] SpriteNormal = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.Alpha, + }; + + public static BlockFieldDescriptor[] SpriteForward = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Alpha, + }; + + public static BlockFieldDescriptor[] SpriteUnlit = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.Alpha, + }; + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/CreateHDLitShaderGraph.cs.meta b/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalBlockMasks.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/CreateHDLitShaderGraph.cs.meta rename to com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalBlockMasks.cs.meta index 529aec842a3..e3e6d1218b5 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/CreateHDLitShaderGraph.cs.meta +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalBlockMasks.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bbd40829fa8125b46b0759b6834cfff2 +guid: 2102cc5328fff429ab79b384a6ba51b2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.shadergraph/Editor/AssetCallbacks/CreateShaderGraph.cs b/com.unity.shadergraph/Editor/AssetCallbacks/CreateShaderGraph.cs index 93b7cd6241e..7da1117be8a 100644 --- a/com.unity.shadergraph/Editor/AssetCallbacks/CreateShaderGraph.cs +++ b/com.unity.shadergraph/Editor/AssetCallbacks/CreateShaderGraph.cs @@ -4,22 +4,10 @@ namespace UnityEditor.ShaderGraph { static class CreateShaderGraph { - [MenuItem("Assets/Create/Shader/Unlit Graph", false, 208)] - public static void CreateUnlitMasterMaterialGraph() + [MenuItem("Assets/Create/Shader/Blank Shader Graph", false, 208)] + public static void CreateBlankShaderGraph() { - GraphUtil.CreateNewGraph(new UnlitMasterNode()); - } - - [MenuItem("Assets/Create/Shader/PBR Graph", false, 208)] - public static void CreatePBRMasterMaterialGraph() - { - GraphUtil.CreateNewGraph(new PBRMasterNode()); - } - - [MenuItem("Assets/Create/Shader/VFX Shader Graph", false, 208)] - public static void CreateVfxShaderGraph() - { - GraphUtil.CreateNewGraph(new VfxMasterNode()); + GraphUtil.CreateNewGraph(); } } } diff --git a/com.unity.shadergraph/Editor/Data/ContextData.cs b/com.unity.shadergraph/Editor/Data/ContextData.cs new file mode 100644 index 00000000000..d0e67b0dd38 --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/ContextData.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Internal; + +namespace UnityEditor.ShaderGraph +{ + [Serializable] + sealed class ContextData : ISerializationCallbackReceiver + { + [SerializeField] + List m_SerializableBlockGuids = new List(); + + [SerializeField] + Vector2 m_Position; + + [NonSerialized] + List m_Blocks = new List(); + + [NonSerialized] + ShaderStage m_ShaderStage; + + public ContextData() + { + } + + public List serializeableBlockGuids => m_SerializableBlockGuids; + + public List blocks => m_Blocks; + + public Vector2 position + { + get => m_Position; + set => m_Position = value; + } + + public ShaderStage shaderStage + { + get => m_ShaderStage; + set => m_ShaderStage = value; + } + + public void OnBeforeSerialize() + { + m_SerializableBlockGuids = new List(); + foreach(var block in blocks) + { + m_SerializableBlockGuids.Add(block.guid.ToString()); + } + } + + public void OnAfterDeserialize() + { + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/CreateFabricShaderGraph.cs.meta b/com.unity.shadergraph/Editor/Data/ContextData.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/CreateFabricShaderGraph.cs.meta rename to com.unity.shadergraph/Editor/Data/ContextData.cs.meta index 03b644fbc59..e49071002ef 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/CreateFabricShaderGraph.cs.meta +++ b/com.unity.shadergraph/Editor/Data/ContextData.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 55a9196e05a8afc468cef4634dfa4ef7 +guid: 8dfa4982c4e3ac6429fc1c375d3ceea2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs b/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs index de888cad9a7..12ea1a6dae7 100644 --- a/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs +++ b/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs @@ -9,6 +9,8 @@ using UnityEditor.ShaderGraph.Internal; using Edge = UnityEditor.Graphing.Edge; +using UnityEngine.UIElements; + namespace UnityEditor.ShaderGraph { [Serializable] @@ -230,6 +232,26 @@ public IEnumerable removedEdges #endregion + #region Context Data + + [SerializeField] + ContextData m_VertexContext; + + [SerializeField] + ContextData m_FragmentContext; + + // We build this once and cache it as it uses reflection + // This list is used to build the Create Node menu entries for Blocks + // as well as when deserializing descriptor fields on serialized Blocks + [NonSerialized] + List m_BlockFieldDescriptors; + + public ContextData vertexContext => m_VertexContext; + public ContextData fragmentContext => m_FragmentContext; + public List blockFieldDescriptors => m_BlockFieldDescriptors; + + #endregion + [SerializeField] InspectorPreviewData m_PreviewData = new InspectorPreviewData(); @@ -268,65 +290,184 @@ public ConcretePrecision concretePrecision } [NonSerialized] - Guid m_ActiveOutputNodeGuid; + private SubGraphOutputNode m_SubGraphOutputNode; - public Guid activeOutputNodeGuid + public SubGraphOutputNode subGraphOutputNode { - get { return m_ActiveOutputNodeGuid; } - set + get { - if (value != m_ActiveOutputNodeGuid) + if (m_SubGraphOutputNode == null) { - m_ActiveOutputNodeGuid = value; - m_OutputNode = null; - didActiveOutputNodeChange = true; - UpdateTargets(); + m_SubGraphOutputNode = GetNodes().FirstOrDefault(); } + + return m_SubGraphOutputNode; } } + internal delegate void SaveGraphDelegate(Shader shader, object context); + internal static SaveGraphDelegate onSaveGraph; + + #region Targets [SerializeField] - string m_ActiveOutputNodeGuidSerialized; + List m_SerializedTargets = new List(); [NonSerialized] - private AbstractMaterialNode m_OutputNode; + List m_ValidTargets = new List(); + + [NonSerialized] + List m_ActiveTargets = new List(); + + int m_ActiveTargetBitmask; - public AbstractMaterialNode outputNode + public List validTargets => m_ValidTargets; + public List activeTargets => m_ActiveTargets; + + // TODO: Need a better way to handle this + public bool isVFXTarget => activeTargets.Count > 0 && activeTargets[0].GetType() == typeof(VFXTarget); + #endregion + + public GraphData() { - get + m_GroupItems[Guid.Empty] = new List(); + GetBlockFieldDescriptors(); + GetTargets(); + } + + public void AddTargets(Target[] targets) + { + if(targets == null) + return; + + foreach(var target in targets) + { + if(m_ValidTargets.Any(x => x.GetType().Equals(target.GetType()))) + { + m_ActiveTargets.Add(target); + } + } + } + + void GetBlockFieldDescriptors() + { + m_BlockFieldDescriptors = new List(); + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { - // find existing node - if (m_OutputNode == null) + foreach (var nestedType in assembly.GetTypes().SelectMany(t => t.GetNestedTypes())) { - if (isSubGraph) + var attrs = nestedType.GetCustomAttributes(typeof(GenerateBlocksAttribute), false); + if (attrs == null || attrs.Length <= 0) + continue; + + // Get all fields that are BlockFieldDescriptor + // If field and context stages match add to list + foreach (var fieldInfo in nestedType.GetFields()) { - m_OutputNode = GetNodes().FirstOrDefault(); + if(fieldInfo.GetValue(nestedType) is BlockFieldDescriptor blockFieldDescriptor) + { + m_BlockFieldDescriptors.Add(blockFieldDescriptor); + } } - else + } + } + } + + void GetTargets() + { + // Find all valid Targets + var typeCollection = TypeCache.GetTypesDerivedFrom(); + foreach(var type in typeCollection) + { + if(type.IsAbstract || type.IsGenericType || !type.IsClass) + continue; + + var target = (Target)Activator.CreateInstance(type); + if(!target.isHidden) + { + m_ValidTargets.Add(target); + } + } + } + + void UpdateActiveTargets() + { + // Update active TargetImplementation list + if(m_ActiveTargets != null) + { + m_ActiveTargets.Clear(); + var targetCount = m_ValidTargets.Count; + for(int i = 0; i < targetCount; i++) + { + if(((1 << i) & m_ActiveTargetBitmask) == (1 << i)) { - m_OutputNode = GetNodeFromGuid(m_ActiveOutputNodeGuid); + m_ActiveTargets.Add(m_ValidTargets[i]); } } - - return m_OutputNode; } } - #region Targets - [NonSerialized] - List m_ValidTargets = new List(); + Dictionary m_TargetFoldouts = new Dictionary(); - public List validTargets => m_ValidTargets; - #endregion + // TODO: We should not have any View code here + // TODO: However, for now we dont know how the InspectorView will work + // TODO: So for now leave it here and dont spill the assemblies outside the method + public UnityEngine.UIElements.VisualElement GetSettings(Action onChange) + { + var element = new UnityEngine.UIElements.VisualElement() { name = "graphSettings" }; - public bool didActiveOutputNodeChange { get; set; } + // Add Label + var targetSettingsLabel = new UnityEngine.UIElements.Label("Target Settings"); + targetSettingsLabel.style.unityFontStyleAndWeight = FontStyle.Bold; + element.Add(new Drawing.PropertyRow(targetSettingsLabel)); - internal delegate void SaveGraphDelegate(Shader shader, object context); - internal static SaveGraphDelegate onSaveGraph; + element.Add(new Drawing.PropertyRow(new UnityEngine.UIElements.Label("Targets")), (row) => + { + row.Add(new UnityEngine.UIElements.IMGUIContainer(() => { + EditorGUI.BeginChangeCheck(); + m_ActiveTargetBitmask = EditorGUILayout.MaskField(m_ActiveTargetBitmask, m_ValidTargets.Select(x => x.displayName).ToArray(), GUILayout.Width(100f)); + if (EditorGUI.EndChangeCheck()) + { + UpdateActiveTargets(); + onChange(); + } + })); + }); - public GraphData() - { - m_GroupItems[Guid.Empty] = new List(); + // Iterate active TargetImplementations + foreach(var target in m_ActiveTargets) + { + // Ensure enabled state is being tracked and get value + bool foldoutActive = true; + if(!m_TargetFoldouts.TryGetValue(target, out foldoutActive)) + { + m_TargetFoldouts.Add(target, foldoutActive); + } + + // Create foldout + var foldout = new UnityEngine.UIElements.Foldout() { text = target.displayName, value = foldoutActive }; + element.Add(foldout); + foldout.RegisterValueChangedCallback(evt => + { + // Update foldout value and rebuild + m_TargetFoldouts[target] = evt.newValue; + foldout.value = evt.newValue; + onChange(); + }); + + if(foldout.value) + { + // Get settings for Target + var context = new TargetPropertyGUIContext(); + target.GetPropertiesGUI(ref context, onChange); + + foreach(var property in context.properties) + { + element.Add(property); + } + } + } + + return element; } public void ClearChanges() @@ -347,7 +488,6 @@ public void ClearChanges() m_RemovedNotes.Clear(); m_PastedStickyNotes.Clear(); m_MostRecentlyCreatedGroup = null; - didActiveOutputNodeChange = false; } public void AddNode(AbstractMaterialNode node) @@ -481,6 +621,66 @@ public void SetGroup(IGroupItem node, GroupData group) m_ParentGroupChanges.Add(groupChange); } + public void AddContexts() + { + m_VertexContext = new ContextData(); + m_VertexContext.shaderStage = ShaderStage.Vertex; + m_VertexContext.position = new Vector2(0, 0); + m_FragmentContext = new ContextData(); + m_FragmentContext.shaderStage = ShaderStage.Fragment; + m_FragmentContext.position = new Vector2(0, 200); + } + + public void AddBlock(BlockNode blockNode, ContextData contextData, int index) + { + AddBlockNoValidate(blockNode, contextData, index); + ValidateGraph(); + } + + void AddBlockNoValidate(BlockNode blockNode, ContextData contextData, int index) + { + // Regular AddNode path + AddNodeNoValidate(blockNode); + + // Set BlockNode properties + blockNode.index = index; + blockNode.contextData = contextData; + + // Add to ContextData + if(index == -1 || index >= contextData.blocks.Count) + { + contextData.blocks.Add(blockNode); + } + else + { + contextData.blocks.Insert(index, blockNode); + } + + // Update support Blocks + UpdateActiveBlocks(); + } + + public void UpdateActiveBlocks() + { + // Get list of active Block types + var activeBlocks = ListPool.Get(); + var context = new TargetActiveBlockContext(); + foreach(var target in activeTargets) + { + target.GetActiveBlocks(ref context); + } + + // Set Blocks as active based on supported Block list + foreach(var vertexBlock in vertexContext.blocks) + { + vertexBlock.isActive = context.blocks.Contains(vertexBlock.descriptor); + } + foreach(var fragmentBlock in fragmentContext.blocks) + { + fragmentBlock.isActive = context.blocks.Contains(fragmentBlock.descriptor); + } + } + void AddNodeNoValidate(AbstractMaterialNode node) { if (node.groupGuid != Guid.Empty && !m_GroupItems.ContainsKey(node.groupGuid)) @@ -520,6 +720,14 @@ void RemoveNodeNoValidate(AbstractMaterialNode node) { groupItems.Remove(node); } + + if(node is BlockNode blockNode && blockNode.contextData != null) + { + // Remove from ContextData + blockNode.contextData.blocks.Remove(blockNode); + blockNode.Dirty(ModificationScope.Graph); + UpdateActiveBlocks(); + } } void AddEdgeToNodeEdges(IEdge edge) @@ -1103,7 +1311,17 @@ public void ReplaceWith(GraphData other) } foreach (var node in other.GetNodes()) - AddNodeNoValidate(node); + { + if(node is BlockNode blockNode) + { + var contextData = blockNode.descriptor.shaderStage == ShaderStage.Vertex ? vertexContext : fragmentContext; + AddBlockNoValidate(blockNode, contextData, blockNode.index); + } + else + { + AddNodeNoValidate(node); + } + } foreach (var edge in other.edges) ConnectNoValidate(edge.outputSlot, edge.inputSlot); @@ -1151,6 +1369,11 @@ internal void PasteGraph(CopyPasteGraph graphToPaste, List var nodeList = graphToPaste.GetNodes(); foreach (var node in nodeList) { + if(node is BlockNode blockNode) + { + continue; + } + AbstractMaterialNode pastedNode = node; var oldGuid = node.guid; @@ -1250,7 +1473,7 @@ public void OnBeforeSerialize() m_SerializableEdges = SerializationHelper.Serialize(m_Edges); m_SerializedProperties = SerializationHelper.Serialize(m_Properties); m_SerializedKeywords = SerializationHelper.Serialize(m_Keywords); - m_ActiveOutputNodeGuidSerialized = m_ActiveOutputNodeGuid == Guid.Empty ? null : m_ActiveOutputNodeGuid.ToString(); + m_SerializedTargets = SerializationHelper.Serialize(m_ActiveTargets); } public void OnAfterDeserialize() @@ -1259,6 +1482,17 @@ public void OnAfterDeserialize() m_Properties = SerializationHelper.Deserialize(m_SerializedProperties, GraphUtil.GetLegacyTypeRemapping()); m_Keywords = SerializationHelper.Deserialize(m_SerializedKeywords, GraphUtil.GetLegacyTypeRemapping()); + var deserializedTargets = SerializationHelper.Deserialize(m_SerializedTargets, GraphUtil.GetLegacyTypeRemapping()); + m_ActiveTargetBitmask = 0; + foreach(var deserializedTarget in deserializedTargets) + { + var activeTargetCurrent = m_ValidTargets.FirstOrDefault(x => x.GetType() == deserializedTarget.GetType()); + var targetIndex = m_ValidTargets.IndexOf(activeTargetCurrent); + m_ActiveTargetBitmask = m_ActiveTargetBitmask | (1 << targetIndex); + m_ValidTargets[targetIndex] = deserializedTarget; + } + UpdateActiveTargets(); + var nodes = SerializationHelper.Deserialize(m_SerializableNodes, GraphUtil.GetLegacyTypeRemapping()); m_Nodes = new List(nodes.Count); @@ -1290,23 +1524,36 @@ public void OnAfterDeserialize() foreach (var edge in m_Edges) AddEdgeToNodeEdges(edge); - m_OutputNode = null; + m_SubGraphOutputNode = null; - if (!isSubGraph) + // -------------------------------------------------- + // Deserialize Contexts & Blocks + + void DeserializeContextData(ContextData contextData, ShaderStage stage) { - if (string.IsNullOrEmpty(m_ActiveOutputNodeGuidSerialized)) - { - var node = (AbstractMaterialNode)GetNodes().FirstOrDefault(); - if (node != null) - { - m_ActiveOutputNodeGuid = node.guid; - } - } - else + // Because Vertex/Fragment Contexts are serialized explicitly + // we do not need to serialize the Stage value on the ContextData + contextData.shaderStage = stage; + + var blockCount = contextData.serializeableBlockGuids.Count; + for(int i = 0; i < blockCount; i++) { - m_ActiveOutputNodeGuid = new Guid(m_ActiveOutputNodeGuidSerialized); + // Deserialize the BlockNode guids on the ContextData + // This needs to be done here as BlockNodes are deserialized before GraphData + var blockGuid = new Guid(contextData.serializeableBlockGuids[i]); + var block = GetNodeFromGuid(blockGuid); + contextData.blocks.Add(block); + + // Update NonSerialized data on the BlockNode + block.descriptor = m_BlockFieldDescriptors.FirstOrDefault(x => $"{x.tag}.{x.name}" == block.serializedDescriptor); + block.contextData = contextData; + block.index = i; } } + + // First deserialize the ContextDatas + DeserializeContextData(m_VertexContext, ShaderStage.Vertex); + DeserializeContextData(m_FragmentContext, ShaderStage.Fragment); } public void OnEnable() @@ -1316,8 +1563,6 @@ public void OnEnable() node.OnEnable(); } - UpdateTargets(); - ShaderGraphPreferences.onVariantLimitChanged += OnKeywordChanged; } @@ -1325,37 +1570,6 @@ public void OnDisable() { ShaderGraphPreferences.onVariantLimitChanged -= OnKeywordChanged; } - - public void UpdateTargets() - { - if(outputNode == null) - return; - - // Clear current Targets - m_ValidTargets.Clear(); - - // SubGraph Target is always PreviewTarget - if(outputNode is SubGraphOutputNode) - { - m_ValidTargets.Add(new PreviewTarget()); - return; - } - - // Find all valid Targets - var typeCollection = TypeCache.GetTypesDerivedFrom(); - foreach(var type in typeCollection) - { - if(type.IsAbstract || type.IsGenericType || !type.IsClass) - continue; - - var masterNode = GetNodeFromGuid(m_ActiveOutputNodeGuid) as IMasterNode; - var target = (Target)Activator.CreateInstance(type); - if(!target.isHidden && target.IsValid(masterNode)) - { - m_ValidTargets.Add(target); - } - } - } } [Serializable] diff --git a/com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs b/com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs index 7f7af884187..1617354c1d7 100644 --- a/com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs +++ b/com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs @@ -101,7 +101,7 @@ public static SlotReference DepthFirstCollectRedirectNodeFromNode(RedirectNodeDa } public static void DepthFirstCollectNodesFromNode(List nodeList, AbstractMaterialNode node, - IncludeSelf includeSelf = IncludeSelf.Include, IEnumerable slotIds = null, List> keywordPermutation = null) + IncludeSelf includeSelf = IncludeSelf.Include, List> keywordPermutation = null) { // no where to start if (node == null) @@ -120,13 +120,9 @@ public static void DepthFirstCollectNodesFromNode(List nod var valueInPermutation = keywordPermutation.Where(x => x.Key.guid == keywordNode.keywordGuid).FirstOrDefault(); ids = new int[] { keywordNode.GetSlotIdForPermutation(valueInPermutation) }; } - else if (slotIds == null) - { - ids = node.GetInputSlots().Select(x => x.id); - } else { - ids = node.GetInputSlots().Where(x => slotIds.Contains(x.id)).Select(x => x.id); + ids = node.GetInputSlots().Select(x => x.id); } foreach (var slot in ids) @@ -143,6 +139,61 @@ public static void DepthFirstCollectNodesFromNode(List nod nodeList.Add(node); } + public static void GetDownsteamNodesForNode(List nodeList, AbstractMaterialNode node) + { + // no where to start + if (node == null) + return; + + // Recursively traverse downstream from the original node + // Traverse down each edge and continue on any connected downstream nodes + // Only nodes with no nodes further downstream are added to node list + bool hasDownstream = false; + var ids = node.GetOutputSlots().Select(x => x.id); + foreach (var slot in ids) + { + foreach (var edge in node.owner.GetEdges(node.FindSlot(slot).slotReference)) + { + var inputNode = node.owner.GetNodeFromGuid(((Edge)edge).inputSlot.nodeGuid); + if (inputNode != null) + { + hasDownstream = true; + GetDownsteamNodesForNode(nodeList, inputNode); + } + } + } + + // No more nodes downstream from here + if(!hasDownstream) + nodeList.Add(node); + } + + public static void UpdateNodeActiveOnEdgeChange(AbstractMaterialNode node) + { + if(node == null) + return; + + // Get downstream node of the output node + var nodes = ListPool.Get(); + NodeUtils.GetDownsteamNodesForNode(nodes, node); + + // If the only downstream node is this node + // This is the end of the chain and should always be active + if(nodes.Count == 1 && nodes[0] == node && !(node is BlockNode)) + { + node.isActive = true; + } + else + { + // If any downstream nodes are active + // then this node is also active + if(nodes.Any(x => x.isActive)) + node.isActive = true; + else + node.isActive = false; + } + } + public static void CollectNodeSet(HashSet nodeSet, MaterialSlot slot) { var node = slot.owner; diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes.meta b/com.unity.shadergraph/Editor/Data/MasterNodes.meta deleted file mode 100644 index f37c53b9e81..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: be7d4ec304eccd8489095f90e0909d93 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/AlphaMode.cs b/com.unity.shadergraph/Editor/Data/MasterNodes/AlphaMode.cs deleted file mode 100644 index 57f13174275..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/AlphaMode.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace UnityEditor.ShaderGraph -{ - enum SurfaceType - { - Opaque, - Transparent - } - - enum AlphaMode - { - Alpha, - Premultiply, - Additive, - Multiply - } -} diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/AlphaMode.cs.meta b/com.unity.shadergraph/Editor/Data/MasterNodes/AlphaMode.cs.meta deleted file mode 100644 index 0880ea1d578..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/AlphaMode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 05d113c37ee6ad24cbd4b11bbaab371f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/DistortionMode.cs b/com.unity.shadergraph/Editor/Data/MasterNodes/DistortionMode.cs deleted file mode 100644 index 73889e0616f..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/DistortionMode.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace UnityEditor.ShaderGraph -{ - enum DistortionMode - { - Add, - Multiply, - Replace - } -} diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/DistortionMode.cs.meta b/com.unity.shadergraph/Editor/Data/MasterNodes/DistortionMode.cs.meta deleted file mode 100644 index 8e2d60425df..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/DistortionMode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: eb944a5bac991ef4ea8ac032544285d3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/DoubleSidedMode.cs b/com.unity.shadergraph/Editor/Data/MasterNodes/DoubleSidedMode.cs deleted file mode 100644 index 69db7af610e..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/DoubleSidedMode.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace UnityEditor.ShaderGraph -{ - enum DoubleSidedMode - { - Disabled, - Enabled, - FlippedNormals, - MirroredNormals, - } -} diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/DoubleSidedMode.cs.meta b/com.unity.shadergraph/Editor/Data/MasterNodes/DoubleSidedMode.cs.meta deleted file mode 100644 index 9375cfcb1a1..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/DoubleSidedMode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 86dd83ebad5d7f34fb6714a01992d4ea -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/EmissionGIMode.cs b/com.unity.shadergraph/Editor/Data/MasterNodes/EmissionGIMode.cs deleted file mode 100644 index 3495d71ff03..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/EmissionGIMode.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace UnityEditor.ShaderGraph -{ - enum EmissionGIMode - { - Disabled, - Realtime, - Baked, - } -} diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/EmissionGIMode.cs.meta b/com.unity.shadergraph/Editor/Data/MasterNodes/EmissionGIMode.cs.meta deleted file mode 100644 index 3db00d345cd..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/EmissionGIMode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 29c3a6d9896aa9b4dad615133f9de841 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs b/com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs deleted file mode 100644 index 7616842492e..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs +++ /dev/null @@ -1,343 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEditor.ShaderGraph.Internal; -using UnityEngine; -using UnityEngine.UIElements; - -namespace UnityEditor.ShaderGraph -{ - [Serializable] - [Title("Master", "PBR")] - class PBRMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string AlbedoSlotName = "Albedo"; - public const string NormalSlotName = "Normal"; - public const string EmissionSlotName = "Emission"; - public const string MetallicSlotName = "Metallic"; - public const string SpecularSlotName = "Specular"; - public const string SmoothnessSlotName = "Smoothness"; - public const string OcclusionSlotName = "Occlusion"; - public const string AlphaSlotName = "Alpha"; - public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; - public const string PositionName = "Vertex Position"; - public const string NormalName = "Vertex Normal"; - public const string TangentName = "Vertex Tangent"; - - public const int AlbedoSlotId = 0; - public const int NormalSlotId = 1; - public const int MetallicSlotId = 2; - public const int SpecularSlotId = 3; - public const int EmissionSlotId = 4; - public const int SmoothnessSlotId = 5; - public const int OcclusionSlotId = 6; - public const int AlphaSlotId = 7; - public const int AlphaThresholdSlotId = 8; - public const int PositionSlotId = 9; - public const int VertNormalSlotId = 10; - public const int VertTangentSlotId = 11; - - public enum Model - { - Specular, - Metallic - } - - [SerializeField] - Model m_Model = Model.Metallic; - - public Model model - { - get { return m_Model; } - set - { - if (m_Model == value) - return; - - m_Model = value; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - AlphaMode m_AlphaMode; - - public AlphaMode alphaMode - { - get { return m_AlphaMode; } - set - { - if (m_AlphaMode == value) - return; - - m_AlphaMode = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_TwoSided; - - public ToggleData twoSided - { - get { return new ToggleData(m_TwoSided); } - set - { - if (m_TwoSided == value.isOn) - return; - m_TwoSided = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - NormalDropOffSpace m_NormalDropOffSpace; - public NormalDropOffSpace normalDropOffSpace - { - get { return m_NormalDropOffSpace; } - set - { - if (m_NormalDropOffSpace == value) - return; - - m_NormalDropOffSpace = value; - if(!IsSlotConnected(NormalSlotId)) - updateNormalSlot = true; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - bool updateNormalSlot; - - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public PBRMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "PBR Master"; - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionName, PositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new NormalMaterialSlot(VertNormalSlotId, NormalName, NormalName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new TangentMaterialSlot(VertTangentSlotId, TangentName, TangentName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - var coordSpace = CoordinateSpace.Tangent; - if (updateNormalSlot) - { - RemoveSlot(NormalSlotId); - //switch drop off delivery space for normal values - switch (m_NormalDropOffSpace) - { - case NormalDropOffSpace.Tangent: - coordSpace = CoordinateSpace.Tangent; - break; - case NormalDropOffSpace.World: - coordSpace = CoordinateSpace.World; - break; - case NormalDropOffSpace.Object: - coordSpace = CoordinateSpace.Object; - break; - } - updateNormalSlot = false; - } - AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, coordSpace, ShaderStageCapability.Fragment)); - AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ColorMode.Default, ShaderStageCapability.Fragment)); - if (model == Model.Metallic) - AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0, ShaderStageCapability.Fragment)); - else - AddSlot(new ColorRGBMaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, Color.grey, ColorMode.Default, ShaderStageCapability.Fragment)); - AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - AddSlot(new Vector1MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, 1f, ShaderStageCapability.Fragment)); - AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1f, ShaderStageCapability.Fragment)); - AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - - // clear out slot names that do not match the slots - // we support - RemoveSlotsNameNotMatching( - new[] - { - PositionSlotId, - VertNormalSlotId, - VertTangentSlotId, - AlbedoSlotId, - NormalSlotId, - EmissionSlotId, - model == Model.Metallic ? MetallicSlotId : SpecularSlotId, - SmoothnessSlotId, - OcclusionSlotId, - AlphaSlotId, - AlphaThresholdSlotId - }, true); - } - - public VisualElement CreateSettingsElement() - { - return new PBRSettingsView(this); - } - - public string renderQueueTag - { - get - { - if(surfaceType == SurfaceType.Transparent) - return $"{RenderQueue.Transparent}"; - else if(IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId) || FindSlot(AlphaThresholdSlotId).value > 0.0f) - return $"{RenderQueue.AlphaTest}"; - else - return $"{RenderQueue.Geometry}"; - } - } - - public string renderTypeTag - { - get - { - if(surfaceType == SurfaceType.Transparent) - return $"{RenderType.Transparent}"; - else - return $"{RenderType.Opaque}"; - } - } - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PBRMasterNode.PositionSlotId) || - IsSlotConnected(PBRMasterNode.VertNormalSlotId) || - IsSlotConnected(PBRMasterNode.VertTangentSlotId)), - new ConditionalField(Fields.GraphPixel, true), - - // Surface Type - new ConditionalField(Fields.SurfaceOpaque, surfaceType == ShaderGraph.SurfaceType.Opaque), - new ConditionalField(Fields.SurfaceTransparent, surfaceType != ShaderGraph.SurfaceType.Opaque), - - // Blend Mode - new ConditionalField(Fields.BlendAdd, surfaceType != ShaderGraph.SurfaceType.Opaque && alphaMode == AlphaMode.Additive), - new ConditionalField(Fields.BlendAlpha, surfaceType != ShaderGraph.SurfaceType.Opaque && alphaMode == AlphaMode.Alpha), - new ConditionalField(Fields.BlendMultiply, surfaceType != ShaderGraph.SurfaceType.Opaque && alphaMode == AlphaMode.Multiply), - new ConditionalField(Fields.BlendPremultiply, surfaceType != ShaderGraph.SurfaceType.Opaque && alphaMode == AlphaMode.Premultiply), - - // Normal Drop Off Space - new ConditionalField(Fields.NormalDropOffOS, normalDropOffSpace == NormalDropOffSpace.Object), - new ConditionalField(Fields.NormalDropOffTS, normalDropOffSpace == NormalDropOffSpace.Tangent), - new ConditionalField(Fields.NormalDropOffWS, normalDropOffSpace == NormalDropOffSpace.World), - - // Misc - new ConditionalField(Fields.AlphaClip, IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId) || - FindSlot(AlphaThresholdSlotId).value > 0.0f), - new ConditionalField(Fields.AlphaTest, IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId) || - FindSlot(AlphaThresholdSlotId).value > 0.0f), - new ConditionalField(Fields.SpecularSetup, model == PBRMasterNode.Model.Specular), - new ConditionalField(Fields.Normal, IsSlotConnected(PBRMasterNode.NormalSlotId)), - new ConditionalField(Fields.DoubleSided, twoSided.isOn), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - } -} diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs.meta b/com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs.meta deleted file mode 100644 index 704887988bb..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ea7519738e2a9b4469abbff8d5c4d657 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/SpecularOcclusionMode.cs b/com.unity.shadergraph/Editor/Data/MasterNodes/SpecularOcclusionMode.cs deleted file mode 100644 index a581298c9ff..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/SpecularOcclusionMode.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace UnityEditor.ShaderGraph -{ - enum SpecularOcclusionMode - { - Off, - FromAO, - FromAOAndBentNormal, - Custom - } -} diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/SpecularOcclusionMode.cs.meta b/com.unity.shadergraph/Editor/Data/MasterNodes/SpecularOcclusionMode.cs.meta deleted file mode 100644 index fc7640b865a..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/SpecularOcclusionMode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 24b31303b6f59144092900b5b71ef81c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs b/com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs deleted file mode 100644 index 4ce5d080ffb..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs +++ /dev/null @@ -1,266 +0,0 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEditor.ShaderGraph.Internal; -using UnityEngine; -using UnityEngine.UIElements; - -namespace UnityEditor.ShaderGraph -{ - [Serializable] - [Title("Master", "Unlit")] - class UnlitMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, ICanChangeShaderGUI, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent - { - public const string ColorSlotName = "Color"; - public const string AlphaSlotName = "Alpha"; - public const string AlphaClipThresholdSlotName = "AlphaClipThreshold"; - public const string PositionName = "Vertex Position"; - public const string NormalName = "Vertex Normal"; - public const string TangentName = "Vertex Tangent"; - - public const int ColorSlotId = 0; - public const int AlphaSlotId = 7; - public const int AlphaThresholdSlotId = 8; - public const int PositionSlotId = 9; - public const int VertNormalSlotId = 10; - public const int VertTangentSlotId = 11; - - [SerializeField] - SurfaceType m_SurfaceType; - - public SurfaceType surfaceType - { - get { return m_SurfaceType; } - set - { - if (m_SurfaceType == value) - return; - - m_SurfaceType = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - AlphaMode m_AlphaMode; - - public AlphaMode alphaMode - { - get { return m_AlphaMode; } - set - { - if (m_AlphaMode == value) - return; - - m_AlphaMode = value; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_TwoSided; - - public ToggleData twoSided - { - get { return new ToggleData(m_TwoSided); } - set - { - if (m_TwoSided == value.isOn) - return; - m_TwoSided = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_AddPrecomputedVelocity = false; - - public ToggleData addPrecomputedVelocity - { - get { return new ToggleData(m_AddPrecomputedVelocity); } - set - { - if (m_AddPrecomputedVelocity == value.isOn) - return; - m_AddPrecomputedVelocity = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] - bool m_DOTSInstancing = false; - - public ToggleData dotsInstancing - { - get { return new ToggleData(m_DOTSInstancing); } - set - { - if (m_DOTSInstancing == value.isOn) - return; - - m_DOTSInstancing = value.isOn; - Dirty(ModificationScope.Graph); - } - } - - [SerializeField] private string m_ShaderGUIOverride; - public string ShaderGUIOverride - { - get => m_ShaderGUIOverride; - set => m_ShaderGUIOverride = value; - } - - [SerializeField] private bool m_OverrideEnabled; - public bool OverrideEnabled - { - get => m_OverrideEnabled; - set => m_OverrideEnabled = value; - } - - public UnlitMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - - public sealed override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - name = "Unlit Master"; - AddSlot(new PositionMaterialSlot(PositionSlotId, PositionName, PositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new NormalMaterialSlot(VertNormalSlotId, NormalName, NormalName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new TangentMaterialSlot(VertTangentSlotId, TangentName, TangentName, CoordinateSpace.Object, ShaderStageCapability.Vertex)); - AddSlot(new ColorRGBMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStageCapability.Fragment)); - AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0.0f, ShaderStageCapability.Fragment)); - - // clear out slot names that do not match the slots - // we support - RemoveSlotsNameNotMatching( - new[] - { - PositionSlotId, - VertNormalSlotId, - VertTangentSlotId, - ColorSlotId, - AlphaSlotId, - AlphaThresholdSlotId - }); - } - - public VisualElement CreateSettingsElement() - { - return new UnlitSettingsView(this); - } - - public string renderQueueTag - { - get - { - if(surfaceType == SurfaceType.Transparent) - return $"{RenderQueue.Transparent}"; - else if(IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId) || FindSlot(AlphaThresholdSlotId).value > 0.0f) - return $"{RenderQueue.AlphaTest}"; - else - return $"{RenderQueue.Geometry}"; - } - } - - public string renderTypeTag - { - get - { - if(surfaceType == SurfaceType.Transparent) - return $"{RenderType.Transparent}"; - else - return $"{RenderType.Opaque}"; - } - } - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - return new ConditionalField[] - { - // Features - new ConditionalField(Fields.GraphVertex, IsSlotConnected(PBRMasterNode.PositionSlotId) || - IsSlotConnected(PBRMasterNode.VertNormalSlotId) || - IsSlotConnected(PBRMasterNode.VertTangentSlotId)), - new ConditionalField(Fields.GraphPixel, true), - - // Surface Type - new ConditionalField(Fields.SurfaceOpaque, surfaceType == ShaderGraph.SurfaceType.Opaque), - new ConditionalField(Fields.SurfaceTransparent, surfaceType != ShaderGraph.SurfaceType.Opaque), - - // Blend Mode - new ConditionalField(Fields.BlendAdd, surfaceType != ShaderGraph.SurfaceType.Opaque && alphaMode == AlphaMode.Additive), - new ConditionalField(Fields.BlendAlpha, surfaceType != ShaderGraph.SurfaceType.Opaque && alphaMode == AlphaMode.Alpha), - new ConditionalField(Fields.BlendMultiply, surfaceType != ShaderGraph.SurfaceType.Opaque && alphaMode == AlphaMode.Multiply), - new ConditionalField(Fields.BlendPremultiply, surfaceType != ShaderGraph.SurfaceType.Opaque && alphaMode == AlphaMode.Premultiply), - - // Misc - new ConditionalField(Fields.AlphaClip, IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId) || - FindSlot(AlphaThresholdSlotId).value > 0.0f), - new ConditionalField(Fields.AlphaTest, IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId) || - FindSlot(AlphaThresholdSlotId).value > 0.0f), - new ConditionalField(Fields.VelocityPrecomputed, addPrecomputedVelocity.isOn), - new ConditionalField(Fields.DoubleSided, twoSided.isOn), - }; - } - - public void ProcessPreviewMaterial(Material material) - { - - } - - public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal(stageCapability)); - } - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - - public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresTangent(stageCapability)); - } - } -} diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs.meta b/com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs.meta deleted file mode 100644 index ef3c0c4d903..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 50acf8d45249d486e9e5ee72178100f4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/VfxMasterNode.cs b/com.unity.shadergraph/Editor/Data/MasterNodes/VfxMasterNode.cs deleted file mode 100644 index 2e7b9ac714d..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/VfxMasterNode.cs +++ /dev/null @@ -1,181 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using UnityEditor.Graphing; -using UnityEditor.ShaderGraph.Internal; -using UnityEditor.ShaderGraph.Drawing; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEngine; -using UnityEngine.Rendering; -using UnityEngine.UIElements; -using UnityEditor.Graphing.Util; - -namespace UnityEditor.ShaderGraph -{ - [Serializable] - [Title("Master", "Visual Effect")] - sealed class VfxMasterNode : AbstractMaterialNode, IMasterNode, IHasSettings, IMayRequirePosition - { - const string BaseColorSlotName = "Base Color"; - const string MetallicSlotName = "Metallic"; - const string SmoothnessSlotName = "Smoothness"; - const string NormalSlotName = "Normal"; - const string AlphaSlotName = "Alpha"; - const string EmissiveSlotName = "Emissive"; - const string ColorSlotName = "Color"; - const string AlphaThresholdSlotName = "AlphaThreshold"; - - public VfxMasterNode() - { - UpdateNodeAfterDeserialization(); - } - - - [SerializeField] - bool m_Lit; - - public ToggleData lit - { - get { return new ToggleData(m_Lit); } - set - { - if (m_Lit == value.isOn) - return; - m_Lit = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - [SerializeField] - bool m_AlphaTest; - - public ToggleData alphaTest - { - get { return new ToggleData(m_AlphaTest); } - set - { - if (m_AlphaTest == value.isOn) - return; - m_AlphaTest = value.isOn; - UpdateNodeAfterDeserialization(); - Dirty(ModificationScope.Topological); - } - } - - public override void UpdateNodeAfterDeserialization() - { - base.UpdateNodeAfterDeserialization(); - - name = "Visual Effect Master"; - - HashSet usedSlots = new HashSet(); - - if ( lit.isOn) - { - AddSlot(new ColorRGBMaterialSlot(ShaderGraphVfxAsset.BaseColorSlotId, BaseColorSlotName, NodeUtils.GetHLSLSafeName(BaseColorSlotName), SlotType.Input, Color.grey.gamma, ColorMode.Default, ShaderStageCapability.Fragment)); - usedSlots.Add(ShaderGraphVfxAsset.BaseColorSlotId); - - AddSlot(new Vector1MaterialSlot(ShaderGraphVfxAsset.MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - usedSlots.Add(ShaderGraphVfxAsset.MetallicSlotId); - - AddSlot(new Vector1MaterialSlot(ShaderGraphVfxAsset.SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment)); - usedSlots.Add(ShaderGraphVfxAsset.SmoothnessSlotId); - - AddSlot(new Vector3MaterialSlot(ShaderGraphVfxAsset.NormalSlotId, NormalSlotName, NormalSlotName, SlotType.Input, new Vector3(0,0,1), ShaderStageCapability.Fragment)); - usedSlots.Add(ShaderGraphVfxAsset.NormalSlotId); - - AddSlot(new ColorRGBMaterialSlot(ShaderGraphVfxAsset.EmissiveSlotId, EmissiveSlotName, NodeUtils.GetHLSLSafeName(EmissiveSlotName), SlotType.Input, Color.black, ColorMode.HDR, ShaderStageCapability.Fragment)); - usedSlots.Add(ShaderGraphVfxAsset.EmissiveSlotId); - } - else - { - AddSlot(new ColorRGBMaterialSlot(ShaderGraphVfxAsset.ColorSlotId, ColorSlotName, NodeUtils.GetHLSLSafeName(ColorSlotName), SlotType.Input, Color.grey.gamma, ColorMode.HDR, ShaderStageCapability.Fragment)); - usedSlots.Add(ShaderGraphVfxAsset.ColorSlotId); - } - - AddSlot(new Vector1MaterialSlot(ShaderGraphVfxAsset.AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStageCapability.Fragment)); - usedSlots.Add(ShaderGraphVfxAsset.AlphaSlotId); - - if( alphaTest.isOn) - { - AddSlot(new Vector1MaterialSlot(ShaderGraphVfxAsset.AlphaThresholdSlotId, AlphaThresholdSlotName, AlphaThresholdSlotName, SlotType.Input, 1, ShaderStageCapability.Fragment)); - usedSlots.Add(ShaderGraphVfxAsset.AlphaThresholdSlotId); - } - - RemoveSlotsNameNotMatching(usedSlots); - } - - class SettingsView : VisualElement - { - readonly VfxMasterNode m_Node; - public SettingsView(VfxMasterNode node) - { - m_Node = node; - PropertySheet ps = new PropertySheet(); - ps.Add(new PropertyRow(new Label("Alpha Mask")), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.alphaTest.isOn; - toggle.OnToggleChanged(ChangeAlphaTest); - }); - }); - ps.Add(new PropertyRow(new Label("Lit")), (System.Action)((row) => - { - row.Add(new Toggle(), (System.Action)((toggle) => - { - toggle.value = m_Node.lit.isOn; - toggle.OnToggleChanged(this.ChangeLit); - })); - })); - Add(ps); - } - - void ChangeAlphaTest(ChangeEvent e) - { - m_Node.alphaTest = new ToggleData(e.newValue, m_Node.alphaTest.isEnabled); - } - void ChangeLit(ChangeEvent e) - { - m_Node.lit = new ToggleData(e.newValue, m_Node.alphaTest.isEnabled); - } - } - - public VisualElement CreateSettingsElement() - { - return new SettingsView(this); - } - - public string renderQueueTag => null; - public string renderTypeTag => null; - - public ConditionalField[] GetConditionalFields(PassDescriptor pass) - { - return null; - } - - public void ProcessPreviewMaterial(Material material) - { - - } - - public override bool hasPreview => false; - - public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) - { - List slots = new List(); - GetSlots(slots); - - List validSlots = new List(); - for (int i = 0; i < slots.Count; i++) - { - if (slots[i].stageCapability != ShaderStageCapability.All && slots[i].stageCapability != stageCapability) - continue; - - validSlots.Add(slots[i]); - } - return validSlots.OfType().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresPosition(stageCapability)); - } - } -} diff --git a/com.unity.shadergraph/Editor/Data/MasterNodes/VfxMasterNode.cs.meta b/com.unity.shadergraph/Editor/Data/MasterNodes/VfxMasterNode.cs.meta deleted file mode 100644 index dc6c5998ffc..00000000000 --- a/com.unity.shadergraph/Editor/Data/MasterNodes/VfxMasterNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8bda76bbd4a3e42f2809a95c732bcd57 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs index e3e7c982b06..d589b1eda0d 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs @@ -36,6 +36,9 @@ abstract class AbstractMaterialNode : ISerializationCallbackReceiver, IGroupItem [NonSerialized] bool m_HasError; + [NonSerialized] + bool m_IsActive = true; + [NonSerialized] private List m_Slots = new List(); @@ -84,7 +87,7 @@ public string name public virtual bool canDeleteNode { - get { return owner != null && guid != owner.activeOutputNodeGuid; } + get { return owner != null; } } public DrawState drawState @@ -145,9 +148,10 @@ public virtual PreviewMode previewMode get { return PreviewMode.Preview2D; } } + // TODO: Can actually delete this public virtual bool allowedInSubGraph { - get { return !(this is IMasterNode); } + get { return !(this is BlockNode); } } public virtual bool allowedInMainGraph @@ -166,8 +170,27 @@ public virtual bool hasError protected set { m_HasError = value; } } - //needed for HDRP material update system - public virtual object saveContext => null; + public virtual bool isActive + { + get { return m_IsActive; } + set + { + if(m_IsActive == value) + return; + + // Update this node + m_IsActive = value; + Dirty(ModificationScope.Node); + + // Get all downsteam nodes and update their active state + var nodes = ListPool.Get(); + NodeUtils.DepthFirstCollectNodesFromNode(nodes, this, NodeUtils.IncludeSelf.Include); + foreach(var upstreamNode in nodes) + { + NodeUtils.UpdateNodeActiveOnEdgeChange(upstreamNode); + } + } + } string m_DefaultVariableName; string m_NameForDefaultVariableName; @@ -546,6 +569,7 @@ public virtual void ValidateNode() } public int version { get; set; } + public virtual bool canCutNode => true; public virtual bool canCopyNode => true; protected virtual void CalculateNodeHasError() diff --git a/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs new file mode 100644 index 00000000000..e13261d007c --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs @@ -0,0 +1,211 @@ +using System; +using UnityEngine; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Internal; + +namespace UnityEditor.ShaderGraph +{ + class BlockNode : AbstractMaterialNode + , IMayRequireNormal + , IMayRequireTangent + , IMayRequireBitangent + , IMayRequireMeshUV + , IMayRequireScreenPosition + , IMayRequireViewDirection + , IMayRequirePosition + , IMayRequireVertexColor + { + [SerializeField] + string m_SerializedDescriptor; + + [NonSerialized] + ContextData m_ContextData; + + [NonSerialized] + int m_Index; + + [NonSerialized] + BlockFieldDescriptor m_Descriptor; + + public BlockNode() + { + } + + public override bool canCutNode => false; + public override bool canCopyNode => false; + + // Because the GraphData is deserialized after its child elements + // the descriptor list is not built (and owner is not set) + // at the time of node deserialization + // Therefore we need to deserialize this element at GraphData.OnAfterDeserialize + public string serializedDescriptor => m_SerializedDescriptor; + + public ContextData contextData + { + get => m_ContextData; + set => m_ContextData = value; + } + + public int index + { + get => m_Index; + set => m_Index = value; + } + + public BlockFieldDescriptor descriptor + { + get => m_Descriptor; + set => m_Descriptor = value; + } + + public void Init(BlockFieldDescriptor fieldDescriptor) + { + name = $"{fieldDescriptor.tag}.{fieldDescriptor.name}"; + m_Descriptor = fieldDescriptor; + + // TODO: This exposes the MaterialSlot API + // TODO: This needs to be removed but is currently required by HDRP for DiffusionProfileInputMaterialSlot + if(m_Descriptor is CustomSlotBlockFieldDescriptor customSlotDescriptor) + { + AddSlot(customSlotDescriptor.slot); + RemoveSlotsNameNotMatching(new int[] {0}); + return; + } + + AddSlot(); + } + + void AddSlot() + { + var stageCapability = m_Descriptor.shaderStage.GetShaderStageCapability(); + switch(descriptor.control) + { + case PositionControl positionControl: + AddSlot(new PositionMaterialSlot(0, descriptor.name, descriptor.name, positionControl.space, stageCapability)); + break; + case NormalControl normalControl: + AddSlot(new NormalMaterialSlot(0, descriptor.name, descriptor.name, normalControl.space, stageCapability)); + break; + case TangentControl tangentControl: + AddSlot(new TangentMaterialSlot(0, descriptor.name, descriptor.name, tangentControl.space, stageCapability)); + break; + case ColorControl colorControl: + var colorMode = colorControl.hdr ? ColorMode.HDR : ColorMode.Default; + AddSlot(new ColorRGBMaterialSlot(0, descriptor.name, descriptor.name, SlotType.Input, colorControl.value, colorMode, stageCapability)); + break; + case ColorRGBAControl colorRGBAControl: + AddSlot(new ColorRGBAMaterialSlot(0, descriptor.name, descriptor.name, SlotType.Input, colorRGBAControl.value, stageCapability)); + break; + case FloatControl floatControl: + AddSlot(new Vector1MaterialSlot(0, descriptor.name, descriptor.name, SlotType.Input, floatControl.value, stageCapability)); + break; + case Vector2Control vector2Control: + AddSlot(new Vector2MaterialSlot(0, descriptor.name, descriptor.name, SlotType.Input, vector2Control.value, stageCapability)); + break; + case Vector3Control vector3Control: + AddSlot(new Vector3MaterialSlot(0, descriptor.name, descriptor.name, SlotType.Input, vector3Control.value, stageCapability)); + break; + } + RemoveSlotsNameNotMatching(new int[] {0}); + } + + public override string GetVariableNameForNode() + { + // Temporary block nodes have temporary guids that cannot be used to set preview data + // Since each block is unique anyway we just omit the guid + return NodeUtils.GetHLSLSafeName(name); + } + + public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) + { + var slot = FindSlot(0); + if(m_Descriptor == null || slot.isConnected || stageCapability != m_Descriptor.shaderStage.GetShaderStageCapability()) + return NeededCoordinateSpace.None; + + var requirements = m_Descriptor.control.GetRequirements(); + return requirements.requiresNormal; + } + + public NeededCoordinateSpace RequiresViewDirection(ShaderStageCapability stageCapability) + { + var slot = FindSlot(0); + if(m_Descriptor == null || slot.isConnected || stageCapability != m_Descriptor.shaderStage.GetShaderStageCapability()) + return NeededCoordinateSpace.None; + + var requirements = m_Descriptor.control.GetRequirements(); + return requirements.requiresViewDir; + } + + public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) + { + var slot = FindSlot(0); + if(m_Descriptor == null || slot.isConnected || stageCapability != m_Descriptor.shaderStage.GetShaderStageCapability()) + return NeededCoordinateSpace.None; + + var requirements = m_Descriptor.control.GetRequirements(); + return requirements.requiresPosition; + } + + public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) + { + var slot = FindSlot(0); + if(m_Descriptor == null || slot.isConnected || stageCapability != m_Descriptor.shaderStage.GetShaderStageCapability()) + return NeededCoordinateSpace.None; + + var requirements = m_Descriptor.control.GetRequirements(); + return requirements.requiresTangent; + } + + public NeededCoordinateSpace RequiresBitangent(ShaderStageCapability stageCapability) + { + var slot = FindSlot(0); + if(m_Descriptor == null || slot.isConnected || stageCapability != m_Descriptor.shaderStage.GetShaderStageCapability()) + return NeededCoordinateSpace.None; + + var requirements = m_Descriptor.control.GetRequirements(); + return requirements.requiresBitangent; + } + + public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability) + { + var slot = FindSlot(0); + if(m_Descriptor == null || slot.isConnected || stageCapability != m_Descriptor.shaderStage.GetShaderStageCapability()) + return false; + + var requirements = m_Descriptor.control.GetRequirements(); + return requirements.requiresMeshUVs.Contains(channel); + } + + public bool RequiresScreenPosition(ShaderStageCapability stageCapability) + { + var slot = FindSlot(0); + if(m_Descriptor == null || slot.isConnected || stageCapability != m_Descriptor.shaderStage.GetShaderStageCapability()) + return false; + + var requirements = m_Descriptor.control.GetRequirements(); + return requirements.requiresScreenPosition; + } + + public bool RequiresVertexColor(ShaderStageCapability stageCapability) + { + var slot = FindSlot(0); + if(m_Descriptor == null || slot.isConnected || stageCapability != m_Descriptor.shaderStage.GetShaderStageCapability()) + return false; + + var requirements = m_Descriptor.control.GetRequirements(); + return requirements.requiresVertexColor; + } + + public override void OnBeforeSerialize() + { + base.OnBeforeSerialize(); + + // TODO: Currently m_Descriptor is null on assembly reload. Why? + // TODO: We should fix this and then clear m_SerializedDescriptor at OnAfterDeserialize + if(m_Descriptor == null) + return; + + m_SerializedDescriptor = $"{m_Descriptor.tag}.{m_Descriptor.name}"; + } + } +} diff --git a/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs.meta b/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs.meta new file mode 100644 index 00000000000..a9760475dd7 --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/Nodes/BlockNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bd5e1b91fdc2348ac9ce3733135e9901 +timeCreated: 1495966736 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/Nodes/ShaderStage.cs b/com.unity.shadergraph/Editor/Data/Nodes/ShaderStage.cs index d7068af7094..b348de60f6a 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/ShaderStage.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/ShaderStage.cs @@ -39,5 +39,18 @@ public static bool TryGetShaderStage(this ShaderStageCapability capability, out return false; } } + + public static ShaderStageCapability GetShaderStageCapability(this ShaderStage stage) + { + switch (stage) + { + case ShaderStage.Vertex: + return ShaderStageCapability.Vertex; + case ShaderStage.Fragment: + return ShaderStageCapability.Fragment; + default: + return ShaderStageCapability.Fragment; + } + } } } diff --git a/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs b/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs index 3c6dc32af58..1d3c8f05efb 100644 --- a/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs +++ b/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs @@ -102,17 +102,18 @@ public PreprocessorIf(string conditional) class NewGraphAction : EndNameEditAction { - AbstractMaterialNode m_Node; - public AbstractMaterialNode node + Target[] m_Targets; + public Target[] targets { - get { return m_Node; } - set { m_Node = value; } + get { return m_Targets; } + set { m_Targets = value; } } public override void Action(int instanceId, string pathName, string resourceFile) { var graph = new GraphData(); - graph.AddNode(node); + graph.AddContexts(); + graph.AddTargets(m_Targets); graph.path = "Shader Graphs"; FileUtilities.WriteShaderGraphToDisk(pathName, graph); AssetDatabase.Refresh(); @@ -142,41 +143,39 @@ internal static string ConvertCamelCase(string text, bool preserveAcronyms) return newText.ToString(); } - public static void CreateNewGraph(AbstractMaterialNode node) + public static void CreateNewGraph() { var graphItem = ScriptableObject.CreateInstance(); - graphItem.node = node; + graphItem.targets = null; ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, graphItem, string.Format("New Shader Graph.{0}", ShaderGraphImporter.Extension), null, null); } - public static Type GetOutputNodeType(string path) + public static void CreateNewGraphWithTargets(Target[] targets) { - ShaderGraphMetadata metadata = null; - foreach (var asset in AssetDatabase.LoadAllAssetsAtPath(path)) - { - if (asset is ShaderGraphMetadata metadataAsset) - { - metadata = metadataAsset; - break; - } - } + var graphItem = ScriptableObject.CreateInstance(); + graphItem.targets = targets; + ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, graphItem, + string.Format("New Shader Graph.{0}", ShaderGraphImporter.Extension), null, null); + } - if (metadata == null) - { - return null; - } + public static bool TryGetMetadataOfType(this Shader shader, out T obj) where T : ScriptableObject + { + obj = null; + if(!shader.IsShaderGraph()) + return false; - var outputNodeTypeName = metadata.outputNodeTypeName; - foreach (var type in TypeCache.GetTypesDerivedFrom()) + var path = AssetDatabase.GetAssetPath(shader); + foreach (var asset in AssetDatabase.LoadAllAssetsAtPath(path)) { - if (type.FullName == outputNodeTypeName) + if (asset is T metadataAsset) { - return type; + obj = metadataAsset; + return true; } } - return null; + return false; } public static bool IsShaderGraph(this Shader shader) @@ -349,24 +348,5 @@ public static void OpenFile(string path) p.Start(); } } - - public static string CurrentPipelinePreferredShaderGUI(IMasterNode masterNode) - { - foreach (var target in (masterNode as AbstractMaterialNode).owner.validTargets) - { - if (target.IsPipelineCompatible(GraphicsSettings.currentRenderPipeline)) - { - var context = new TargetSetupContext(); - context.SetMasterNode(masterNode); - target.Setup(ref context); - - var defaultShaderGUI = context.defaultShaderGUI; - if (!string.IsNullOrEmpty(defaultShaderGUI)) - return defaultShaderGUI; - } - } - - return null; - } } } diff --git a/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs b/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs index 27e9fe733cf..29c2b29fe44 100644 --- a/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs @@ -30,7 +30,6 @@ public Image previewTextureView Vector2 m_PreviewScrollPosition; ObjectField m_PreviewMeshPicker; - IMasterNode m_MasterNode; Mesh m_PreviousMesh; bool m_Expanded = true; @@ -141,11 +140,6 @@ void BuildContextualMenu(ContextualMenuPopulateEvent evt) evt.menu.AppendAction("Custom Mesh", e => ChangeMeshCustom(), DropdownMenuAction.AlwaysEnabled); } - void DirtyMasterNode(ModificationScope scope) - { - m_Graph?.outputNode?.Dirty(scope); - } - void OnPreviewChanged() { m_PreviewTextureView.image = m_PreviewRenderHandle?.texture ?? Texture2D.blackTexture; @@ -167,7 +161,7 @@ void ChangeMesh(Mesh mesh) { Mesh changedMesh = mesh; - DirtyMasterNode(ModificationScope.Node); + m_PreviewManager.UpdateMasterPreview(ModificationScope.Node); if (m_Graph.previewData.serializedMesh.mesh != changedMesh) { @@ -230,7 +224,7 @@ void OnScroll(float scrollValue) float rescaleAmount = -scrollValue * .03f; m_Graph.previewData.scale = Mathf.Clamp(m_Graph.previewData.scale + rescaleAmount, 0.2f, 5f); - DirtyMasterNode(ModificationScope.Node); + m_PreviewManager.UpdateMasterPreview(ModificationScope.Node); } void OnMouseDragPreviewMesh(Vector2 deltaMouse) @@ -242,7 +236,7 @@ void OnMouseDragPreviewMesh(Vector2 deltaMouse) Quaternion previewRotation = Quaternion.Euler(m_PreviewScrollPosition.y, 0, 0) * Quaternion.Euler(0, m_PreviewScrollPosition.x, 0); m_Graph.previewData.rotation = previewRotation; - DirtyMasterNode(ModificationScope.Node); + m_PreviewManager.UpdateMasterPreview(ModificationScope.Node); } } } diff --git a/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs b/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs index 3984eb75489..d62e0da715e 100644 --- a/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs +++ b/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs @@ -380,20 +380,30 @@ public void UpdateAsset() ShaderUtil.ClearShaderMessages(oldShader); UpdateShaderGraphOnDisk(path); - - if (GraphData.onSaveGraph != null) - { - var shader = AssetDatabase.LoadAssetAtPath(path); - if (shader != null) - { - GraphData.onSaveGraph(shader, (graphObject.graph.outputNode as AbstractMaterialNode).saveContext); - } - } + OnSaveGraph(path); } UpdateTitle(); } + void OnSaveGraph(string path) + { + if(GraphData.onSaveGraph == null) + return; + + if(graphObject.graph.isSubGraph) + return; + + var shader = AssetDatabase.LoadAssetAtPath(path); + if(shader == null) + return; + + foreach(var target in graphObject.graph.activeTargets) + { + GraphData.onSaveGraph(shader, target.saveContext); + } + } + public void SaveAs() { SaveAsImplementation(); @@ -424,13 +434,7 @@ bool SaveAsImplementation() if (success) { ShaderGraphImporterEditor.ShowGraphEditWindow(newPath); - // This is for updating material dependencies so we exclude subgraphs here. - if (GraphData.onSaveGraph != null && extension != ShaderSubGraphImporter.Extension) - { - var shader = AssetDatabase.LoadAssetAtPath(newPath); - // Retrieve graph context, note that if we're here the output node will always be a master node - GraphData.onSaveGraph(shader, (graphObject.graph.outputNode as AbstractMaterialNode).saveContext); - } + OnSaveGraph(newPath); } } @@ -725,7 +729,7 @@ public void ToSubGraph() var externalOutputsNeedingConnection = new List>(); foreach (var group in uniqueOutgoingEdges) { - var outputNode = subGraph.outputNode as SubGraphOutputNode; + var outputNode = subGraph.subGraphOutputNode; AbstractMaterialNode node = graphView.graph.GetNodeFromGuid(group.edges[0].outputSlot.nodeGuid); MaterialSlot slot = node.FindSlot(group.edges[0].outputSlot.slotId); diff --git a/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs b/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs index fbfaee3168b..531c56ff9fb 100644 --- a/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs +++ b/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs @@ -25,12 +25,15 @@ class PreviewManager : IDisposable HashSet m_NodesToUpdate = new HashSet(); HashSet m_NodesToDraw = new HashSet(); HashSet m_TimedNodes = new HashSet(); + HashSet m_Blocks = new HashSet(); bool m_RefreshTimedNodes; PreviewSceneResources m_SceneResources; Texture2D m_ErrorTexture; Vector2? m_NewMasterPreviewSize; + Identifier m_MasterIdentifier; + public PreviewRenderData masterRenderData { get { return m_MasterRenderData; } @@ -42,9 +45,15 @@ public PreviewManager(GraphData graph, MessageManager messenger) m_Messenger = messenger; m_ErrorTexture = GenerateFourSquare(Color.magenta, Color.black); m_SceneResources = new PreviewSceneResources(); + m_MasterIdentifier = new Identifier(0); foreach (var node in m_Graph.GetNodes()) AddPreview(node); + + if(!graph.isSubGraph) + { + AddMasterPreview(); + } } public OnPrimaryMasterChanged onPrimaryMasterChanged; @@ -71,13 +80,64 @@ public PreviewRenderData GetPreview(AbstractMaterialNode node) return m_RenderDatas[node.guid]; } + void AddMasterPreview() + { + var renderData = new PreviewRenderData + { + renderTexture = + new RenderTexture(200, 200, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) + { + hideFlags = HideFlags.HideAndDontSave + }, + previewMode = PreviewMode.Preview3D, + }; + + m_MasterRenderData = renderData; + renderData.renderTexture.width = renderData.renderTexture.height = 400; + renderData.renderTexture.Create(); + + var shaderData = new PreviewShaderData + { + node = null, + isCompiling = false, + hasError = false, + shader = ShaderUtil.CreateShaderAsset(k_EmptyShader, false), + }; + shaderData.shader.hideFlags = HideFlags.HideAndDontSave; + shaderData.mat = new Material(shaderData.shader) {hideFlags = HideFlags.HideAndDontSave}; + renderData.shaderData = shaderData; + + m_NodesToUpdate.Add(null); + m_RefreshTimedNodes = true; + } + + public void UpdateMasterPreview(ModificationScope scope) + { + if (scope == ModificationScope.Topological || + scope == ModificationScope.Graph) + { + m_NodesToUpdate.Add(null); + m_RefreshTimedNodes = true; + } + else if (scope == ModificationScope.Node) + { + m_NodesToDraw.Add(null); + } + } + void AddPreview(AbstractMaterialNode node) { + if(node is BlockNode) + { + node.RegisterCallback(OnNodeModified); + return; + } + var isMaster = false; - if (node is IMasterNode || node is SubGraphOutputNode) + if (node is SubGraphOutputNode) { - if (masterRenderData != null || (node is IMasterNode && node.guid != node.owner.activeOutputNodeGuid)) + if (masterRenderData != null) { return; } @@ -121,16 +181,16 @@ void AddPreview(AbstractMaterialNode node) m_RefreshTimedNodes = true; } - if (m_MasterRenderData == renderData && onPrimaryMasterChanged != null) - { - onPrimaryMasterChanged(); - } - m_NodesToUpdate.Add(node); } void OnNodeModified(AbstractMaterialNode node, ModificationScope scope) { + if(node is BlockNode blockNode) + { + node = null; + } + if (scope == ModificationScope.Topological || scope == ModificationScope.Graph) { @@ -208,13 +268,15 @@ void GetConnectedNodes(AbstractMaterialNode node, PropagationDirection dir, T public bool HandleGraphChanges() { - if (m_Graph.didActiveOutputNodeChange) - { - DestroyPreview(masterRenderData.shaderData.node.guid); - } - foreach (var node in m_Graph.removedNodes) { + if(node is BlockNode) + { + node.UnregisterCallback(OnNodeModified); + UpdateMasterPreview(ModificationScope.Topological); + continue; + } + DestroyPreview(node.guid); m_NodesToUpdate.Remove(node); m_NodesToDraw.Remove(node); @@ -225,6 +287,13 @@ public bool HandleGraphChanges() foreach (var node in m_Graph.addedNodes) { + if(node is BlockNode) + { + node.RegisterCallback(OnNodeModified); + UpdateMasterPreview(ModificationScope.Topological); + continue; + } + AddPreview(node); m_RefreshTimedNodes = true; } @@ -234,6 +303,12 @@ public bool HandleGraphChanges() var node = m_Graph.GetNodeFromGuid(edge.inputSlot.nodeGuid); if (node != null) { + if(node is BlockNode) + { + UpdateMasterPreview(ModificationScope.Topological); + continue; + } + m_NodesToUpdate.Add(node); m_RefreshTimedNodes = true; } @@ -243,6 +318,12 @@ public bool HandleGraphChanges() var node = m_Graph.GetNodeFromGuid(edge.inputSlot.nodeGuid); if(node != null) { + if(node is BlockNode) + { + UpdateMasterPreview(ModificationScope.Topological); + continue; + } + m_NodesToUpdate.Add(node); m_RefreshTimedNodes = true; } @@ -259,7 +340,20 @@ void CollectShaderProperties(AbstractMaterialNode node, PreviewRenderData render m_PreviewProperties.Clear(); m_PropertyNodes.Clear(); - m_PropertyNodes.Add(node); + // TODO: Temporary. Remove + // TODO: While Master nodes still exist, branch and collect Blocks instead + if(node == null) + { + foreach(var block in m_Blocks) + { + m_PropertyNodes.Add(block); + } + } + else + { + m_PropertyNodes.Add(node); + } + PropagateNodeList(m_PropertyNodes, PropagationDirection.Upstream); foreach (var propNode in m_PropertyNodes) @@ -290,10 +384,18 @@ public void RenderPreviews() foreach (var node in m_NodesToDraw) { - if(node == null || !node.hasPreview || !node.previewExpanded) - continue; + PreviewRenderData renderData; + if(node == null) + { + renderData = m_MasterRenderData; + } + else + { + if(!node.hasPreview || !node.previewExpanded) + continue; - var renderData = m_RenderDatas[node.guid]; + renderData = m_RenderDatas[node.guid]; + } CollectShaderProperties(node, renderData); renderData.shaderData.mat.SetVector("_TimeParameters", timeParameters); @@ -311,10 +413,13 @@ public void RenderPreviews() continue; } - if (renderData.previewMode == PreviewMode.Preview2D) - m_RenderList2D.Add(renderData); - else - m_RenderList3D.Add(renderData); + if(node != null) + { + if (renderData.previewMode == PreviewMode.Preview2D) + m_RenderList2D.Add(renderData); + else + m_RenderList3D.Add(renderData); + } } EditorUtility.SetCameraAnimateMaterialsTime(m_SceneResources.camera, time); @@ -343,7 +448,7 @@ public void RenderPreviews() foreach (var renderData in m_RenderList3D) RenderPreview(renderData, m_SceneResources.sphere, Matrix4x4.identity); - var renderMasterPreview = masterRenderData != null && m_NodesToDraw.Contains(masterRenderData.shaderData.node); + var renderMasterPreview = masterRenderData != null && m_NodesToDraw.Contains(null); if (renderMasterPreview) { CollectShaderProperties(masterRenderData.shaderData.node, masterRenderData); @@ -387,12 +492,13 @@ public void ForceShaderUpdate() { m_NodesToUpdate.Add(data.shaderData.node); } + + m_NodesToUpdate.Add(null); } void UpdateShaders() { - // Check for shaders that finished compiling and set them to redraw - foreach (var renderData in m_RenderDatas.Values) + void CompilingProcess(PreviewRenderData renderData) { if (renderData.shaderData.isCompiling) { @@ -408,7 +514,7 @@ void UpdateShaders() if (!isCompiled) { - continue; + return; } // Force the material to re-generate all it's shader properties. @@ -418,11 +524,26 @@ void UpdateShaders() CheckForErrors(renderData.shaderData); m_NodesToDraw.Add(renderData.shaderData.node); - var masterNode = renderData.shaderData.node as IMasterNode; - masterNode?.ProcessPreviewMaterial(renderData.shaderData.mat); + // Process preview materials + foreach(var target in m_Graph.activeTargets) + { + if(target.IsActive()) + { + target.ProcessPreviewMaterial(renderData.shaderData.mat); + } + } } } + // Check for shaders that finished compiling and set them to redraw + foreach (var renderData in m_RenderDatas.Values) + { + CompilingProcess(renderData); + } + + // MasterRenderData is not added to m_RenderDatas + CompilingProcess(masterRenderData); + if (m_NodesToUpdate.Count == 0) return; @@ -434,13 +555,13 @@ void UpdateShaders() foreach (var node in m_NodesToUpdate) { - if (node is IMasterNode && node == masterRenderData.shaderData.node && !(node is VfxMasterNode)) + if (node == null) { UpdateMasterNodeShader(); continue; } - if (!node.hasPreview && !(node is SubGraphOutputNode || node is VfxMasterNode)) + if (!node.hasPreview && !(node is SubGraphOutputNode)) continue; var renderData = m_RenderDatas[node.guid]; @@ -504,8 +625,8 @@ void UpdateTimedNodeList() void RenderPreview(PreviewRenderData renderData, Mesh mesh, Matrix4x4 transform) { - var node = renderData.shaderData.node; - Assert.IsTrue((node != null && node.hasPreview && node.previewExpanded) || node == masterRenderData?.shaderData?.node); + // var node = renderData.shaderData.node; + // Assert.IsTrue((node != null && node.hasPreview && node.previewExpanded) || node == masterRenderData?.shaderData?.node); if (renderData.shaderData.hasError) { @@ -520,11 +641,16 @@ void RenderPreview(PreviewRenderData renderData, Mesh mesh, Matrix4x4 transform) RenderTexture.active = temp; Graphics.Blit(Texture2D.whiteTexture, temp, m_SceneResources.checkerboardMaterial); - m_SceneResources.camera.targetTexture = temp; - Graphics.DrawMesh(mesh, transform, renderData.shaderData.mat, 1, m_SceneResources.camera, 0, null, ShadowCastingMode.Off, false, null, false); + // Mesh is invalid for VFXTarget + // We should handle this more gracefully + if(!m_Graph.isVFXTarget) + { + m_SceneResources.camera.targetTexture = temp; + Graphics.DrawMesh(mesh, transform, renderData.shaderData.mat, 1, m_SceneResources.camera, 0, null, ShadowCastingMode.Off, false, null, false); + } var previousUseSRP = Unsupported.useScriptableRenderPipeline; - Unsupported.useScriptableRenderPipeline = renderData.shaderData.node is IMasterNode; + Unsupported.useScriptableRenderPipeline = renderData.shaderData.node == null; m_SceneResources.camera.Render(); Unsupported.useScriptableRenderPipeline = previousUseSRP; @@ -543,6 +669,10 @@ void CheckForErrors(PreviewShaderData shaderData) var messages = ShaderUtil.GetShaderMessages(shaderData.shader); if (messages.Length > 0) { + // TODO: Where to add errors to the stack?? + if(shaderData.node == null) + return; + m_Messenger.AddOrAppendError(this, shaderData.node.guid, messages[0]); } } @@ -551,13 +681,21 @@ void CheckForErrors(PreviewShaderData shaderData) void UpdateMasterNodeShader() { var shaderData = masterRenderData?.shaderData; - var masterNode = shaderData?.node as IMasterNode; - - if (masterNode == null) - return; + + // Skip generation for VFXTarget + if(!m_Graph.isVFXTarget) + { + var generator = new Generator(m_Graph, shaderData?.node, GenerationMode.Preview, "Master"); + shaderData.shaderString = generator.generatedShader; - var generator = new Generator(m_Graph, shaderData?.node, GenerationMode.Preview, shaderData?.node.name); - shaderData.shaderString = generator.generatedShader; + // Blocks from the generation include those temporarily created for missing stack blocks + // We need to hold on to these to set preview property values during CollectShaderProperties + m_Blocks.Clear(); + foreach(var block in generator.blocks) + { + m_Blocks.Add(block); + } + } if (string.IsNullOrEmpty(shaderData.shaderString)) { @@ -613,19 +751,6 @@ void DestroyPreview(Guid nodeId) DestroyRenderData(renderData); m_RenderDatas.Remove(nodeId); - - // Check if we're destroying the shader data used by the master preview - if (masterRenderData == renderData) - { - m_MasterRenderData = null; - if (!m_Graph.isSubGraph && renderData.shaderData.node.guid != m_Graph.activeOutputNodeGuid) - { - AddPreview(m_Graph.outputNode); - } - - if (onPrimaryMasterChanged != null) - onPrimaryMasterChanged(); - } } void ReleaseUnmanagedResources() diff --git a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs index 51969b4caeb..538f9b5c65b 100644 --- a/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs +++ b/com.unity.shadergraph/Editor/Drawing/SearchWindowProvider.cs @@ -31,6 +31,7 @@ class SearchWindowProvider : ScriptableObject public bool nodeNeedsRepositioning { get; set; } public SlotReference targetSlotReference { get; internal set; } public Vector2 targetPosition { get; internal set; } + public VisualElement target { get; internal set; } public bool regenerateEntries { get; set; } private const string k_HiddenFolderName = "Hidden"; @@ -62,7 +63,30 @@ void OnDestroy() public void GenerateNodeEntries() { // First build up temporary data structure containing group & title as an array of strings (the last one is the actual title) and associated node type. - var nodeEntries = new List(); + List nodeEntries = new List(); + + if(target is ContextView contextView) + { + // Iterate all BlockFieldDescriptors currently cached on GraphData + foreach(var field in m_Graph.blockFieldDescriptors) + { + if(field.isHidden) + continue; + + // Test stage + if(field.shaderStage != contextView.contextData.shaderStage) + continue; + + // Create and initialize BlockNode instance then add entry + var node = (BlockNode)Activator.CreateInstance(typeof(BlockNode)); + node.Init(field); + AddEntries(node, new string[]{ field.name }, nodeEntries); + } + + currentNodeEntries = nodeEntries; + return; + } + foreach (var type in TypeCache.GetTypesDerivedFrom()) { if ((!type.IsClass || type.IsAbstract) @@ -208,6 +232,7 @@ public Searcher.Searcher LoadSearchWindow() GenerateNodeEntries(); regenerateEntries = false; } + //create empty root for searcher tree var root = new List(); var dummyEntry = new NodeEntry(); @@ -256,6 +281,7 @@ public Searcher.Searcher LoadSearchWindow() return new Searcher.Searcher(nodeDatabase, new SearchWindowAdapter("Create Node")); } + public bool OnSearcherSelectEntry(SearcherItem entry, Vector2 screenMousePosition) { if(entry == null || (entry as SearchNodeItem).NodeGUID.node == null) @@ -264,16 +290,32 @@ public bool OnSearcherSelectEntry(SearcherItem entry, Vector2 screenMousePositio var nodeEntry = (entry as SearchNodeItem).NodeGUID; var node = CopyNodeForGraph(nodeEntry.node); - var drawState = node.drawState; - - var windowRoot = m_EditorWindow.rootVisualElement; var windowMousePosition = windowRoot.ChangeCoordinatesTo(windowRoot.parent, screenMousePosition );//- m_EditorWindow.position.position); var graphMousePosition = m_GraphView.contentViewContainer.WorldToLocal(windowMousePosition); - drawState.position = new Rect(graphMousePosition, Vector2.zero); - node.drawState = drawState; m_Graph.owner.RegisterCompleteObjectUndo("Add " + node.name); + + if(node is BlockNode blockNode) + { + if(!(target is ContextView contextView)) + return false; + + // Test against all current BlockNodes in the Context + // Never allow duplicate BlockNodes + if(contextView.contextData.blocks.Where(x => x.name == blockNode.name).FirstOrDefault() != null) + return false; + + // Insert block to Data + blockNode.owner = m_Graph; + int index = contextView.GetInsertionIndex(screenMousePosition); + m_Graph.AddBlock(blockNode, contextView.contextData, index); + return true; + } + + var drawState = node.drawState; + drawState.position = new Rect(graphMousePosition, Vector2.zero); + node.drawState = drawState; m_Graph.AddNode(node); if (connectedPort != null) @@ -293,6 +335,7 @@ public bool OnSearcherSelectEntry(SearcherItem entry, Vector2 screenMousePositio return true; } + public AbstractMaterialNode CopyNodeForGraph(AbstractMaterialNode oldNode) { var newNode = (AbstractMaterialNode)Activator.CreateInstance(oldNode.GetType()); @@ -312,8 +355,12 @@ public AbstractMaterialNode CopyNodeForGraph(AbstractMaterialNode oldNode) keywordNode.keywordGuid = ((KeywordNode)oldNode).keywordGuid; keywordNode.owner = null; } + else if(newNode is BlockNode blockNode) + { + blockNode.owner = m_Graph; + blockNode.Init(((BlockNode)oldNode).descriptor); + } return newNode; } } - } diff --git a/com.unity.shadergraph/Editor/Drawing/Views/ContextView.cs b/com.unity.shadergraph/Editor/Drawing/Views/ContextView.cs new file mode 100644 index 00000000000..581d2c6dd2e --- /dev/null +++ b/com.unity.shadergraph/Editor/Drawing/Views/ContextView.cs @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEditor.Experimental.GraphView; +using UnityEditor.ShaderGraph.Drawing; + +namespace UnityEditor.ShaderGraph +{ + sealed class ContextView : StackNode + { + ContextData m_ContextData; + + // Currently we only need one Port per context + // As the Contexts are hardcoded we know their directions + Port m_Port; + + // When dealing with more Contexts, `name` should be serialized in the ContextData + // Right now we dont do this so we dont overcommit to serializing unknowns + public ContextView(string name, ContextData contextData) + { + // Set data + m_ContextData = contextData; + + // Header + var headerLabel = new Label() { name = "headerLabel" }; + headerLabel.text = name; + headerContainer.Add(headerLabel); + } + + public ContextData contextData => m_ContextData; + public Port port => m_Port; + + // We need to use graphViewChange.movedElements to check whether a BlockNode has moved onto the GraphView + // but Nodes return in movedElements when they are mid-drag because they are removed from the stack (placeholder) + // StackNode has `dragEntered` but its protected so we need `isDragging` + public bool isDragging => dragEntered; + + public void AddPort(Direction direction) + { + var capacity = direction == Direction.Input ? Port.Capacity.Single : Port.Capacity.Multi; + var container = direction == Direction.Input ? inputContainer : outputContainer; + m_Port = Port.Create(Orientation.Vertical, direction, capacity, null); + m_Port.portName = ""; + + // Vertical ports have no representation in Model + // Therefore we need to disable interaction + m_Port.pickingMode = PickingMode.Ignore; + + container.Add(m_Port); + } + + public void InsertBlock(MaterialNodeView nodeView) + { + if(!(nodeView.userData is BlockNode blockNode)) + return; + + // If index is -1 the node is being added to the end of the Stack + if(blockNode.index == -1) + { + AddElement(nodeView); + return; + } + + // Add or Insert based on index + if(blockNode.index >= contentContainer.childCount) + { + AddElement(nodeView); + } + else + { + InsertElement(blockNode.index, nodeView); + } + } + + public void InsertElements(int insertIndex, IEnumerable elements) + { + var blockDatas = elements.Select(x => x.userData as BlockNode).ToArray(); + for(int i = 0; i < blockDatas.Length; i++) + { + contextData.blocks.Remove(blockDatas[i]); + } + + contextData.blocks.InsertRange(insertIndex, blockDatas); + } + + protected override bool AcceptsElement(GraphElement element, ref int proposedIndex, int maxIndex) + { + return element.userData is BlockNode blockNode && + blockNode.descriptor.shaderStage == contextData.shaderStage; + } + } +} diff --git a/com.unity.shadergraph/Editor/Drawing/Views/ContextView.cs.meta b/com.unity.shadergraph/Editor/Drawing/Views/ContextView.cs.meta new file mode 100644 index 00000000000..ab336d66c03 --- /dev/null +++ b/com.unity.shadergraph/Editor/Drawing/Views/ContextView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86f8ce6f2b8e29c45a3d40f1c0cfd4d4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs index bc54b058dff..d077a90f6d6 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs @@ -29,6 +29,9 @@ class FloatingWindowsLayout [Serializable] class UserViewSettings { + // TODO: Temporary Inspector + public bool isInspectorVisible = true; + public bool isBlackboardVisible = true; public bool isPreviewVisible = true; public string colorProvider = NoColors.Title; @@ -48,6 +51,9 @@ class GraphEditorView : VisualElement, IDisposable ColorManager m_ColorManager; EditorWindow m_EditorWindow; + // TODO: Temporary Inspector + InspectorView m_InspectorView; + public BlackboardProvider blackboardProvider { get { return m_BlackboardProvider; } @@ -203,6 +209,11 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage GUILayout.Label("Color Mode"); var newColorIdx = EditorGUILayout.Popup(m_ColorManager.activeIndex, colorProviders, GUILayout.Width(100f)); GUILayout.Space(4); + + // TODO: Temporary Inspector + m_UserViewSettings.isInspectorVisible = GUILayout.Toggle(m_UserViewSettings.isInspectorVisible, "Inspector", EditorStyles.toolbarButton); + GUILayout.Space(6); + m_UserViewSettings.isBlackboardVisible = GUILayout.Toggle(m_UserViewSettings.isBlackboardVisible, "Blackboard", EditorStyles.toolbarButton); GUILayout.Space(6); @@ -240,6 +251,10 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage m_BlackboardProvider = new BlackboardProvider(graph); m_GraphView.Add(m_BlackboardProvider.blackboard); + // TODO: Temporary Inspector + m_InspectorView = new InspectorView(m_Graph, previewManager); + m_GraphView.Add(m_InspectorView); + CreateMasterPreview(); UpdateSubWindowsVisibility(); @@ -261,6 +276,8 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider, editorWindow); + AddContexts(); + foreach (var graphGroup in graph.groups) { AddGroup(graphGroup); @@ -271,18 +288,60 @@ public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManage AddStickyNote(stickyNote); } - foreach (var node in graph.GetNodes()) + foreach (var node in graph.GetNodes().Where(x => !(x is BlockNode))) + AddNode(node); + + // As they can be reordered, we cannot be sure BlockNodes are deserialized in the same order as their stack position + // To handle this we reorder the BlockNodes here to avoid having to reorder them on the fly as they are added + foreach (var node in graph.GetNodes().OrderBy(s => s.index)) AddNode(node); foreach (var edge in graph.edges) AddEdge(edge); Add(content); + + // Active block lists need to be initialized on window start up + // Do this here to as we cant do this inside GraphData + // This is due to targets not being deserialized yet + m_Graph.UpdateActiveBlocks(); + } + + void AddContexts() + { + ContextView AddContext(string name, ContextData contextData, Direction portDirection) + { + var contextView = new ContextView(name, contextData); + contextView.SetPosition(new Rect(contextData.position, Vector2.zero)); + contextView.AddPort(portDirection); + m_GraphView.AddElement(contextView); + return contextView; + } + + // Add Contexts + // As Contexts are hardcoded and contain a single port we can just give the direction + var vertexContext = AddContext("Vertex", m_Graph.vertexContext, Direction.Output); + var fragmentContext = AddContext("Fragment", m_Graph.fragmentContext, Direction.Input); + + // Connect Contexts + // Vertical Edges have no representation in Model + // Therefore just draw it and dont allow interaction + var contextEdge = new Edge() + { + output = vertexContext.port, + input = fragmentContext.port, + pickingMode = PickingMode.Ignore, + }; + m_GraphView.AddElement(contextEdge); + + // Update the Context list on MaterialGraphView + m_GraphView.UpdateContextList(); } void NodeCreationRequest(NodeCreationContext c) { m_SearchWindowProvider.connectedPort = null; + m_SearchWindowProvider.target = c.target; SearcherWindow.Show(m_EditorWindow, (m_SearchWindowProvider as SearcherProvider).LoadSearchWindow(), item => (m_SearchWindowProvider as SearcherProvider).OnSearcherSelectEntry(item, c.screenMousePosition - m_EditorWindow.position.position), c.screenMousePosition - m_EditorWindow.position.position, null); @@ -290,6 +349,17 @@ void NodeCreationRequest(NodeCreationContext c) void UpdateSubWindowsVisibility() { + // TODO: Temporary Inspector + if (m_UserViewSettings.isInspectorVisible) + m_GraphView.Insert(m_GraphView.childCount, m_InspectorView); + else + m_InspectorView.RemoveFromHierarchy(); + + // if (m_UserViewSettings.isBlackboardVisible) + // m_GraphView.Insert(m_GraphView.childCount, m_BlackboardProvider.blackboard); + // else + // m_BlackboardProvider.blackboard.RemoveFromHierarchy(); + // Master Preview and Blackboard both need to keep their layouts when hidden in order to restore user preferences. // Because of their differences we do this is different ways, for now. + Blackboard needs to be effectively removed when hidden to avoid bugs. m_MasterPreviewView.visible = m_UserViewSettings.isPreviewVisible; @@ -408,12 +478,35 @@ GraphViewChange GraphViewChanged(GraphViewChange graphViewChange) var drawState = node.drawState; drawState.position = element.parent.ChangeCoordinatesTo(m_GraphView.contentViewContainer, element.GetPosition()); node.drawState = drawState; + + // BlockNode moved outside a Context + // This isnt allowed but there is no way to disallow it on the GraphView + if(node is BlockNode blockNode && + element.GetFirstAncestorOfType() == null) + { + var context = graphView.GetContext(blockNode.contextData); + + // isDragging ensures we arent calling this when moving + // the BlockNode into the GraphView during dragging + if(context.isDragging) + continue; + + // Remove from GraphView and add back to Context + m_GraphView.RemoveElement(element); + context.InsertBlock(element as MaterialNodeView); + } } if (element is StickyNote stickyNote) { SetStickyNotePosition(stickyNote); } + + if (element is ContextView contextView) + { + var rect = element.parent.ChangeCoordinatesTo(m_GraphView.contentViewContainer, element.GetPosition()); + contextView.contextData.position = rect.position; + } } } @@ -574,10 +667,20 @@ public void HandleGraphChanges() node.UnregisterCallback(OnNodeChanged); var nodeView = m_GraphView.nodes.ToList().OfType() .FirstOrDefault(p => p.node != null && p.node.guid == node.guid); + if (nodeView != null) { nodeView.Dispose(); - m_GraphView.RemoveElement((Node)nodeView); + + if(node is BlockNode blockNode) + { + var context = m_GraphView.GetContext(blockNode.contextData); + context.RemoveElement(nodeView as Node); + } + else + { + m_GraphView.RemoveElement((Node)nodeView); + } if (node.groupGuid != Guid.Empty) { @@ -680,10 +783,13 @@ public void HandleGraphChanges() .FirstOrDefault(p => p.userData is IEdge && Equals((IEdge) p.userData, edge)); if (edgeView != null) { - var nodeView = (IShaderNodeView)edgeView.input.node; + var nodeView = (IShaderNodeView)edgeView.output.node; if (nodeView?.node != null) { nodesToUpdate.Add(nodeView); + + // Update active state for connected Nodes + NodeUtils.UpdateNodeActiveOnEdgeChange(nodeView?.node); } edgeView.output.Disconnect(edgeView); @@ -700,7 +806,13 @@ public void HandleGraphChanges() { var edgeView = AddEdge(edge); if (edgeView != null) - nodesToUpdate.Add((IShaderNodeView)edgeView.input.node); + { + var outputNodeView = (IShaderNodeView)edgeView.output.node; + nodesToUpdate.Add(outputNodeView); + + // Update active state for connected Nodes + NodeUtils.UpdateNodeActiveOnEdgeChange(outputNodeView?.node); + } } foreach (var node in nodesToUpdate) @@ -765,6 +877,16 @@ void AddNode(AbstractMaterialNode node) m_GraphView.AddElement(tokenNode); nodeView = tokenNode; } + else if(node is BlockNode blockNode) + { + var blockNodeView = new MaterialNodeView { userData = blockNode }; + blockNodeView.Initialize(blockNode, m_PreviewManager, m_EdgeConnectorListener, graphView); + blockNodeView.MarkDirtyRepaint(); + nodeView = blockNodeView; + + var context = m_GraphView.GetContext(blockNode.contextData); + context.InsertBlock(blockNodeView); + } else if (node is RedirectNodeData redirectNodeData) { var redirectNodeView = new RedirectNodeView { userData = redirectNodeData }; @@ -1043,6 +1165,10 @@ void ApplyMasterPreviewLayout() void UpdateSerializedWindowLayout() { + // TODO: Temporary Inspector + m_FloatingWindowsLayout.previewLayout.CalculateDockingCornerAndOffset(m_InspectorView.layout, m_GraphView.layout); + m_FloatingWindowsLayout.previewLayout.ClampToParentWindow(); + m_FloatingWindowsLayout.previewLayout.CalculateDockingCornerAndOffset(m_MasterPreviewView.layout, m_GraphView.layout); m_FloatingWindowsLayout.previewLayout.ClampToParentWindow(); diff --git a/com.unity.shadergraph/Editor/Drawing/Views/InspectorView.cs b/com.unity.shadergraph/Editor/Drawing/Views/InspectorView.cs new file mode 100644 index 00000000000..3333b238baf --- /dev/null +++ b/com.unity.shadergraph/Editor/Drawing/Views/InspectorView.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEditor.Graphing; + +namespace UnityEditor.ShaderGraph.Drawing +{ + // TODO: Temporary Inspector + // TODO: Replace this with Sai's work + class InspectorView : VisualElement + { + GraphData m_GraphData; + PreviewManager m_PreviewManager; + VisualElement m_Element; + + public InspectorView(GraphData graphData, PreviewManager previewManager) + { + name = "inspectorView"; + m_GraphData = graphData; + m_PreviewManager = previewManager; + + // Styles + style.width = 400; + style.height = 800; + style.position = Position.Absolute; + style.right = 0; + style.top = 0; + style.backgroundColor = new Color(.17f, .17f, .17f, 1); + style.flexDirection = FlexDirection.Column; + + Rebuild(); + } + + void Rebuild() + { + m_Element = new VisualElement(); + + m_Element.Add(m_GraphData.GetSettings(() => + { + OnChange(); + })); + + Add(m_Element); + } + + void OnChange() + { + m_GraphData.UpdateActiveBlocks(); + m_PreviewManager.UpdateMasterPreview(ModificationScope.Topological); + Remove(m_Element); + Rebuild(); + } + } +} diff --git a/com.unity.shadergraph/Editor/Drawing/Views/InspectorView.cs.meta b/com.unity.shadergraph/Editor/Drawing/Views/InspectorView.cs.meta new file mode 100644 index 00000000000..c47d694b20d --- /dev/null +++ b/com.unity.shadergraph/Editor/Drawing/Views/InspectorView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 872eac3455864495094ab273dc954ce9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Drawing/Views/MasterNodeSettingsView.cs b/com.unity.shadergraph/Editor/Drawing/Views/MasterNodeSettingsView.cs deleted file mode 100644 index c4437d5e26b..00000000000 --- a/com.unity.shadergraph/Editor/Drawing/Views/MasterNodeSettingsView.cs +++ /dev/null @@ -1,188 +0,0 @@ -using System; -using System.Text.RegularExpressions; -using UnityEditor.Graphing; -using UnityEngine; -using UnityEditor.Graphing.Util; -using UnityEditor.Rendering; -using UnityEngine.UIElements; - -namespace UnityEditor.ShaderGraph.Drawing -{ - class MasterNodeSettingsView : VisualElement - { - private const string k_InvalidShaderGUI = "No class named {0} which derives from ShaderGUI was found in this project."; - private const string k_ShaderGUIToolTip = "Provide a ShaderGUI class that will be used as the Material Inspector for Materials using this Shader Graph"; - - private ICanChangeShaderGUI m_CanChangeShaderGUI; - private AbstractMaterialNode m_MasterNode; - - private TextField m_ShaderGUITextField; - private PropertyRow m_OverrideFieldRow; - private PropertySheet m_PropertySheet; - - public MasterNodeSettingsView(AbstractMaterialNode node) - { - m_MasterNode = node; - m_CanChangeShaderGUI = node as ICanChangeShaderGUI; - if (m_CanChangeShaderGUI == null) - { - Debug.LogError("MasterNodeSettingsView should only used on Master Nodes that implement ICanChangeShaderGUI"); - } - } - - protected PropertySheet GetShaderGUIOverridePropertySheet() - { - m_PropertySheet = new PropertySheet(); - - Toggle enabledToggle = new Toggle(); - m_PropertySheet.Add(new PropertyRow(new Label("Override ShaderGUI")), (row) => - { - enabledToggle = new Toggle(); - row.Add(enabledToggle, (toggle) => - { - toggle.value = m_CanChangeShaderGUI.OverrideEnabled; - toggle.OnToggleChanged(ChangeOverrideEnabled); - }); - }); - - m_OverrideFieldRow = new PropertyRow(new Label("ShaderGUI")); - m_ShaderGUITextField = new TextField(); - m_OverrideFieldRow.Add(m_ShaderGUITextField, (text) => - { - text.isDelayed = true; - text.RegisterValueChangedCallback(ChangeShaderGUIOverride); - }); - - // Set up such that both fields have the correct values (if displayed) & spawn warning if needed - ProcessOverrideEnabledToggle(m_CanChangeShaderGUI.OverrideEnabled); - - m_PropertySheet.tooltip = k_ShaderGUIToolTip; - - return m_PropertySheet; - } - - private void ChangeOverrideEnabled(ChangeEvent evt) - { - m_MasterNode.owner.owner.RegisterCompleteObjectUndo("Override Enabled Change"); - ProcessOverrideEnabledToggle(evt.newValue); - } - - private void ChangeShaderGUIOverride(ChangeEvent evt) - { - ProcessShaderGUIField(evt.newValue, true); - } - - private void ProcessOverrideEnabledToggle(bool newValue) - { - string storedValue = m_CanChangeShaderGUI.ShaderGUIOverride; - string preferredGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode); - - m_CanChangeShaderGUI.OverrideEnabled = newValue; - - // Display the ShaderGUI text field only when the override is enabled - if (m_CanChangeShaderGUI.OverrideEnabled) - { - m_PropertySheet.Add(m_OverrideFieldRow); - - // Display the pipeline's default upon activation, if it has one. Otherwise set up field to display user setting. - if (string.IsNullOrEmpty(storedValue) && !string.IsNullOrEmpty(preferredGUI)) - { - ProcessShaderGUIField(preferredGUI, false); - } - else - { - ProcessShaderGUIField(storedValue, false); - } - } - else if (m_PropertySheet.Contains(m_OverrideFieldRow)) - { - m_PropertySheet.Remove(m_OverrideFieldRow); - - // Upon disable, set the value back to null (for pipeline switching reasons, among other reasons) - if (storedValue == preferredGUI) - { - m_CanChangeShaderGUI.ShaderGUIOverride = null; - } - } - - AddWarningIfNeeded(); - } - - private void ProcessShaderGUIField(string newValue, bool recordUndo) - { - if (newValue == null) - { - newValue = ""; - } - - string sanitizedInput = Regex.Replace(newValue, @"(?:[^A-Za-z0-9._])|(?:\s)", ""); - - if (sanitizedInput != m_CanChangeShaderGUI.ShaderGUIOverride) - { - if (recordUndo) - { - m_MasterNode.owner.owner.RegisterCompleteObjectUndo("ShaderGUI Change"); - } - - // Reset to default when the field is wiped out - if (HasPreferredGUI() && string.IsNullOrEmpty(sanitizedInput)) - { - m_CanChangeShaderGUI.ShaderGUIOverride = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode); - } - else - { - m_CanChangeShaderGUI.ShaderGUIOverride = sanitizedInput; - } - } - - m_ShaderGUITextField.value = m_CanChangeShaderGUI.ShaderGUIOverride; - - AddWarningIfNeeded(); - } - - // Add a warning to the node if the ShaderGUI is not found by Unity. - private void AddWarningIfNeeded() - { - if (m_CanChangeShaderGUI.OverrideEnabled && m_CanChangeShaderGUI.ShaderGUIOverride != null && !ValidCustomEditorType(m_CanChangeShaderGUI.ShaderGUIOverride)) - { - m_MasterNode.owner.messageManager?.ClearNodesFromProvider(this, m_MasterNode.ToEnumerable()); - m_MasterNode.owner.messageManager?.AddOrAppendError(this, m_MasterNode.guid, - new ShaderMessage(string.Format(k_InvalidShaderGUI, m_CanChangeShaderGUI.ShaderGUIOverride), ShaderCompilerMessageSeverity.Warning)); - } - else - { - m_MasterNode.owner.messageManager?.ClearNodesFromProvider(this, m_MasterNode.ToEnumerable()); - } - } - - // Matches what trunk does to extract CustomEditors (Editor/Mono/Inspector/ShaderGUI.cs: ExtractCustomEditorType) - private bool ValidCustomEditorType(string customEditorName) - { - if (string.IsNullOrEmpty(customEditorName)) - { - if (HasPreferredGUI()) - { - return false; - } - return true; // No default, so this is valid. - } - - var unityEditorFullName = $"UnityEditor.{customEditorName}"; // For convenience: adding UnityEditor namespace is not needed in the shader - foreach (var type in TypeCache.GetTypesDerivedFrom()) - { - if (type.FullName.Equals(customEditorName, StringComparison.Ordinal) || type.FullName.Equals(unityEditorFullName, StringComparison.Ordinal)) - { - return typeof(ShaderGUI).IsAssignableFrom(type); - } - } - return false; - } - - private bool HasPreferredGUI() - { - return !string.IsNullOrEmpty(GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode)); - } - - } - -} diff --git a/com.unity.shadergraph/Editor/Drawing/Views/MasterNodeSettingsView.cs.meta b/com.unity.shadergraph/Editor/Drawing/Views/MasterNodeSettingsView.cs.meta deleted file mode 100644 index 6e7e6fe7f45..00000000000 --- a/com.unity.shadergraph/Editor/Drawing/Views/MasterNodeSettingsView.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 81a2b49fe3ca1a94e92a36511b8329e7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs b/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs index 04877cea52d..33f110f110f 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs @@ -28,11 +28,17 @@ public MaterialGraphView() canPasteSerializedData = CanPasteSerializedDataImplementation; unserializeAndPaste = UnserializeAndPasteImplementation; deleteSelection = DeleteSelectionImplementation; + elementsInsertedToStackNode = ElementsInsertedToStackNode; RegisterCallback(OnDragUpdatedEvent); RegisterCallback(OnDragPerformEvent); RegisterCallback(OnMouseMoveEvent); } + protected override bool canCutSelection + { + get { return selection.OfType().Any(x => x.node.canCutNode) || selection.OfType().Any() || selection.OfType().Any(); } + } + protected override bool canCopySelection { get { return selection.OfType().Any(x => x.node.canCopyNode) || selection.OfType().Any() || selection.OfType().Any(); } @@ -47,6 +53,24 @@ public MaterialGraphView(GraphData graph) : this() public Action onConvertToSubgraphClick { get; set; } public Vector2 cachedMousePosition { get; private set; } + // GraphView has UQueryState nodes built in to query for Nodes + // We need this for Contexts but we might as well cast it to a list once + List contexts { get; set; } + + // We have to manually update Contexts + // Currently only called during GraphEditorView ctor as our Contexts are static + public void UpdateContextList() + { + var contextQuery = contentViewContainer.Query().Build(); + contexts = contextQuery.ToList(); + } + + // We need a way to access specific ContextViews + public ContextView GetContext(ContextData contextData) + { + return contexts.FirstOrDefault(s => s.contextData == contextData); + } + public override List GetCompatiblePorts(Port startAnchor, NodeAdapter nodeAdapter) { var compatibleAnchors = new List(); @@ -170,6 +194,10 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt) if (selectedObject is Group) return DropdownMenuAction.Status.Disabled; GraphElement ge = selectedObject as GraphElement; + if (ge.userData is BlockNode) + { + return DropdownMenuAction.Status.Disabled; + } if (ge.userData is IGroupItem) { filteredSelection.Add(ge); @@ -262,10 +290,10 @@ void SelectUnusedNodes(DropdownMenuAction action) List endNodes = new List(); if (!graph.isSubGraph) { - var nodeView = graph.GetNodes(); - foreach (IMasterNode masterNode in nodeView) + var nodeView = graph.GetNodes(); + foreach (BlockNode blockNode in nodeView) { - endNodes.Add(masterNode as AbstractMaterialNode); + endNodes.Add(blockNode as AbstractMaterialNode); } } else @@ -1041,6 +1069,12 @@ void CreateNode(object obj, Vector2 nodePosition) } #endregion + + void ElementsInsertedToStackNode(StackNode stackNode, int insertIndex, IEnumerable elements) + { + var contextView = stackNode as ContextView; + contextView.InsertElements(insertIndex, elements); + } } static class GraphViewExtensions diff --git a/com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs b/com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs index 8290c9cdee4..d06a493f290 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/MaterialNodeView.cs @@ -58,6 +58,9 @@ public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManage viewDataKey = node.guid.ToString(); UpdateTitle(); + // Add disabled overlay + Add(new VisualElement() { name = "disabledOverlay", pickingMode = PickingMode.Ignore }); + // Add controls container var controlsContainer = new VisualElement { name = "controls" }; { @@ -143,8 +146,6 @@ public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManage RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here UpdatePortInputVisibilities(); - SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0)); - if (node is SubGraphNode) { RegisterCallback(OnSubGraphDoubleClick); @@ -154,30 +155,14 @@ public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManage m_TitleContainer = this.Q("title"); - var masterNode = node as IMasterNode; - if (masterNode != null) + if(node is BlockNode blockData) { - AddToClassList("master"); - bool validTarget = false; - foreach(Target activeTarget in node.owner.validTargets) - { - //if we have a valid active target implementation and render pipeline, don't display the error - if (activeTarget.IsPipelineCompatible(GraphicsSettings.currentRenderPipeline)) - { - validTarget = true; - break; - } - } - //if no active target implementations are valid with the current pipeline, display the error - m_GraphView.graph.messageManager?.ClearAllFromProvider(this); - if (!validTarget) - { - m_GraphView.graph.messageManager?.AddOrAppendError(this, node.guid, - new ShaderMessage("The active Master Node is not compatible with the current Render Pipeline," + - " or no Render Pipeline is assigned." + - " Assign a Render Pipeline in the graphics settings that is compatible with this Master Node.", - ShaderCompilerMessageSeverity.Error)); - } + AddToClassList("blockData"); + m_TitleContainer.RemoveFromHierarchy(); + } + else + { + SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0)); } m_NodeSettingsView = new NodeSettingsView(); @@ -210,6 +195,9 @@ public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManage m_TitleContainer.Add(m_ButtonContainer); } + // Update active state + SetActive(node.isActive); + // Register OnMouseHover callbacks for node highlighting RegisterCallback(OnMouseHover); RegisterCallback(OnMouseHover); @@ -232,6 +220,28 @@ public void AttachMessage(string errString, ShaderCompilerMessageSeverity severi badge.AttachTo(m_TitleContainer, SpriteAlignment.RightCenter); } + public void SetActive(bool state) + { + // Setup + var disabledString = "disabled"; + var inputViews = m_PortInputContainer.Children().OfType(); + + if (!state) + { + // Add elements to disabled class list + AddToClassList(disabledString); + foreach(var inputView in inputViews) + inputView.AddToClassList(disabledString); + } + else + { + // Remove elements from disabled class list + RemoveFromClassList(disabledString); + foreach(var inputView in inputViews) + inputView.RemoveFromClassList(disabledString); + } + } + public void ClearMessage() { var badge = this.Q(); @@ -310,15 +320,7 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt) { if (evt.target is Node) { - var isMaster = node is IMasterNode; - var isActive = node.guid == node.owner.activeOutputNodeGuid; - if (isMaster) - { - evt.menu.AppendAction("Set Active", SetMasterAsActive, - _ => isActive ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal); - } - - var canViewShader = node.hasPreview || node is IMasterNode || node is SubGraphOutputNode; + var canViewShader = node.hasPreview || node is SubGraphOutputNode; evt.menu.AppendAction("Copy Shader", CopyToClipboard, _ => canViewShader ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Hidden, GenerationMode.ForReals); @@ -337,11 +339,6 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt) base.BuildContextualMenu(evt); } - void SetMasterAsActive(DropdownMenuAction action) - { - node.owner.activeOutputNodeGuid = node.guid; - } - void CopyToClipboard(DropdownMenuAction action) { GUIUtility.systemCopyBuffer = ConvertToShader((GenerationMode) action.userData); @@ -468,7 +465,7 @@ void SetPreviewExpandedStateOnSelection(bool state) public bool CanToggleNodeExpanded() { - return m_CollapseButton.enabledInHierarchy; + return !(node is BlockNode) && m_CollapseButton.enabledInHierarchy; } void UpdatePreviewExpandedState(bool expanded) @@ -509,6 +506,7 @@ void UpdateTitle() public void OnModified(ModificationScope scope) { UpdateTitle(); + SetActive(node.isActive); if (node.hasPreview) UpdatePreviewExpandedState(node.previewExpanded); @@ -622,6 +620,16 @@ void UpdatePortInputs() portInputView = new PortInputView(port.slot) { style = { position = Position.Absolute } }; m_PortInputContainer.Add(portInputView); SetPortInputPosition(port, portInputView); + + // Update active state + if(node.isActive) + { + portInputView.RemoveFromClassList("disabled"); + } + else + { + portInputView.AddToClassList("disabled"); + } } port.RegisterCallback(UpdatePortInput); diff --git a/com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs b/com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs deleted file mode 100644 index a79ba3e80d7..00000000000 --- a/com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEditor.UIElements; -using UnityEngine.UIElements; -using UnityEditor.ShaderGraph.Internal; - -namespace UnityEditor.ShaderGraph.Drawing -{ - class PBRSettingsView : MasterNodeSettingsView - { - PBRMasterNode m_Node; - public PBRSettingsView(PBRMasterNode node) : base(node) - { - m_Node = node; - - PropertySheet ps = new PropertySheet(); - - ps.Add(new PropertyRow(new Label("Workflow")), (row) => - { - row.Add(new EnumField(PBRMasterNode.Model.Metallic), (field) => - { - field.value = m_Node.model; - field.RegisterValueChangedCallback(ChangeWorkFlow); - }); - }); - - ps.Add(new PropertyRow(new Label("Surface")), (row) => - { - row.Add(new EnumField(SurfaceType.Opaque), (field) => - { - field.value = m_Node.surfaceType; - field.RegisterValueChangedCallback(ChangeSurface); - }); - }); - - ps.Add(new PropertyRow(new Label("Blend")), (row) => - { - row.Add(new EnumField(AlphaMode.Additive), (field) => - { - field.value = m_Node.alphaMode; - field.RegisterValueChangedCallback(ChangeAlphaMode); - }); - }); - - ps.Add(new PropertyRow(new Label("Fragment Normal Space")), (row) => - { - row.Add(new EnumField(NormalDropOffSpace.Tangent), (field) => - { - field.value = m_Node.normalDropOffSpace; - field.RegisterValueChangedCallback(ChangeSpaceOfNormalDropOffMode); - }); - }); - - ps.Add(new PropertyRow(new Label("Two Sided")), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.twoSided.isOn; - toggle.OnToggleChanged(ChangeTwoSided); - }); - }); - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeWorkFlow(ChangeEvent evt) - { - if (Equals(m_Node.model, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Work Flow Change"); - m_Node.model = (PBRMasterNode.Model)evt.newValue; - } - - void ChangeSurface(ChangeEvent evt) - { - if (Equals(m_Node.surfaceType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Change"); - m_Node.surfaceType = (SurfaceType)evt.newValue; - } - - void ChangeAlphaMode(ChangeEvent evt) - { - if (Equals(m_Node.alphaMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); - m_Node.alphaMode = (AlphaMode)evt.newValue; - } - - void ChangeSpaceOfNormalDropOffMode(ChangeEvent evt) - { - if (Equals(m_Node.normalDropOffSpace, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Normal Space Drop-Off Mode Change"); - m_Node.normalDropOffSpace = (NormalDropOffSpace)evt.newValue; - } - - void ChangeTwoSided(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Two Sided Change"); - ToggleData td = m_Node.twoSided; - td.isOn = evt.newValue; - m_Node.twoSided = td; - } - } -} diff --git a/com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs.meta b/com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs.meta deleted file mode 100644 index 9a39e82ec36..00000000000 --- a/com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0f6aa10456b30264a9bd4aeded39530a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Drawing/Views/PortInputView.cs b/com.unity.shadergraph/Editor/Drawing/Views/PortInputView.cs index e5f7f5ddaeb..b0f8584ef96 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/PortInputView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/PortInputView.cs @@ -60,6 +60,7 @@ public PortInputView(MaterialSlot slot) } Add(m_Container); + m_Container.Add(new VisualElement() { name = "disabledOverlay", pickingMode = PickingMode.Ignore }); m_Container.visible = m_EdgeControl.visible = m_Control != null; RegisterCallback(OnCustomStyleResolved); diff --git a/com.unity.shadergraph/Editor/Drawing/Views/PropertyNodeView.cs b/com.unity.shadergraph/Editor/Drawing/Views/PropertyNodeView.cs index 36be1bc21ef..6374b1ecfbf 100644 --- a/com.unity.shadergraph/Editor/Drawing/Views/PropertyNodeView.cs +++ b/com.unity.shadergraph/Editor/Drawing/Views/PropertyNodeView.cs @@ -32,6 +32,12 @@ public PropertyNodeView(PropertyNode node, EdgeConnectorListener edgeConnectorLi // Removing the title label since it is not used and taking up space this.Q("title-label").RemoveFromHierarchy(); + // Add disabled overlay + Add(new VisualElement() { name = "disabledOverlay", pickingMode = PickingMode.Ignore }); + + // Update active state + SetActive(node.isActive); + // Registering the hovering callbacks for highlighting RegisterCallback(OnMouseHover); RegisterCallback(OnMouseHover); @@ -58,6 +64,8 @@ public void UpdatePortInputTypes() public void OnModified(ModificationScope scope) { + SetActive(node.isActive); + if (scope == ModificationScope.Graph) { // changing the icon to be exposed or not @@ -77,6 +85,23 @@ public void OnModified(ModificationScope scope) } } + public void SetActive(bool state) + { + // Setup + var disabledString = "disabled"; + + if (!state) + { + // Add elements to disabled class list + AddToClassList(disabledString); + } + else + { + // Remove elements from disabled class list + RemoveFromClassList(disabledString); + } + } + public void AttachMessage(string errString, ShaderCompilerMessageSeverity severity) { ClearMessage(); diff --git a/com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs b/com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs deleted file mode 100644 index 78c9fdc35e5..00000000000 --- a/com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor.Graphing.Util; -using UnityEditor.ShaderGraph.Drawing.Controls; -using UnityEditor.UIElements; -using UnityEngine.UIElements; - -namespace UnityEditor.ShaderGraph.Drawing -{ - class UnlitSettingsView : MasterNodeSettingsView - { - UnlitMasterNode m_Node; - public UnlitSettingsView(UnlitMasterNode node) : base(node) - { - m_Node = node; - - PropertySheet ps = new PropertySheet(); - - ps.Add(new PropertyRow(new Label("Surface")), (row) => - { - row.Add(new EnumField(SurfaceType.Opaque), (field) => - { - field.value = m_Node.surfaceType; - field.RegisterValueChangedCallback(ChangeSurface); - }); - }); - - ps.Add(new PropertyRow(new Label("Blend")), (row) => - { - row.Add(new EnumField(AlphaMode.Additive), (field) => - { - field.value = m_Node.alphaMode; - field.RegisterValueChangedCallback(ChangeAlphaMode); - }); - }); - - ps.Add(new PropertyRow(new Label("Two Sided")), (row) => - { - row.Add(new Toggle(), (toggle) => - { - toggle.value = m_Node.twoSided.isOn; - toggle.OnToggleChanged(ChangeTwoSided); - }); - }); - - Add(ps); - Add(GetShaderGUIOverridePropertySheet()); - } - - void ChangeSurface(ChangeEvent evt) - { - if (Equals(m_Node.surfaceType, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Surface Change"); - m_Node.surfaceType = (SurfaceType)evt.newValue; - } - - void ChangeAlphaMode(ChangeEvent evt) - { - if (Equals(m_Node.alphaMode, evt.newValue)) - return; - - m_Node.owner.owner.RegisterCompleteObjectUndo("Alpha Mode Change"); - m_Node.alphaMode = (AlphaMode)evt.newValue; - } - - void ChangeTwoSided(ChangeEvent evt) - { - m_Node.owner.owner.RegisterCompleteObjectUndo("Two Sided Change"); - ToggleData td = m_Node.twoSided; - td.isOn = evt.newValue; - m_Node.twoSided = td; - } - } -} diff --git a/com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs.meta b/com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs.meta deleted file mode 100644 index 0cc983ac52a..00000000000 --- a/com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 66dcef8109abbfc4fa27499aaa708dd4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks.meta b/com.unity.shadergraph/Editor/Generation/Attributes.meta similarity index 77% rename from com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks.meta rename to com.unity.shadergraph/Editor/Generation/Attributes.meta index b6234b3a970..19406e57f26 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/AssetCallbacks.meta +++ b/com.unity.shadergraph/Editor/Generation/Attributes.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 92ce9656ee586234085f20c3dbed1f88 +guid: 95d4f3eaeba344017b164174ed877b77 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/com.unity.shadergraph/Editor/Generation/Attributes/GenerateBlocksAttribute.cs b/com.unity.shadergraph/Editor/Generation/Attributes/GenerateBlocksAttribute.cs new file mode 100644 index 00000000000..cc47de30f6d --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Attributes/GenerateBlocksAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace UnityEditor.ShaderGraph +{ + [AttributeUsage(AttributeTargets.Struct)] + class GenerateBlocksAttribute : Attribute + { + } +} diff --git a/com.unity.shadergraph/Editor/Generation/Attributes/GenerateBlocksAttribute.cs.meta b/com.unity.shadergraph/Editor/Generation/Attributes/GenerateBlocksAttribute.cs.meta new file mode 100644 index 00000000000..370278399a5 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Attributes/GenerateBlocksAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8192fc2e63c354dff92db5dde0c564b7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs b/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs new file mode 100644 index 00000000000..54d31ce179f --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace UnityEditor.ShaderGraph +{ + [GenerationAPI] + internal class TargetActiveBlockContext + { + public List blocks { get; private set; } + + public TargetActiveBlockContext() + { + blocks = new List(); + } + + public void AddBlock(BlockFieldDescriptor block, bool conditional = true) + { + if(conditional == true) + { + blocks.Add(block); + } + } + } +} diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs.meta b/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs.meta new file mode 100644 index 00000000000..c862d6c7011 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 860eceef9d9eeb64789007e44a1935fe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetFieldContext.cs b/com.unity.shadergraph/Editor/Generation/Contexts/TargetFieldContext.cs new file mode 100644 index 00000000000..779d4d375a8 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetFieldContext.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace UnityEditor.ShaderGraph +{ + [GenerationAPI] + internal class TargetFieldContext + { + public List conditionalFields { get; private set; } + public PassDescriptor pass { get; private set; } + public List blocks { get; private set; } + public bool hasDotsProperties { get; private set; } + + public TargetFieldContext(PassDescriptor pass, List blocks, bool hasDotsProperties) + { + conditionalFields = new List(); + this.pass = pass; + this.blocks = blocks; + this.hasDotsProperties = hasDotsProperties; + } + + public void AddField(FieldDescriptor field, bool conditional = true) + { + conditionalFields.Add(new ConditionalField(field, conditional)); + } + } +} diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetFieldContext.cs.meta b/com.unity.shadergraph/Editor/Generation/Contexts/TargetFieldContext.cs.meta new file mode 100644 index 00000000000..4f942c041c2 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetFieldContext.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1b72eab244c7bf14cabec1afc06beebb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs new file mode 100644 index 00000000000..f3b42956912 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using UnityEditor.UIElements; +using UnityEngine.UIElements; +using UnityEditor.Graphing.Util; +using UnityEditor.ShaderGraph.Drawing; + +namespace UnityEditor.ShaderGraph +{ + [GenerationAPI] + internal class TargetPropertyGUIContext + { + public List properties { get; private set; } + + public TargetPropertyGUIContext() + { + properties = new List(); + } + + public void AddProperty(string label, BaseField field, bool condition, EventCallback> evt) + { + if(condition == true) + { + AddProperty(label, field, evt); + } + } + + public void AddProperty(string label, int indentLevel, BaseField field, bool condition, EventCallback> evt) + { + if(condition == true) + { + AddProperty(label, indentLevel, field, evt); + } + } + + public void AddProperty(string label, BaseField field, EventCallback> evt) + { + AddProperty(label, 0, field, evt); + } + + public void AddProperty(string label, int indentLevel, BaseField field, EventCallback> evt) + { + if(field is INotifyValueChanged notifyValueChanged) + { + notifyValueChanged.RegisterValueChangedCallback(evt); + } + + string labelText = ""; + for (var i = 0; i < indentLevel; i++) + { + labelText += " "; + } + labelText += label; + + var propertyRow = new PropertyRow(new Label(labelText)); + propertyRow.Add(field); + properties.Add(propertyRow); + } + + public void AddLabel(string label, int indentLevel) + { + string labelText = ""; + for (var i = 0; i < indentLevel; i++) + { + labelText += " "; + } + labelText += label; + + var propertyRow = new PropertyRow(new Label(labelText)); + properties.Add(propertyRow); + } + } +} diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs.meta b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs.meta new file mode 100644 index 00000000000..13b4765f075 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5b0e9f1f7df8dc34a984c30b56cf998b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetSetupContext.cs b/com.unity.shadergraph/Editor/Generation/Contexts/TargetSetupContext.cs index 14b14505d94..6679a97b78f 100644 --- a/com.unity.shadergraph/Editor/Generation/Contexts/TargetSetupContext.cs +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetSetupContext.cs @@ -5,7 +5,6 @@ namespace UnityEditor.ShaderGraph [GenerationAPI] internal class TargetSetupContext { - public IMasterNode masterNode { get; private set; } public List subShaders { get; private set; } public List assetDependencyPaths { get; private set; } public string defaultShaderGUI { get; private set; } @@ -16,11 +15,6 @@ public TargetSetupContext() assetDependencyPaths = new List(); } - public void SetMasterNode(IMasterNode masterNode) - { - this.masterNode = masterNode; - } - public void AddSubShader(SubShaderDescriptor subShader) { subShaders.Add(subShader); diff --git a/com.unity.shadergraph/Editor/Generation/Controls.cs b/com.unity.shadergraph/Editor/Generation/Controls.cs new file mode 100644 index 00000000000..0747343a156 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Controls.cs @@ -0,0 +1,138 @@ +using UnityEngine; +using UnityEditor.ShaderGraph.Internal; + +namespace UnityEditor.ShaderGraph +{ + // This whole file is regrettable. + // However, right now we need an abstraction for MaterialSlot for use with BlockFieldDescriptors. + // MaterialSlot is very leaky, so we cant make it public but we need BlockFieldDescriptor to be public. + // All MaterialSlot types required by a BlockFieldDescriptor need a matching Control here. + // We also need a corresponding case in BlockNode.AddSlot for each control. + + public interface IControl + { + ShaderGraphRequirements GetRequirements(); + } + + public class PositionControl : IControl + { + public CoordinateSpace space { get; private set; } + + public PositionControl(CoordinateSpace space) + { + this.space = space; + } + + public ShaderGraphRequirements GetRequirements() + { + return new ShaderGraphRequirements() { requiresPosition = space.ToNeededCoordinateSpace() }; + } + } + + public class NormalControl : IControl + { + public CoordinateSpace space { get; private set; } + + public NormalControl(CoordinateSpace space) + { + this.space = space; + } + + public ShaderGraphRequirements GetRequirements() + { + return new ShaderGraphRequirements() { requiresNormal = space.ToNeededCoordinateSpace() }; + } + } + + public class TangentControl : IControl + { + public CoordinateSpace space { get; private set; } + + public TangentControl(CoordinateSpace space) + { + this.space = space; + } + + public ShaderGraphRequirements GetRequirements() + { + return new ShaderGraphRequirements() { requiresTangent = space.ToNeededCoordinateSpace() }; + } + } + + public class ColorControl : IControl + { + public Color value { get; private set; } + public bool hdr { get; private set; } + + public ColorControl(Color value, bool hdr) + { + this.value = value; + this.hdr = hdr; + } + + public ShaderGraphRequirements GetRequirements() + { + return ShaderGraphRequirements.none; + } + } + + public class ColorRGBAControl : IControl + { + public Color value { get; private set; } + + public ColorRGBAControl(Color value) + { + this.value = value; + } + + public ShaderGraphRequirements GetRequirements() + { + return ShaderGraphRequirements.none; + } + } + + public class FloatControl : IControl + { + public float value { get; private set; } + + public FloatControl(float value) + { + this.value = value; + } + + public ShaderGraphRequirements GetRequirements() + { + return ShaderGraphRequirements.none; + } + } + + public class Vector2Control : IControl + { + public Vector2 value { get; private set; } + + public Vector2Control(Vector2 value) + { + this.value = value; + } + + public ShaderGraphRequirements GetRequirements() + { + return ShaderGraphRequirements.none; + } + } + + public class Vector3Control : IControl + { + public Vector3 value { get; private set; } + + public Vector3Control(Vector3 value) + { + this.value = value; + } + + public ShaderGraphRequirements GetRequirements() + { + return ShaderGraphRequirements.none; + } + } +} diff --git a/com.unity.shadergraph/Editor/Generation/Controls.cs.meta b/com.unity.shadergraph/Editor/Generation/Controls.cs.meta new file mode 100644 index 00000000000..0dc6b7dcebd --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Controls.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f3470767c2eef44f845b47f9ae5538d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Descriptors/BlockFieldDescriptor.cs b/com.unity.shadergraph/Editor/Generation/Descriptors/BlockFieldDescriptor.cs new file mode 100644 index 00000000000..625dc64edba --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Descriptors/BlockFieldDescriptor.cs @@ -0,0 +1,30 @@ +namespace UnityEditor.ShaderGraph +{ + internal class BlockFieldDescriptor : FieldDescriptor + { + public IControl control { get; } + public ShaderStage shaderStage { get; } + public bool isHidden { get; } + + public BlockFieldDescriptor(string tag, string name, string define, IControl control, ShaderStage shaderStage, bool isHidden = false) + : base (tag, name, define) + { + this.control = control; + this.shaderStage = shaderStage; + this.isHidden = isHidden; + } + } + + // TODO: This exposes the MaterialSlot API + // TODO: This needs to be removed but is currently required by HDRP for DiffusionProfileInputMaterialSlot + internal class CustomSlotBlockFieldDescriptor : BlockFieldDescriptor + { + public MaterialSlot slot { get; } + + public CustomSlotBlockFieldDescriptor(string tag, string name, string define, MaterialSlot slot) + : base (tag, name, define, null, ShaderStage.Fragment) + { + this.slot = slot; + } + } +} diff --git a/com.unity.shadergraph/Editor/Generation/Descriptors/BlockFieldDescriptor.cs.meta b/com.unity.shadergraph/Editor/Generation/Descriptors/BlockFieldDescriptor.cs.meta new file mode 100644 index 00000000000..965004c61b9 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/Descriptors/BlockFieldDescriptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 82f47029c21684be390696599c52fb76 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Descriptors/PassDescriptor.cs b/com.unity.shadergraph/Editor/Generation/Descriptors/PassDescriptor.cs index 93000bb629e..8030c89a56a 100644 --- a/com.unity.shadergraph/Editor/Generation/Descriptors/PassDescriptor.cs +++ b/com.unity.shadergraph/Editor/Generation/Descriptors/PassDescriptor.cs @@ -14,8 +14,8 @@ internal struct PassDescriptor public string sharedTemplateDirectory; // Port mask - public int[] vertexPorts; - public int[] pixelPorts; + public BlockFieldDescriptor[] vertexBlocks; + public BlockFieldDescriptor[] pixelBlocks; // Collections public StructCollection structs; diff --git a/com.unity.shadergraph/Editor/Generation/Descriptors/SubShaderDescriptor.cs b/com.unity.shadergraph/Editor/Generation/Descriptors/SubShaderDescriptor.cs index 95497d810e9..1b6c3de9d18 100644 --- a/com.unity.shadergraph/Editor/Generation/Descriptors/SubShaderDescriptor.cs +++ b/com.unity.shadergraph/Editor/Generation/Descriptors/SubShaderDescriptor.cs @@ -4,8 +4,8 @@ internal struct SubShaderDescriptor { public string pipelineTag; - public string renderQueueOverride; - public string renderTypeOverride; + public string renderType; + public string renderQueue; public bool generatesPreview; public PassCollection passes; } diff --git a/com.unity.shadergraph/Editor/Generation/IHasMetaData.cs b/com.unity.shadergraph/Editor/Generation/IHasMetaData.cs new file mode 100644 index 00000000000..098e8f7e831 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/IHasMetaData.cs @@ -0,0 +1,11 @@ +using UnityEngine; + +namespace UnityEditor.ShaderGraph +{ + [GenerationAPI] + interface IHasMetadata + { + string identifier { get; } + ScriptableObject GetMetadataObject(); + } +} diff --git a/com.unity.shadergraph/Editor/Importers/ShaderGraphMetadata.cs.meta b/com.unity.shadergraph/Editor/Generation/IHasMetaData.cs.meta similarity index 100% rename from com.unity.shadergraph/Editor/Importers/ShaderGraphMetadata.cs.meta rename to com.unity.shadergraph/Editor/Generation/IHasMetaData.cs.meta diff --git a/com.unity.shadergraph/Editor/Generation/Interface.meta b/com.unity.shadergraph/Editor/Generation/Interface.meta deleted file mode 100644 index 923cf615570..00000000000 --- a/com.unity.shadergraph/Editor/Generation/Interface.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e4148ea0b4577294082f845f1fe9ae5b -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Interface/IMasterNode.cs b/com.unity.shadergraph/Editor/Generation/Interface/IMasterNode.cs deleted file mode 100644 index 5d89a845bb4..00000000000 --- a/com.unity.shadergraph/Editor/Generation/Interface/IMasterNode.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.Rendering; -using UnityEditor.ShaderGraph; - -namespace UnityEditor.ShaderGraph -{ - [GenerationAPI] - internal interface IMasterNode - { - string renderQueueTag { get; } - string renderTypeTag { get; } - ConditionalField[] GetConditionalFields(PassDescriptor pass); - void ProcessPreviewMaterial(Material material); - } -} diff --git a/com.unity.shadergraph/Editor/Generation/Interface/IMasterNode.cs.meta b/com.unity.shadergraph/Editor/Generation/Interface/IMasterNode.cs.meta deleted file mode 100644 index a8b62434844..00000000000 --- a/com.unity.shadergraph/Editor/Generation/Interface/IMasterNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 570cf3dfbfc001e46a74d5f1342a3cfc -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Processors/GenerationUtils.cs b/com.unity.shadergraph/Editor/Generation/Processors/GenerationUtils.cs index 419b341e2d3..4ee969cff60 100644 --- a/com.unity.shadergraph/Editor/Generation/Processors/GenerationUtils.cs +++ b/com.unity.shadergraph/Editor/Generation/Processors/GenerationUtils.cs @@ -15,18 +15,21 @@ internal static class GenerationUtils internal static List GetActiveFieldsFromConditionals(ConditionalField[] conditionalFields) { var fields = new List(); - foreach(ConditionalField conditionalField in conditionalFields) + if(conditionalFields != null) { - if(conditionalField.condition == true) + foreach(ConditionalField conditionalField in conditionalFields) { - fields.Add(conditionalField.field); + if(conditionalField.condition == true) + { + fields.Add(conditionalField.field); + } } } return fields; } - internal static void GenerateSubShaderTags(IMasterNode masterNode, SubShaderDescriptor descriptor, ShaderStringBuilder builder) + internal static void GenerateSubShaderTags(Target target, SubShaderDescriptor descriptor, ShaderStringBuilder builder) { builder.AppendLine("Tags"); using (builder.BlockScope()) @@ -38,18 +41,14 @@ internal static void GenerateSubShaderTags(IMasterNode masterNode, SubShaderDesc builder.AppendLine("// RenderPipeline: "); // Render Type - string renderType = !string.IsNullOrEmpty(descriptor.renderTypeOverride) ? - descriptor.renderTypeOverride : masterNode?.renderTypeTag; - if(!string.IsNullOrEmpty(renderType)) - builder.AppendLine($"\"RenderType\"=\"{renderType}\""); + if(!string.IsNullOrEmpty(descriptor.renderType)) + builder.AppendLine($"\"RenderType\"=\"{descriptor.renderType}\""); else builder.AppendLine("// RenderType: "); // Render Queue - string renderQueue = !string.IsNullOrEmpty(descriptor.renderQueueOverride) ? - descriptor.renderQueueOverride : masterNode?.renderQueueTag; - if(!string.IsNullOrEmpty(renderQueue)) - builder.AppendLine($"\"Queue\"=\"{renderQueue}\""); + if(!string.IsNullOrEmpty(descriptor.renderQueue)) + builder.AppendLine($"\"Queue\"=\"{descriptor.renderQueue}\""); else builder.AppendLine("// Queue: "); } @@ -255,13 +254,13 @@ internal static void GetUpstreamNodesForShaderPass(AbstractMaterialNode outputNo { // Traverse Graph Data vertexNodes = Graphing.ListPool.Get(); - NodeUtils.DepthFirstCollectNodesFromNode(vertexNodes, outputNode, NodeUtils.IncludeSelf.Include, pass.vertexPorts); + NodeUtils.DepthFirstCollectNodesFromNode(vertexNodes, outputNode, NodeUtils.IncludeSelf.Include); pixelNodes = Graphing.ListPool.Get(); - NodeUtils.DepthFirstCollectNodesFromNode(pixelNodes, outputNode, NodeUtils.IncludeSelf.Include, pass.pixelPorts); + NodeUtils.DepthFirstCollectNodesFromNode(pixelNodes, outputNode, NodeUtils.IncludeSelf.Include); } - internal static void GetActiveFieldsAndPermutationsForNodes(AbstractMaterialNode outputNode, PassDescriptor pass, + internal static void GetActiveFieldsAndPermutationsForNodes(PassDescriptor pass, KeywordCollector keywordCollector, List vertexNodes, List pixelNodes, List[] vertexNodePermutations, List[] pixelNodePermutations, ActiveFields activeFields, out ShaderGraphRequirementsPerKeyword graphRequirements) @@ -279,8 +278,16 @@ internal static void GetActiveFieldsAndPermutationsForNodes(AbstractMaterialNode // Get active nodes for this permutation var localVertexNodes = Graphing.ListPool.Get(); var localPixelNodes = Graphing.ListPool.Get(); - NodeUtils.DepthFirstCollectNodesFromNode(localVertexNodes, outputNode, NodeUtils.IncludeSelf.Include, pass.vertexPorts, keywordCollector.permutations[i]); - NodeUtils.DepthFirstCollectNodesFromNode(localPixelNodes, outputNode, NodeUtils.IncludeSelf.Include, pass.pixelPorts, keywordCollector.permutations[i]); + + foreach(var vertexNode in vertexNodes) + { + NodeUtils.DepthFirstCollectNodesFromNode(localVertexNodes, vertexNode, NodeUtils.IncludeSelf.Include, keywordCollector.permutations[i]); + } + + foreach(var pixelNode in pixelNodes) + { + NodeUtils.DepthFirstCollectNodesFromNode(localPixelNodes, pixelNode, NodeUtils.IncludeSelf.Include, keywordCollector.permutations[i]); + } // Track each vertex node in this permutation foreach(AbstractMaterialNode vertexNode in localVertexNodes) @@ -307,8 +314,11 @@ internal static void GetActiveFieldsAndPermutationsForNodes(AbstractMaterialNode pixelRequirements[i].SetRequirements(ShaderGraphRequirements.FromNodes(localPixelNodes, ShaderStageCapability.Fragment, false)); // Add active fields - var conditionalFields = GetActiveFieldsFromConditionals(GetConditionalFieldsFromGraphRequirements(vertexRequirements[i].requirements, activeFields[i])); - conditionalFields.AddRange(GetActiveFieldsFromConditionals(GetConditionalFieldsFromGraphRequirements(pixelRequirements[i].requirements, activeFields[i]))); + var conditionalFields = GetActiveFieldsFromConditionals(GetConditionalFieldsFromPixelRequirements(pixelRequirements[i].requirements)); + if(activeFields[i].Contains(Fields.GraphVertex)) + { + conditionalFields.AddRange(GetActiveFieldsFromConditionals(GetConditionalFieldsFromVertexRequirements(vertexRequirements[i].requirements))); + } foreach(var field in conditionalFields) { activeFields[i].Add(field); @@ -323,8 +333,11 @@ internal static void GetActiveFieldsAndPermutationsForNodes(AbstractMaterialNode pixelRequirements.baseInstance.SetRequirements(ShaderGraphRequirements.FromNodes(pixelNodes, ShaderStageCapability.Fragment, false)); // Add active fields - var conditionalFields = GetActiveFieldsFromConditionals(GetConditionalFieldsFromGraphRequirements(vertexRequirements.baseInstance.requirements, activeFields.baseInstance)); - conditionalFields.AddRange(GetActiveFieldsFromConditionals(GetConditionalFieldsFromGraphRequirements(pixelRequirements.baseInstance.requirements, activeFields.baseInstance))); + var conditionalFields = GetActiveFieldsFromConditionals(GetConditionalFieldsFromPixelRequirements(pixelRequirements.baseInstance.requirements)); + if(activeFields.baseInstance.Contains(Fields.GraphVertex)) + { + conditionalFields.AddRange(GetActiveFieldsFromConditionals(GetConditionalFieldsFromVertexRequirements(vertexRequirements.baseInstance.requirements))); + } foreach(var field in conditionalFields) { activeFields.baseInstance.Add(field); @@ -336,103 +349,90 @@ internal static void GetActiveFieldsAndPermutationsForNodes(AbstractMaterialNode graphRequirements.UnionWith(vertexRequirements); } - static ConditionalField[] GetConditionalFieldsFromGraphRequirements(ShaderGraphRequirements requirements, IActiveFields activeFields) + static ConditionalField[] GetConditionalFieldsFromVertexRequirements(ShaderGraphRequirements requirements) + { + return new ConditionalField[] + { + new ConditionalField(StructFields.VertexDescriptionInputs.ScreenPosition, requirements.requiresScreenPosition), + new ConditionalField(StructFields.VertexDescriptionInputs.VertexColor, requirements.requiresVertexColor), + + new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.Object) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.View) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.World) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.Tangent) > 0), + + new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpaceViewDirection, (requirements.requiresViewDir & NeededCoordinateSpace.Object) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpaceViewDirection, (requirements.requiresViewDir & NeededCoordinateSpace.View) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpaceViewDirection, (requirements.requiresViewDir & NeededCoordinateSpace.World) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpaceViewDirection,(requirements.requiresViewDir & NeededCoordinateSpace.Tangent) > 0), + + new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.Object) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.View) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.World) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.Tangent) > 0), + + new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.Object) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.View) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.World) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.Tangent) > 0), + + new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.Object) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.View) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.World) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.Tangent) > 0), + new ConditionalField(StructFields.VertexDescriptionInputs.AbsoluteWorldSpacePosition,(requirements.requiresPosition & NeededCoordinateSpace.AbsoluteWorld) > 0), + + new ConditionalField(StructFields.VertexDescriptionInputs.uv0, requirements.requiresMeshUVs.Contains(UVChannel.UV0)), + new ConditionalField(StructFields.VertexDescriptionInputs.uv1, requirements.requiresMeshUVs.Contains(UVChannel.UV1)), + new ConditionalField(StructFields.VertexDescriptionInputs.uv2, requirements.requiresMeshUVs.Contains(UVChannel.UV2)), + new ConditionalField(StructFields.VertexDescriptionInputs.uv3, requirements.requiresMeshUVs.Contains(UVChannel.UV3)), + + new ConditionalField(StructFields.VertexDescriptionInputs.TimeParameters, requirements.requiresTime), + }; + } + + static ConditionalField[] GetConditionalFieldsFromPixelRequirements(ShaderGraphRequirements requirements) { return new ConditionalField[] { new ConditionalField(StructFields.SurfaceDescriptionInputs.ScreenPosition, requirements.requiresScreenPosition), - new ConditionalField(StructFields.VertexDescriptionInputs.ScreenPosition, requirements.requiresScreenPosition && - activeFields.Contains(Fields.GraphVertex)), new ConditionalField(StructFields.SurfaceDescriptionInputs.VertexColor, requirements.requiresVertexColor), - new ConditionalField(StructFields.VertexDescriptionInputs.VertexColor, requirements.requiresVertexColor && - activeFields.Contains(Fields.GraphVertex)), new ConditionalField(StructFields.SurfaceDescriptionInputs.FaceSign, requirements.requiresFaceSign), new ConditionalField(StructFields.SurfaceDescriptionInputs.ObjectSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.Object) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.ViewSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.View) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.WorldSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.World) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.TangentSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.Tangent) > 0), - new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.Object) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.View) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.World) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpaceNormal, (requirements.requiresNormal & NeededCoordinateSpace.Tangent) > 0 && - activeFields.Contains(Fields.GraphVertex)), new ConditionalField(StructFields.SurfaceDescriptionInputs.ObjectSpaceViewDirection,(requirements.requiresViewDir & NeededCoordinateSpace.Object) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.ViewSpaceViewDirection, (requirements.requiresViewDir & NeededCoordinateSpace.View) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.WorldSpaceViewDirection, (requirements.requiresViewDir & NeededCoordinateSpace.World) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.TangentSpaceViewDirection,(requirements.requiresViewDir & NeededCoordinateSpace.Tangent) > 0), - new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpaceViewDirection, (requirements.requiresViewDir & NeededCoordinateSpace.Object) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpaceViewDirection, (requirements.requiresViewDir & NeededCoordinateSpace.View) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpaceViewDirection, (requirements.requiresViewDir & NeededCoordinateSpace.World) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpaceViewDirection,(requirements.requiresViewDir & NeededCoordinateSpace.Tangent) > 0 && - activeFields.Contains(Fields.GraphVertex)), new ConditionalField(StructFields.SurfaceDescriptionInputs.ObjectSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.Object) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.ViewSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.View) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.WorldSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.World) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.TangentSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.Tangent) > 0), - new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.Object) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.View) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.World) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpaceTangent, (requirements.requiresTangent & NeededCoordinateSpace.Tangent) > 0 && - activeFields.Contains(Fields.GraphVertex)), new ConditionalField(StructFields.SurfaceDescriptionInputs.ObjectSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.Object) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.ViewSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.View) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.WorldSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.World) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.TangentSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.Tangent) > 0), - new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.Object) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.View) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.World) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpaceBiTangent, (requirements.requiresBitangent & NeededCoordinateSpace.Tangent) > 0 && - activeFields.Contains(Fields.GraphVertex)), new ConditionalField(StructFields.SurfaceDescriptionInputs.ObjectSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.Object) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.ViewSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.View) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.WorldSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.World) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.TangentSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.Tangent) > 0), new ConditionalField(StructFields.SurfaceDescriptionInputs.AbsoluteWorldSpacePosition,(requirements.requiresPosition & NeededCoordinateSpace.AbsoluteWorld) > 0), - new ConditionalField(StructFields.VertexDescriptionInputs.ObjectSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.Object) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.ViewSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.View) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.WorldSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.World) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.TangentSpacePosition, (requirements.requiresPosition & NeededCoordinateSpace.Tangent) > 0 && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.AbsoluteWorldSpacePosition,(requirements.requiresPosition & NeededCoordinateSpace.AbsoluteWorld) > 0 && - activeFields.Contains(Fields.GraphVertex)), new ConditionalField(StructFields.SurfaceDescriptionInputs.uv0, requirements.requiresMeshUVs.Contains(UVChannel.UV0)), new ConditionalField(StructFields.SurfaceDescriptionInputs.uv1, requirements.requiresMeshUVs.Contains(UVChannel.UV1)), new ConditionalField(StructFields.SurfaceDescriptionInputs.uv2, requirements.requiresMeshUVs.Contains(UVChannel.UV2)), new ConditionalField(StructFields.SurfaceDescriptionInputs.uv3, requirements.requiresMeshUVs.Contains(UVChannel.UV3)), - new ConditionalField(StructFields.VertexDescriptionInputs.uv0, requirements.requiresMeshUVs.Contains(UVChannel.UV0) && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.uv1, requirements.requiresMeshUVs.Contains(UVChannel.UV1) && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.uv2, requirements.requiresMeshUVs.Contains(UVChannel.UV2) && - activeFields.Contains(Fields.GraphVertex)), - new ConditionalField(StructFields.VertexDescriptionInputs.uv3, requirements.requiresMeshUVs.Contains(UVChannel.UV3) && - activeFields.Contains(Fields.GraphVertex)), new ConditionalField(StructFields.SurfaceDescriptionInputs.TimeParameters, requirements.requiresTime), - new ConditionalField(StructFields.VertexDescriptionInputs.TimeParameters, requirements.requiresTime && - activeFields.Contains(Fields.GraphVertex)), + // TODO: These did not require GraphVertex to be enabled. Is this correct? new ConditionalField(StructFields.VertexDescriptionInputs.BoneWeights, requirements.requiresVertexSkinning), new ConditionalField(StructFields.VertexDescriptionInputs.BoneIndices, requirements.requiresVertexSkinning), }; @@ -816,19 +816,19 @@ static void GenerateSurfaceDescriptionRemap( ShaderStringBuilder surfaceDescriptionFunction, GenerationMode mode) { - if (rootNode is IMasterNode) + if (rootNode == null) { - var usedSlots = slots ?? rootNode.GetInputSlots(); - foreach (var input in usedSlots) + foreach (var input in slots) { if (input != null) { + var node = input.owner; var foundEdges = graph.GetEdges(input.slotReference).ToArray(); var hlslName = NodeUtils.GetHLSLSafeName(input.shaderOutputName); if (foundEdges.Any()) - surfaceDescriptionFunction.AppendLine($"surface.{hlslName} = {rootNode.GetSlotValue(input.id, mode, rootNode.concretePrecision)};"); + surfaceDescriptionFunction.AppendLine($"surface.{hlslName} = {node.GetSlotValue(input.id, mode, node.concretePrecision)};"); else - surfaceDescriptionFunction.AppendLine($"surface.{hlslName} = {input.GetDefaultValue(mode, rootNode.concretePrecision)};"); + surfaceDescriptionFunction.AppendLine($"surface.{hlslName} = {input.GetDefaultValue(mode, node.concretePrecision)};"); } } } @@ -915,7 +915,7 @@ internal static void GenerateVertexDescriptionFunction( { foreach (var slot in slots) { - var isSlotConnected = slot.owner.owner.GetEdges(slot.slotReference).Any(); + var isSlotConnected = graph.GetEdges(slot.slotReference).Any(); var slotName = NodeUtils.GetHLSLSafeName(slot.shaderOutputName); var slotValue = isSlotConnected ? ((AbstractMaterialNode)slot.owner).GetSlotValue(slot.id, mode, slot.owner.concretePrecision) : slot.GetDefaultValue(mode, slot.owner.concretePrecision); diff --git a/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs b/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs index c81f78e8432..839f63e2a02 100644 --- a/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs +++ b/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs @@ -18,6 +18,7 @@ class Generator GraphData m_GraphData; AbstractMaterialNode m_OutputNode; Target[] m_Targets; + List m_Blocks; GenerationMode m_Mode; string m_Name; @@ -28,6 +29,7 @@ class Generator public string generatedShader => m_Builder.ToCodeBlock(); public List configuredTextures => m_ConfiguredTextures; public List assetDependencyPaths => m_AssetDependencyPaths; + public List blocks => m_Blocks; public Generator(GraphData graphData, AbstractMaterialNode outputNode, GenerationMode mode, string name) { @@ -40,12 +42,14 @@ public Generator(GraphData graphData, AbstractMaterialNode outputNode, Generatio m_ConfiguredTextures = new List(); m_AssetDependencyPaths = new List(); + GetTargetImplementations(); + GetBlocksFromStack(); BuildShader(); } void GetTargetImplementations() { - if(m_OutputNode is IMasterNode masterNode) + if(m_OutputNode == null) { m_Targets = m_GraphData.validTargets.ToArray(); } @@ -55,6 +59,19 @@ void GetTargetImplementations() } } + void GetBlocksFromStack() + { + m_Blocks = Graphing.ListPool.Get(); + foreach(var vertexBlock in m_GraphData.vertexContext.blocks) + { + m_Blocks.Add(vertexBlock); + } + foreach(var fragmentBlock in m_GraphData.fragmentContext.blocks) + { + m_Blocks.Add(fragmentBlock); + } + } + void GetAssetDependencyPaths(TargetSetupContext context) { foreach(string assetDependency in context.assetDependencyPaths) @@ -63,12 +80,20 @@ void GetAssetDependencyPaths(TargetSetupContext context) } } - public static ActiveFields GatherActiveFieldsFromNode(AbstractMaterialNode outputNode, PassDescriptor pass) + public ActiveFields GatherActiveFieldsFromNode(AbstractMaterialNode outputNode, PassDescriptor pass, List blocks, Target target) { var activeFields = new ActiveFields(); - if(outputNode is IMasterNode masterNode) + if(outputNode == null) { - var fields = GenerationUtils.GetActiveFieldsFromConditionals(masterNode.GetConditionalFields(pass)); + // HDRP needs to know if there are any Dots properties active + // Ideally we can determine this in the Target without exposing the PropertyCollector + var shaderProperties = new PropertyCollector(); + m_GraphData.CollectShaderProperties(shaderProperties, GenerationMode.ForReals); + bool hasDotsProperties = shaderProperties.GetDotsInstancingPropertiesCount(GenerationMode.ForReals) > 0; + + var context = new TargetFieldContext(pass, blocks, hasDotsProperties); + target.GetFields(ref context); + var fields = GenerationUtils.GetActiveFieldsFromConditionals(context.conditionalFields.ToArray()); foreach(FieldDescriptor field in fields) activeFields.baseInstance.Add(field); } @@ -83,7 +108,22 @@ public static ActiveFields GatherActiveFieldsFromNode(AbstractMaterialNode outpu void BuildShader() { var activeNodeList = Graphing.ListPool.Get(); - NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, m_OutputNode); + if(m_OutputNode == null) + { + foreach(var block in m_Blocks) + { + // IsActive is equal to if any active implementation has set active blocks + // This avoids another call to SetActiveBlocks on each TargetImplementation + if(!block.isActive) + continue; + + NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, block, NodeUtils.IncludeSelf.Include); + } + } + else + { + NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, m_OutputNode); + } var shaderProperties = new PropertyCollector(); var shaderKeywords = new KeywordCollector(); @@ -98,11 +138,20 @@ void BuildShader() m_Builder.AppendLines(ShaderGraphImporter.k_ErrorShader); } - GetTargetImplementations(); - foreach (var activeNode in activeNodeList.OfType()) activeNode.CollectShaderProperties(shaderProperties, m_Mode); + // Collect excess shader properties from the TargetImplementation + foreach(var target in m_Targets) + { + // TODO: Setup is required to ensure all Targets are initialized + // TODO: Find a way to only require this once + TargetSetupContext context = new TargetSetupContext(); + target.Setup(ref context); + + target.CollectShaderProperties(shaderProperties, m_Mode); + } + m_Builder.AppendLine(@"Shader ""{0}""", m_Name); using (m_Builder.BlockScope()) { @@ -111,7 +160,6 @@ void BuildShader() for(int i = 0; i < m_Targets.Length; i++) { TargetSetupContext context = new TargetSetupContext(); - context.SetMasterNode(m_OutputNode as IMasterNode); // Instead of setup target, we can also just do get context m_Targets[i].Setup(ref context); @@ -121,28 +169,18 @@ void BuildShader() { GenerateSubShader(i, subShader); } - - // Either grab the Target default shader GUI or the user override - if (m_OutputNode is ICanChangeShaderGUI canChangeShaderGui) + + var customEditor = context.defaultShaderGUI; + if (customEditor != null) { - string customEditor = string.Empty; - if(canChangeShaderGui.OverrideEnabled) - { - customEditor = GenerationUtils.FinalCustomEditorString(canChangeShaderGui); - } - else - { - customEditor = context.defaultShaderGUI; - } - - if (customEditor != null) - { - m_Builder.AppendLine("CustomEditor \"" + customEditor + "\""); - } + m_Builder.AppendLine("CustomEditor \"" + customEditor + "\""); } } - m_Builder.AppendLine(@"FallBack ""Hidden/Shader Graph/FallbackError"""); + if(m_Mode != GenerationMode.Preview) + { + m_Builder.AppendLine(@"FallBack ""Hidden/Shader Graph/FallbackError"""); + } } m_ConfiguredTextures = shaderProperties.GetConfiguredTexutres(); @@ -160,11 +198,14 @@ void GenerateSubShader(int targetIndex, SubShaderDescriptor descriptor) m_Builder.AppendLine("SubShader"); using(m_Builder.BlockScope()) { - GenerationUtils.GenerateSubShaderTags(m_OutputNode as IMasterNode, descriptor, m_Builder); + GenerationUtils.GenerateSubShaderTags(m_Targets[targetIndex], descriptor, m_Builder); + + // Get block descriptor list here as we will add temporary blocks to m_Blocks during pass evaluations + var blockFieldDescriptors = m_Blocks.Select(x => x.descriptor).ToList(); foreach(PassCollection.Item pass in descriptor.passes) { - var activeFields = GatherActiveFieldsFromNode(m_OutputNode, pass.descriptor); + var activeFields = GatherActiveFieldsFromNode(m_OutputNode, pass.descriptor, blockFieldDescriptors, m_Targets[targetIndex]); // TODO: cleanup this preview check, needed for HD decal preview pass if(m_Mode == GenerationMode.Preview) @@ -198,37 +239,77 @@ void GenerateShaderPass(int targetIndex, PassDescriptor pass, ActiveFields activ // Initiailize Collectors var propertyCollector = new PropertyCollector(); var keywordCollector = new KeywordCollector(); - m_OutputNode.owner.CollectShaderKeywords(keywordCollector, m_Mode); + m_GraphData.CollectShaderKeywords(keywordCollector, m_Mode); // Get upstream nodes from ShaderPass port mask List vertexNodes; List pixelNodes; - GenerationUtils.GetUpstreamNodesForShaderPass(m_OutputNode, pass, out vertexNodes, out pixelNodes); - // Track permutation indices for all nodes - List[] vertexNodePermutations = new List[vertexNodes.Count]; - List[] pixelNodePermutations = new List[pixelNodes.Count]; + // Get Port references from ShaderPass + var pixelSlots = new List(); + var vertexSlots = new List(); - // Get active fields from upstream Node requirements - ShaderGraphRequirementsPerKeyword graphRequirements; - GenerationUtils.GetActiveFieldsAndPermutationsForNodes(m_OutputNode, pass, keywordCollector, vertexNodes, pixelNodes, - vertexNodePermutations, pixelNodePermutations, activeFields, out graphRequirements); + if(m_OutputNode == null) + { + // Update supported block list for current target implementation + var activeBlockContext = new TargetActiveBlockContext(); + m_Targets[targetIndex].GetActiveBlocks(ref activeBlockContext); - // GET CUSTOM ACTIVE FIELDS HERE! + void ProcessStackForPass(ContextData contextData, BlockFieldDescriptor[] passBlockMask, + List nodeList, List slotList) + { + if(passBlockMask == null) + return; - // Get active fields from ShaderPass - GenerationUtils.AddRequiredFields(pass.requiredFields, activeFields.baseInstance); + foreach(var blockFieldDescriptor in passBlockMask) + { + // Mask blocks on active state + // TODO: Can we merge these? + if(!activeBlockContext.blocks.Contains(blockFieldDescriptor)) + continue; + + // Attempt to get BlockNode from the stack + var block = contextData.blocks.FirstOrDefault(x => x.descriptor == blockFieldDescriptor); - // Get Port references from ShaderPass - List pixelSlots; - List vertexSlots; - if(m_OutputNode is IMasterNode) - { - pixelSlots = GenerationUtils.FindMaterialSlotsOnNode(pass.pixelPorts, m_OutputNode); - vertexSlots = GenerationUtils.FindMaterialSlotsOnNode(pass.vertexPorts, m_OutputNode); + // If the BlockNode doesnt exist in the stack we need to create one + // TODO: Can we do the code gen without a node instance? + if(block == null) + { + block = new BlockNode(); + block.Init(blockFieldDescriptor); + block.owner = m_GraphData; + + // Add temporary blocks to m_Blocks + // This is used by the PreviewManager to generate a PreviewProperty + m_Blocks.Add(block); + } + // Dont collect properties from temp nodes + else + { + block.CollectShaderProperties(propertyCollector, m_Mode); + } + + // Add nodes and slots from supported vertex blocks + NodeUtils.DepthFirstCollectNodesFromNode(nodeList, block, NodeUtils.IncludeSelf.Include); + slotList.Add(block.FindSlot(0)); + activeFields.baseInstance.Add(block.descriptor); + } + } + + // Mask blocks per pass + vertexNodes = Graphing.ListPool.Get(); + pixelNodes = Graphing.ListPool.Get(); + + // Process stack for vertex and fragment + ProcessStackForPass(m_GraphData.vertexContext, pass.vertexBlocks, vertexNodes, vertexSlots); + ProcessStackForPass(m_GraphData.fragmentContext, pass.pixelBlocks, pixelNodes, pixelSlots); + + // Collect excess shader properties from the TargetImplementation + m_Targets[targetIndex].CollectShaderProperties(propertyCollector, m_Mode); } else if(m_OutputNode is SubGraphOutputNode) { + GenerationUtils.GetUpstreamNodesForShaderPass(m_OutputNode, pass, out vertexNodes, out pixelNodes); var slot = m_OutputNode.GetInputSlots().FirstOrDefault(); if(slot != null) pixelSlots = new List() { slot }; @@ -238,10 +319,28 @@ void GenerateShaderPass(int targetIndex, PassDescriptor pass, ActiveFields activ } else { - pixelSlots = new List() { new Vector4MaterialSlot(0, "Out", "Out", SlotType.Output, Vector4.zero) { owner = m_OutputNode } }; + GenerationUtils.GetUpstreamNodesForShaderPass(m_OutputNode, pass, out vertexNodes, out pixelNodes); + pixelSlots = new List() + { + new Vector4MaterialSlot(0, "Out", "Out", SlotType.Output, Vector4.zero) { owner = m_OutputNode }, + }; vertexSlots = new List(); } + // Track permutation indices for all nodes + List[] vertexNodePermutations = new List[vertexNodes.Count]; + List[] pixelNodePermutations = new List[pixelNodes.Count]; + + // Get active fields from upstream Node requirements + ShaderGraphRequirementsPerKeyword graphRequirements; + GenerationUtils.GetActiveFieldsAndPermutationsForNodes(pass, keywordCollector, vertexNodes, pixelNodes, + vertexNodePermutations, pixelNodePermutations, activeFields, out graphRequirements); + + // GET CUSTOM ACTIVE FIELDS HERE! + + // Get active fields from ShaderPass + GenerationUtils.AddRequiredFields(pass.requiredFields, activeFields.baseInstance); + // Function Registry var functionBuilder = new ShaderStringBuilder(); var functionRegistry = new FunctionRegistry(functionBuilder); diff --git a/com.unity.shadergraph/Editor/Generation/SubTarget.cs b/com.unity.shadergraph/Editor/Generation/SubTarget.cs index a1712b60d98..94773dce96a 100644 --- a/com.unity.shadergraph/Editor/Generation/SubTarget.cs +++ b/com.unity.shadergraph/Editor/Generation/SubTarget.cs @@ -1,18 +1,36 @@ using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UIElements; namespace UnityEditor.ShaderGraph { - [GenerationAPI] // TODO: Public + [Serializable, GenerationAPI] // TODO: Public internal abstract class SubTarget { internal abstract Type targetType { get; } + internal Target target { get; set; } public string displayName { get; set; } + public abstract bool IsActive(); public abstract void Setup(ref TargetSetupContext context); + public abstract void GetFields(ref TargetFieldContext context); + public abstract void GetActiveBlocks(ref TargetActiveBlockContext context); + public abstract void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange); + + public virtual void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { } + public virtual void ProcessPreviewMaterial(Material material) { } + public virtual object saveContext => null; } [GenerationAPI] // TODO: Public internal abstract class SubTarget : SubTarget where T : Target { internal override Type targetType => typeof(T); + + public new T target + { + get => base.target as T; + set => base.target = value; + } } } diff --git a/com.unity.shadergraph/Editor/Generation/Target.cs b/com.unity.shadergraph/Editor/Generation/Target.cs index 832cf0f1c66..ad14df645b2 100644 --- a/com.unity.shadergraph/Editor/Generation/Target.cs +++ b/com.unity.shadergraph/Editor/Generation/Target.cs @@ -1,14 +1,24 @@ +using System; +using System.Collections.Generic; +using UnityEngine; using UnityEngine.Rendering; +using UnityEngine.UIElements; namespace UnityEditor.ShaderGraph { - [GenerationAPI] // TODO: Public + [Serializable, GenerationAPI] // TODO: Public internal abstract class Target { public string displayName { get; set; } public bool isHidden { get; set; } + public abstract bool IsActive(); public abstract void Setup(ref TargetSetupContext context); - public abstract bool IsValid(IMasterNode masterNode); - public abstract bool IsPipelineCompatible(RenderPipelineAsset currentPipeline); + public abstract void GetFields(ref TargetFieldContext context); + public abstract void GetActiveBlocks(ref TargetActiveBlockContext context); + public abstract void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange); + + public virtual void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { } + public virtual void ProcessPreviewMaterial(Material material) { } + public virtual object saveContext => null; } } diff --git a/com.unity.shadergraph/Editor/Generation/TargetResources/BlockFields.cs b/com.unity.shadergraph/Editor/Generation/TargetResources/BlockFields.cs new file mode 100644 index 00000000000..adb42356d89 --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/TargetResources/BlockFields.cs @@ -0,0 +1,50 @@ +using UnityEngine; +using UnityEditor.ShaderGraph.Internal; + +namespace UnityEditor.ShaderGraph +{ + internal static class BlockFields + { + [GenerateBlocks] + public struct VertexDescription + { + public static string name = "VertexDescription"; + public static BlockFieldDescriptor Position = new BlockFieldDescriptor(VertexDescription.name, "Position", "VERTEXDESCRIPTION_POSITION", + new PositionControl(CoordinateSpace.Object), ShaderStage.Vertex); + public static BlockFieldDescriptor Normal = new BlockFieldDescriptor(VertexDescription.name, "Normal", "VERTEXDESCRIPTION_NORMAL", + new NormalControl(CoordinateSpace.Object), ShaderStage.Vertex); + public static BlockFieldDescriptor Tangent = new BlockFieldDescriptor(VertexDescription.name, "Tangent", "VERTEXDESCRIPTION_TANGENT", + new TangentControl(CoordinateSpace.Object), ShaderStage.Vertex); + } + + [GenerateBlocks] + public struct SurfaceDescription + { + public static string name = "SurfaceDescription"; + public static BlockFieldDescriptor BaseColor = new BlockFieldDescriptor(SurfaceDescription.name, "BaseColor", "SURFACEDESCRIPTION_BASECOLOR", + new ColorControl(UnityEngine.Color.grey, false), ShaderStage.Fragment); + public static BlockFieldDescriptor NormalTS = new BlockFieldDescriptor(SurfaceDescription.name, "NormalTS", "SURFACEDESCRIPTION_NORMALTS", + new NormalControl(CoordinateSpace.Tangent), ShaderStage.Fragment); + public static BlockFieldDescriptor NormalOS = new BlockFieldDescriptor(SurfaceDescription.name, "NormalOS", "SURFACEDESCRIPTION_NORMALOS", + new NormalControl(CoordinateSpace.Object), ShaderStage.Fragment); + public static BlockFieldDescriptor NormalWS = new BlockFieldDescriptor(SurfaceDescription.name, "NormalWS", "SURFACEDESCRIPTION_NORMALWS", + new NormalControl(CoordinateSpace.World), ShaderStage.Fragment); + public static BlockFieldDescriptor Metallic = new BlockFieldDescriptor(SurfaceDescription.name, "Metallic", "SURFACEDESCRIPTION_METALLIC", + new FloatControl(0.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor Specular = new BlockFieldDescriptor(SurfaceDescription.name, "Specular", "SURFACEDESCRIPTION_SPECULAR", + new ColorControl(UnityEngine.Color.grey, false), ShaderStage.Fragment); + public static BlockFieldDescriptor Smoothness = new BlockFieldDescriptor(SurfaceDescription.name, "Smoothness", "SURFACEDESCRIPTION_SMOOTHNESS", + new FloatControl(0.5f), ShaderStage.Fragment); + public static BlockFieldDescriptor Occlusion = new BlockFieldDescriptor(SurfaceDescription.name, "Occlusion", "SURFACEDESCRIPTION_OCCLUSION", + new FloatControl(1.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor Emission = new BlockFieldDescriptor(SurfaceDescription.name, "Emission", "SURFACEDESCRIPTION_EMISSION", + new ColorControl(UnityEngine.Color.black, true), ShaderStage.Fragment); + public static BlockFieldDescriptor Alpha = new BlockFieldDescriptor(SurfaceDescription.name, "Alpha", "SURFACEDESCRIPTION_ALPHA", + new FloatControl(1.0f), ShaderStage.Fragment); + public static BlockFieldDescriptor AlphaClipThreshold = new BlockFieldDescriptor(SurfaceDescription.name, "AlphaClipThreshold", "SURFACEDESCRIPTION_ALPHACLIPTHRESHOLD", + new FloatControl(0.5f), ShaderStage.Fragment); + public static BlockFieldDescriptor SpriteMask = new BlockFieldDescriptor(SurfaceDescription.name, "SpriteMask", "SURFACEDESCRIPTION_SPRITEMASK", + new ColorRGBAControl(new Color(1, 1, 1, 1)), ShaderStage.Fragment); + } + } +} \ No newline at end of file diff --git a/com.unity.shadergraph/Editor/Generation/TargetResources/BlockFields.cs.meta b/com.unity.shadergraph/Editor/Generation/TargetResources/BlockFields.cs.meta new file mode 100644 index 00000000000..a4068163cbb --- /dev/null +++ b/com.unity.shadergraph/Editor/Generation/TargetResources/BlockFields.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8f2459b0837a8411dbfa2b61fdaca36e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Generation/Targets/PreviewTarget.cs b/com.unity.shadergraph/Editor/Generation/Targets/PreviewTarget.cs index 762d9e19ea7..58943e83a92 100644 --- a/com.unity.shadergraph/Editor/Generation/Targets/PreviewTarget.cs +++ b/com.unity.shadergraph/Editor/Generation/Targets/PreviewTarget.cs @@ -1,4 +1,8 @@ -using UnityEngine.Rendering; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.UIElements; namespace UnityEditor.ShaderGraph { @@ -10,28 +14,32 @@ public PreviewTarget() isHidden = true; } + public override bool IsActive() => false; + public override void Setup(ref TargetSetupContext context) { context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath("7464b9fcde08e5645a16b9b8ae1e573c")); // PreviewTarget context.AddSubShader(SubShaders.Preview); } - public override bool IsValid(IMasterNode masterNode) + public override void GetFields(ref TargetFieldContext context) { - return false; } - public override bool IsPipelineCompatible(RenderPipelineAsset currentPipeline) + public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - return currentPipeline != null; } - + + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange) + { + } + static class SubShaders { public static SubShaderDescriptor Preview = new SubShaderDescriptor() { - renderQueueOverride = "Geometry", - renderTypeOverride = "Opaque", + renderQueue = "Geometry", + renderType = "Opaque", generatesPreview = true, passes = new PassCollection { Passes.Preview }, }; diff --git a/com.unity.shadergraph/Editor/Generation/Targets/VFXTarget.cs b/com.unity.shadergraph/Editor/Generation/Targets/VFXTarget.cs index e49a8ea0938..230599f17c7 100644 --- a/com.unity.shadergraph/Editor/Generation/Targets/VFXTarget.cs +++ b/com.unity.shadergraph/Editor/Generation/Targets/VFXTarget.cs @@ -1,26 +1,78 @@ -using UnityEngine.Rendering; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.UIElements; +using UnityEditor.ShaderGraph.Drawing; +using UnityEditor.Graphing.Util; namespace UnityEditor.ShaderGraph { sealed class VFXTarget : Target { + [SerializeField] + bool m_Lit; + + [SerializeField] + bool m_AlphaTest = false; + public VFXTarget() { displayName = "Visual Effect"; } + public bool lit + { + get => m_Lit; + set => m_Lit = value; + } + + public bool alphaTest + { + get => m_AlphaTest; + set => m_AlphaTest = value; + } + + public override bool IsActive() => true; + public override void Setup(ref TargetSetupContext context) { } - public override bool IsValid(IMasterNode masterNode) + public override void GetFields(ref TargetFieldContext context) { - return masterNode is VfxMasterNode; } - public override bool IsPipelineCompatible(RenderPipelineAsset currentPipeline) + public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - return currentPipeline != null; + context.AddBlock(BlockFields.SurfaceDescription.BaseColor); + context.AddBlock(BlockFields.SurfaceDescription.Alpha); + context.AddBlock(BlockFields.SurfaceDescription.Metallic, lit); + context.AddBlock(BlockFields.SurfaceDescription.Smoothness, lit); + context.AddBlock(BlockFields.SurfaceDescription.NormalTS, lit); + context.AddBlock(BlockFields.SurfaceDescription.Emission, lit); + context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, alphaTest); + } + + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange) + { + context.AddProperty("Lit", new Toggle() { value = m_Lit }, (evt) => + { + if (Equals(m_Lit, evt.newValue)) + return; + + m_Lit = evt.newValue; + onChange(); + }); + + context.AddProperty("Alpha Test", new Toggle() { value = m_AlphaTest }, (evt) => + { + if (Equals(m_AlphaTest, evt.newValue)) + return; + + m_AlphaTest = evt.newValue; + onChange(); + }); } } } diff --git a/com.unity.shadergraph/Editor/Generation/Utils/TargetUtils.cs b/com.unity.shadergraph/Editor/Generation/Utils/TargetUtils.cs index b726a07e37f..264c3fe7a46 100644 --- a/com.unity.shadergraph/Editor/Generation/Utils/TargetUtils.cs +++ b/com.unity.shadergraph/Editor/Generation/Utils/TargetUtils.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using UnityEditor.Graphing; @@ -6,7 +7,25 @@ namespace UnityEditor.ShaderGraph { static class TargetUtils { - public static List GetSubTargetsOfType() where T : Target + public static void ProcessSubTargetList(ref SubTarget activeSubTarget, ref List subTargets) + { + if(subTargets == null || subTargets.Count == 0) + return; + + if(activeSubTarget == null) + { + activeSubTarget = subTargets[0]; + return; + } + + // Update SubTarget list with active SubTarget + var activeSubTargetType = activeSubTarget.GetType(); + var activeSubTargetCurrent = subTargets.FirstOrDefault(x => x.GetType() == activeSubTargetType); + var index = subTargets.IndexOf(activeSubTargetCurrent); + subTargets[index] = activeSubTarget; + } + + public static List GetSubTargets(T target) where T : Target { // Get Variants var subTargets = ListPool.Get(); @@ -19,6 +38,7 @@ public static List GetSubTargetsOfType() where T : Target var subTarget = (SubTarget)Activator.CreateInstance(type); if(subTarget.targetType.Equals(typeof(T))) { + subTarget.target = target; subTargets.Add(subTarget); } } diff --git a/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs b/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs index 62c6629a294..94dcb9368f2 100644 --- a/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs +++ b/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs @@ -103,10 +103,10 @@ public override void OnImportAsset(AssetImportContext ctx) graph.OnEnable(); graph.ValidateGraph(); - if (graph.outputNode is VfxMasterNode vfxMasterNode) + // TODO: How to handle this? + if (graph.isVFXTarget) { - var vfxAsset = GenerateVfxShaderGraphAsset(vfxMasterNode); - + var vfxAsset = GenerateVfxShaderGraphAsset(graph); mainObject = vfxAsset; } else @@ -138,13 +138,21 @@ public override void OnImportAsset(AssetImportContext ctx) ctx.AddObjectToAsset("MainAsset", mainObject, texture); ctx.SetMainObject(mainObject); - var metadata = ScriptableObject.CreateInstance(); - metadata.hideFlags = HideFlags.HideInHierarchy; - if (graph != null) + if(graph != null) { - metadata.outputNodeTypeName = graph.outputNode.GetType().FullName; + foreach(var target in graph.activeTargets) + { + if(target is IHasMetadata iHasMetadata) + { + var metadata = iHasMetadata.GetMetadataObject(); + if(metadata == null) + continue; + + metadata.hideFlags = HideFlags.HideInHierarchy; + ctx.AddObjectToAsset($"{iHasMetadata.identifier}:Metadata", metadata); + } + } } - ctx.AddObjectToAsset("Metadata", metadata); foreach (var sourceAssetDependencyPath in sourceAssetDependencyPaths.Distinct()) { @@ -167,7 +175,7 @@ internal static string GetShaderText(string path, out List x is VFXTarget) as VFXTarget; + if(target == null) + return null; + var nl = Environment.NewLine; var indent = new string(' ', 4); var asset = ScriptableObject.CreateInstance(); var result = asset.compilationResult = new GraphCompilationResult(); var mode = GenerationMode.ForReals; - var graph = masterNode.owner; - asset.lit = masterNode.lit.isOn; + asset.lit = target.lit; - var assetGuid = masterNode.owner.assetGuid; + var assetGuid = graph.assetGuid; var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid); var hlslName = NodeUtils.GetHLSLSafeName(Path.GetFileNameWithoutExtension(assetPath)); var ports = new List(); - masterNode.GetInputSlots(ports); - var nodes = new List(); - NodeUtils.DepthFirstCollectNodesFromNode(nodes, masterNode); + + foreach(var vertexBlock in graph.vertexContext.blocks) + { + vertexBlock.GetInputSlots(ports); + NodeUtils.DepthFirstCollectNodesFromNode(nodes, vertexBlock); + } + + foreach(var fragmentBlock in graph.fragmentContext.blocks) + { + fragmentBlock.GetInputSlots(ports); + NodeUtils.DepthFirstCollectNodesFromNode(nodes, fragmentBlock); + } var bodySb = new ShaderStringBuilder(1); var registry = new FunctionRegistry(new ShaderStringBuilder(), true); @@ -536,14 +557,14 @@ void AddCoordinateSpaceSnippets(InterpolatorType interpolatorType, Func(); + graphObject.hideFlags = HideFlags.HideAndDontSave; + graphObject.graph = JsonUtility.FromJson(textGraph); + graphObject.graph.OnEnable(); + graphObject.graph.ValidateGraph(); + return graphObject.graph; + } + if (GUILayout.Button("Open Shader Editor")) { AssetImporter importer = target as AssetImporter; Debug.Assert(importer != null, "importer != null"); ShowGraphEditWindow(importer.assetPath); } + if (GUILayout.Button("View Generated Shader")) + { + AssetImporter importer = target as AssetImporter; + string assetName = Path.GetFileNameWithoutExtension(importer.assetPath); + string path = String.Format("Temp/GeneratedFromGraph-{0}.shader", assetName.Replace(" ", "")); + + var graphData = GetGraphData(importer); + var generator = new Generator(graphData, null, GenerationMode.ForReals, assetName); + if (GraphUtil.WriteToFile(path, generator.generatedShader)) + GraphUtil.OpenFile(path); + } + if (Unsupported.IsDeveloperMode()) + { + if (GUILayout.Button("View Preview Shader")) + { + AssetImporter importer = target as AssetImporter; + string assetName = Path.GetFileNameWithoutExtension(importer.assetPath); + string path = String.Format("Temp/GeneratedFromGraph-{0}-Preview.shader", assetName.Replace(" ", "")); + + var graphData = GetGraphData(importer); + var generator = new Generator(graphData, null, GenerationMode.Preview, $"{assetName}-Preview"); + if (GraphUtil.WriteToFile(path, generator.generatedShader)) + GraphUtil.OpenFile(path); + } + } + if (GUILayout.Button("Copy Shader")) + { + AssetImporter importer = target as AssetImporter; + string assetName = Path.GetFileNameWithoutExtension(importer.assetPath); + + var graphData = GetGraphData(importer); + var generator = new Generator(graphData, null, GenerationMode.ForReals, assetName); + GUIUtility.systemCopyBuffer = generator.generatedShader; + } ApplyRevertGUI(); } diff --git a/com.unity.shadergraph/Editor/Importers/ShaderGraphMetadata.cs b/com.unity.shadergraph/Editor/Importers/ShaderGraphMetadata.cs deleted file mode 100644 index 95815486036..00000000000 --- a/com.unity.shadergraph/Editor/Importers/ShaderGraphMetadata.cs +++ /dev/null @@ -1,9 +0,0 @@ -using UnityEngine; - -namespace UnityEditor.ShaderGraph -{ - class ShaderGraphMetadata : ScriptableObject - { - public string outputNodeTypeName; - } -} diff --git a/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs b/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs index fb97f37ba0b..8677cb1e4b5 100644 --- a/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs +++ b/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs @@ -93,7 +93,7 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph) asset.functionName = $"SG_{asset.hlslName}_{asset.assetGuid}"; asset.path = graph.path; - var outputNode = (SubGraphOutputNode)graph.outputNode; + var outputNode = graph.subGraphOutputNode; asset.outputs.Clear(); outputNode.GetInputSlots(asset.outputs); diff --git a/com.unity.shadergraph/Editor/Resources/Styles/MaterialNodeView.uss b/com.unity.shadergraph/Editor/Resources/Styles/MaterialNodeView.uss index e035ffc7ccc..5285e94f29f 100644 --- a/com.unity.shadergraph/Editor/Resources/Styles/MaterialNodeView.uss +++ b/com.unity.shadergraph/Editor/Resources/Styles/MaterialNodeView.uss @@ -9,6 +9,14 @@ MaterialNodeView.master { min-width: 200px; } +MaterialNodeView.blockData { + width: 200px; +} + +MaterialNodeView.blockData > #portInputContainer { + top: 6px; +} + MaterialNodeView #collapsible-area { width: 0; height: 0; @@ -170,3 +178,17 @@ MaterialNodeView.hovered #selection-border{ .node.expanded > #node-border > #title > #button-container > #collapse-button > #icon { background-image : resource("GraphView/Nodes/NodeChevronDown.png"); } + +MaterialNodeView > #disabledOverlay { + border-radius: 4; + position: absolute; + left: 4; + right: 4; + top: 4; + bottom: 4; + background-color: rgba(32, 32, 32, 0); +} + +MaterialNodeView.disabled #disabledOverlay { + background-color: rgba(32, 32, 32, 0.75); +} diff --git a/com.unity.shadergraph/Editor/Resources/Styles/PortInputView.uss b/com.unity.shadergraph/Editor/Resources/Styles/PortInputView.uss index b25a92b451f..c894f702508 100644 --- a/com.unity.shadergraph/Editor/Resources/Styles/PortInputView.uss +++ b/com.unity.shadergraph/Editor/Resources/Styles/PortInputView.uss @@ -20,6 +20,19 @@ PortInputView > #container { border-radius: 2px; } +PortInputView > #container > #disabledOverlay { + position: absolute; + left: 0; + right: 0; + top: 0; + bottom: 0; + background-color: rgba(32, 32, 32, 0.0); +} + +PortInputView.disabled > #container > #disabledOverlay { + background-color: rgba(32, 32, 32, 0.75); +} + PortInputView > #container > #slot { width: 8px; height: 8px; diff --git a/com.unity.shadergraph/Editor/Resources/Styles/PropertyNodeView.uss b/com.unity.shadergraph/Editor/Resources/Styles/PropertyNodeView.uss index f1d0e84b301..02999c5b0f5 100644 --- a/com.unity.shadergraph/Editor/Resources/Styles/PropertyNodeView.uss +++ b/com.unity.shadergraph/Editor/Resources/Styles/PropertyNodeView.uss @@ -6,3 +6,17 @@ PropertyNodeView.hovered #selection-border{ border-top-width: 2px; border-bottom-width: 2px; } + +PropertyNodeView > #disabledOverlay { + border-radius: 8; + position: absolute; + left: 4; + right: 4; + top: 4; + bottom: 4; + background-color: rgba(32, 32, 32, 0); +} + +PropertyNodeView.disabled #disabledOverlay { + background-color: rgba(32, 32, 32, 0.75); +} diff --git a/com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss b/com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss index 0ad09b26d5b..ae394beb8da 100644 --- a/com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss +++ b/com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss @@ -1,4 +1,6 @@ PropertyRow EnumField, +PropertyRow PopupField, +PropertyRow TextField, PropertyRow Label, PropertyRow Toggle, PropertyRow IntegerField,