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.

55 lines
2.2 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( "Simple Contrast", "Image Effects", "Simple contrast matrix multiplication" )]
  8. public sealed class SimpleContrastOpNode : ParentNode
  9. {
  10. private const string InputTypeStr = "Contrast";
  11. private const string FunctionHeader = "CalculateContrast({0},{1})";
  12. private readonly string[] m_functionBody = { "float4 CalculateContrast( float contrastValue, float4 colorTarget )\n",
  13. "{\n",
  14. "\tfloat t = 0.5 * ( 1.0 - contrastValue );\n",
  15. "\treturn mul( float4x4( contrastValue,0,0,t, 0,contrastValue,0,t, 0,0,contrastValue,t, 0,0,0,1 ), colorTarget );\n",
  16. "}"};
  17. protected override void CommonInit( int uniqueId )
  18. {
  19. base.CommonInit( uniqueId );
  20. AddPorts();
  21. m_textLabelWidth = 70;
  22. m_useInternalPortData = true;
  23. m_previewShaderGUID = "8d76799413f9f0547ac9b1de7ba798f1";
  24. }
  25. void AddPorts()
  26. {
  27. AddInputPort( WirePortDataType.COLOR, false, "RGBA", -1, MasterNodePortCategory.Fragment, 1 );
  28. AddInputPort( WirePortDataType.FLOAT, false, "Value", -1, MasterNodePortCategory.Fragment, 0 );
  29. AddOutputPort( WirePortDataType.COLOR, Constants.EmptyPortValue );
  30. }
  31. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalVar )
  32. {
  33. if( m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  34. return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
  35. string contrastValue = m_inputPorts[ 1 ].GeneratePortInstructions( ref dataCollector );
  36. string colorTarget = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
  37. string result = dataCollector.AddFunctions( FunctionHeader, m_functionBody, false, contrastValue, colorTarget );
  38. return CreateOutputLocalVariable( 0, result, ref dataCollector );
  39. }
  40. public override void ReadFromString( ref string[] nodeParams )
  41. {
  42. base.ReadFromString( ref nodeParams );
  43. if( UIUtils.CurrentShaderVersion() < 5004 )
  44. {
  45. m_inputPorts[ 1 ].FloatInternalData = Convert.ToSingle( GetCurrentParam( ref nodeParams ) );
  46. }
  47. }
  48. }
  49. }