summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/ImageEffects/DesaturateOpNode.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/ImageEffects/DesaturateOpNode.cs
parent917e9e0b320775634dc2e710f7deac74fd0822f0 (diff)
*移动amplify shader editor到third party目录
Diffstat (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/ImageEffects/DesaturateOpNode.cs')
-rw-r--r--Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/ImageEffects/DesaturateOpNode.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/ImageEffects/DesaturateOpNode.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/ImageEffects/DesaturateOpNode.cs
new file mode 100644
index 00000000..507c678d
--- /dev/null
+++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Nodes/ImageEffects/DesaturateOpNode.cs
@@ -0,0 +1,57 @@
+// Amplify Shader Editor - Visual Shader Editing Tool
+// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
+
+// http://stackoverflow.com/questions/9320953/what-algorithm-does-photoshop-use-to-desaturate-an-image
+// https://www.shadertoy.com/view/lsdXDH
+
+namespace AmplifyShaderEditor
+{
+ [System.Serializable]
+ [NodeAttributes( "Desaturate", "Image Effects", "Generic desaturation operation" )]
+ public sealed class DesaturateOpNode : ParentNode
+ {
+ private const string GenericDesaturateOp0 = "dot( {0}, float3( 0.299, 0.587, 0.114 ))";
+ private const string GenericDesaturateOp1 = "lerp( {0}, {1}.xxx, {2} )";
+ //private const string GenericDesaturateOp = "lerp( {0},dot({0},float3(0.299,0.587,0.114)).xxx,{1})";
+
+ protected override void CommonInit( int uniqueId )
+ {
+ base.CommonInit( uniqueId );
+ AddInputPort( WirePortDataType.FLOAT3, false, "RGB" );
+ AddInputPort( WirePortDataType.FLOAT, false, "Fraction" );
+ AddOutputPort( WirePortDataType.FLOAT3, Constants.EmptyPortValue );
+ m_useInternalPortData = true;
+ m_previewShaderGUID = "faabe9efdf44b9648a523f1742abdfd3";
+ }
+
+ void UpdatePorts( int portId )
+ {
+ if ( portId == 0 )
+ {
+ m_inputPorts[ 0 ].MatchPortToConnection();
+ m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false );
+ }
+ }
+
+ 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 initalColorValue = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
+ string fraction = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
+
+ string initialColorVarName = "desaturateInitialColor" + OutputId;
+ dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT3, initialColorVarName, initalColorValue );
+
+ string dotVarName = "desaturateDot" + OutputId;
+ string dotVarValue = string.Format( GenericDesaturateOp0, initialColorVarName );
+
+ dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, WirePortDataType.FLOAT, dotVarName, dotVarValue );
+ RegisterLocalVariable( 0, string.Format( GenericDesaturateOp1, initialColorVarName, dotVarName,fraction ), ref dataCollector, "desaturateVar" + OutputId );
+
+ return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
+ }
+ }
+}