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.

52 lines
2.0 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. //
  4. // Custom Node HeightMap Texture Masking
  5. // Donated by Rea
  6. using UnityEngine;
  7. using System;
  8. namespace AmplifyShaderEditor
  9. {
  10. [Serializable]
  11. [NodeAttributes( "HeightMap Texture Blend", "Textures", "Advanced Texture Blending by using heightMap and splatMask, usefull for texture layering ", null, KeyCode.None, true, false, null, null, "Rea" )]
  12. public sealed class HeightMapBlendNode : ParentNode
  13. {
  14. protected override void CommonInit( int uniqueId )
  15. {
  16. base.CommonInit( uniqueId );
  17. AddInputPort( WirePortDataType.FLOAT, false, "HeightMap" );
  18. AddInputPort( WirePortDataType.FLOAT, false, "SplatMask" );
  19. AddInputPort( WirePortDataType.FLOAT, false, "BlendStrength" );
  20. AddOutputVectorPorts( WirePortDataType.FLOAT, Constants.EmptyPortValue );
  21. m_textLabelWidth = 120;
  22. m_useInternalPortData = true;
  23. m_inputPorts[ 2 ].FloatInternalData = 1;
  24. }
  25. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  26. {
  27. if ( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  28. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  29. string HeightMap = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  30. string SplatMask = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector);
  31. string Blend = m_inputPorts[ 2 ].GeneratePortInstructions( ref dataCollector );
  32. string HeightMask = "saturate(pow(((" + HeightMap + "*" + SplatMask + ")*4)+(" + SplatMask + "*2)," + Blend + "))";
  33. string varName = "HeightMask" + OutputId;
  34. RegisterLocalVariable( 0, HeightMask, ref dataCollector , varName );
  35. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  36. }
  37. /*
  38. A = (heightMap * SplatMask)*4
  39. B = SplatMask*2
  40. C = pow(A+B,Blend)
  41. saturate(C)
  42. saturate(pow(((heightMap * SplatMask)*4)+(SplatMask*2),Blend));
  43. */
  44. }
  45. }