From 0f71bb4d097f1cbbbc96f183b6cbda1148ea6853 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 25 Oct 2026 19:39:23 +0900 Subject: [PATCH] =?UTF-8?q?=E6=94=BE=E5=B0=84=E3=82=92=E5=8F=96=E3=82=8A?= =?UTF-8?q?=E5=87=BA=E3=81=99=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 --- VolumetricLight/EmissionCustomEffect.cs | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 VolumetricLight/EmissionCustomEffect.cs diff --git a/VolumetricLight/EmissionCustomEffect.cs b/VolumetricLight/EmissionCustomEffect.cs new file mode 100644 index 0000000..45c64a9 --- /dev/null +++ b/VolumetricLight/EmissionCustomEffect.cs @@ -0,0 +1,75 @@ +using System.Runtime.InteropServices; +using Vortice; +using Vortice.Direct2D1; +using YukkuriMovieMaker.Commons; +using YukkuriMovieMaker.Player.Video; + +namespace VolumetricLight; + +internal sealed class EmissionCustomEffect : D2D1CustomShaderEffectBase +{ + public EmissionCustomEffect(IGraphicsDevicesAndContext devices) : base(Create(devices)) + { + if (IsEnabled) + SetValue((int)Property.Precision, BufferPrecision.PerChannel16Float); + } + + internal enum PropertyIndex + { + Threshold = 0, + } + + public float Threshold { set => SetValue((int)PropertyIndex.Threshold, value); } + + [CustomEffect(1)] + internal sealed class EffectImpl : D2D1CustomShaderEffectImplBase + { + private ConstantBuffer _cb; + + [CustomEffectProperty(PropertyType.Float, (int)PropertyIndex.Threshold)] + public float Threshold { get => _cb.Threshold; set { _cb.Threshold = float.IsNaN(value) ? 0f : Math.Clamp(value, 0f, 1f); UpdateConstants(); } } + + public EffectImpl() : base(ShaderResourceUri.Get("Emission")) + { + } + + protected override void UpdateConstants() + { + if (drawInformation is null) + return; + + try + { + drawInformation.SetPixelShaderConstantBuffer(_cb); + } + catch (Exception exception) + { + VolumetricLightTelemetry.Report(exception); + throw; + } + } + + public override void MapInputRectsToOutputRect( + RawRect[] inputRects, + RawRect[] inputOpaqueSubRects, + out RawRect outputRect, + out RawRect outputOpaqueSubRect) + { + inputRect = ClampInputRect(inputRects[0]); + outputRect = inputRect; + outputOpaqueSubRect = default; + } + + public override void MapOutputRectToInputRects(RawRect outputRect, RawRect[] inputRects) + => inputRects[0] = outputRect; + + [StructLayout(LayoutKind.Sequential)] + private struct ConstantBuffer + { + public float Threshold; + public float Padding0; + public float Padding1; + public float Padding2; + } + } +}