using Godot;

namespace Rokojori
{  
  [Tool]
  [GlobalClass]
  public abstract partial class FlareChromaticAberation:Resource
  {
    [Export( PropertyHint.Range, "0,100" ) ]
    public float amount = 0.1f;    

    [Export( PropertyHint.Range, "0,32" ) ]
    public int steps = 3;    

    [Export( PropertyHint.Range, "1,50" ) ]
    public float smear = 2f;    

    [ExportGroup("Channel Offset")]
    [Export( PropertyHint.Range, "0,1" ) ]
    public float offsetScale = 0.2f;
    
    [Export( PropertyHint.Range, "-1,1" ) ]
    public float offsetR = -0.1f;

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

    [Export( PropertyHint.Range, "-1,1" ) ]
    public float offsetB = 0.1f;




    public abstract void ApplyChromaticAberation( FlareLayer.Data data );

    protected void ApplyChromaticAberationBase( FlareLayer.Data data )
    {
      var material = data.material;

      BaseFlareShader.chromaticAberationMode.Set( material, 1 );
      BaseFlareShader.chromaticAberationAmount.Set( material, amount );

      var shifts = Vector3.One;
      shifts.X += offsetR * offsetScale;
      shifts.Y += offsetG * offsetScale;
      shifts.Z += offsetB * offsetScale;

      BaseFlareShader.chromaticAberationShifts.Set( material, shifts );

      BaseFlareShader.chromaticAberationSteps.Set( material, steps );
      BaseFlareShader.chromaticAberationSmear.Set( material, smear );
    }

  }
}