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.

61 lines
2.0 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. using UnityEditor;
  6. namespace AmplifyShaderEditor
  7. {
  8. [Serializable]
  9. [NodeAttributes( "Layered Blend", "Miscellaneous", "Mix all channels through interpolation factors", null, KeyCode.None, true )]
  10. public sealed class LayeredBlendNode : WeightedAvgNode
  11. {
  12. protected override void CommonInit( int uniqueId )
  13. {
  14. base.CommonInit( uniqueId );
  15. m_inputPorts[ 1 ].Name = "Layer Base";
  16. AddInputPort( WirePortDataType.FLOAT, false, string.Empty );
  17. for ( int i = 2; i < m_inputPorts.Count; i++ )
  18. {
  19. m_inputPorts[ i ].Name = AmountsStr[ i - 2 ];
  20. }
  21. m_inputData = new string[ 6 ];
  22. m_minimumSize = 2;
  23. UpdateConnection( 0 );
  24. m_previewShaderGUID = "48faca2f6506fc44c97adb1e2b79c37d";
  25. }
  26. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  27. {
  28. if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  29. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  30. GetInputData( ref dataCollector, ignoreLocalvar );
  31. string result = string.Empty;
  32. string localVarName = "layeredBlendVar" + OutputId;
  33. dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, m_inputPorts[ 0 ].DataType, localVarName, m_inputData[ 0 ] );
  34. if ( m_activeCount == 1 )
  35. {
  36. result = m_inputData[ 0 ];
  37. }
  38. else if ( m_activeCount == 2 )
  39. {
  40. result += "lerp( " + m_inputData[ 1 ] + "," + m_inputData[ 2 ] + " , " + localVarName + " )";
  41. }
  42. else
  43. {
  44. result = m_inputData[ 1 ];
  45. for ( int i = 1; i < m_activeCount; i++ )
  46. {
  47. result = "lerp( " + result + " , " + m_inputData[ i + 1 ] + " , " + localVarName + Constants.VectorSuffixes[ i - 1 ] + " )";
  48. }
  49. }
  50. result = UIUtils.AddBrackets( result );
  51. RegisterLocalVariable( 0, result, ref dataCollector, "layeredBlend" + OutputId );
  52. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  53. }
  54. }
  55. }