
using Godot;
using Godot.Collections;
using System.Collections.Generic;

namespace Rokojori
{  
  [Tool]
  [GlobalClass]
  public partial class UnsharpMaskingEffect:BlurOrSharpenEffect
  {
    public UnsharpMaskingEffect():base()
    {
      Initialize();
    }

    [Export( PropertyHint.Range, "0,1")]
    public float amount = 1f;

    [Export( PropertyHint.Range, "1,10")]
    public int kernelOffset = 1;

    RG_ScreenColorTexure screenColorTexture;
    RG_BufferTexture bufferTexture;    

    CEG_Copy copy;
    RG_Kernel3 unsharpMaskingKernel;    

    void Initialize()
    { 
      screenColorTexture = new RG_ScreenColorTexure( graph );
      bufferTexture = RG_BufferTexture.ScreenSize( graph );

      copy = new CEG_Copy( graph );
      unsharpMaskingKernel = new RG_Kernel3( graph );
      graph.InitializeNodes();

      copy.SetTextureSlotInputs( screenColorTexture, bufferTexture );
      unsharpMaskingKernel.SetTextureSlotInputs( copy.output, copy.input );

      

      graph.SetProcessOrder(
        screenColorTexture, 
        bufferTexture, 
        copy,
        unsharpMaskingKernel 
      );
      
    }
    
    protected override void ForAllViews()
    {
      unsharpMaskingKernel.constants.Set(
       [ 
        amount,
        0f, -1f, 0f, 
        -1f, 5f, -1f,
        0f, -1f,0f,
        (float)kernelOffset,
        0f
        
       ]
      );
     
    }

   
  }
}