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

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

    [Export]
    public Vector2 rShift = new Vector2( -0.001f, 0.0f );

    [Export]
    public Vector2 gShift = new Vector2( 0.0f, 0.0f );

    [Export]
    public Vector2 bShift = new Vector2( 0.001f, 0.0f );

        
    [Export]
    public float intensity = 0.5f;

    [Export]
    public float shiftAll = 0.5f;

    [Export]
    public float centerUnshiftPower = 1f;

    [Export]
    public float centerUnshiftMinRadius = 0.1f;

    RG_ScreenColorTexure screenColorTexture;
    RG_BufferTexture bufferTexture;    

    CEG_Copy copy;
    RG_ChromaticAberation chromaticAberation;    

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

      copy = new CEG_Copy( graph );
      chromaticAberation = new RG_ChromaticAberation( graph );


      graph.InitializeNodes();      

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


      graph.SetProcessOrder( 
        screenColorTexture, 
        bufferTexture, 
        copy, 
        chromaticAberation 
      );
    }
   

    protected override void ForAllViews()
    {

      chromaticAberation.constants.Set(

        rShift,
        gShift,
        bShift,
        Vector2.Zero, // padding

        intensity, 
        shiftAll, 
        centerUnshiftPower,
        centerUnshiftMinRadius // padding       
      );

    }

   
  }
}