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.

55 lines
1.9 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. [NodeAttributes( "Normalize", "Vector Operators", "Normalizes a vector", null, KeyCode.N )]
  9. public sealed class NormalizeNode : SingleInputOp
  10. {
  11. protected override void CommonInit( int uniqueId )
  12. {
  13. base.CommonInit( uniqueId );
  14. m_selectedLocation = PreviewLocation.TopCenter;
  15. m_inputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT4, false );
  16. m_inputPorts[ 0 ].CreatePortRestrictions( WirePortDataType.FLOAT, WirePortDataType.FLOAT2, WirePortDataType.FLOAT3, WirePortDataType.FLOAT4, WirePortDataType.COLOR, WirePortDataType.OBJECT, WirePortDataType.INT );
  17. m_previewShaderGUID = "a51b11dfb6b32884e930595e5f9defa8";
  18. }
  19. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  20. {
  21. if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  22. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  23. string result = string.Empty;
  24. switch ( m_inputPorts[ 0 ].DataType )
  25. {
  26. case WirePortDataType.FLOAT:
  27. case WirePortDataType.FLOAT2:
  28. case WirePortDataType.FLOAT3:
  29. case WirePortDataType.FLOAT4:
  30. case WirePortDataType.OBJECT:
  31. case WirePortDataType.COLOR:
  32. {
  33. result = "normalize( " + m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector ) + " )";
  34. }
  35. break;
  36. case WirePortDataType.INT:
  37. {
  38. return m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  39. }
  40. case WirePortDataType.FLOAT3x3:
  41. case WirePortDataType.FLOAT4x4:
  42. {
  43. result = UIUtils.InvalidParameter( this );
  44. }
  45. break;
  46. }
  47. RegisterLocalVariable( 0, result, ref dataCollector, "normalizeResult" + OutputId );
  48. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  49. }
  50. }
  51. }