From 50adf4e0164f8903b1e4164b17f94f80b9135101 Mon Sep 17 00:00:00 2001 From: Esmeralda Salamone Date: Thu, 28 Jan 2021 21:16:31 -0800 Subject: [PATCH 1/3] init node impls --- .../Material/ShaderGraph/HDStructFields.cs | 2 +- .../ShaderGraph/Templates/ShaderPass.template | 1 + .../ShaderGraph/Templates/ShaderPass.template | 1 + .../Nodes/Input/Geometry/InstanceIDNode.cs | 34 ++++++++++++++++++ .../Input/Geometry/InstanceIDNode.cs.meta | 11 ++++++ .../Data/Nodes/Input/Geometry/VertexIDNode.cs | 36 +++++++++++++++++++ .../Nodes/Input/Geometry/VertexIDNode.cs.meta | 11 ++++++ .../Data/Nodes/Input/Scene/EyeIndexNode.cs | 34 ++++++++++++++++++ .../Nodes/Input/Scene/EyeIndexNode.cs.meta | 11 ++++++ 9 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/InstanceIDNode.cs create mode 100644 com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/InstanceIDNode.cs.meta create mode 100644 com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs create mode 100644 com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs.meta create mode 100644 com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/EyeIndexNode.cs create mode 100644 com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/EyeIndexNode.cs.meta diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs index 8211a3067f6..95916dabd04 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDStructFields.cs @@ -29,7 +29,7 @@ public struct AttributesMesh public static FieldDescriptor instanceID = new FieldDescriptor(AttributesMesh.name, "instanceID", "", ShaderValueType.Uint, "INSTANCEID_SEMANTIC", "UNITY_ANY_INSTANCING_ENABLED"); public static FieldDescriptor vertexID = new FieldDescriptor(AttributesMesh.name, "vertexID", "ATTRIBUTES_NEED_VERTEXID", ShaderValueType.Uint, - "SV_VertexID", subscriptOptions: StructFieldOptions.Optional); + "VERTEXID_SEMANTIC", subscriptOptions: StructFieldOptions.Optional); } public struct VaryingsMeshToPS diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template index c5abaa8c21b..d9bb49edfd3 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/Templates/ShaderPass.template @@ -43,6 +43,7 @@ Pass $AttributesMesh.uv2: #define ATTRIBUTES_NEED_TEXCOORD2 $AttributesMesh.uv3: #define ATTRIBUTES_NEED_TEXCOORD3 $AttributesMesh.color: #define ATTRIBUTES_NEED_COLOR + $AttributesMesh.vertexID: #define ATTRIBUTES_NEED_VERTEXID $VaryingsMeshToPS.positionRWS: #define VARYINGS_NEED_POSITION_WS $VaryingsMeshToPS.normalWS: #define VARYINGS_NEED_TANGENT_TO_WORLD $VaryingsMeshToPS.texCoord0: #define VARYINGS_NEED_TEXCOORD0 diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/ShaderPass.template b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/ShaderPass.template index e61e8b19c32..3a958efc255 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/ShaderPass.template +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/ShaderPass.template @@ -44,6 +44,7 @@ $Attributes.uv1: #define ATTRIBUTES_NEED_TEXCOORD1 $Attributes.uv2: #define ATTRIBUTES_NEED_TEXCOORD2 $Attributes.uv3: #define ATTRIBUTES_NEED_TEXCOORD3 $Attributes.color: #define ATTRIBUTES_NEED_COLOR +$Attributes.vertexID: #define ATTRIBUTES_NEED_VERTEXID $Varyings.positionWS: #define VARYINGS_NEED_POSITION_WS $Varyings.normalWS: #define VARYINGS_NEED_NORMAL_WS $Varyings.tangentWS: #define VARYINGS_NEED_TANGENT_WS diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/InstanceIDNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/InstanceIDNode.cs new file mode 100644 index 00000000000..d15dcb706cf --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/InstanceIDNode.cs @@ -0,0 +1,34 @@ +using System.Reflection; + +namespace UnityEditor.ShaderGraph +{ + [Title("Input", "Geometry", "Instance ID")] + class InstanceIDNode : CodeFunctionNode + { + public override bool hasPreview { get { return false; } } + + public InstanceIDNode() + { + name = "Instance ID"; + } + + protected override MethodInfo GetFunctionToConvert() + { + return GetType().GetMethod("UnityGetInstanceID", BindingFlags.Static | BindingFlags.NonPublic); + } + + static string UnityGetInstanceID([Slot(0, Binding.None)] out Vector1 Out) + { + return +@" +{ +#if UNITY_ANY_INSTANCING_ENABLED + Out = unity_InstanceID; +#else + Out = 0; +#endif +} +"; + } + } +} diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/InstanceIDNode.cs.meta b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/InstanceIDNode.cs.meta new file mode 100644 index 00000000000..264cdec99c6 --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/InstanceIDNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 215e6221fbd6f9a4bbd14e951c9575d6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs new file mode 100644 index 00000000000..c686269ddaf --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs @@ -0,0 +1,36 @@ +using UnityEngine; +using UnityEditor.Graphing; + +namespace UnityEditor.ShaderGraph +{ + [Title("Input", "Geometry", "Vertex ID")] + class VertexIDNode : AbstractMaterialNode, IMayRequireVertexID + { + private const int kOutputSlotId = 0; + private const string kOutputSlotName = "Out"; + + public override bool hasPreview { get { return false; } } + + public VertexIDNode() + { + name = "Vertex ID"; + UpdateNodeAfterDeserialization(); + } + + public sealed override void UpdateNodeAfterDeserialization() + { + AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, (int)1)); + RemoveSlotsNameNotMatching(new[] { kOutputSlotId }); + } + + public override string GetVariableNameForSlot(int slotId) + { + return string.Format("IN.{0}", ShaderGeneratorNames.VertexID); + } + + public bool RequiresVertexID(ShaderStageCapability stageCapability) + { + return true; + } + } +} diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs.meta b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs.meta new file mode 100644 index 00000000000..2d5149121bc --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8cc9905543f080945b4250dfa558e604 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/EyeIndexNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/EyeIndexNode.cs new file mode 100644 index 00000000000..4a48fbda661 --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/EyeIndexNode.cs @@ -0,0 +1,34 @@ +using System.Reflection; + +namespace UnityEditor.ShaderGraph +{ + [Title("Input", "Scene", "Eye Index")] + class EyeIndexNode : CodeFunctionNode + { + public override bool hasPreview { get { return false; } } + + public EyeIndexNode() + { + name = "Eye Index"; + } + + protected override MethodInfo GetFunctionToConvert() + { + return GetType().GetMethod("UnityGetEyeIndex", BindingFlags.Static | BindingFlags.NonPublic); + } + + static string UnityGetEyeIndex([Slot(0, Binding.None)] out Vector1 Out) + { + return +@" +{ +#if defined(UNITY_SINGLE_PASS_STEREO) || defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED) + Out = unity_StereoEyeIndex; +#else + Out = 0; +#endif +} +"; + } + } +} diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/EyeIndexNode.cs.meta b/com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/EyeIndexNode.cs.meta new file mode 100644 index 00000000000..4a5c207c61f --- /dev/null +++ b/com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/EyeIndexNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8ef30ebbb2a5c6c4989bfa74ad4600bf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From ef42d37cb961015f7fa939c07b5f510b2d7c34eb Mon Sep 17 00:00:00 2001 From: Esmeralda Salamone Date: Fri, 29 Jan 2021 10:27:14 -0800 Subject: [PATCH 2/3] stage restriction for verteix --- .../Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs index c686269ddaf..dfdcdf1964d 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/Input/Geometry/VertexIDNode.cs @@ -19,7 +19,7 @@ public VertexIDNode() public sealed override void UpdateNodeAfterDeserialization() { - AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, (int)1)); + AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, (int)0, ShaderStageCapability.Vertex)); RemoveSlotsNameNotMatching(new[] { kOutputSlotId }); } From 4b784e0f5dd1434c97ed3b55f3fbd3edc1f4ec7b Mon Sep 17 00:00:00 2001 From: Esmeralda Salamone Date: Fri, 29 Jan 2021 10:41:04 -0800 Subject: [PATCH 3/3] changelog --- com.unity.shadergraph/CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 10e45433aeb..8407272d7d7 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -6,8 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [12.0.0] - 2021-01-11 -Version Updated -The version number for this package has increased due to a version update of a related graphics package. +### Added + - Stereo Eye Index, Instance ID, and Vertex ID nodes added to the shadergraph library. + +### Changed + +### Fixed ## [11.0.0] - 2020-10-21