diff options
author | chai <chaifix@163.com> | 2020-10-22 23:30:02 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-22 23:30:02 +0800 |
commit | 917e9e0b320775634dc2e710f7deac74fd0822f0 (patch) | |
tree | 637f3cccc80e7738c8a077fa3ff59218b8b18ee8 /Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators | |
parent | 8268e4e308bd110dfea4ad849a7ff74e66951349 (diff) |
* amplify shader editor
Diffstat (limited to 'Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators')
118 files changed, 3936 insertions, 0 deletions
diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ACosOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ACosOpNode.cs new file mode 100644 index 00000000..32fff2c9 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ACosOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "ACos", "Trigonometry Operators", "Arccosine of scalars and vectors" )] + public sealed class ACosOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "acos"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + m_previewShaderGUID = "710f3c0bbd7ba0c4aada6d7dfadd49c2"; + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ACosOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ACosOpNode.cs.meta new file mode 100644 index 00000000..74fdc7aa --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ACosOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 8238f389c28938544b56035531b3f1be +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ASinOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ASinOpNode.cs new file mode 100644 index 00000000..936e1d19 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ASinOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "ASin", "Trigonometry Operators", "Arcsine of scalars and vectors" )] + public sealed class ASinOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "asin"; + m_previewShaderGUID = "2b016c135284add4cb3364d4a0bd0638"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ASinOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ASinOpNode.cs.meta new file mode 100644 index 00000000..0e1aa0ab --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ASinOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 268ebf76d03c2e84f8c80a375773b46c +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATan2OpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATan2OpNode.cs new file mode 100644 index 00000000..70f9fb73 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATan2OpNode.cs @@ -0,0 +1,28 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "ATan2", "Trigonometry Operators", "Arctangent of y/x" )] + public sealed class ATan2OpNode : DynamicTypeNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_dynamicOutputType = true; + m_useInternalPortData = true; + m_previewShaderGUID = "02e3ff61784e38840af6313936b6a730"; + } + + public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + base.BuildResults( outputId, ref dataCollector, ignoreLocalvar ); + string result = "atan2( " + m_inputA + " , " + m_inputB + " )"; + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATan2OpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATan2OpNode.cs.meta new file mode 100644 index 00000000..9109fe76 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATan2OpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f5957d9ac2cc12146bc862cd0c92815a +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATanOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATanOpNode.cs new file mode 100644 index 00000000..c36c599a --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATanOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "ATan", "Trigonometry Operators", "Arctangent of scalars and vectors" )] + public sealed class ATanOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "atan"; + m_previewShaderGUID = "7d7f3331a98831241b017364e80625ea"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATanOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATanOpNode.cs.meta new file mode 100644 index 00000000..a382707b --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ATanOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d84f7e90e793aaa4891b4c1fe400dc4c +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/AbsOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/AbsOpNode.cs new file mode 100644 index 00000000..18adcbd9 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/AbsOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Abs", "Math Operators", "Absolute value of scalars and vectors" )] + public sealed class AbsOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "abs"; + m_previewShaderGUID = "cd6d6dfa3df214a479f68a490e177db6"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/AbsOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/AbsOpNode.cs.meta new file mode 100644 index 00000000..50ca8f58 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/AbsOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 46aea6c13d71ec74da7f23abba3704d6 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CeilOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CeilOpNode.cs new file mode 100644 index 00000000..6767231e --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CeilOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Ceil", "Math Operators", "Smallest integer not less than a scalar or each vector component" )] + public sealed class CeilOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "ceil"; + m_previewShaderGUID = "ce0588227a766a245a85291977c1f222"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CeilOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CeilOpNode.cs.meta new file mode 100644 index 00000000..aba35895 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CeilOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 555db3754f84db947846519630ea303b +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClampOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClampOpNode.cs new file mode 100644 index 00000000..fe15a01e --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClampOpNode.cs @@ -0,0 +1,103 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Clamp", "Math Operators", "Value clamped to the range [min,max]" )] + public sealed class ClampOpNode : ParentNode + { + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue ); + AddInputPort( WirePortDataType.FLOAT, false, "Min" ); + AddInputPort( WirePortDataType.FLOAT, false, "Max" ); + m_inputPorts[ m_inputPorts.Count - 1 ].FloatInternalData = 1; + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_useInternalPortData = true; + m_textLabelWidth = 55; + m_previewShaderGUID = "ab6163c4b10bfc84da8e3c486520490a"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + if ( portId == 0 ) + { + m_inputPorts[ 0 ].MatchPortToConnection(); + m_inputPorts[ 1 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_inputPorts[ 2 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + //else + //{ + // _inputPorts[ portId ].MatchPortToConnection(); + //} + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + if ( outputPortId == 0 ) + { + m_inputPorts[ 0 ].MatchPortToConnection(); + m_inputPorts[ 1 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_inputPorts[ 2 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + 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 ); + + WirePortDataType valueType = m_inputPorts[ 0 ].ConnectionType(); + WirePortDataType minType = m_inputPorts[ 1 ].ConnectionType(); + WirePortDataType maxType = m_inputPorts[ 2 ].ConnectionType(); + + string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string min = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + if ( minType != valueType ) + { + min = UIUtils.CastPortType( ref dataCollector, CurrentPrecisionType, new NodeCastInfo( UniqueId, outputId ), null, m_inputPorts[ 1 ].DataType, m_inputPorts[ 0 ].DataType, min ); + } + + string max = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + if ( maxType != valueType ) + { + max = UIUtils.CastPortType( ref dataCollector, CurrentPrecisionType, new NodeCastInfo( UniqueId, outputId ), null, m_inputPorts[ 2 ].DataType, m_inputPorts[ 0 ].DataType, max ); + } + + string result = string.Empty; + switch ( valueType ) + { + case WirePortDataType.FLOAT: + case WirePortDataType.FLOAT2: + case WirePortDataType.FLOAT3: + case WirePortDataType.FLOAT4: + case WirePortDataType.INT: + case WirePortDataType.COLOR: + case WirePortDataType.OBJECT: + { + result = "clamp( " + value + " , " + min + " , " + max + " )"; + } + break; + case WirePortDataType.FLOAT3x3: + case WirePortDataType.FLOAT4x4: + { + return UIUtils.InvalidParameter( this ); + } + } + + RegisterLocalVariable( 0, result, ref dataCollector, "clampResult" + OutputId ); + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClampOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClampOpNode.cs.meta new file mode 100644 index 00000000..dd3c8f70 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClampOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5d7101830aa0c524f9519fef95c90dc3 +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClipNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClipNode.cs new file mode 100644 index 00000000..606cb822 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClipNode.cs @@ -0,0 +1,123 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Clip", "Miscellaneous", "Conditionally kill a pixel before output" )] + public sealed class ClipNode : ParentNode + { + private const string ClipOpFormat = "clip( {0} );"; + private const string ClipSubOpFormat = "clip( {0} - {1});"; + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue ); + AddInputPort( WirePortDataType.FLOAT, false, "Alpha" ); + AddInputPort( WirePortDataType.FLOAT, false, "Threshold" ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_useInternalPortData = true; + + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + + m_previewShaderGUID = "1fca7774f364aee4d8c64e8634ef4be4"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + m_inputPorts[ portId ].MatchPortToConnection(); + UpdatePortConnection( portId ); + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + m_inputPorts[ outputPortId ].MatchPortToConnection(); + UpdatePortConnection( outputPortId ); + } + + void UpdatePortConnection( int portId ) + { + if( portId == 0 ) + { + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + else + { + int otherPortId = portId == 1 ? 2 : 1; + if( m_inputPorts[ otherPortId ].IsConnected ) + { + WirePortDataType type1 = m_inputPorts[ portId ].DataType; + WirePortDataType type2 = m_inputPorts[ otherPortId ].DataType; + + WirePortDataType mainType = UIUtils.GetPriority( type1 ) > UIUtils.GetPriority( type2 ) ? type1 : type2; + + m_inputPorts[ portId ].ChangeType( mainType, false ); + m_inputPorts[ otherPortId ].ChangeType( mainType , false ); + } + else + { + m_inputPorts[ otherPortId ].ChangeType( m_inputPorts[ portId ].DataType,false ); + } + } + } + + public override void OnInputPortDisconnected( int portId ) + { + base.OnInputPortDisconnected( portId ); + if( portId == 0 ) + return; + int otherPortId = portId == 1 ? 2 : 1; + if( m_inputPorts[ otherPortId ].IsConnected ) + { + m_inputPorts[ portId ].ChangeType( m_inputPorts[ otherPortId ].DataType, false ); + } + else + { + m_inputPorts[ portId ].ChangeType( WirePortDataType.FLOAT, false ); + m_inputPorts[ otherPortId ].ChangeType( WirePortDataType.FLOAT, false ); + } + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.PortCategory == MasterNodePortCategory.Vertex || + dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) + { + UIUtils.ShowMessage( UniqueId, "Clip can only be used in fragment functions", MessageSeverity.Warning ); + return GenerateErrorValue(); + } + + string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string alpha = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + if( m_inputPorts[ 2 ].IsConnected ) + { + string threshold = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + dataCollector.AddLocalVariable( UniqueId, string.Format( ClipSubOpFormat, alpha , threshold) ); + } + else + { + if( m_inputPorts[ 2 ].IsZeroInternalData ) + { + dataCollector.AddLocalVariable( UniqueId, string.Format( ClipOpFormat, alpha ) ); + } + else + { + string threshold = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + dataCollector.AddLocalVariable( UniqueId, string.Format( ClipSubOpFormat, alpha, threshold ) ); + } + } + + return value; + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClipNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClipNode.cs.meta new file mode 100644 index 00000000..0d24e6e4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ClipNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 78e9954f4d587b74fa38ae1dd9922d77 +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ComponentMaskNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ComponentMaskNode.cs new file mode 100644 index 00000000..3ed727cd --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ComponentMaskNode.cs @@ -0,0 +1,382 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Component Mask", "Vector Operators", "Mask certain channels from vectors/color components", null, KeyCode.K )] + public sealed class ComponentMaskNode : ParentNode + { + private const string OutputLocalVarName = "componentMask"; + [SerializeField] + private bool[] m_selection = { true, true, true, true }; + + [SerializeField] + private int m_outputPortCount = 4; + + [SerializeField] + private string[] m_labels; + + private int m_cachedOrderId = -1; + private int m_cachedSingularId = -1; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT4, false, Constants.EmptyPortValue ); + AddOutputPort( WirePortDataType.FLOAT4, Constants.EmptyPortValue ); + m_useInternalPortData = true; + m_autoWrapProperties = true; + m_selectedLocation = PreviewLocation.TopCenter; + m_labels = new string[] { "X", "Y", "Z", "W" }; + m_previewShaderGUID = "b78e2b295c265cd439c80d218fb3e88e"; + SetAdditonalTitleText( "Value( XYZW )" ); + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + Vector4 order = new Vector4(-1,-1,-1,-1); + int lastIndex = 0; + int singularId = -1; + var datatype = m_inputPorts[ 0 ].DataType; + + if( m_selection[ 0 ] ) + { + order.Set( lastIndex, order.y, order.z, order.w ); + lastIndex++; + singularId = 0; + } + if( m_selection[ 1 ] && datatype >= WirePortDataType.FLOAT2 ) + { + order.Set( order.x, lastIndex, order.z, order.w ); + lastIndex++; + singularId = 1; + } + if( m_selection[ 2 ] && datatype >= WirePortDataType.FLOAT3 ) + { + order.Set( order.x, order.y, lastIndex, order.w ); + lastIndex++; + singularId = 2; + } + if( m_selection[ 3 ] && ( datatype == WirePortDataType.FLOAT4 || datatype == WirePortDataType.COLOR ) ) + { + order.Set( order.x, order.y, order.z, lastIndex ); + lastIndex++; + singularId = 3; + } + + if ( lastIndex != 1 ) + singularId = -1; + + if ( m_cachedOrderId == -1 ) + m_cachedOrderId = Shader.PropertyToID( "_Order" ); + + if ( m_cachedSingularId == -1 ) + m_cachedSingularId = Shader.PropertyToID( "_Singular" ); + + PreviewMaterial.SetVector( m_cachedOrderId, order ); + PreviewMaterial.SetFloat( m_cachedSingularId, singularId ); + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + UpdatePorts(); + UpdateTitle(); + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + UpdatePorts(); + UpdateTitle(); + } + + public override void OnInputPortDisconnected( int portId ) + { + base.OnInputPortDisconnected( portId ); + UpdateTitle(); + } + + void UpdatePorts() + { + m_inputPorts[ 0 ].MatchPortToConnection(); + int count = 0; + switch ( m_inputPorts[ 0 ].DataType ) + { + case WirePortDataType.FLOAT4: + case WirePortDataType.OBJECT: + case WirePortDataType.COLOR: + { + count = 4; + } + break; + case WirePortDataType.FLOAT3: + { + count = 3; + } + break; + case WirePortDataType.FLOAT2: + { + count = 2; + } + break; + case WirePortDataType.FLOAT: + case WirePortDataType.INT: + case WirePortDataType.FLOAT3x3: + case WirePortDataType.FLOAT4x4: + { } + break; + } + + int activeCount = 0; + if ( count > 0 ) + { + for ( int i = 0; i < count; i++ ) + { + if ( m_selection[ i ] ) + activeCount += 1; + } + } + + m_outputPortCount = activeCount; + switch ( activeCount ) + { + case 0: ChangeOutputType( m_inputPorts[ 0 ].DataType, false ); break; + case 1: ChangeOutputType( WirePortDataType.FLOAT, false ); break; + case 2: ChangeOutputType( WirePortDataType.FLOAT2, false ); break; + case 3: ChangeOutputType( WirePortDataType.FLOAT3, false ); break; + case 4: ChangeOutputType( m_inputPorts[ 0 ].DataType, false ); break; + } + + } + + private void UpdateTitle() + { + int count = 0; + string additionalText = string.Empty; + switch ( m_inputPorts[ 0 ].DataType ) + { + case WirePortDataType.FLOAT4: + case WirePortDataType.OBJECT: + case WirePortDataType.COLOR: + { + count = 4; + } + break; + case WirePortDataType.FLOAT3: + { + count = 3; + } + break; + case WirePortDataType.FLOAT2: + { + count = 2; + } + break; + case WirePortDataType.FLOAT: + case WirePortDataType.INT: + { + count = 0; + } + break; + case WirePortDataType.FLOAT3x3: + case WirePortDataType.FLOAT4x4: + { } + break; + } + + if ( count > 0 ) + { + for ( int i = 0; i < count; i++ ) + { + if ( m_selection[ i ] ) + { + additionalText += UIUtils.GetComponentForPosition( i, m_inputPorts[ 0 ].DataType ).ToUpper(); + } + } + } + + if ( additionalText.Length > 0 ) + SetAdditonalTitleText( "Value( " + additionalText + " )" ); + else + SetAdditonalTitleText( string.Empty ); + } + + public override void DrawProperties() + { + base.DrawProperties(); + + EditorGUILayout.BeginVertical(); + + int count = 0; + switch ( m_inputPorts[ 0 ].DataType ) + { + case WirePortDataType.FLOAT4: + case WirePortDataType.OBJECT: + case WirePortDataType.COLOR: + { + count = 4; + } + break; + case WirePortDataType.FLOAT3: + { + count = 3; + } + break; + case WirePortDataType.FLOAT2: + { + count = 2; + } + break; + case WirePortDataType.FLOAT: + case WirePortDataType.INT: + case WirePortDataType.FLOAT3x3: + case WirePortDataType.FLOAT4x4: + { } + break; + } + + int activeCount = 0; + if ( count > 0 ) + { + for ( int i = 0; i < count; i++ ) + { + m_selection[ i ] = EditorGUILayoutToggleLeft( m_labels[i], m_selection[ i ] ); + m_labels[ i ] = UIUtils.GetComponentForPosition( i, m_inputPorts[ 0 ].DataType ).ToUpper(); + if ( m_selection[ i ] ) + { + activeCount += 1; + } + } + } + + if ( activeCount != m_outputPortCount ) + { + m_outputPortCount = activeCount; + switch ( activeCount ) + { + case 0: ChangeOutputType( m_inputPorts[ 0 ].DataType, false ); break; + case 1: ChangeOutputType( WirePortDataType.FLOAT, false ); break; + case 2: ChangeOutputType( WirePortDataType.FLOAT2, false ); break; + case 3: ChangeOutputType( WirePortDataType.FLOAT3, false ); break; + case 4: ChangeOutputType( m_inputPorts[ 0 ].DataType, false ); break; + } + UpdateTitle(); + SetSaveIsDirty(); + } + + EditorGUILayout.EndVertical(); + } + + 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 value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + + int count = 0; + switch ( m_inputPorts[ 0 ].DataType ) + { + case WirePortDataType.FLOAT4: + case WirePortDataType.OBJECT: + case WirePortDataType.COLOR: + { + count = 4; + } + break; + case WirePortDataType.FLOAT3: + { + count = 3; + } + break; + case WirePortDataType.FLOAT2: + { + count = 2; + } + break; + case WirePortDataType.FLOAT: + case WirePortDataType.INT: + { + count = 0; + } + break; + case WirePortDataType.FLOAT3x3: + case WirePortDataType.FLOAT4x4: + { } + break; + } + + if ( count > 0 ) + { + bool firstElement = true; + value = string.Format("({0})",value); + for ( int i = 0; i < count; i++ ) + { + if ( m_selection[ i ] ) + { + if( firstElement ) + { + firstElement = false; + value += "."; + } + value += UIUtils.GetComponentForPosition( i, m_inputPorts[ 0 ].DataType ); + } + } + } + + return CreateOutputLocalVariable( 0, value, ref dataCollector ); + } + + public string GetComponentForPosition( int i ) + { + switch ( i ) + { + case 0: + { + return ( ( m_outputPorts[ 0 ].DataType == WirePortDataType.COLOR ) ? "r" : "x" ); + } + case 1: + { + return ( ( m_outputPorts[ 0 ].DataType == WirePortDataType.COLOR ) ? "g" : "y" ); + } + case 2: + { + return ( ( m_outputPorts[ 0 ].DataType == WirePortDataType.COLOR ) ? "b" : "z" ); + } + case 3: + { + return ( ( m_outputPorts[ 0 ].DataType == WirePortDataType.COLOR ) ? "a" : "w" ); + } + } + return string.Empty; + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + for ( int i = 0; i < 4; i++ ) + { + m_selection[ i ] = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + UpdateTitle(); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + for ( int i = 0; i < 4; i++ ) + { + IOUtils.AddFieldValueToString( ref nodeInfo, m_selection[ i ] ); + } + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ComponentMaskNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ComponentMaskNode.cs.meta new file mode 100644 index 00000000..fd1be0b3 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ComponentMaskNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 85082b6932d1c9a4f8b64605534ef118 +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CosOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CosOpNode.cs new file mode 100644 index 00000000..a7f799f9 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CosOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Cos", "Trigonometry Operators", "Cosine of scalars and vectors" )] + public sealed class CosOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "cos"; + m_previewShaderGUID = "3dde9e80389196f459eb94137268de4a"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CosOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CosOpNode.cs.meta new file mode 100644 index 00000000..132f1bfa --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CosOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ee9c446e7e41d524f8b4c93e6a8886c5 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CoshOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CoshOpNode.cs new file mode 100644 index 00000000..24b6205f --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CoshOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Cosh", "Trigonometry Operators", "Hyperbolic cosine of scalars and vectors" )] + public sealed class CoshOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "cosh"; + m_previewShaderGUID = "154a4c85fe88657489a54a02416402c0"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CoshOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CoshOpNode.cs.meta new file mode 100644 index 00000000..46ec8178 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CoshOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2b50a187f488a004aaa2dabbe558ab3a +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CrossProductOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CrossProductOpNode.cs new file mode 100644 index 00000000..354db0d2 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CrossProductOpNode.cs @@ -0,0 +1,35 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Cross", "Vector Operators", "Cross product of two three-component vectors ( A x B )", null, KeyCode.X )] + public sealed class CrossProductOpNode : ParentNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT3, false, "Lhs" ); + AddInputPort( WirePortDataType.FLOAT3, false, "Rhs" ); + AddOutputPort( WirePortDataType.FLOAT3, "Out" ); + m_useInternalPortData = true; + m_previewShaderGUID = "65a9be5cc7037654db8e148d669f03ee"; + } + + 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 lhsStr = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string rhsStr = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + + string result = "cross( " + lhsStr + " , " + rhsStr + " )"; + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CrossProductOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CrossProductOpNode.cs.meta new file mode 100644 index 00000000..61758de7 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/CrossProductOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 283bc0645ce925346b33c024ff5a7dad +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdxOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdxOpNode.cs new file mode 100644 index 00000000..53b8821d --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdxOpNode.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "DDX", "Math Operators", "Approximate partial derivative with respect to window-space X" )] + public sealed class DdxOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "ddx"; + m_previewShaderGUID = "b54ea73d5568b3540977557813eb9c3c"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsFragmentCategory ) + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + else + return m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdxOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdxOpNode.cs.meta new file mode 100644 index 00000000..d83171e8 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdxOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2e14c4a7c0be9f146ac912130c280b15 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdyOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdyOpNode.cs new file mode 100644 index 00000000..604a341b --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdyOpNode.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "DDY", "Math Operators", "Approximate partial derivative with respect to window-space Y" )] + public sealed class DdyOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "ddy"; + m_previewShaderGUID = "197dcc7f05339da47b6b0e681c475c5e"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( dataCollector.IsFragmentCategory ) + return base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar ); + else + return m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdyOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdyOpNode.cs.meta new file mode 100644 index 00000000..d32275f6 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DdyOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 722a2ad531fefdc4d8782d5c7cdfd012 +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DegreesOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DegreesOpNode.cs new file mode 100644 index 00000000..97afc8ba --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DegreesOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Degrees", "Trigonometry Operators", "Converts values of scalars and vectors from radians to degrees" )] + public sealed class DegreesOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "degrees"; + m_previewShaderGUID = "2a8eebb5566830c4a9d7c4b9021bb743"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DegreesOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DegreesOpNode.cs.meta new file mode 100644 index 00000000..93e8abe4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DegreesOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3d88a21f3ece742408c7748897a21c79 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DeterminantOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DeterminantOpNode.cs new file mode 100644 index 00000000..d48f775d --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DeterminantOpNode.cs @@ -0,0 +1,25 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Determinant", "Matrix Operators", "Scalar determinant of a square matrix" )] + public sealed class DeterminantOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "determinant"; + m_drawPreview = false; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.FLOAT3x3, + WirePortDataType.FLOAT4x4 ); + + m_autoUpdateOutputPort = false; + m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4x4, false ); + m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT, false ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DeterminantOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DeterminantOpNode.cs.meta new file mode 100644 index 00000000..16d62ceb --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DeterminantOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e5cded78687f09442895bc96cc5b683d +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DistanceOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DistanceOpNode.cs new file mode 100644 index 00000000..8e3a6dbc --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DistanceOpNode.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Distance", "Vector Operators", "Euclidean distance between two points" )] + public sealed class DistanceOpNode : DynamicTypeNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false ); + m_inputPorts[ 1 ].ChangeType( WirePortDataType.FLOAT4, false ); + m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT, false ); + m_dynamicOutputType = false; + m_useInternalPortData = true; + m_previewShaderGUID = "3be9a95031c0cb740ae982e465dfc242"; + } + + public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + base.BuildResults( outputId, ref dataCollector, ignoreLocalvar ); + string result = "distance( " + m_inputA + " , " + m_inputB + " )"; + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DistanceOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DistanceOpNode.cs.meta new file mode 100644 index 00000000..3d28c02d --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DistanceOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4b8bd7fecbc728f4b89d398cef86ada8 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DotProductOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DotProductOpNode.cs new file mode 100644 index 00000000..892ae533 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DotProductOpNode.cs @@ -0,0 +1,34 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Dot", "Vector Operators", "Scalar dot product of two vectors ( A . B )", null, KeyCode.Period )] + public sealed class DotProductOpNode : DynamicTypeNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false ); + m_inputPorts[ 1 ].ChangeType( WirePortDataType.FLOAT4, false ); + m_dynamicOutputType = false; + m_useInternalPortData = true; + m_allowMatrixCheck = true; + m_previewShaderGUID = "85f11fd5cb9bb954c8615a45c57a3784"; + } + + public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + base.BuildResults( outputId, ref dataCollector, ignoreLocalvar ); + string result = "dot( " + m_inputA + " , " + m_inputB + " )"; + RegisterLocalVariable( 0, result, ref dataCollector, "dotResult" + OutputId ); + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DotProductOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DotProductOpNode.cs.meta new file mode 100644 index 00000000..a84594ff --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/DotProductOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c2bf0375fb75ce245b2f30857a111972 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Exp2OpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Exp2OpNode.cs new file mode 100644 index 00000000..b94d5610 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Exp2OpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Exp2", "Math Operators", "Base-2 exponential of scalars and vectors" )] + public sealed class Exp2OpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "exp2"; + m_previewShaderGUID = "ceb70ed5423a36647a504a41de7dbfe6"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Exp2OpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Exp2OpNode.cs.meta new file mode 100644 index 00000000..edea0de0 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Exp2OpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a9881734e0217bc45bb422dc83f6ee1a +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ExpOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ExpOpNode.cs new file mode 100644 index 00000000..29bded7b --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ExpOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Exp", "Math Operators", "Base-e exponential of scalars and vectors" )] + public sealed class ExpOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "exp"; + m_previewShaderGUID = "6416ff506137d97479a7ebde790b45e5"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ExpOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ExpOpNode.cs.meta new file mode 100644 index 00000000..f5989769 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ExpOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 81ef96bc69f897d4e8bc21e2731e065f +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FWidthOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FWidthOpNode.cs new file mode 100644 index 00000000..41f14b3f --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FWidthOpNode.cs @@ -0,0 +1,25 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "FWidth", "Math Operators", "Sum of approximate window-space partial derivatives magnitudes" )] + public sealed class FWidthOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "fwidth"; + m_previewShaderGUID = "81ea481faaef9c8459a555479ba64df7"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + //m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FWidthOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FWidthOpNode.cs.meta new file mode 100644 index 00000000..f97901e5 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FWidthOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2e17448829221b04bb3185bef727b19f +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FloorOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FloorOpNode.cs new file mode 100644 index 00000000..5fe190e6 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FloorOpNode.cs @@ -0,0 +1,24 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Floor", "Math Operators", "Largest integer not greater than a scalar or each vector component" )] + public sealed class FloorOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "floor"; + m_previewShaderGUID = "46ae4a72a9a38de40a2d8f20cfccc67d"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FloorOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FloorOpNode.cs.meta new file mode 100644 index 00000000..bd8bbdb0 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FloorOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 176154e86c6c3544fab0d67e098c645d +timeCreated: 1481126953 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FmodOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FmodOpNode.cs new file mode 100644 index 00000000..698e3701 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FmodOpNode.cs @@ -0,0 +1,36 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Fmod", "Math Operators", "Floating point remainder of x/y with the same sign as x" )] + public sealed class FmodOpNode : DynamicTypeNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_previewShaderGUID = "65083930f9d7812479fd6ff203ad2992"; + } + + public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + base.BuildResults( outputId, ref dataCollector, ignoreLocalvar ); + if( m_inputPorts[ 0 ].DataType == WirePortDataType.INT ) + m_inputA = "(float)" + m_inputA; + + + if( m_inputPorts[ 1 ].DataType == WirePortDataType.INT ) + m_inputB = "(float)" + m_inputB; + + + string result = "fmod( " + m_inputA + " , " + m_inputB + " )"; + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FmodOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FmodOpNode.cs.meta new file mode 100644 index 00000000..c4d07b80 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FmodOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 599ae67e52ac45f46acc0efd9285b97c +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FractNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FractNode.cs new file mode 100644 index 00000000..62c54dcb --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FractNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Fract", "Math Operators", "Fractional portion of a scalar or each vector component" )] + public sealed class FractNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "frac"; + m_previewShaderGUID = "53a335f8f18d4694b8d94e8aee21fdca"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FractNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FractNode.cs.meta new file mode 100644 index 00000000..004f9c6c --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/FractNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fd6da00dbcdf3d04cb35a61cda01ae77 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/GradientSampleNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/GradientSampleNode.cs new file mode 100644 index 00000000..893521dc --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/GradientSampleNode.cs @@ -0,0 +1,207 @@ +using System; +using UnityEngine; +using UnityEditor; +using System.Collections; +using System.Collections.Generic; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Gradient Sample", "Miscellaneous", "Samples a gradient" )] + public sealed class GradientSampleNode : ParentNode + { + private string m_functionHeader = "SampleGradient( {0}, {1} )"; + private string m_functionBody = string.Empty; + + private GradientNode m_gradientNode = null; + private InputPort m_gradPort; + + private Gradient m_blankGrandient = new Gradient(); + + private int m_cachedTimeId = -1; + private int m_cachedTypeId = -1; + private int m_cachedColorNumId = -1; + private int m_cachedAlphaNumId = -1; + + private Vector4 m_auxVec4 = Vector4.zero; + + private string m_functionHeaderStruct = "Gradient( {0} )"; + private string m_functionBodyStruct = string.Empty; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.OBJECT, true, Constants.EmptyPortValue ); + AddInputPort( WirePortDataType.FLOAT, false, "Time" ); + AddOutputColorPorts( "RGBA", true ); + m_gradPort = m_inputPorts[ 0 ]; + m_useInternalPortData = true; + m_autoDrawInternalPortData = true; + m_drawPreviewExpander = false; + m_drawPreview = true; + m_showPreview = true; + m_selectedLocation = PreviewLocation.TopCenter; + m_previewShaderGUID = "8a09124cd6e4aa54a996e7487ec16b90"; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if( m_cachedTypeId == -1 ) + m_cachedTypeId = Shader.PropertyToID( "_GType" ); + + if( m_cachedTimeId == -1 ) + m_cachedTimeId = Shader.PropertyToID( "_GTime" ); + + if( m_cachedColorNumId == -1 ) + m_cachedColorNumId = Shader.PropertyToID( "_GColorNum" ); + + if( m_cachedAlphaNumId == -1 ) + m_cachedAlphaNumId = Shader.PropertyToID( "_GAlphaNum" ); + + PreviewMaterial.SetTexture( m_cachedTimeId, m_inputPorts[ 1 ].InputPreviewTexture( ContainerGraph ) ); + + Gradient curGrad = m_blankGrandient; + if( m_gradientNode != null ) + curGrad = m_gradientNode.Gradient; + + PreviewMaterial.SetInt( m_cachedTypeId, (int)curGrad.mode ); + PreviewMaterial.SetInt( m_cachedColorNumId, curGrad.colorKeys.Length ); + PreviewMaterial.SetInt( m_cachedAlphaNumId, curGrad.alphaKeys.Length ); + + for( int i = 0; i < 8; i++ ) + { + if( i < curGrad.colorKeys.Length ) + { + m_auxVec4.x = curGrad.colorKeys[ i ].color.r; + m_auxVec4.y = curGrad.colorKeys[ i ].color.g; + m_auxVec4.z = curGrad.colorKeys[ i ].color.b; + m_auxVec4.w = curGrad.colorKeys[ i ].time; + PreviewMaterial.SetVector( "_Col" + i, m_auxVec4 ); + } + else + { + PreviewMaterial.SetVector( "_Col" + i, Vector4.zero ); + } + } + + for( int i = 0; i < 8; i++ ) + { + if( i < curGrad.alphaKeys.Length ) + { + m_auxVec4.x = curGrad.alphaKeys[ i ].alpha; + m_auxVec4.y = curGrad.alphaKeys[ i ].time; + PreviewMaterial.SetVector( "_Alp" + i, m_auxVec4 ); + } + else + { + PreviewMaterial.SetVector( "_Alp" + i, Vector4.zero ); + } + } + } + + public override void OnNodeLogicUpdate( DrawInfo drawInfo ) + { + base.OnNodeLogicUpdate( drawInfo ); + + if( m_gradPort.IsConnected ) + { + m_gradientNode = RecursiveBackCheck( m_gradPort.GetOutputNode( 0 ) ); + } + else + { + m_gradientNode = null; + } + } + + GradientNode RecursiveBackCheck( ParentNode node ) + { + if( node is GradientNode ) + { + return node as GradientNode; + } + else + { + if( node is RelayNode || node is WireNode || node is RegisterLocalVarNode ) + { + return RecursiveBackCheck( node.InputPorts[ 0 ].GetOutputNode( 0 ) ); + } + else if( node is GetLocalVarNode) + { + var gnode = node as GetLocalVarNode; + if( gnode.CurrentSelected != null ) + return RecursiveBackCheck( gnode.CurrentSelected ); + else + return null; + } + else + { + return null; + } + } + + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + m_functionBodyStruct = string.Empty; + if( !dataCollector.IsSRP ) + { + GradientNode.GenerateGradientStruct( ref m_functionBodyStruct ); + dataCollector.AddFunctions( m_functionHeaderStruct, m_functionBodyStruct, "0" ); + } + else + { + dataCollector.AddToIncludes( UniqueId, "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" ); + } + + GenerateGradientSampler( dataCollector.IsSRP ); + + string gradient = "(Gradient)0"; + if( m_inputPorts[ 0 ].IsConnected && m_gradientNode != null ) + gradient = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string time = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + + string functionResult = dataCollector.AddFunctions( m_functionHeader, m_functionBody, gradient, time ); + return GetOutputVectorItem( 0, outputId, functionResult ); + } + + void GenerateGradientSampler( bool isSrp ) + { + m_functionBody = string.Empty; + IOUtils.AddFunctionHeader( ref m_functionBody, "float4 SampleGradient( Gradient gradient, float time )" ); + IOUtils.AddFunctionLine( ref m_functionBody, "float3 color = gradient.colors[0].rgb;" ); + IOUtils.AddFunctionLine( ref m_functionBody, "UNITY_UNROLL" ); + IOUtils.AddFunctionLine( ref m_functionBody, "for (int c = 1; c < 8; c++)" ); + IOUtils.AddFunctionLine( ref m_functionBody, "{" ); + if( isSrp ) + IOUtils.AddFunctionLine( ref m_functionBody, "float colorPos = saturate((time - gradient.colors[c-1].w) / (gradient.colors[c].w - gradient.colors[c-1].w)) * step(c, gradient.colorsLength-1);" ); + else + IOUtils.AddFunctionLine( ref m_functionBody, "float colorPos = saturate((time - gradient.colors[c-1].w) / (gradient.colors[c].w - gradient.colors[c-1].w)) * step(c, (float)gradient.colorsLength-1);" ); + IOUtils.AddFunctionLine( ref m_functionBody, "color = lerp(color, gradient.colors[c].rgb, lerp(colorPos, step(0.01, colorPos), gradient.type));" ); + IOUtils.AddFunctionLine( ref m_functionBody, "}" ); + + IOUtils.AddFunctionLine( ref m_functionBody, "#ifndef UNITY_COLORSPACE_GAMMA" ); + if( isSrp ) + IOUtils.AddFunctionLine( ref m_functionBody, "color = SRGBToLinear(color);" ); + else + IOUtils.AddFunctionLine( ref m_functionBody, "color = half3(GammaToLinearSpaceExact(color.r), GammaToLinearSpaceExact(color.g), GammaToLinearSpaceExact(color.b));" ); + IOUtils.AddFunctionLine( ref m_functionBody, "#endif" ); + + IOUtils.AddFunctionLine( ref m_functionBody, "float alpha = gradient.alphas[0].x;" ); + IOUtils.AddFunctionLine( ref m_functionBody, "UNITY_UNROLL" ); + IOUtils.AddFunctionLine( ref m_functionBody, "for (int a = 1; a < 8; a++)" ); + IOUtils.AddFunctionLine( ref m_functionBody, "{" ); + if( isSrp ) + IOUtils.AddFunctionLine( ref m_functionBody, "float alphaPos = saturate((time - gradient.alphas[a-1].y) / (gradient.alphas[a].y - gradient.alphas[a-1].y)) * step(a, gradient.alphasLength-1);" ); + else + IOUtils.AddFunctionLine( ref m_functionBody, "float alphaPos = saturate((time - gradient.alphas[a-1].y) / (gradient.alphas[a].y - gradient.alphas[a-1].y)) * step(a, (float)gradient.alphasLength-1);" ); + IOUtils.AddFunctionLine( ref m_functionBody, "alpha = lerp(alpha, gradient.alphas[a].x, lerp(alphaPos, step(0.01, alphaPos), gradient.type));" ); + IOUtils.AddFunctionLine( ref m_functionBody, "}" ); + IOUtils.AddFunctionLine( ref m_functionBody, "return float4(color, alpha);" ); + IOUtils.CloseFunctionBody( ref m_functionBody ); + } + + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/GradientSampleNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/GradientSampleNode.cs.meta new file mode 100644 index 00000000..51d0b9e5 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/GradientSampleNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b90e416e2fa93a249952fabc78f659c8 +timeCreated: 1562847602 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/InverseOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/InverseOpNode.cs new file mode 100644 index 00000000..178fc545 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/InverseOpNode.cs @@ -0,0 +1,138 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +// 4x4 Invert by DBN in +// http://answers.unity3d.com/questions/218333/shader-inversefloat4x4-function.html?childToView=641391#answer-641391 + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Inverse", "Matrix Operators", "Inverse matrix of a matrix" )] + public sealed class InverseOpNode : SingleInputOp + { + private string Inverse4x4Header = "Inverse4x4( {0} )"; + + //4x4 + private string[] Inverse4x4Function = + { + "{0}4x4 Inverse4x4({0}4x4 input)\n", + "{\n", + "\t#define minor(a,b,c) determinant({0}3x3(input.a, input.b, input.c))\n", + "\t{0}4x4 cofactors = {0}4x4(\n", + "\tminor( _22_23_24, _32_33_34, _42_43_44 ),\n", + "\t-minor( _21_23_24, _31_33_34, _41_43_44 ),\n", + "\tminor( _21_22_24, _31_32_34, _41_42_44 ),\n", + "\t-minor( _21_22_23, _31_32_33, _41_42_43 ),\n", + "\n", + "\t-minor( _12_13_14, _32_33_34, _42_43_44 ),\n", + "\tminor( _11_13_14, _31_33_34, _41_43_44 ),\n", + "\t-minor( _11_12_14, _31_32_34, _41_42_44 ),\n", + "\tminor( _11_12_13, _31_32_33, _41_42_43 ),\n", + "\n", + "\tminor( _12_13_14, _22_23_24, _42_43_44 ),\n", + "\t-minor( _11_13_14, _21_23_24, _41_43_44 ),\n", + "\tminor( _11_12_14, _21_22_24, _41_42_44 ),\n", + "\t-minor( _11_12_13, _21_22_23, _41_42_43 ),\n", + "\n", + "\t-minor( _12_13_14, _22_23_24, _32_33_34 ),\n", + "\tminor( _11_13_14, _21_23_24, _31_33_34 ),\n", + "\t-minor( _11_12_14, _21_22_24, _31_32_34 ),\n", + "\tminor( _11_12_13, _21_22_23, _31_32_33 ));\n", + "\t#undef minor\n", + "\treturn transpose( cofactors ) / determinant( input );\n", + "}\n" + }; + + private bool[] Inverse4x4FunctionFlags = + { + true, + false, + true, + true, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + }; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "inverse"; + m_drawPreview = false; + + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.FLOAT3x3, + WirePortDataType.FLOAT4x4 ); + m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4x4, false ); + m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4x4, 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 precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, WirePortDataType.FLOAT ); + string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + + if ( m_outputPorts[ 0 ].DataType == WirePortDataType.FLOAT3x3 ) + { + GeneratorUtils.Add3x3InverseFunction( ref dataCollector, precisionString ); + RegisterLocalVariable( 0, string.Format( GeneratorUtils.Inverse3x3Header, value ), ref dataCollector, "invertVal" + OutputId ); + } + else + { + if ( !dataCollector.HasFunction( Inverse4x4Header ) ) + { + //Hack to be used util indent is properly used + int currIndent = UIUtils.ShaderIndentLevel; + + if ( dataCollector.IsTemplate ) + { + UIUtils.ShaderIndentLevel = 0; + } + else + { + UIUtils.ShaderIndentLevel = 1; + UIUtils.ShaderIndentLevel++; + } + + string finalFunction = string.Empty; + for ( int i = 0; i < Inverse4x4Function.Length; i++ ) + { + finalFunction += UIUtils.ShaderIndentTabs + ( Inverse4x4FunctionFlags[ i ] ? string.Format( Inverse4x4Function[ i ], precisionString ) : Inverse4x4Function[ i ] ); + } + + + UIUtils.ShaderIndentLevel = currIndent; + + dataCollector.AddFunction( Inverse4x4Header, finalFunction ); + } + + RegisterLocalVariable( 0, string.Format( Inverse4x4Header, value ), ref dataCollector, "invertVal" + OutputId ); + } + + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/InverseOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/InverseOpNode.cs.meta new file mode 100644 index 00000000..bc47ad0f --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/InverseOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 785830160e033d24280df9c5b4cec368 +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LengthOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LengthOpNode.cs new file mode 100644 index 00000000..c67f26b4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LengthOpNode.cs @@ -0,0 +1,41 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +namespace AmplifyShaderEditor +{ + [System.Serializable] + [NodeAttributes( "Length", "Vector Operators", "Scalar Euclidean length of a vector" )] + public sealed class LengthOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "length"; + m_previewShaderGUID = "1c1f6d6512b758942a8b9dd1bea12f34"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false ); + m_autoUpdateOutputPort = false; + } + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + switch( m_inputPorts[0].DataType ) + { + case WirePortDataType.OBJECT: + case WirePortDataType.INT: + case WirePortDataType.FLOAT: + case WirePortDataType.UINT:m_previewMaterialPassId = 0;break; + case WirePortDataType.FLOAT2:m_previewMaterialPassId = 1;break; + case WirePortDataType.FLOAT3:m_previewMaterialPassId = 2;break; + case WirePortDataType.FLOAT4: + case WirePortDataType.COLOR:m_previewMaterialPassId = 3;break; + } + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LengthOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LengthOpNode.cs.meta new file mode 100644 index 00000000..c13dd4f4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LengthOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bb3fd570e41cfa24d93b53e80eac02d5 +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LerpOp.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LerpOp.cs new file mode 100644 index 00000000..1ec7199d --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LerpOp.cs @@ -0,0 +1,116 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Lerp", "Math Operators", "Linear interpolation of two scalars or vectors based on a weight", null, KeyCode.L )] + public sealed class LerpOp : ParentNode + { + private const string LertOpFormat = "lerp( {0} , {1} , {2})"; + + [UnityEngine.SerializeField] + private WirePortDataType m_mainDataType = WirePortDataType.FLOAT; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_textLabelWidth = 55; + AddInputPort( WirePortDataType.FLOAT, false, "A" ); + AddInputPort( WirePortDataType.FLOAT, false, "B" ); + AddInputPort( WirePortDataType.FLOAT, false, "Alpha" ); + AddOutputPort( WirePortDataType.FLOAT,Constants.EmptyPortValue); + m_useInternalPortData = true; + m_previewShaderGUID = "34d9c4cdcf1fadb49af2de3f90bbc57d"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + UpdateConnection( portId ); + } + + public override void OnConnectedOutputNodeChanges( int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( inputPortId, otherNodeId, otherPortId, name, type ); + UpdateConnection( inputPortId ); + } + + public override void OnInputPortDisconnected( int portId ) + { + base.OnInputPortDisconnected( portId ); + UpdateConnection( portId ); + } + + void UpdateConnection( int portId ) + { + WirePortDataType type1 = WirePortDataType.FLOAT; + if( m_inputPorts[ 0 ].IsConnected ) + type1 = m_inputPorts[ 0 ].GetOutputConnection( 0 ).DataType; + + WirePortDataType type2 = WirePortDataType.FLOAT; + if( m_inputPorts[ 1 ].IsConnected ) + type2 = m_inputPorts[ 1 ].GetOutputConnection( 0 ).DataType; + + WirePortDataType typealpha = WirePortDataType.FLOAT; + if( m_inputPorts[ 2 ].IsConnected ) + typealpha = m_inputPorts[ 2 ].GetOutputConnection( 0 ).DataType; + + m_mainDataType = UIUtils.GetPriority( type1 ) > UIUtils.GetPriority( type2 ) ? type1 : type2; + + if( !m_inputPorts[ 0 ].IsConnected && !m_inputPorts[ 1 ].IsConnected && m_inputPorts[ 2 ].IsConnected ) + m_mainDataType = m_inputPorts[ 2 ].GetOutputConnection( 0 ).DataType; + + m_inputPorts[ 0 ].ChangeType( m_mainDataType, false ); + + m_inputPorts[ 1 ].ChangeType( m_mainDataType, false ); + if( m_inputPorts[ 2 ].IsConnected && ( typealpha == WirePortDataType.FLOAT || typealpha == WirePortDataType.INT ) ) + m_inputPorts[ 2 ].ChangeType( WirePortDataType.FLOAT, false ); + else + m_inputPorts[ 2 ].ChangeType( m_mainDataType, false ); + + m_outputPorts[ 0 ].ChangeType( m_mainDataType, false ); + } + + //void UpdateDisconnection( int portId ) + //{ + // int otherPortId = ( portId + 1 ) % 2; + // if ( m_inputPorts[ otherPortId ].IsConnected ) + // { + // m_mainDataType = m_inputPorts[ otherPortId ].DataType; + // m_inputPorts[ portId ].ChangeType( m_mainDataType, false ); + // m_outputPorts[ 0 ].ChangeType( m_mainDataType, 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 aValue = m_inputPorts[ 0 ].GenerateShaderForOutput( ref dataCollector, m_mainDataType, ignoreLocalVar, true ); + string bValue = m_inputPorts[ 1 ].GenerateShaderForOutput( ref dataCollector, m_mainDataType, ignoreLocalVar, true ); + string interp = string.Empty; + if( m_inputPorts[ 2 ].DataType == WirePortDataType.FLOAT ) + interp = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + else + interp = m_inputPorts[ 2 ].GenerateShaderForOutput( ref dataCollector, m_mainDataType, ignoreLocalVar,true ); + string result = string.Format( LertOpFormat, aValue,bValue,interp); + + RegisterLocalVariable( 0, result, ref dataCollector, "lerpResult"+OutputId ); + + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + + //public override void RefreshExternalReferences() + //{ + // if ( m_inputPorts[ 2 ].DataType != WirePortDataType.FLOAT ) + // { + // m_inputPorts[ 2 ].ChangeType( WirePortDataType.FLOAT, false ); + // } + //} + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LerpOp.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LerpOp.cs.meta new file mode 100644 index 00000000..22b8eec4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LerpOp.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1e38abf6e3c7dfa409a5fe40d2ce8a19 +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log10OpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log10OpNode.cs new file mode 100644 index 00000000..35914c34 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log10OpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Log10", "Math Operators", "Base-10 logarithm of scalars and vectors" )] + public sealed class Log10OpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "log10"; + m_previewShaderGUID = "9e7cfa357dd261f499d0ba8637ff2614"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log10OpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log10OpNode.cs.meta new file mode 100644 index 00000000..e9ae3c31 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log10OpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: be47a76f1f42fbe47bf2568584c31196 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log2OpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log2OpNode.cs new file mode 100644 index 00000000..614a82a2 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log2OpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Log2", "Math Operators", "Base-2 logarithm of scalars and vectors" )] + public sealed class Log2OpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "log2"; + m_previewShaderGUID = "5975a154432d4c64cacd78d015ed08ba"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log2OpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log2OpNode.cs.meta new file mode 100644 index 00000000..9511991b --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/Log2OpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b9489308aad1f794982afc1faf646013 +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LogOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LogOpNode.cs new file mode 100644 index 00000000..ff7d7863 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LogOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Log", "Math Operators", "Natural logarithm of scalars and vectors" )] + public sealed class LogOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "log"; + m_previewShaderGUID = "a3293e0a73834b24682775f5d8ee1e7c"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LogOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LogOpNode.cs.meta new file mode 100644 index 00000000..7aab4f70 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/LogOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1ed2c12cea61a8c4fa67eebdc10d2a2a +timeCreated: 1481126954 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/MultipleInputOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/MultipleInputOpNode.cs new file mode 100644 index 00000000..9cb64e97 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/MultipleInputOpNode.cs @@ -0,0 +1,3 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +// Deprecated file diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/MultipleInputOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/MultipleInputOpNode.cs.meta new file mode 100644 index 00000000..597824ca --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/MultipleInputOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 8804c7e5888738547b5a704f788fc18b +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NegateNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NegateNode.cs new file mode 100644 index 00000000..00c174dc --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NegateNode.cs @@ -0,0 +1,46 @@ +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Negate", "Math Operators", "Negate or invert an input value" )] + public sealed class NegateNode : ParentNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_useInternalPortData = true; + m_previewShaderGUID = "b035bc40da1ac7c4eafad4116382ec79"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + m_inputPorts[ 0 ].MatchPortToConnection(); + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + m_inputPorts[ 0 ].MatchPortToConnection(); + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + string result = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + + if ( result.StartsWith( "-" ) ) + { + return result.Remove( 0, 1 ); + } + else + { + return "-" + result; + } + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NegateNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NegateNode.cs.meta new file mode 100644 index 00000000..83f5922e --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NegateNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 01c91005470f6b94eba168a127cecd6c +timeCreated: 1481126953 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NormalizeNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NormalizeNode.cs new file mode 100644 index 00000000..140a1173 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NormalizeNode.cs @@ -0,0 +1,55 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Normalize", "Vector Operators", "Normalizes a vector", null, KeyCode.N )] + public sealed class NormalizeNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_selectedLocation = PreviewLocation.TopCenter; + m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false ); + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.FLOAT, WirePortDataType.FLOAT2, WirePortDataType.FLOAT3, WirePortDataType.FLOAT4, WirePortDataType.COLOR, WirePortDataType.OBJECT, WirePortDataType.INT ); + m_previewShaderGUID = "a51b11dfb6b32884e930595e5f9defa8"; + } + 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 result = string.Empty; + switch ( m_inputPorts[ 0 ].DataType ) + { + case WirePortDataType.FLOAT: + case WirePortDataType.FLOAT2: + case WirePortDataType.FLOAT3: + case WirePortDataType.FLOAT4: + case WirePortDataType.OBJECT: + case WirePortDataType.COLOR: + { + result = "normalize( " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + " )"; + } + break; + case WirePortDataType.INT: + { + return m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + } + case WirePortDataType.FLOAT3x3: + case WirePortDataType.FLOAT4x4: + { + result = UIUtils.InvalidParameter( this ); + } + break; + } + RegisterLocalVariable( 0, result, ref dataCollector, "normalizeResult" + OutputId ); + + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NormalizeNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NormalizeNode.cs.meta new file mode 100644 index 00000000..8bec377b --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/NormalizeNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fa6682c371754094f88b3c2a7e96ae26 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/OneMinusNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/OneMinusNode.cs new file mode 100644 index 00000000..10792114 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/OneMinusNode.cs @@ -0,0 +1,45 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "One Minus", "Math Operators", "1 - input value", null, KeyCode.O )] + public sealed class OneMinusNode : ParentNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_useInternalPortData = true; + m_previewShaderGUID = "bed5300b92e7bb0419d0f4accb853312"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + m_inputPorts[ 0 ].MatchPortToConnection(); + m_outputPorts[ 0 ].ChangeType( InputPorts[ 0 ].DataType, false ); + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + m_inputPorts[ 0 ].MatchPortToConnection(); + m_outputPorts[ 0 ].ChangeType( 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 result = "( 1.0 - " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + " )"; + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/OneMinusNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/OneMinusNode.cs.meta new file mode 100644 index 00000000..ff94c53d --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/OneMinusNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 727743b66e17d7b4f9c2fbe7dde98bd9 +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/PowerNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/PowerNode.cs new file mode 100644 index 00000000..82357b67 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/PowerNode.cs @@ -0,0 +1,93 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Power", "Math Operators", "Base to the Exp-th power of scalars and vectors", null, KeyCode.E )] + public sealed class PowerNode : ParentNode + { + public const string SafePowerStr = "max( {0} , 0.0001 )"; + public const string SafePowerLabel = "Safe Power"; + + [SerializeField] + private bool m_safePower = false; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, "Base" ); + AddInputPort( WirePortDataType.FLOAT, false, "Exp" ); + m_inputPorts[ 1 ].FloatInternalData = 1; + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_useInternalPortData = true; + m_autoWrapProperties = true; + m_textLabelWidth = 85; + m_previewShaderGUID = "758cc2f8b537b4e4b93d9833075d138c"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + UpdateConnections( portId ); + } + + public override void OnConnectedOutputNodeChanges( int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( inputPortId, otherNodeId, otherPortId, name, type ); + UpdateConnections( inputPortId ); + } + + void UpdateConnections( int inputPort ) + { + m_inputPorts[ inputPort ].MatchPortToConnection(); + if ( inputPort == 0 ) + { + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + } + + public override void DrawProperties() + { + base.DrawProperties(); + m_safePower = EditorGUILayoutToggle( SafePowerLabel, m_safePower ); + } + + 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 x = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + if( m_safePower ) + { + string safePowerName = "saferPower" + OutputId; + string safePowerValue = string.Format( SafePowerStr, x ); + dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, m_inputPorts[ 0 ].DataType, safePowerName, safePowerValue ); + x = safePowerName; + } + + string y = m_inputPorts[ 1 ].GenerateShaderForOutput( ref dataCollector, m_inputPorts[ 0 ].DataType, ignoreLocalvar, true ); + string result = "pow( " + x + " , " + y + " )"; + + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + if( UIUtils.CurrentShaderVersion() > 17502 ) + m_safePower = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_safePower ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/PowerNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/PowerNode.cs.meta new file mode 100644 index 00000000..bedc464e --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/PowerNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 520a55839e863ce47b3558be612f4691 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RSqrtOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RSqrtOpNode.cs new file mode 100644 index 00000000..659c86cd --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RSqrtOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Rsqrt", "Math Operators", "Reciprocal square root of scalars and vectors" )] + public sealed class RSqrtOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "rsqrt"; + m_previewShaderGUID = "c58c17cb1f7f6e6429a2c7a6cdaef87d"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RSqrtOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RSqrtOpNode.cs.meta new file mode 100644 index 00000000..e124e47a --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RSqrtOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 513de50bd4766d0448bb471ca272608f +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RadiansOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RadiansOpNode.cs new file mode 100644 index 00000000..19f478ff --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RadiansOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Radians", "Trigonometry Operators", "Converts values of scalars and vectors from degrees to radians" )] + public sealed class RadiansOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "radians"; + m_previewShaderGUID = "d27d189eaf6eeb04fae9913d9617ece5"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RadiansOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RadiansOpNode.cs.meta new file mode 100644 index 00000000..f90ec876 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RadiansOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b6ca01d5c16f73c42996318c140eddb7 +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ReflectOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ReflectOpNode.cs new file mode 100644 index 00000000..1488cb1c --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ReflectOpNode.cs @@ -0,0 +1,33 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Reflect", "Vector Operators", "Reflection vector given an incidence vector and a normal vector" )] + public sealed class ReflectOpNode : DynamicTypeNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_inputPorts[ 0 ].ChangeProperties( "Incident", WirePortDataType.FLOAT4, false ); + m_inputPorts[ 1 ].ChangeProperties( "Normal", WirePortDataType.FLOAT4, false ); + m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false ); + + m_textLabelWidth = 67; + m_previewShaderGUID = "fb520f2145c0fa0409320a9e6d720758"; + } + + public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + + base.BuildResults( outputId, ref dataCollector, ignoreLocalvar ); + string result = "reflect( " + m_inputA + " , " + m_inputB + " )"; + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ReflectOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ReflectOpNode.cs.meta new file mode 100644 index 00000000..2b7f085f --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ReflectOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bcd77715f8db1564abc96d502312d476 +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RefractOpVec.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RefractOpVec.cs new file mode 100644 index 00000000..ba59e2ca --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RefractOpVec.cs @@ -0,0 +1,92 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Refract", "Vector Operators", "Computes a refraction vector" )] + public sealed class RefractOpVec : ParentNode + { + [UnityEngine.SerializeField] + private WirePortDataType m_mainDataType = WirePortDataType.FLOAT; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT4, false , "Incident" ); + AddInputPort( WirePortDataType.FLOAT4, false , "Normal" ); + AddInputPort( WirePortDataType.FLOAT, false, "Eta" ); + AddOutputPort( WirePortDataType.FLOAT4, Constants.EmptyPortValue ); + m_textLabelWidth = 67; + m_previewShaderGUID = "5ab44ca484bed8b4884b03b1c00fdc3d"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + UpdateConnection( portId ); + } + + public override void OnConnectedOutputNodeChanges( int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( inputPortId, otherNodeId, otherPortId, name, type ); + UpdateConnection( inputPortId ); + } + + public override void OnInputPortDisconnected( int portId ) + { + base.OnInputPortDisconnected( portId ); + UpdateConnection( portId ); + } + + void UpdateConnection( int portId ) + { + if( portId == 2 ) + return; + + bool hasConnection = false; + + WirePortDataType type1 = WirePortDataType.FLOAT; + if( m_inputPorts[ 0 ].IsConnected ) + { + type1 = m_inputPorts[ 0 ].GetOutputConnection( 0 ).DataType; + hasConnection = true; + } + WirePortDataType type2 = WirePortDataType.FLOAT; + if( m_inputPorts[ 1 ].IsConnected ) + { + type2 = m_inputPorts[ 1 ].GetOutputConnection( 0 ).DataType; + hasConnection = true; + } + + if( hasConnection ) + { + m_mainDataType = UIUtils.GetPriority( type1 ) > UIUtils.GetPriority( type2 ) ? type1 : type2; + } + else + { + m_mainDataType = WirePortDataType.FLOAT4; + } + + m_inputPorts[ 0 ].ChangeType( m_mainDataType, false ); + m_inputPorts[ 1 ].ChangeType( m_mainDataType, false ); + m_outputPorts[ 0 ].ChangeType( m_mainDataType, 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 incident = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string normal = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector ); + string interp = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector ); + string result = "refract( " + incident + " , " + normal + " , " + interp + " )"; + + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RefractOpVec.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RefractOpVec.cs.meta new file mode 100644 index 00000000..58b705a4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RefractOpVec.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c5bb608b83cdc894cab572c72baa5f84 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RoundOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RoundOpNode.cs new file mode 100644 index 00000000..95b1dd8f --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RoundOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Round", "Math Operators", "Rounded value of scalars or vectors" )] + public sealed class RoundOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "round"; + m_previewShaderGUID = "554d561417b207c4bb3cd4a0c86b6907"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RoundOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RoundOpNode.cs.meta new file mode 100644 index 00000000..9b3740db --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/RoundOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f7b5f29bc7f6bb844ae4ea698404adc3 +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SaturateNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SaturateNode.cs new file mode 100644 index 00000000..ed91f4d4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SaturateNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Saturate", "Math Operators", "Saturate clamps the input values into the [0,1] range" )] + public sealed class SaturateNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "saturate"; + m_previewShaderGUID = "d9e53418dc8b9d34fb395e3ea3c75985"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SaturateNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SaturateNode.cs.meta new file mode 100644 index 00000000..e199e9cf --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SaturateNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9d56f68d94c889443af651140ef86948 +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleAndOffsetNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleAndOffsetNode.cs new file mode 100644 index 00000000..0d79fe81 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleAndOffsetNode.cs @@ -0,0 +1,78 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Scale And Offset", "Math Operators", "Scales and offsets an input value\n( ( <b>Value</b> * <b>Scale</b> ) + <b>Offset</b> )" )] + public sealed class ScaleAndOffsetNode : ParentNode + { + private const string ScaleOffsetOpStr = "({0}*{1} + {2})"; + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue ); + AddInputPort( WirePortDataType.FLOAT, false, "Scale" ); + m_inputPorts[ 1 ].FloatInternalData = 1; + AddInputPort( WirePortDataType.FLOAT, false, "Offset" ); + AddOutputPort( WirePortDataType.FLOAT, " " ); + m_useInternalPortData = true; + m_previewShaderGUID = "a1f1053d4d9c3be439e0382038b74771"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + UpdateConnection( portId ); + } + + public override void OnConnectedOutputNodeChanges( int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( inputPortId, otherNodeId, otherPortId, name, type ); + UpdateConnection( inputPortId ); + } + + public override void OnInputPortDisconnected( int portId ) + { + base.OnInputPortDisconnected( portId ); + m_inputPorts[ portId ].ChangeType( WirePortDataType.FLOAT, false ); + if( portId == 0 ) + { + m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT, false ); + } + } + + void UpdateConnection( int portId ) + { + if( portId == 0 ) + { + m_inputPorts[ 0 ].MatchPortToConnection(); + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + else + { + WirePortDataType newDataType = m_inputPorts[ portId ].ConnectionType() == WirePortDataType.FLOAT ? WirePortDataType.FLOAT : m_outputPorts[ 0 ].DataType; + m_inputPorts[ portId ].ChangeType( newDataType, 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 value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + + // If scale or offset ports are floats then there's no need to cast them to any other type since they can be multiplied with everything + WirePortDataType scaleType = ( m_inputPorts[ 1 ].ConnectionType() == WirePortDataType.FLOAT ) ? WirePortDataType.FLOAT : m_outputPorts[ 0 ].DataType; + string scale = m_inputPorts[ 1 ].GenerateShaderForOutput( ref dataCollector, scaleType, ignoreLocalvar , true ); + + WirePortDataType offsetType = ( m_inputPorts[ 2 ].ConnectionType() == WirePortDataType.FLOAT ) ? WirePortDataType.FLOAT : m_outputPorts[ 0 ].DataType; + string offset = m_inputPorts[ 2 ].GenerateShaderForOutput( ref dataCollector, offsetType, ignoreLocalvar, true ); + + string result = string.Format( ScaleOffsetOpStr, value, scale, offset ); + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleAndOffsetNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleAndOffsetNode.cs.meta new file mode 100644 index 00000000..4a508a82 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleAndOffsetNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b594feaa69ad03449b563f834fe0c18e +timeCreated: 1484582091 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleNode.cs new file mode 100644 index 00000000..7445a10d --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleNode.cs @@ -0,0 +1,152 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Scale", "Math Operators", "Scales input value by a float factor" )] + public sealed class ScaleNode : ParentNode + { + private const string ScaleFactorStr = "Scale"; + + [SerializeField] + private float m_scaleFactor = 1; + + private int m_cachedPropertyId = -1; + + private const float LabelWidth = 8; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, " " ); + AddOutputPort( WirePortDataType.FLOAT, " " ); + m_insideSize.Set( 50, 10 ); + m_autoWrapProperties = true; + m_previewShaderGUID = "6d8ec9d9dab62c44aa2dcc0e3987760d"; + } + + public override void SetPreviewInputs() + { + base.SetPreviewInputs(); + + if ( m_cachedPropertyId == -1 ) + m_cachedPropertyId = Shader.PropertyToID( "_ScaleFloat" ); + + PreviewMaterial.SetFloat( m_cachedPropertyId, m_scaleFactor ); + } + + public override void DrawProperties() + { + base.DrawProperties(); + m_scaleFactor = EditorGUILayoutFloatField( ScaleFactorStr, m_scaleFactor ); + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + m_inputPorts[ 0 ].MatchPortToConnection(); + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + m_inputPorts[ 0 ].MatchPortToConnection(); + m_outputPorts[ 0 ].ChangeType( InputPorts[ 0 ].DataType, false ); + } + + public override void OnNodeLayout( DrawInfo drawInfo ) + { + base.OnNodeLayout( drawInfo ); + + m_propertyDrawPos.x = m_remainingBox.x + Constants.FLOAT_WIDTH_SPACING * drawInfo.InvertedZoom * 0.5f; + m_propertyDrawPos.y = m_remainingBox.y + Constants.INPUT_PORT_DELTA_Y * drawInfo.InvertedZoom * 0.5f; + m_propertyDrawPos.width = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_WIDTH_FIELD_SIZE; + m_propertyDrawPos.height = drawInfo.InvertedZoom * Constants.FLOAT_DRAW_HEIGHT_FIELD_SIZE; + } + + public override void DrawGUIControls( DrawInfo drawInfo ) + { + base.DrawGUIControls( drawInfo ); + + if ( drawInfo.CurrentEventType != EventType.MouseDown ) + return; + + Rect hitBox = m_remainingBox; + hitBox.xMin -= LabelWidth * drawInfo.InvertedZoom; + bool insideBox = hitBox.Contains( drawInfo.MousePosition ); + + if ( insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = true; + } + else if ( m_isEditingFields && !insideBox ) + { + GUI.FocusControl( null ); + m_isEditingFields = false; + } + } + + private bool m_isEditingFields; + private float m_previousValue; + private string m_fieldText = "0"; + + public override void Draw( DrawInfo drawInfo ) + { + base.Draw( drawInfo ); + + if ( !m_isVisible ) + return; + + if ( m_isEditingFields ) + { + UIUtils.DrawFloat( this, ref m_propertyDrawPos, ref m_scaleFactor, LabelWidth ); + } + else if ( drawInfo.CurrentEventType == EventType.Repaint ) + { + Rect fakeField = m_propertyDrawPos; + fakeField.xMin += LabelWidth * drawInfo.InvertedZoom; + Rect fakeLabel = m_propertyDrawPos; + fakeLabel.xMax = fakeField.xMin; + EditorGUIUtility.AddCursorRect( fakeLabel, MouseCursor.SlideArrow ); + EditorGUIUtility.AddCursorRect( fakeField, MouseCursor.Text ); + + if ( m_previousValue != m_scaleFactor ) + { + m_previousValue = m_scaleFactor; + m_fieldText = m_scaleFactor.ToString(); + } + + GUI.Label( fakeField, m_fieldText, UIUtils.MainSkin.textField ); + } + } + + 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 portResult = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string result = "( " + portResult + " * " + m_scaleFactor + " )"; + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_scaleFactor ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_scaleFactor = Convert.ToSingle( GetCurrentParam( ref nodeParams ) ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleNode.cs.meta new file mode 100644 index 00000000..49bd4b82 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/ScaleNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ec926b11f9c698c458f746e4e55fd7df +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SignOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SignOpNode.cs new file mode 100644 index 00000000..90f83dcf --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SignOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Sign", "Math Operators", "Sign of scalar or each vector component" )] + public sealed class SignOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "sign"; + m_previewShaderGUID = "3aca80b49aadf5046b7133730818e18f"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT , + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR , + WirePortDataType.INT); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SignOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SignOpNode.cs.meta new file mode 100644 index 00000000..1a1d0ff6 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SignOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 429f407c2b590df45b215f0edfa49b97 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SimplifiedFModOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SimplifiedFModOpNode.cs new file mode 100644 index 00000000..4726b848 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SimplifiedFModOpNode.cs @@ -0,0 +1,32 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Simplified Fmod", "Math Operators", "Floating point remainder of x/y" )] + public sealed class SimplifiedFModOpNode : DynamicTypeNode + { + private const string FmodCustomOp = "frac({0}/{1})*{1}"; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_previewShaderGUID = "2688236fb4f37ce47b81cc818c53321d"; + } + + public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) ) + { + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + + base.BuildResults( outputId, ref dataCollector, ignoreLocalvar ); + RegisterLocalVariable( 0, string.Format( FmodCustomOp, m_inputA, m_inputB ), ref dataCollector, ( "fmodResult" + OutputId ) ); + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SimplifiedFModOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SimplifiedFModOpNode.cs.meta new file mode 100644 index 00000000..77efda87 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SimplifiedFModOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f186e1b03a8ee2b4b9e45918576e8cf6 +timeCreated: 1484731588 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinOpNode.cs new file mode 100644 index 00000000..6d0d363b --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Sin", "Trigonometry Operators", "Sine of scalars and vectors" )] + public sealed class SinOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "sin"; + m_previewShaderGUID = "bcd9f8749ddd3ac4f94f4c2071c1d0d4"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinOpNode.cs.meta new file mode 100644 index 00000000..24e23e66 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: be2a11b08ee8cbb458dbcc4c1a61ad1b +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SingleInputOp.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SingleInputOp.cs new file mode 100644 index 00000000..4af0cba4 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SingleInputOp.cs @@ -0,0 +1,67 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using System; + + +namespace AmplifyShaderEditor +{ + [Serializable] + public class SingleInputOp : ParentNode + { + + [SerializeField] + protected string m_opName; + //[SerializeField] + //protected int m_validTypes; + + protected bool m_autoUpdateOutputPort = true; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue ); + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + //m_validTypes = 0; + m_useInternalPortData = true; + + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + m_inputPorts[ 0 ].MatchPortToConnection(); + if ( m_autoUpdateOutputPort ) + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + m_inputPorts[ 0 ].MatchPortToConnection(); + if ( m_autoUpdateOutputPort ) + 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 result = "0"; + if ( m_inputPorts[ 0 ].IsConnected ) + { + ParentNode node = m_inputPorts[ 0 ].GetOutputNode(); + int localOutputId = m_inputPorts[ 0 ].ExternalReferences[ 0 ].PortId; + result = m_opName + "( " + node.GenerateShaderForOutput( localOutputId, ref dataCollector, ignoreLocalvar ) + " )"; + } + else + { + result = m_opName + "( " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + " )"; + } + + return CreateOutputLocalVariable( 0, result, ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SingleInputOp.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SingleInputOp.cs.meta new file mode 100644 index 00000000..751db40f --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SingleInputOp.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ed03e964ff9aa274cbf392769b61170b +timeCreated: 1481126960 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinhOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinhOpNode.cs new file mode 100644 index 00000000..f38a192a --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinhOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Sinh", "Trigonometry Operators", "Hyperbolic sine of scalars and vectors" )] + public sealed class SinhOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "sinh"; + m_previewShaderGUID = "4e9c00e6dceb4024f80d4e3d7786abad"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinhOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinhOpNode.cs.meta new file mode 100644 index 00000000..292ae67c --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SinhOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 52092e3985c556943895f86c585bcd25 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SmoothstepOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SmoothstepOpNode.cs new file mode 100644 index 00000000..09d86cb0 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SmoothstepOpNode.cs @@ -0,0 +1,122 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Smoothstep", "Math Operators", "Returns a smooth Hermite interpolation between 0 and 1, if input is in the range [min, max]." )] + public sealed class SmoothstepOpNode : ParentNode + { + //[UnityEngine.SerializeField] + //private WirePortDataType m_mainDataType = WirePortDataType.FLOAT; + + private int m_alphaPortId = 0; + private int m_minPortId = 0; + private int m_maxPortId = 0; + private const string SmoothstepOpFormat = "smoothstep( {0} , {1} , {2})";//min max alpha + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue, -1, MasterNodePortCategory.Fragment, 0 ); + m_alphaPortId = m_inputPorts.Count - 1; + AddInputPort( WirePortDataType.FLOAT, false, "Min", -1, MasterNodePortCategory.Fragment, 1 ); + m_minPortId = m_inputPorts.Count - 1; + AddInputPort( WirePortDataType.FLOAT, false, "Max", -1, MasterNodePortCategory.Fragment, 2 ); + m_maxPortId = m_inputPorts.Count - 1; + + GetInputPortByUniqueId( m_maxPortId ).FloatInternalData = 1; + + AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue ); + m_useInternalPortData = true; + m_textLabelWidth = 55; + m_previewShaderGUID = "954cdd40a7a528344a0a4d3ff1db5176"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + if( portId == 0 ) + { + m_inputPorts[ 0 ].MatchPortToConnection(); + m_inputPorts[ 1 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_inputPorts[ 2 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + if( outputPortId == 0 ) + { + m_inputPorts[ 0 ].MatchPortToConnection(); + m_inputPorts[ 1 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_inputPorts[ 2 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + } + + //public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + //{ + // base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + // UpdateConnection( portId ); + //} + + //public override void OnConnectedOutputNodeChanges( int inputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + //{ + // base.OnConnectedOutputNodeChanges( inputPortId, otherNodeId, otherPortId, name, type ); + // UpdateConnection( inputPortId ); + //} + + //public override void OnInputPortDisconnected( int portId ) + //{ + // base.OnInputPortDisconnected( portId ); + // UpdateConnection( portId ); + //} + + //void UpdateConnection( int portId ) + //{ + // WirePortDataType type1 = WirePortDataType.FLOAT; + // if( m_inputPorts[ m_minPortId ].IsConnected ) + // type1 = m_inputPorts[ m_minPortId ].GetOutputConnection( 0 ).DataType; + + // WirePortDataType type2 = WirePortDataType.FLOAT; + // if( m_inputPorts[ m_maxPortId ].IsConnected ) + // type2 = m_inputPorts[ m_maxPortId ].GetOutputConnection( 0 ).DataType; + + // m_mainDataType = UIUtils.GetPriority( type1 ) > UIUtils.GetPriority( type2 ) ? type1 : type2; + + // if( !m_inputPorts[ m_minPortId ].IsConnected && !m_inputPorts[ m_maxPortId ].IsConnected && m_inputPorts[ m_alphaPortId ].IsConnected ) + // m_mainDataType = m_inputPorts[ m_alphaPortId ].GetOutputConnection( 0 ).DataType; + + // m_inputPorts[ m_minPortId ].ChangeType( m_mainDataType, false ); + + // m_inputPorts[ m_maxPortId ].ChangeType( m_mainDataType, false ); + // if( m_inputPorts[ m_alphaPortId ].IsConnected && m_inputPorts[ m_alphaPortId ].GetOutputConnection( 0 ).DataType == WirePortDataType.FLOAT ) + // m_inputPorts[ m_alphaPortId ].ChangeType( WirePortDataType.FLOAT, false ); + // else + // m_inputPorts[ m_alphaPortId ].ChangeType( m_mainDataType, false ); + + // m_outputPorts[ 0 ].ChangeType( m_mainDataType, 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 aValue = m_inputPorts[ m_minPortId ].GeneratePortInstructions( ref dataCollector ); + string bValue = m_inputPorts[ m_maxPortId ].GeneratePortInstructions( ref dataCollector ); + string interp = m_inputPorts[ m_alphaPortId ].GeneratePortInstructions( ref dataCollector ); + + string result = string.Format( SmoothstepOpFormat, aValue, bValue, interp ); + + RegisterLocalVariable( 0, result, ref dataCollector, "smoothstepResult" + OutputId ); + + return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SmoothstepOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SmoothstepOpNode.cs.meta new file mode 100644 index 00000000..98387ebd --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SmoothstepOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0f64eb769f843a349a0d249beacc6fc3 +timeCreated: 1481126953 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SqrtOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SqrtOpNode.cs new file mode 100644 index 00000000..e35c1b25 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SqrtOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Sqrt", "Math Operators", "Square root of scalars and vectors" )] + public sealed class SqrtOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "sqrt"; + m_previewShaderGUID = "1791e2fbf36af084da7ecfc289e89b6e"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SqrtOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SqrtOpNode.cs.meta new file mode 100644 index 00000000..164b7c59 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/SqrtOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4820b591b73a7fe4ab13261deebf76f7 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/StepOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/StepOpNode.cs new file mode 100644 index 00000000..ab1a1b86 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/StepOpNode.cs @@ -0,0 +1,24 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Step", "Math Operators", "Step function returning either zero or one" )] + public sealed class StepOpNode : DynamicTypeNode + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_previewShaderGUID = "2c757add7f97ecd4abd9ce6ec4659697"; + } + + public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + base.BuildResults( outputId, ref dataCollector, ignoreLocalvar ); + return "step( " + m_inputA + " , " + m_inputB + " )"; + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/StepOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/StepOpNode.cs.meta new file mode 100644 index 00000000..52155547 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/StepOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c4305e64271097249a198b2e8aed3046 +timeCreated: 1481126959 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TFHCRemapNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TFHCRemapNode.cs new file mode 100644 index 00000000..1b77ed5f --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TFHCRemapNode.cs @@ -0,0 +1,64 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> +// +// Custom Node Remap +// Donated by The Four Headed Cat - @fourheadedcat +using UnityEngine; +using System; +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Remap", "Math Operators", "Remap value from old min - max range to new min - max range", null, KeyCode.None, true, false, null, null, "The Four Headed Cat - @fourheadedcat" )] + public sealed class TFHCRemapNode : DynamicTypeNode + { + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_inputPorts[ 0 ].Name = Constants.EmptyPortValue; + m_inputPorts[ 1 ].Name = "Min Old"; + AddInputPort( WirePortDataType.FLOAT, false, "Max Old" ); + m_inputPorts[ 2 ].FloatInternalData = 1; + AddInputPort( WirePortDataType.FLOAT, false, "Min New" ); + AddInputPort( WirePortDataType.FLOAT, false, "Max New" ); + m_inputPorts[ 4 ].FloatInternalData = 1; + m_textLabelWidth = 100; + m_useInternalPortData = true; + m_previewShaderGUID = "72dd1cbea889fa047b929d5191e360c0"; + } + + public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true ) + { + base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode ); + UpdateConnections(); + } + + public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) + { + base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type ); + UpdateConnections(); + } + + void UpdateConnections() + { + m_inputPorts[ 0 ].MatchPortToConnection(); + m_inputPorts[ 1 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_inputPorts[ 2 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_inputPorts[ 3 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_inputPorts[ 4 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false ); + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + string oldMin = m_inputPorts[ 1 ].GenerateShaderForOutput( ref dataCollector, m_inputPorts[ 0 ].DataType, ignoreLocalvar, true ); + string oldMax = m_inputPorts[ 2 ].GenerateShaderForOutput( ref dataCollector, m_inputPorts[ 0 ].DataType, ignoreLocalvar, true ); + string newMin = m_inputPorts[ 3 ].GenerateShaderForOutput( ref dataCollector, m_inputPorts[ 0 ].DataType, ignoreLocalvar, true ); + string newMax = m_inputPorts[ 4 ].GenerateShaderForOutput( ref dataCollector, m_inputPorts[ 0 ].DataType, ignoreLocalvar, true ); + string strout = "(" + newMin + " + (" + value + " - " + oldMin + ") * (" + newMax + " - " + newMin + ") / (" + oldMax + " - " + oldMin + "))"; + + return CreateOutputLocalVariable( 0, strout, ref dataCollector ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TFHCRemapNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TFHCRemapNode.cs.meta new file mode 100644 index 00000000..e255ee66 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TFHCRemapNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 637508d44a97b5449a3d7223c461e58c +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanOpNode.cs new file mode 100644 index 00000000..409937ea --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Tan", "Trigonometry Operators", "Tangent of scalars and vectors" )] + public sealed class TanOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "tan"; + m_previewShaderGUID = "312e291832cac5749a3626547dfc8607"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanOpNode.cs.meta new file mode 100644 index 00000000..e78333f8 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 535b4367719ca2146bb7ddac217dad94 +timeCreated: 1481126955 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanhOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanhOpNode.cs new file mode 100644 index 00000000..e9f88faf --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanhOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Tanh", "Trigonometry Operators", "Hyperbolic tangent of scalars and vectors" )] + public sealed class TanhOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "tanh"; + m_previewShaderGUID = "52f78d3a1c66d1c489cd63b0a9300b38"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanhOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanhOpNode.cs.meta new file mode 100644 index 00000000..e2a2ef7f --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TanhOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 792e48b83a6387a4d826d6445417372f +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransformVectorOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransformVectorOpNode.cs new file mode 100644 index 00000000..c4c7e325 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransformVectorOpNode.cs @@ -0,0 +1,160 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; +using UnityEngine; + +namespace AmplifyShaderEditor +{ + public enum CoordinateSpaces + { + Tangent, + Local, + World, + View, + Clip, + Screen + } + + [Serializable] + [NodeAttributes( "Transform Vector", "Math Operators", "Transforma a vector into another", null, KeyCode.None, false )] + public sealed class TransformVectorOpNode : ParentNode + { + [SerializeField] + private CoordinateSpaces m_source = CoordinateSpaces.Tangent; + [SerializeField] + private CoordinateSpaces m_destination = CoordinateSpaces.World; + + private const string InputTangentrStr = "float4 tangent: TANGENT"; + private const string ColorValueStr = ".tangent"; + + private const string InputNormalStr = "float3 normal : NORMAL"; + private const string NormalValueStr = ".normal"; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddInputPort( WirePortDataType.FLOAT4, false, Constants.EmptyPortValue ); + AddOutputPort( WirePortDataType.FLOAT4, Constants.EmptyPortValue ); + m_useInternalPortData = true; + } + + void AddTangentInfo( ref MasterNodeDataCollector dataCollector ) + { + dataCollector.AddToInput( UniqueId, InputTangentrStr, true ); + dataCollector.AddToInput( UniqueId, InputTangentrStr, true ); + dataCollector.AddToInput( UniqueId, InputNormalStr, true ); + dataCollector.AddToLocalVariables( UniqueId, "float3 binormal = cross( normalize( v.normal ), normalize( v.tangent.xyz ) ) * v.tangent.w;" ); + dataCollector.AddToLocalVariables( UniqueId, "float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal );" ); + + } + + public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar ) + { + + //if ( !InputPorts[ 0 ].IsConnected ) + //{ + // return UIUtils.NoConnection( this ); + //} + + string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ); + + dataCollector.AddToIncludes( UniqueId, Constants.UnityShaderVariables ); + + + + switch ( m_source ) + { + case CoordinateSpaces.Tangent: + { + AddTangentInfo( ref dataCollector ); + switch ( m_destination ) + { + case CoordinateSpaces.Tangent: + { + return value; + } + //case eCoordinateSpaces.Local: + //{ + //} + //case eCoordinateSpaces.World: + //{ + //} + //case eCoordinateSpaces.View: + //{ + //} + } + } + break; + case CoordinateSpaces.Local: + { + switch ( m_destination ) + { + case CoordinateSpaces.Tangent: + { + AddTangentInfo( ref dataCollector ); + return "float4(mul( rotation , " + value + ".xyz ),1)"; + } + case CoordinateSpaces.Local: + { + return value; + } + case CoordinateSpaces.World: + { + return "mul( _Object2World , " + value + " )"; + } + case CoordinateSpaces.View: + { + return "mul( UNITY_MATRIX_MV , " + value + " )"; + } + } + } + break; + case CoordinateSpaces.World: + { + switch ( m_destination ) + { + //case eCoordinateSpaces.Tangent: + //{ + //} + case CoordinateSpaces.Local: + { + return "mul( _World2Object , " + value + " )"; + } + case CoordinateSpaces.World: + { + return value; + } + case CoordinateSpaces.View: + { + return "mul( UNITY_MATRIX_V , " + value + " )"; + } + } + } + break; + case CoordinateSpaces.View: + { + UIUtils.ShowMessage( UniqueId, "View as Source is not supported", MessageSeverity.Warning ); + return value; + } + } + + return UIUtils.UnknownError( this ); + } + + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_source = ( CoordinateSpaces ) Enum.Parse( typeof( CoordinateSpaces ), GetCurrentParam( ref nodeParams ) ); + m_destination = ( CoordinateSpaces ) Enum.Parse( typeof( CoordinateSpaces ), GetCurrentParam( ref nodeParams ) ); + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_source ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_destination ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransformVectorOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransformVectorOpNode.cs.meta new file mode 100644 index 00000000..3169b4e9 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransformVectorOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 928c21155a9c1a74b953da2d24269035 +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransposeOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransposeOpNode.cs new file mode 100644 index 00000000..6e83e512 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransposeOpNode.cs @@ -0,0 +1,23 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Transpose", "Matrix Operators", "Transpose matrix of a matrix" )] + public sealed class TransposeOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "transpose"; + m_drawPreview = false; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.FLOAT3x3, + WirePortDataType.FLOAT4x4 ); + m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4x4, false ); + m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4x4, false ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransposeOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransposeOpNode.cs.meta new file mode 100644 index 00000000..1df556ee --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TransposeOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ba1613dad4af0da4b9f4619b90916cbf +timeCreated: 1481126958 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TruncOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TruncOpNode.cs new file mode 100644 index 00000000..f190b0c8 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TruncOpNode.cs @@ -0,0 +1,26 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using System; + +namespace AmplifyShaderEditor +{ + [Serializable] + [NodeAttributes( "Trunc", "Math Operators", "Largest integer not greater than a scalar or each vector component" )] + public sealed class TruncOpNode : SingleInputOp + { + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + m_opName = "trunc"; + m_previewShaderGUID = "c717aaa68f4ac9e469b15763e82933e1"; + m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT, + WirePortDataType.FLOAT, + WirePortDataType.FLOAT2, + WirePortDataType.FLOAT3, + WirePortDataType.FLOAT4, + WirePortDataType.COLOR, + WirePortDataType.INT ); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TruncOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TruncOpNode.cs.meta new file mode 100644 index 00000000..9b873107 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/TruncOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5f78e9a796a94d54482caa15d4971feb +timeCreated: 1481126956 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/VariablePortTypeOpNode.cs b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/VariablePortTypeOpNode.cs new file mode 100644 index 00000000..f5610899 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/VariablePortTypeOpNode.cs @@ -0,0 +1,76 @@ +// Amplify Shader Editor - Visual Shader Editing Tool +// Copyright (c) Amplify Creations, Lda <info@amplify.pt> + +using UnityEngine; +using UnityEditor; +using System; + +namespace AmplifyShaderEditor +{ + public class VariablePortTypeOpNode : ParentNode + { + private const string InputTypeStr = "Input type"; + + [SerializeField] + protected WirePortDataType m_selectedType = WirePortDataType.FLOAT; + + [SerializeField] + protected WirePortDataType m_lastSelectedType = WirePortDataType.FLOAT; + + [SerializeField] + protected int _inputAmount = 1; + + protected override void CommonInit( int uniqueId ) + { + base.CommonInit( uniqueId ); + AddPorts(); + } + + void AddPorts() + { + for ( int i = 0; i < _inputAmount; i++ ) + { + AddInputPort( m_selectedType, true, i.ToString() ); + } + AddOutputPort( m_selectedType, Constants.EmptyPortValue ); + m_sizeIsDirty = true; + } + + public override void DrawProperties() + { + base.DrawProperties(); + EditorGUILayout.BeginVertical(); + { + EditorGUILayout.LabelField( InputTypeStr ); + m_selectedType = ( WirePortDataType ) EditorGUILayoutEnumPopup( m_selectedType ); + } + EditorGUILayout.EndVertical(); + if ( m_selectedType != m_lastSelectedType ) + { + m_lastSelectedType = m_selectedType; + + DeleteAllInputConnections( true ); + DeleteAllOutputConnections( true ); + + AddPorts(); + + } + } + + public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) + { + base.WriteToString( ref nodeInfo, ref connectionsInfo ); + IOUtils.AddFieldValueToString( ref nodeInfo, m_selectedType ); + } + + public override void ReadFromString( ref string[] nodeParams ) + { + base.ReadFromString( ref nodeParams ); + m_selectedType = ( WirePortDataType ) Enum.Parse( typeof( WirePortDataType ), GetCurrentParam( ref nodeParams ) ); + m_lastSelectedType = m_selectedType; + DeleteAllInputConnections( true ); + DeleteAllOutputConnections( true ); + AddPorts(); + } + } +} diff --git a/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/VariablePortTypeOpNode.cs.meta b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/VariablePortTypeOpNode.cs.meta new file mode 100644 index 00000000..f0328b05 --- /dev/null +++ b/Assets/AmplifyShaderEditor/Plugins/Editor/Nodes/Operators/VariablePortTypeOpNode.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 97be7adea7b8ae44c9bebb753277e0c2 +timeCreated: 1481126957 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |