From b82da95b5181ac8bbae38efb13e950d5e88a4caa Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 23 Oct 2020 13:08:43 +0800 Subject: =?UTF-8?q?*=E7=A7=BB=E5=8A=A8amplify=20shader=20editor=E5=88=B0th?= =?UTF-8?q?ird=20party=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugins/Editor/Nodes/Textures/PannerNode.cs | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/PannerNode.cs (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/PannerNode.cs') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/PannerNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/PannerNode.cs new file mode 100644 index 00000000..e20c8c05 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/PannerNode.cs @@ -0,0 +1,110 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda + +using UnityEngine; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Panner", "UV Coordinates", "Pans UV texture coordinates according to its inputs" )] + public sealed class PannerNode : ParentNode + { + private const string _speedXStr = "Speed X"; + private const string _speedYStr = "Speed Y"; + + private int m_cachedUsingEditorId = -1; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT2, false, "UV" ,-1,MasterNodePortCategory.Fragment,0); + AddInputPort( WirePortDataType.FLOAT2, false, "Speed", -1, MasterNodePortCategory.Fragment, 2 ); + AddInputPort( WirePortDataType.FLOAT, false, "Time", -1, MasterNodePortCategory.Fragment, 1 ); + AddOutputPort( WirePortDataType.FLOAT2, "Out" ); + m_textLabelWidth = 70; + m_useInternalPortData = true; + m_previewShaderGUID = "6f89a5d96bdad114b9bbd0c236cac622"; + m_inputPorts[ 2 ].FloatInternalData = 1; + m_continuousPreviewRefresh = true; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if ( m_cachedUsingEditorId == -1 ) + m_cachedUsingEditorId = Shader.PropertyToID( "_UsingEditor" ); + + PreviewMaterial.SetFloat( m_cachedUsingEditorId, ( m_inputPorts[ 2 ].IsConnected ? 0 : 1 ) ); + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + if( portId == 1 ) + { + m_continuousPreviewRefresh = false; + } + } + + public override void OnInputPortDisconnected( int portId ) + { + base.OnInputPortDisconnected( portId ); + if( portId == 1 ) + { + m_continuousPreviewRefresh = true; + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + string timePort = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + + if( !m_inputPorts[ 2 ].IsConnected ) + { + if( !( dataCollector.IsTemplate && dataCollector.IsSRP ) ) + dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables ); + timePort += " * _Time.y"; + } + + string speed = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + string result = "( " + timePort + " * " + speed + " + " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + ")"; + + RegisterLocalVariable( 0, result, ref dataCollector, "panner" + OutputId ); + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() < 13107 ) + { + // The internal data for the new port can be set in here since it didn't existed + // on older shader versions + float speedX = Convert.ToSingle( GetCurrentParam( ref nodeParams ) ); + float speedY = Convert.ToSingle( GetCurrentParam( ref nodeParams ) ); + m_inputPorts[ 1 ].Vector2InternalData = new Vector2( speedX, speedY ); + } + } + + public override void ReadInputDataFromString( ref string[] nodeParams ) + { + base.ReadInputDataFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() < 13107 ) + { + //Time Port must be rewritten after internal data is read + // already existed in previous shaders + m_inputPorts[ 2 ].FloatInternalData = 1; + } + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + } + } +} -- cgit v1.1-26-g67d0