From 917e9e0b320775634dc2e710f7deac74fd0822f0 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 22 Oct 2020 23:30:02 +0800 Subject: * amplify shader editor --- .../Editor/Nodes/Textures/UnpackScaleNormalNode.cs | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/UnpackScaleNormalNode.cs (limited to 'Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/UnpackScaleNormalNode.cs') diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/UnpackScaleNormalNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/UnpackScaleNormalNode.cs new file mode 100644 index 00000000..364cfcca --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Textures/UnpackScaleNormalNode.cs @@ -0,0 +1,68 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda + +using System; +namespace AmplifyShaderEditor +{ + [NodeAttributes( "Unpack Scale Normal", "Textures", "Applies UnpackNormal/UnpackScaleNormal function" )] + [Serializable] + public class UnpackScaleNormalNode : ParentNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT4, false, "Value" ); + AddInputPort( WirePortDataType.FLOAT, false, "Scale" ); + m_inputPorts[ 1 ].FloatInternalData = 1; + AddOutputVectorPorts( WirePortDataType.FLOAT3, "XYZ" ); + m_useInternalPortData = true; + m_previewShaderGUID = "8b0ae05e25d280c45af81ded56f8012e"; + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + string src = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + + + bool isScaledNormal = false; + if ( m_inputPorts[ 1 ].IsConnected ) + { + isScaledNormal = true; + } + else + { + if ( m_inputPorts[ 1 ].FloatInternalData != 1 ) + { + isScaledNormal = true; + } + } + + string normalMapUnpackMode = string.Empty; + string scaleValue = isScaledNormal?m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ):"1.0"; + normalMapUnpackMode = string.Format( TemplateHelperFunctions.CreateUnpackNormalStr( dataCollector, isScaledNormal, scaleValue ), src); + if( isScaledNormal && !( dataCollector.IsTemplate && dataCollector.IsSRP ) ) + { + dataCollector.AddToIncludes( UniqueId, Constants.UnityStandardUtilsLibFuncs ); + } + + int outputUsage = 0; + for ( int i = 0; i < m_outputPorts.Count; i++ ) + { + if ( m_outputPorts[ i ].IsConnected ) + outputUsage += 1; + } + + + if ( outputUsage > 1 ) + { + string varName = "localUnpackNormal" + OutputId; + dataCollector.AddLocalVariable( UniqueId, "float3 " + varName + " = " + normalMapUnpackMode + ";" ); + return GetOutputVectorItem( 0, outputId, varName ); + } + else + { + return GetOutputVectorItem( 0, outputId, normalMapUnpackMode ); + } + } + } +} -- cgit v1.1-26-g67d0