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 --- .../Nodes/HelperFuncs/ComputeScreenPosHlpNode.cs | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/HelperFuncs/ComputeScreenPosHlpNode.cs (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/HelperFuncs/ComputeScreenPosHlpNode.cs') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/HelperFuncs/ComputeScreenPosHlpNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/HelperFuncs/ComputeScreenPosHlpNode.cs new file mode 100644 index 00000000..883009b9 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/HelperFuncs/ComputeScreenPosHlpNode.cs @@ -0,0 +1,76 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda +using UnityEngine; +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Compute Screen Pos", "Camera And Screen", "Computes texture coordinate for doing a screenspace-mapped texture sample. Input is clip space position" )] + public sealed class ComputeScreenPosHlpNode : HelperParentNode + { + [SerializeField] + private bool m_normalize = false; + private string NormalizeStr = "Normalize"; + private readonly string[] NormalizeOps = + { "{0} = {0} / {0}.w;", + "{0}.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? {0}.z : {0}.z* 0.5 + 0.5;" + }; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_funcType = "ComputeScreenPos"; + m_funcHDFormatOverride = "ComputeScreenPos( {0} , _ProjectionParams.x )"; + m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false ); + m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false ); + m_outputPorts[ 0 ].Name = "XYZW"; + m_autoWrapProperties = true; + m_previewShaderGUID = "97bd4895d847d764eb21d2bf7aa13671"; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + m_previewMaterialPassId = m_normalize ? 1 : 0; + } + + protected override void OnUniqueIDAssigned() + { + base.OnUniqueIDAssigned(); + m_localVarName = "computeScreenPos" + OutputId; + } + + public override void DrawProperties() + { + base.DrawProperties(); + m_normalize = EditorGUILayoutToggle( NormalizeStr, m_normalize ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + string result = base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + if( m_normalize ) + { + dataCollector.AddLocalVariable( UniqueId, string.Format( NormalizeOps[ 0 ], m_localVarName ) ); + dataCollector.AddLocalVariable( UniqueId, string.Format( NormalizeOps[ 1 ], m_localVarName ) ); + } + return result; + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_normalize ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() > 15404 ) + { + m_normalize = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + } + + } +} -- cgit v1.1-26-g67d0