summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Master/FunctionSwitchByPipeline.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-23 13:08:43 +0800
committerchai <chaifix@163.com>2020-10-23 13:08:43 +0800
commitb82da95b5181ac8bbae38efb13e950d5e88a4caa (patch)
tree48a6f3269276484bbc7cfc95f0651f40a2176aa1 /Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Master/FunctionSwitchByPipeline.cs
parent917e9e0b320775634dc2e710f7deac74fd0822f0 (diff)
*移动amplify shader editor到third party目录
Diffstat (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Master/FunctionSwitchByPipeline.cs')
-rw-r--r--Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Master/FunctionSwitchByPipeline.cs102
1 files changed, 102 insertions, 0 deletions
diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Master/FunctionSwitchByPipeline.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Master/FunctionSwitchByPipeline.cs
new file mode 100644
index 00000000..5a05605e
--- /dev/null
+++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Master/FunctionSwitchByPipeline.cs
@@ -0,0 +1,102 @@
+// Amplify Shader Editor - Visual Shader Editing Tool
+// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
+
+using UnityEngine;
+using UnityEditor;
+using System;
+
+namespace AmplifyShaderEditor
+{
+ [Serializable]
+ [NodeAttributes( "Switch by Pipeline", "Functions", "Executes branch according to current pipeline", NodeAvailabilityFlags = (int)NodeAvailability.ShaderFunction )]
+ public sealed class FunctionSwitchByPipeline : ParentNode
+ {
+ protected override void CommonInit( int uniqueId )
+ {
+ base.CommonInit( uniqueId );
+ AddInputPort( WirePortDataType.FLOAT, false, "Surface", -1, MasterNodePortCategory.Fragment, 0 );
+ AddInputPort( WirePortDataType.FLOAT, false, "Default RP", -1, MasterNodePortCategory.Fragment, 3 );
+ AddInputPort( WirePortDataType.FLOAT, false, "Lightweight", -1, MasterNodePortCategory.Fragment, 1 );
+ AddInputPort( WirePortDataType.FLOAT, false, "HD", -1, MasterNodePortCategory.Fragment, 2 );
+ AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
+
+ }
+
+ public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
+ {
+ base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
+ GetInputPortByUniqueId( portId ).MatchPortToConnection();
+ UpdateOutputPort();
+ }
+
+ public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
+ {
+ base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type );
+ GetInputPortByUniqueId( outputPortId ).MatchPortToConnection();
+ UpdateOutputPort();
+ }
+
+ void UpdateOutputPort()
+ {
+ switch( UIUtils.CurrentWindow.OutsideGraph.CurrentSRPType )
+ {
+ case TemplateSRPType.BuiltIn:
+ {
+ InputPort port = UIUtils.CurrentWindow.OutsideGraph.IsStandardSurface ? GetInputPortByUniqueId( 0 ) : GetInputPortByUniqueId( 3 );
+ m_outputPorts[ 0 ].ChangeType( port.DataType, false );
+ }
+ break;
+ case TemplateSRPType.Lightweight:
+ {
+ InputPort port = GetInputPortByUniqueId( 1 );
+ m_outputPorts[ 0 ].ChangeType( port.DataType, false );
+ }
+ break;
+ case TemplateSRPType.HD:
+ {
+ InputPort port = GetInputPortByUniqueId( 2 );
+ m_outputPorts[ 0 ].ChangeType( port.DataType, false );
+ }
+ break;
+ }
+ }
+
+ public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
+ {
+ base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
+ switch( dataCollector.CurrentSRPType )
+ {
+ case TemplateSRPType.BuiltIn:
+ {
+ InputPort port = UIUtils.CurrentWindow.OutsideGraph.IsStandardSurface ? GetInputPortByUniqueId( 0 ) : GetInputPortByUniqueId( 3 );
+ return port.GeneratePortInstructions( ref dataCollector );
+ }
+ case TemplateSRPType.Lightweight:
+ {
+ InputPort port = GetInputPortByUniqueId( 1 );
+ return port.GeneratePortInstructions( ref dataCollector );
+ }
+ case TemplateSRPType.HD:
+ {
+ InputPort port = GetInputPortByUniqueId( 2 );
+ return port.GeneratePortInstructions( ref dataCollector );
+ }
+ }
+
+ return "0";
+ }
+
+ public override void RefreshExternalReferences()
+ {
+ base.RefreshExternalReferences();
+ if( UIUtils.CurrentShaderVersion() < 16303 )
+ {
+ InputPort standardPort = GetInputPortByUniqueId( 0 );
+ if( standardPort.IsConnected )
+ {
+ UIUtils.SetConnection( UniqueId, 3, standardPort.GetConnection().NodeId, standardPort.GetConnection().PortId );
+ }
+ }
+ }
+ }
+}