From 3e0ef537889840aa8aedd8166c9ca60bed5e0b14 Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 20 Oct 2026 09:09:55 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=82=A8?= =?UTF-8?q?=E3=83=95=E3=82=A7=E3=82=AF=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inflate/InflateCustomEffect.cs | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Inflate/InflateCustomEffect.cs 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, + } + } +}