SimpleRemainderNode.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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( "Remainder", "Math Operators", "Remainder between two int variables",tags:"modulo fmod" )]
  8. public sealed class SimpleRemainderNode : DynamicTypeNode
  9. {
  10. private const string VertexFragRemainder = "( {0} % {1} )";
  11. //private const string SurfaceRemainder = "fmod( {0} , {1} )";
  12. private const string RemainderCalculationInt = "( {0} - {1} * ({0}/{1}))";
  13. private const string RemainderCalculationFloat = "( {0} - {1} * floor({0}/{1}))";
  14. protected override void CommonInit( int uniqueId )
  15. {
  16. base.CommonInit( uniqueId );
  17. m_useInternalPortData = true;
  18. m_textLabelWidth = 35;
  19. ChangeInputType( WirePortDataType.INT, false );
  20. ChangeOutputType( WirePortDataType.INT, false );
  21. m_useInternalPortData = true;
  22. m_previewShaderGUID = "8fdfc429d6b191c4985c9531364c1a95";
  23. }
  24. public override string BuildResults( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  25. {
  26. if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  27. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  28. base.BuildResults( outputId, ref dataCollector, ignoreLocalvar );
  29. string opMode = VertexFragRemainder;
  30. string result = string.Empty;
  31. switch( m_outputPorts[ 0 ].DataType )
  32. {
  33. case WirePortDataType.FLOAT:
  34. case WirePortDataType.FLOAT2:
  35. case WirePortDataType.FLOAT3:
  36. case WirePortDataType.FLOAT4:
  37. case WirePortDataType.INT:
  38. case WirePortDataType.COLOR:
  39. case WirePortDataType.OBJECT:
  40. {
  41. result = string.Format( opMode, m_inputA, m_inputB );
  42. }
  43. break;
  44. case WirePortDataType.FLOAT3x3:
  45. case WirePortDataType.FLOAT4x4:
  46. {
  47. result = UIUtils.InvalidParameter( this );
  48. }
  49. break;
  50. }
  51. return CreateOutputLocalVariable( 0, result, ref dataCollector );
  52. }
  53. }
  54. }