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.

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