diff --git a/Inflate/InflateCustomEffect.cs b/Inflate/InflateCustomEffect.cs new file mode 100644 index 0000000..b8057d8 --- /dev/null +++ b/Inflate/InflateCustomEffect.cs @@ -0,0 +1,80 @@ +using System.Runtime.InteropServices; +using Vortice; +using Vortice.Direct2D1; +using YukkuriMovieMaker.Commons; +using YukkuriMovieMaker.Player.Video; + +namespace Inflate; + +internal sealed class InflateCustomEffect(IGraphicsDevicesAndContext devices) + : D2D1CustomShaderEffectBase(Create(devices)) +{ + public float Amount { set => SetValue((int)EffectImpl.Properties.Amount, value); } + + [CustomEffect(2)] + private sealed class EffectImpl : D2D1CustomShaderEffectImplBase + { + private ConstantBuffer _cb; + + [CustomEffectProperty(PropertyType.Float, (int)Properties.Amount)] + public float Amount + { + get => _cb.Amount; + set + { + _cb.Amount = Math.Clamp(value, 0f, 1f); + UpdateConstants(); + } + } + + public EffectImpl() : base(ShaderResourceUri.Get("Inflate")) + { + } + + protected override void UpdateConstants() + { + if (drawInformation is null) + return; + + try + { + drawInformation.SetPixelShaderConstantBuffer(_cb); + } + catch (Exception exception) + { + InflateTelemetry.Report(exception); + throw; + } + } + + public override void MapInputRectsToOutputRect( + RawRect[] inputRects, + RawRect[] inputOpaqueSubRects, + out RawRect outputRect, + out RawRect outputOpaqueSubRect) + { + outputRect = inputRects.Length > 0 ? inputRects[0] : default; + outputOpaqueSubRect = default; + } + + public override void MapOutputRectToInputRects(RawRect outputRect, RawRect[] inputRects) + { + for (var i = 0; i < inputRects.Length; i++) + inputRects[i] = outputRect; + } + + [StructLayout(LayoutKind.Sequential)] + private struct ConstantBuffer + { + public float Amount; + public float Pad0; + public float Pad1; + public float Pad2; + } + + public enum Properties + { + Amount = 0, + } + } +}