summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/SurfaceShaderInputs/GrabScreenPosition.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/SurfaceShaderInputs/GrabScreenPosition.cs
parent917e9e0b320775634dc2e710f7deac74fd0822f0 (diff)
*移动amplify shader editor到third party目录
Diffstat (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/SurfaceShaderInputs/GrabScreenPosition.cs')
-rw-r--r--Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/SurfaceShaderInputs/GrabScreenPosition.cs118
1 files changed, 118 insertions, 0 deletions
diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/SurfaceShaderInputs/GrabScreenPosition.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/SurfaceShaderInputs/GrabScreenPosition.cs
new file mode 100644
index 00000000..3e2a5117
--- /dev/null
+++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/SurfaceShaderInputs/GrabScreenPosition.cs
@@ -0,0 +1,118 @@
+// Amplify Shader Editor - Visual Shader Editing Tool
+// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
+
+using System;
+using UnityEditor;
+using UnityEngine;
+
+namespace AmplifyShaderEditor
+{
+ [Serializable]
+ [NodeAttributes( "Grab Screen Position", "Camera And Screen", "Screen position correctly transformed to be used with Grab Screen Color" )]
+ public sealed class GrabScreenPosition : ParentNode
+ {
+ private readonly string[] m_outputTypeStr = { "Normalized", "Screen" };
+
+ [SerializeField]
+ private int m_outputTypeInt = 0;
+
+ private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
+
+ protected override void CommonInit( int uniqueId )
+ {
+ base.CommonInit( uniqueId );
+ AddOutputVectorPorts( WirePortDataType.FLOAT4, "XYZW" );
+ m_autoWrapProperties = true;
+ m_hasLeftDropdown = true;
+ m_textLabelWidth = 65;
+ ConfigureHeader();
+ }
+
+ public override void AfterCommonInit()
+ {
+ base.AfterCommonInit();
+
+ if( PaddingTitleLeft == 0 )
+ {
+ PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
+ if( PaddingTitleRight == 0 )
+ PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
+ }
+ }
+
+ public override void Destroy()
+ {
+ base.Destroy();
+ m_upperLeftWidget = null;
+ }
+
+ public override void Draw( DrawInfo drawInfo )
+ {
+ base.Draw( drawInfo );
+ EditorGUI.BeginChangeCheck();
+ m_outputTypeInt = m_upperLeftWidget.DrawWidget( this, m_outputTypeInt, m_outputTypeStr );
+ if( EditorGUI.EndChangeCheck() )
+ {
+ ConfigureHeader();
+ }
+ }
+
+ public override void DrawProperties()
+ {
+ base.DrawProperties();
+
+ EditorGUI.BeginChangeCheck();
+ m_outputTypeInt = EditorGUILayoutPopup( "Type", m_outputTypeInt, m_outputTypeStr );
+ if( EditorGUI.EndChangeCheck() )
+ {
+ ConfigureHeader();
+ }
+ }
+
+ void ConfigureHeader()
+ {
+ SetAdditonalTitleText( string.Format( Constants.SubTitleTypeFormatStr, m_outputTypeStr[ m_outputTypeInt ] ) );
+ }
+
+ public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
+ {
+ if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
+ return GetOutputColorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
+
+ string localVarName = string.Empty;
+
+ if( m_outputTypeInt == 0 )
+ localVarName = GeneratorUtils.GenerateGrabScreenPositionNormalized( ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos );
+ else
+ localVarName = GeneratorUtils.GenerateGrabScreenPosition( ref dataCollector, UniqueId, CurrentPrecisionType, !dataCollector.UsingCustomScreenPos );
+
+ m_outputPorts[ 0 ].SetLocalValue( localVarName, dataCollector.PortCategory );
+ return GetOutputColorItem( 0, outputId, localVarName );
+ }
+
+ public override void ReadFromString( ref string[] nodeParams )
+ {
+ base.ReadFromString( ref nodeParams );
+ if( UIUtils.CurrentShaderVersion() > 3108 )
+ {
+ if( UIUtils.CurrentShaderVersion() < 6102 )
+ {
+ bool project = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
+ m_outputTypeInt = project ? 0 : 1;
+ }
+ else
+ {
+ m_outputTypeInt = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
+ }
+ }
+
+ ConfigureHeader();
+ }
+
+ public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
+ {
+ base.WriteToString( ref nodeInfo, ref connectionsInfo );
+ IOUtils.AddFieldValueToString( ref nodeInfo, m_outputTypeInt );
+ }
+ }
+}