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.

45 lines
1.8 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using UnityEngine;
  5. namespace AmplifyShaderEditor
  6. {
  7. [Serializable]
  8. [NodeAttributes( "One Minus", "Math Operators", "1 - input value", null, KeyCode.O )]
  9. public sealed class OneMinusNode : ParentNode
  10. {
  11. protected override void CommonInit( int uniqueId )
  12. {
  13. base.CommonInit( uniqueId );
  14. AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue );
  15. AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
  16. m_useInternalPortData = true;
  17. m_previewShaderGUID = "bed5300b92e7bb0419d0f4accb853312";
  18. }
  19. public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
  20. {
  21. base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
  22. m_inputPorts[ 0 ].MatchPortToConnection();
  23. m_outputPorts[ 0 ].ChangeType( InputPorts[ 0 ].DataType, false );
  24. }
  25. public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
  26. {
  27. base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type );
  28. m_inputPorts[ 0 ].MatchPortToConnection();
  29. m_outputPorts[ 0 ].ChangeType( InputPorts[ 0 ].DataType, false );
  30. }
  31. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  32. {
  33. if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  34. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  35. string result = "( 1.0 - " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + " )";
  36. return CreateOutputLocalVariable( 0, result, ref dataCollector );
  37. }
  38. }
  39. }