From 679cab03b5a3450090a0f937c0f96b045346f58e Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 28 Jun 2026 14:35:14 +0900 Subject: [PATCH] =?UTF-8?q?LuaScriptEffectProcessor=E3=81=ABobj.effect?= =?UTF-8?q?=E3=83=81=E3=82=A7=E3=83=BC=E3=83=B3=E9=81=A9=E7=94=A8=E3=82=92?= =?UTF-8?q?=E7=B5=B1=E5=90=88=E3=81=97=E3=80=81=E5=A4=B1=E6=95=97=E6=99=82?= =?UTF-8?q?=E3=81=AF=E5=85=83=E7=94=BB=E5=83=8F=E3=81=B8=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=83=90=E3=83=83=E3=82=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/LuaScriptEffectProcessor.cs | 42 +++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/LuaScript/LuaScriptEffectProcessor.cs b/LuaScript/LuaScriptEffectProcessor.cs index dd56c9c..d2cb754 100644 --- a/LuaScript/LuaScriptEffectProcessor.cs +++ b/LuaScript/LuaScriptEffectProcessor.cs @@ -63,6 +63,7 @@ namespace LuaScript private LuaJitWorker? _nativeWorker; private double[]? _nativeFields; private bool _nativeWarned; + private bool _effectChainWarned; private EffectDescription? _frameDesc; private SceneObjectResolver? _frameResolver; @@ -91,7 +92,9 @@ namespace LuaScript private RenderKey _cachedKey; private SceneObjectQuery[] _cachedQueries = []; private DrawDescription? _cachedOutputDesc; - private bool _cachedPixelsModified; + private ID2D1Image? _cachedEffectOutput; + + private VideoEffectChain? _effectChain; protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices) { @@ -189,7 +192,7 @@ namespace LuaScript if (!_isFirst && key == _cachedKey && (_cachedQueries.Length == 0 || QueriesMatch(_cachedQueries, GetFrameResolver()))) { - effectOutput = _cachedPixelsModified ? _transformEffect?.Output : null; + effectOutput = _cachedEffectOutput; return _cachedOutputDesc ?? inDesc; } @@ -202,7 +205,6 @@ namespace LuaScript ctx.SetPixelLoader(() => LoadInputPixels(bounds, imgW, imgH)); DrawDescription outDesc = inDesc; - bool pixelsModified = false; try { @@ -214,7 +216,7 @@ namespace LuaScript if (nativeReady) { - pixelsModified = ExecuteNative(runnable, ctx, bounds, imgW, imgH); + ExecuteNative(runnable, ctx, bounds, imgW, imgH); } else { @@ -231,7 +233,6 @@ namespace LuaScript else UpdateTransformEffect(bounds.Left, bounds.Top); effectOutput = _transformEffect!.Output; - pixelsModified = true; } else { @@ -240,6 +241,20 @@ namespace LuaScript } outDesc = BuildOutputDesc(inDesc, ctx); + + if (ctx.EffectRequests.Count > 0) + { + var source = effectOutput ?? input; + try + { + effectOutput = ApplyEffectChain(source, ctx.EffectRequests, desc, ref outDesc); + } + catch (Exception ex) + { + effectOutput = source; + WarnEffectChainFailureOnce(ex); + } + } } catch (LuaScriptTimeoutException ex) { @@ -265,11 +280,17 @@ namespace LuaScript _cachedKey = key; _cachedQueries = ctx.ObjectQueries.Count == 0 ? [] : [.. ctx.ObjectQueries]; _cachedOutputDesc = outDesc; - _cachedPixelsModified = pixelsModified; + _cachedEffectOutput = effectOutput; return outDesc; } + private ID2D1Image ApplyEffectChain(ID2D1Image source, IReadOnlyList requests, EffectDescription desc, ref DrawDescription drawDescription) + { + _effectChain ??= new VideoEffectChain(_ownCtx!); + return _effectChain.Apply(source, requests, desc, ref drawDescription); + } + private static SceneObjectResolver BuildSceneObjectResolver(EffectDescription desc) { var scenes = desc.Scenes; @@ -326,6 +347,7 @@ namespace LuaScript : 0d; ctx.ClearQueries(); + ctx.ClearEffects(); ctx.ImageWidth = imgW; ctx.ImageHeight = imgH; @@ -400,6 +422,13 @@ namespace LuaScript Log.Default.Write($"LuaScript: native runtime not found at '{NativeDirectory}'. Falling back to MoonSharp (slow). Deploy the 'native' folder next to the plugin."); } + private void WarnEffectChainFailureOnce(Exception ex) + { + if (_effectChainWarned) return; + _effectChainWarned = true; + Log.Default.Write("LuaScript: obj.effect chain failed and was skipped for this frame. The source image is passed through unchanged.", ex); + } + private bool ExecuteNative(string script, AviUtlScriptContext ctx, RawRectF bounds, int imgW, int imgH) { _nativeWorker ??= new LuaJitWorker(NativeDirectory); @@ -548,6 +577,7 @@ namespace LuaScript { _engine.Dispose(); _nativeWorker?.Dispose(); + _effectChain?.Dispose(); _pixelLoaderSemaphore.Dispose(); _renderTarget?.Dispose(); _stagingBitmap?.Dispose();