エフェクトが基底を継承せずに前処理のエフェクトを持つ形にし、光の入力の名前を直す

このコミットが含まれているのは:
routersys committed 2026-10-13 15:55:26 +09:00
1 親 31a052feb1
コミット a77dbbe13f
12ファイル変更
+63 -58

検索条件に一致するファイルはありません

+3 -3
ファイルの表示
@@ -4,8 +4,8 @@
#include "Srgb.hlsli"
Texture2D LinearTexture : register(t1);
SamplerState LinearSampler : register(s1);
Texture2D LightTexture : register(t1);
SamplerState LightSampler : register(s1);
static const int MaxSteps = 64;
static const int TableSize = 128;
@@ -69,7 +69,7 @@ float4 SampleCovered(float2 uv, float2 pixelStep, float2 scenePosition, float2 t
float2 minimum = inputBounds.xy + 0.5;
float2 maximum = inputBounds.zw - 0.5;
float2 clamped = clamp(target, minimum, maximum);
float4 color = LinearTexture.SampleLevel(LinearSampler, uv + (clamped - scenePosition) * pixelStep, 0);
float4 color = LightTexture.SampleLevel(LightSampler, uv + (clamped - scenePosition) * pixelStep, 0);
float2 coverage = saturate(min(target - inputBounds.xy, inputBounds.zw - target) + 0.5);
return color * (coverage.x * coverage.y);
}
+3 -3
ファイルの表示
@@ -9,7 +9,7 @@ void AccumulateRadial(int index, float2 uv, float2 offsetStep, float rate, inout
float4 gain = samples[index * 2];
float4 basis = samples[index * 2 + 1];
float scale = clamp(basis.w * rate, -MaxRadialShift, MaxRadialShift);
Accumulate(gain, basis.rgb, LinearTexture.SampleLevel(LinearSampler, uv - offsetStep * scale, 0), color, alpha);
Accumulate(gain, basis.rgb, LightTexture.SampleLevel(LightSampler, uv - offsetStep * scale, 0), color, alpha);
}
void AccumulateRotational(int index, float2 uv, float2 offset, float2 pixelStep, float rate, inout float3 color, inout float alpha)
@@ -20,14 +20,14 @@ void AccumulateRotational(int index, float2 uv, float2 offset, float2 pixelStep,
float cosine;
sincos(basis.w * rate, sine, cosine);
float2 delta = float2((cosine - 1.0) * offset.x + sine * offset.y, (cosine - 1.0) * offset.y - sine * offset.x);
Accumulate(gain, basis.rgb, LinearTexture.SampleLevel(LinearSampler, uv + delta * pixelStep, 0), color, alpha);
Accumulate(gain, basis.rgb, LightTexture.SampleLevel(LightSampler, uv + delta * pixelStep, 0), color, alpha);
}
void AccumulateLinear(int index, float2 uv, float2 stride, inout float3 color, inout float alpha)
{
float4 gain = samples[index * 2];
float4 basis = samples[index * 2 + 1];
Accumulate(gain, basis.rgb, LinearTexture.SampleLevel(LinearSampler, uv - basis.w * stride, 0), color, alpha);
Accumulate(gain, basis.rgb, LightTexture.SampleLevel(LightSampler, uv - basis.w * stride, 0), color, alpha);
}
float4 GatherInside(float2 uv, float2 pixelStep, float2 scenePosition)
+1 -1
ファイルの表示
@@ -6,7 +6,7 @@
void AccumulateTap(int tap, float2 position, inout float3 color, inout float alpha)
{
float4 shifted = LinearTexture.SampleLevel(LinearSampler, position, 0);
float4 shifted = LightTexture.SampleLevel(LightSampler, position, 0);
float4 red = taps[tap * 3];
float4 green = taps[tap * 3 + 1];
float4 blue = taps[tap * 3 + 2];
+2 -2
ファイルの表示
@@ -35,7 +35,7 @@ public sealed class FilterRenderingTests
using var context = devices.CreateContext();
using var source = new SourceImage(context, 64, 40, Gradient);
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, source.Bitmap, true);
effect.SetSource(source.Bitmap, true);
using var output = effect.Output;
var settings = new ShiftSettings(ShiftMode.Linear, distance, angle, default, 1f, law, 550f, steps, true);
settings.Apply(effect);
@@ -60,7 +60,7 @@ public sealed class FilterRenderingTests
using var context = devices.CreateContext();
using var source = new SourceImage(context, 64, 40, Gradient);
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, source.Bitmap, true);
effect.SetSource(source.Bitmap, true);
using var output = effect.Output;
foreach (var (angle, distance) in new[] { (0f, 8f), (30f, 8f), (0f, 8f), (0f, 40f), (90f, 8f), (0f, 0f), (0f, 8f) })
+4 -4
ファイルの表示
@@ -48,7 +48,7 @@ public sealed class SpectralRenderingTests
static Rendering Render(IGraphicsDevicesAndContext devices, SourceImage source, ShiftSettings settings)
{
using var effect = new SpectrumColorShiftCustomEffect(devices);
effect.SetInput(0, source.Bitmap, true);
effect.SetSource(source.Bitmap, true);
settings.Apply(effect);
using var output = effect.Output;
@@ -602,7 +602,7 @@ public sealed class SpectralRenderingTests
var inPlace = Render(context, source, settings);
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, movedOutput, true);
effect.SetSource(movedOutput, true);
settings.Apply(effect);
using var output = effect.Output;
var travelled = Rendering.Capture(context, output);
@@ -698,7 +698,7 @@ public sealed class SpectralRenderingTests
using var bitmap = context.DeviceContext.CreateBitmap(new SizeI(96, 96), nint.Zero, stride, new BitmapProperties1(SourceImage.PixelFormat, SourceImage.Dpi, SourceImage.Dpi, BitmapOptions.None));
bitmap.CopyFromMemory(pixels, stride);
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, bitmap, true);
effect.SetSource(bitmap, true);
Settings(Mode: mode, Distance: 12f).Apply(effect);
using var output = effect.Output;
@@ -735,7 +735,7 @@ public sealed class SpectralRenderingTests
var expected = Render(context, source, legacy);
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, source.Bitmap, true);
effect.SetSource(source.Bitmap, true);
legacy.Apply(effect);
effect.Physical = 1;
using var output = effect.Output;
+3 -5
ファイルの表示
@@ -33,14 +33,12 @@ public sealed partial class SpectralShaderContractTests
static string Here([CallerFilePath] string path = "") => path;
static int LinearInput { get; } = (int)typeof(SpectrumColorShiftCustomEffect).GetField("LinearInput", BindingFlags.NonPublic | BindingFlags.Static)!.GetRawConstantValue()!;
static Type ConstantBuffer => typeof(EffectImpl).GetNestedType("PhysicalConstantBuffer", BindingFlags.NonPublic)!;
[GeneratedRegex(@"static const (?:int|float) (?<name>\w+) = (?<value>[0-9.]+);")]
private static partial Regex ConstantPattern();
[GeneratedRegex(@"Texture2D\s+LinearTexture\s*:\s*register\(t(?<register>\d+)\)")]
[GeneratedRegex(@"Texture2D\s+LightTexture\s*:\s*register\(t(?<register>\d+)\)")]
private static partial Regex TexturePattern();
[GeneratedRegex(@"float4\s+\w+\s*:\s*TEXCOORD(?<index>\d+)")]
@@ -65,7 +63,7 @@ public sealed partial class SpectralShaderContractTests
[Fact]
public void TheShaderReadsTheTextureOfTheLinearizedInput()
{
Assert.Equal(LinearInput, int.Parse(TexturePattern().Match(Source).Groups["register"].Value, CultureInfo.InvariantCulture));
Assert.Equal(SpectrumColorShiftCustomEffect.LightInput, int.Parse(TexturePattern().Match(Source).Groups["register"].Value, CultureInfo.InvariantCulture));
}
[Fact]
@@ -73,7 +71,7 @@ public sealed partial class SpectralShaderContractTests
{
var declared = CoordinatePattern().Matches(Source).Select(match => int.Parse(match.Groups["index"].Value, CultureInfo.InvariantCulture));
Assert.Equal(Enumerable.Range(0, LinearInput + 1), declared.Order());
Assert.Equal(Enumerable.Range(0, SpectrumColorShiftCustomEffect.LightInput + 1), declared.Order());
}
[Theory]
+5 -5
ファイルの表示
@@ -10,14 +10,14 @@ public sealed class SpectrumColorShiftCustomEffectTests
{
const float MaxInputPixel = 4096f;
static float Read(SpectrumColorShiftCustomEffect effect, PropertyIndex index) => effect.GetFloatValue((int)index);
static float Read(SpectrumColorShiftCustomEffect effect, PropertyIndex index) => effect.ReadFloat(index);
static int ReadInt(SpectrumColorShiftCustomEffect effect, PropertyIndex index) => effect.GetIntValue((int)index);
static int ReadInt(SpectrumColorShiftCustomEffect effect, PropertyIndex index) => effect.ReadInt(index);
static (float Left, float Top, float Right, float Bottom) Bounds(IGraphicsDevicesAndContext devices, SourceImage source, Action<SpectrumColorShiftCustomEffect> configure)
{
using var effect = new SpectrumColorShiftCustomEffect(devices);
effect.SetInput(0, source.Bitmap, true);
effect.SetSource(source.Bitmap, true);
configure(effect);
using var output = effect.Output;
var bounds = devices.DeviceContext.GetImageLocalBounds(output);
@@ -318,7 +318,7 @@ public sealed class SpectrumColorShiftCustomEffectTests
using var context = devices.CreateContext();
using var source = SourceImage.Solid(context, 40, 30, Bgra.Opaque(10, 20, 30));
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, source.Bitmap, true);
effect.SetSource(source.Bitmap, true);
effect.Mode = (int)ShiftMode.Rotational;
effect.Distance = MaxInputPixel;
using var output = effect.Output;
@@ -388,7 +388,7 @@ public sealed class SpectrumColorShiftCustomEffectTests
crop.SetInput(0, source.Bitmap, true);
using var cropped = crop.Output;
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, cropped, true);
effect.SetSource(cropped, true);
effect.Mode = (int)mode;
effect.Distance = 3f;
using var output = effect.Output;
+1 -1
ファイルの表示
@@ -228,7 +228,7 @@ public sealed class SpectrumColorShiftEffectProcessorTests
using var processor = effect.CreateVideoEffect(context);
processor.SetInput(source.Bitmap);
using var direct = new SpectrumColorShiftCustomEffect(context);
direct.SetInput(0, source.Bitmap, true);
direct.SetSource(source.Bitmap, true);
direct.Distance = 14.5f;
direct.Mode = (int)ShiftMode.Rotational;
direct.Angle = 33f;
+3 -3
ファイルの表示
@@ -37,7 +37,7 @@ public sealed class SpectrumColorShiftRenderingTests
static Rendering Render(IGraphicsDevicesAndContext devices, SourceImage source, ShiftSettings settings)
{
using var effect = new SpectrumColorShiftCustomEffect(devices);
effect.SetInput(0, source.Bitmap, true);
effect.SetSource(source.Bitmap, true);
settings.Apply(effect);
using var output = effect.Output;
@@ -476,7 +476,7 @@ public sealed class SpectrumColorShiftRenderingTests
var inPlace = Render(context, source, settings);
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, movedOutput, true);
effect.SetSource(movedOutput, true);
settings.Apply(effect);
using var output = effect.Output;
var travelled = Rendering.Capture(context, output);
@@ -572,7 +572,7 @@ public sealed class SpectrumColorShiftRenderingTests
using var bitmap = context.DeviceContext.CreateBitmap(new SizeI(96, 96), nint.Zero, stride, new BitmapProperties1(SourceImage.PixelFormat, SourceImage.Dpi, SourceImage.Dpi, BitmapOptions.None));
bitmap.CopyFromMemory(pixels, stride);
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, bitmap, true);
effect.SetSource(bitmap, true);
new ShiftSettings(Mode: mode, Distance: 12f).Apply(effect);
using var output = effect.Output;
+1 -1
ファイルの表示
@@ -24,7 +24,7 @@ public sealed class StepCountRenderingTests
using var context = devices.CreateContext();
using var source = new SourceImage(context, 48, 32, Gradient);
using var effect = new SpectrumColorShiftCustomEffect(context);
effect.SetInput(0, source.Bitmap, true);
effect.SetSource(source.Bitmap, true);
using var output = effect.Output;
foreach (var steps in Enumerable.Range(Spectrum.MinSteps, Spectrum.MaxSteps - Spectrum.MinSteps + 1))
+35 -28
ファイルの表示
@@ -9,39 +9,40 @@ using YukkuriMovieMaker.Player.Video;
namespace SpectrumColorShift;
internal sealed class SpectrumColorShiftCustomEffect : D2D1CustomShaderEffectBase
internal sealed class SpectrumColorShiftCustomEffect : IDisposable
{
private const int SourceInput = 0;
private const int LinearInput = 1;
private const int EffectInputs = LinearInput + 1;
internal const int SourceInput = 0;
internal const int LightInput = 1;
private const int EffectInputs = LightInput + 1;
private readonly ShiftEffect _shift;
private readonly LinearizeCustomEffect _linearized;
public SpectrumColorShiftCustomEffect(IGraphicsDevicesAndContext devices) : base(Create<EffectImpl>(devices))
public SpectrumColorShiftCustomEffect(IGraphicsDevicesAndContext devices)
{
_shift = new ShiftEffect(devices);
_linearized = new LinearizeCustomEffect(devices);
if (!IsEnabled)
return;
using var linearized = _linearized.Output;
base.SetInput(LinearInput, linearized, true);
using var light = _linearized.Output;
_shift.SetInput(LightInput, light, true);
}
public new bool IsEnabled => base.IsEnabled && _linearized.IsEnabled;
public bool IsEnabled => _shift.IsEnabled && _linearized.IsEnabled;
public new void SetInput(int index, ID2D1Image? input, RawBool invalidate)
public ID2D1Image Output => _shift.Output;
public void SetSource(ID2D1Image? source, RawBool invalidate)
{
base.SetInput(index, input, invalidate);
if (index == SourceInput)
_linearized.SetInput(SourceInput, input, invalidate);
_shift.SetInput(SourceInput, source, invalidate);
_linearized.SetInput(0, source, invalidate);
}
protected override void DisposeCore(nint nativePointer, bool disposing)
public void Dispose()
{
if (disposing)
_linearized.Dispose();
base.DisposeCore(nativePointer, disposing);
_linearized.Dispose();
_shift.Dispose();
}
internal enum PropertyIndex
@@ -58,16 +59,22 @@ internal sealed class SpectrumColorShiftCustomEffect : D2D1CustomShaderEffectBas
Physical,
}
public float Distance { set => SetValue((int)PropertyIndex.Distance, value); }
public int Mode { set => SetValue((int)PropertyIndex.Mode, value); }
public float Angle { set => SetValue((int)PropertyIndex.Angle, value); }
public float CenterX { set => SetValue((int)PropertyIndex.CenterX, value); }
public float CenterY { set => SetValue((int)PropertyIndex.CenterY, value); }
public float Strength { set => SetValue((int)PropertyIndex.Strength, value); }
public int Dispersion { set => SetValue((int)PropertyIndex.Dispersion, value); }
public float ReferenceWavelength { set => SetValue((int)PropertyIndex.ReferenceWavelength, value); }
public int Steps { set => SetValue((int)PropertyIndex.Steps, value); }
public int Physical { set => SetValue((int)PropertyIndex.Physical, value); }
public float Distance { set => _shift.SetValue((int)PropertyIndex.Distance, value); }
public int Mode { set => _shift.SetValue((int)PropertyIndex.Mode, value); }
public float Angle { set => _shift.SetValue((int)PropertyIndex.Angle, value); }
public float CenterX { set => _shift.SetValue((int)PropertyIndex.CenterX, value); }
public float CenterY { set => _shift.SetValue((int)PropertyIndex.CenterY, value); }
public float Strength { set => _shift.SetValue((int)PropertyIndex.Strength, value); }
public int Dispersion { set => _shift.SetValue((int)PropertyIndex.Dispersion, value); }
public float ReferenceWavelength { set => _shift.SetValue((int)PropertyIndex.ReferenceWavelength, value); }
public int Steps { set => _shift.SetValue((int)PropertyIndex.Steps, value); }
public int Physical { set => _shift.SetValue((int)PropertyIndex.Physical, value); }
internal float ReadFloat(PropertyIndex index) => _shift.GetFloatValue((int)index);
internal int ReadInt(PropertyIndex index) => _shift.GetIntValue((int)index);
private sealed class ShiftEffect(IGraphicsDevicesAndContext devices) : D2D1CustomShaderEffectBase(Create<EffectImpl>(devices));
[CustomEffect(EffectInputs)]
internal sealed class EffectImpl : D2D1CustomShaderEffectImplBase<EffectImpl>
@@ -323,7 +330,7 @@ internal sealed class SpectrumColorShiftCustomEffect : D2D1CustomShaderEffectBas
var requested = inputRect.Right <= inputRect.Left || inputRect.Bottom <= inputRect.Top
? inputRect
: ShiftGeometry.Input(outputRect, _mode, _header.Distance, _header.Direction, _header.Center, _header.Radius);
var activeInput = _physical ? LinearInput : SourceInput;
var activeInput = _physical ? LightInput : SourceInput;
for (var index = 0; index < inputRects.Length; index++)
inputRects[index] = index == activeInput ? requested : default;
+2 -2
ファイルの表示
@@ -94,7 +94,7 @@ internal sealed class SpectrumColorShiftEffectProcessor(
protected override void setInput(ID2D1Image? input)
{
_effect?.SetInput(0, input, true);
_effect?.SetSource(input, true);
}
protected override void ClearEffectChain()
@@ -112,7 +112,7 @@ internal sealed class SpectrumColorShiftEffectProcessor(
private void ClearEffectChainCore()
{
_effect?.SetInput(0, null, true);
_effect?.SetSource(null, true);
_isFirst = true;
}