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.

67 lines
2.2 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using System;
  5. namespace AmplifyShaderEditor
  6. {
  7. [Serializable]
  8. public class SingleInputOp : ParentNode
  9. {
  10. [SerializeField]
  11. protected string m_opName;
  12. //[SerializeField]
  13. //protected int m_validTypes;
  14. protected bool m_autoUpdateOutputPort = true;
  15. protected override void CommonInit( int uniqueId )
  16. {
  17. base.CommonInit( uniqueId );
  18. AddInputPort( WirePortDataType.FLOAT, false, Constants.EmptyPortValue );
  19. AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
  20. //m_validTypes = 0;
  21. m_useInternalPortData = true;
  22. }
  23. public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
  24. {
  25. base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
  26. m_inputPorts[ 0 ].MatchPortToConnection();
  27. if ( m_autoUpdateOutputPort )
  28. m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false );
  29. }
  30. public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
  31. {
  32. base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type );
  33. m_inputPorts[ 0 ].MatchPortToConnection();
  34. if ( m_autoUpdateOutputPort )
  35. m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false );
  36. }
  37. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  38. {
  39. if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  40. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  41. string result = "0";
  42. if ( m_inputPorts[ 0 ].IsConnected )
  43. {
  44. ParentNode node = m_inputPorts[ 0 ].GetOutputNode();
  45. int localOutputId = m_inputPorts[ 0 ].ExternalReferences[ 0 ].PortId;
  46. result = m_opName + "( " + node.GenerateShaderForOutput( localOutputId, ref dataCollector, ignoreLocalvar ) + " )";
  47. }
  48. else
  49. {
  50. result = m_opName + "( " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + " )";
  51. }
  52. return CreateOutputLocalVariable( 0, result, ref dataCollector );
  53. }
  54. }
  55. }