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.

34 lines
1.5 KiB

  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( "Position From Transform", "Matrix Operators", "Gets the position vector from a transformation matrix" )]
  8. public sealed class PosFromTransformMatrix : ParentNode
  9. {
  10. protected override void CommonInit( int uniqueId )
  11. {
  12. base.CommonInit( uniqueId );
  13. AddInputPort( WirePortDataType.FLOAT4x4, true, Constants.EmptyPortValue );
  14. AddOutputPort( WirePortDataType.FLOAT4, "XYZW" );
  15. AddOutputPort( WirePortDataType.FLOAT, "X" );
  16. AddOutputPort( WirePortDataType.FLOAT, "Y" );
  17. AddOutputPort( WirePortDataType.FLOAT, "Z" );
  18. AddOutputPort( WirePortDataType.FLOAT, "W" );
  19. }
  20. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  21. {
  22. if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  23. return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
  24. string value = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  25. string result = string.Format( "float4( {0},{1},{2},{3})", value + "[3][0]", value + "[3][1]", value + "[3][2]", value + "[3][3]" );
  26. RegisterLocalVariable( 0, result, ref dataCollector, "matrixToPos" + OutputId );
  27. return GetOutputVectorItem( 0, outputId, m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory ) );
  28. }
  29. }
  30. }