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.

56 lines
1.7 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( "Summed Blend", "Miscellaneous", "Mix all channels through weighted sum", null, KeyCode.None, true )]
  9. public sealed class SummedBlendNode : WeightedAvgNode
  10. {
  11. protected override void CommonInit( int uniqueId )
  12. {
  13. base.CommonInit( uniqueId );
  14. m_inputData = new string[ 6 ];
  15. m_previewShaderGUID = "eda18b96e13f78b49bbdaa4da3fead19";
  16. }
  17. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  18. {
  19. if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  20. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  21. GetInputData( ref dataCollector, ignoreLocalvar );
  22. string result = string.Empty;
  23. string localVarName = "weightedBlendVar" + OutputId;
  24. dataCollector.AddLocalVariable( UniqueId, m_currentPrecisionType, m_inputPorts[ 0 ].DataType, localVarName, m_inputData[ 0 ] );
  25. if ( m_activeCount == 0 )
  26. {
  27. result = m_inputData[ 0 ];
  28. }
  29. else if ( m_activeCount == 1 )
  30. {
  31. result += localVarName + "*" + m_inputData[ 1 ];
  32. }
  33. else
  34. {
  35. for ( int i = 0; i < m_activeCount; i++ )
  36. {
  37. result += localVarName + Constants.VectorSuffixes[ i ] + "*" + m_inputData[ i + 1 ];
  38. if ( i != ( m_activeCount - 1 ) )
  39. {
  40. result += " + ";
  41. }
  42. }
  43. }
  44. result = UIUtils.AddBrackets( result );
  45. RegisterLocalVariable( 0, result, ref dataCollector, "weightedBlend" + OutputId );
  46. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  47. }
  48. }
  49. }