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.

71 lines
2.4 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. namespace AmplifyShaderEditor
  7. {
  8. [Serializable]
  9. [NodeAttributes( "Switch by Pipeline", "Functions", "Executes branch according to current pipeline", NodeAvailabilityFlags = (int)NodeAvailability.ShaderFunction )]
  10. public sealed class FunctionSwitchByPipeline : ParentNode
  11. {
  12. protected override void CommonInit( int uniqueId )
  13. {
  14. base.CommonInit( uniqueId );
  15. AddInputPort( WirePortDataType.FLOAT, false, "Standard" );
  16. AddInputPort( WirePortDataType.FLOAT, false, "Lightweight" );
  17. AddInputPort( WirePortDataType.FLOAT, false, "HD" );
  18. AddOutputPort( WirePortDataType.FLOAT, Constants.EmptyPortValue );
  19. }
  20. public override void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
  21. {
  22. base.OnInputPortConnected( portId, otherNodeId, otherPortId, activateNode );
  23. m_inputPorts[ portId ].MatchPortToConnection();
  24. UpdateOutputPort();
  25. }
  26. public override void OnConnectedOutputNodeChanges( int outputPortId, int otherNodeId, int otherPortId, string name, WirePortDataType type )
  27. {
  28. base.OnConnectedOutputNodeChanges( outputPortId, otherNodeId, otherPortId, name, type );
  29. m_inputPorts[ outputPortId ].MatchPortToConnection();
  30. UpdateOutputPort();
  31. }
  32. void UpdateOutputPort()
  33. {
  34. switch( m_containerGraph.CurrentSRPType )
  35. {
  36. case TemplateSRPType.BuiltIn:
  37. m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType, false );
  38. break;
  39. case TemplateSRPType.Lightweight:
  40. m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 1 ].DataType, false );
  41. break;
  42. case TemplateSRPType.HD:
  43. m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 2 ].DataType, false );
  44. break;
  45. }
  46. }
  47. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  48. {
  49. base.GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
  50. switch( dataCollector.CurrentSRPType )
  51. {
  52. case TemplateSRPType.BuiltIn:
  53. return m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  54. case TemplateSRPType.Lightweight:
  55. return m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
  56. case TemplateSRPType.HD:
  57. return m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector );
  58. }
  59. return "0";
  60. }
  61. }
  62. }