LengthOpNode.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. namespace AmplifyShaderEditor
  4. {
  5. [System.Serializable]
  6. [NodeAttributes( "Length", "Vector Operators", "Scalar Euclidean length of a vector" )]
  7. public sealed class LengthOpNode : SingleInputOp
  8. {
  9. protected override void CommonInit( int uniqueId )
  10. {
  11. base.CommonInit( uniqueId );
  12. m_opName = "length";
  13. m_previewShaderGUID = "1c1f6d6512b758942a8b9dd1bea12f34";
  14. m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.OBJECT,
  15. WirePortDataType.FLOAT ,
  16. WirePortDataType.FLOAT2,
  17. WirePortDataType.FLOAT3,
  18. WirePortDataType.FLOAT4,
  19. WirePortDataType.COLOR ,
  20. WirePortDataType.INT);
  21. m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
  22. m_autoUpdateOutputPort = false;
  23. }
  24. public override void SetPreviewInputs()
  25. {
  26. base.SetPreviewInputs();
  27. switch( m_inputPorts[0].DataType )
  28. {
  29. case WirePortDataType.OBJECT:
  30. case WirePortDataType.INT:
  31. case WirePortDataType.FLOAT:
  32. case WirePortDataType.UINT:m_previewMaterialPassId = 0;break;
  33. case WirePortDataType.FLOAT2:m_previewMaterialPassId = 1;break;
  34. case WirePortDataType.FLOAT3:m_previewMaterialPassId = 2;break;
  35. case WirePortDataType.FLOAT4:
  36. case WirePortDataType.COLOR:m_previewMaterialPassId = 3;break;
  37. }
  38. }
  39. }
  40. }