diff options
author | chai <chaifix@163.com> | 2020-10-23 13:08:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-23 13:08:43 +0800 |
commit | b82da95b5181ac8bbae38efb13e950d5e88a4caa (patch) | |
tree | 48a6f3269276484bbc7cfc95f0651f40a2176aa1 /Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/LinearDepthNode.cs | |
parent | 917e9e0b320775634dc2e710f7deac74fd0822f0 (diff) |
*移动amplify shader editor到third party目录
Diffstat (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/LinearDepthNode.cs')
-rw-r--r-- | Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/LinearDepthNode.cs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/LinearDepthNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/LinearDepthNode.cs new file mode 100644 index 00000000..0193bbc9 --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/Misc/LinearDepthNode.cs @@ -0,0 +1,97 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Linear Depth", "Miscellaneous", "Converts depth values given on logarithmic space to linear" )] + public sealed class LinearDepthNode : ParentNode + { + private readonly string[] LinearModeLabels = { "Eye Space", "0-1 Space" }; + + private const string LinearEyeFuncFormat = "LinearEyeDepth({0})"; + private const string Linear01FuncFormat = "Linear01Depth({0})"; + private const string LinerValName = "depthToLinear"; + private const string ViewSpaceLabel = "View Space"; + + private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper(); + + [SerializeField] + private int m_currentOption = 0; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_autoWrapProperties = true; + m_hasLeftDropdown = true; + m_previewShaderGUID = "2b0785cc8b854974ab4e45419072705a"; + UpdateFromOption(); + } + + public override void Destroy() + { + base.Destroy(); + m_upperLeftWidget = null; + } + + void UpdateFromOption() + { + m_previewMaterialPassId = m_currentOption; + SetAdditonalTitleText( string.Format( Constants.SubTitleSpaceFormatStr, LinearModeLabels[ m_currentOption ] ) ); + } + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + EditorGUI.BeginChangeCheck(); + m_currentOption = m_upperLeftWidget.DrawWidget( this, m_currentOption, LinearModeLabels ); + if( EditorGUI.EndChangeCheck() ) + { + UpdateFromOption(); + } + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUI.BeginChangeCheck(); + m_currentOption = EditorGUILayoutPopup( ViewSpaceLabel, m_currentOption, LinearModeLabels ); + if( EditorGUI.EndChangeCheck() ) + { + SetAdditonalTitleText( string.Format( Constants.SubTitleSpaceFormatStr, LinearModeLabels[ m_currentOption ] ) ); + } + } + + 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 ); + + base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + + string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + value = string.Format( (( m_currentOption == 0 ) ? LinearEyeFuncFormat : Linear01FuncFormat), value ); + RegisterLocalVariable( 0, value, ref dataCollector, LinerValName + OutputId ); + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_currentOption ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + int.TryParse( GetCurrentParam( ref nodeParams ), out m_currentOption ); + UpdateFromOption(); + } + } +} |