You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.8 KiB

  1. using System;
  2. namespace AmplifyShaderEditor
  3. {
  4. [Serializable]
  5. [NodeAttributes( "Negate", "Math Operators", "Negate or invert an input value" )]
  6. public sealed class NegateNode : ParentNode
  7. {
  8. protected override void CommonInit( int uniqueId )
  9. {
  10. base.CommonInit( uniqueId );
  11. AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue );
  12. AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
  13. m_useInternalPortData = true;
  14. m_previewShaderGUID = "b035bc40da1ac7c4eafad4116382ec79";
  15. }
  16. public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
  17. {
  18. base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
  19. m_inputPorts[ 0 ].MatchPortToConnection();
  20. m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false );
  21. }
  22. public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
  23. {
  24. base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type );
  25. m_inputPorts[ 0 ].MatchPortToConnection();
  26. m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false );
  27. }
  28. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  29. {
  30. string result = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  31. if ( result.StartsWith( "-" ) )
  32. {
  33. return result.Remove( 0, 1 );
  34. }
  35. else
  36. {
  37. return "-" + result;
  38. }
  39. }
  40. }
  41. }