EncodeDepthNormalNode.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. namespace AmplifyShaderEditor
  5. {
  6. [Serializable]
  7. [NodeAttributes( "Encode Depth Normal", "Miscellaneous", "Encodes both Depth and Normal values into a Float4 value" )]
  8. public sealed class EncodeDepthNormalNode : ParentNode
  9. {
  10. private const string EncodeDepthNormalFunc = "EncodeDepthNormal( {0}, {1} )";
  11. protected override void CommonInit( int uniqueId )
  12. {
  13. base.CommonInit( uniqueId );
  14. AddInputPort( WirePortDataType.FLOAT, false, "Depth" );
  15. AddInputPort( WirePortDataType.FLOAT3, false, "Normal" );
  16. AddOutputPort( WirePortDataType.FLOAT4, Constants.EmptyPortValue );
  17. }
  18. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  19. {
  20. if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  21. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  22. dataCollector.AddToIncludes( UniqueId, Constants.UnityCgLibFuncs );
  23. string depthValue = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  24. string normalValue = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
  25. RegisterLocalVariable( 0, string.Format( EncodeDepthNormalFunc, depthValue, normalValue ), ref dataCollector, "encodedDepthNormal" + OutputId );
  26. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  27. }
  28. }
  29. }