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

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

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

    [Export( PropertyHint.Range, "-10,10") ]
    public float rimOffsetX = 2f;

    [Export( PropertyHint.Range, "-10,10") ]
    public float rimOffsetY = 0f;

    [Export( PropertyHint.Range, "0.0001,1") ]
    public float minDepth = 0.001f;

    [Export( PropertyHint.Range, "0.01,500.0") ]
    public float depthScale = 1f;

    [Export( PropertyHint.Range, "-10,10.0") ]
    public float depthOffset = 1f;

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

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


    RG_ScreenColorTexure _colorTexture;
    RG_ScreenDepthTexture _depthTexture;
    RG_Rim _rim;


    void Initialize()
    {
      _colorTexture = new RG_ScreenColorTexure( graph );
      _depthTexture = new RG_ScreenDepthTexture( graph );
      _rim = new RG_Rim( graph );

       graph.InitializeNodes();

      _rim.SetTextureSlotInputs( _colorTexture, _colorTexture );
      _rim.AddTextureSlotInput( _depthTexture ).UseLinearSamplerEdgeClamped();

      graph.SetProcessOrder(
        _colorTexture, 
        _depthTexture,

        _rim
      );

    }

    

    protected override void ForAllViews()
    {     
      _rim.constants.Set(        
        new Vector2( depthScale, depthOffset ),

        effectStrength,
        rimOffsetX,
        rimOffsetY,
        minDepth,

        contrast
      );
    }
    
  }
}