rj-action-library/Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestEffect.cs

70 lines
1.7 KiB
C#

using Godot;
using Godot.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class AlphaGrabTestEffect:SingleShaderCompositorEffect
{
public static readonly string shaderPath =
RokojoriPlugin.Path( "Runtime/Rendering/CompositorEffects/AlphaGrabTest/AlphaGrabTestShader.glsl" );
protected override void OnConfigure()
{
EffectCallbackType = EffectCallbackTypeEnum.PostTransparent;
_shaderPath = shaderPath;
_groupSize = 32;
}
RDTexture _bufferTexture;
RDTexture _copyTexture;
bool _grabFlag;
byte[] _data;
bool _ready = false;
bool _canDraw = true;
public async Task<Texture2D> GetImageTexture( System.Func<Task> waiter )
{
var fmt = _bufferTexture.format;
var imgF = Image.Format.Rgbah;
var data = _rd.TextureGetData( _bufferTexture.rid, 0 );
var image = Image.CreateFromData( (int) fmt.Width, (int)fmt.Height, false, imgF, data );
return ImageTexture.CreateFromImage( image );
}
protected override void SetConstants()
{
// constants.Set(
// center,
// radius,
// intensity,
// samples,
// Vector2.Zero
// );
}
protected override void RenderView()
{
_bufferTexture = RDTexture.EnsureScreenSizeTexture( _bufferTexture, this );
_copyTexture = RDTexture.EnsureScreenSizeTexture( _copyTexture, this );
context.AssignScreenColorTexture();
context.AssignTexture( _bufferTexture );
// context.pushConstants = constants;
context.Render();
}
}
}