影響する列の範囲をシェーダーで求めて窓の設定を取り除く
このコミットが含まれているのは:
7ファイル変更
+27
-100
検索条件に一致するファイルはありません
@@ -4,9 +4,8 @@ cbuffer Constants : register(b0)
|
||||
{
|
||||
float4 field : packoffset(c0);
|
||||
float4 style : packoffset(c1);
|
||||
float4 options : packoffset(c2);
|
||||
float4 tint : packoffset(c3);
|
||||
float4 values[64] : packoffset(c4);
|
||||
float4 tint : packoffset(c2);
|
||||
float4 values[64] : packoffset(c3);
|
||||
};
|
||||
|
||||
float4 main(
|
||||
@@ -25,8 +24,7 @@ float4 main(
|
||||
float threshold = style.x;
|
||||
float rimThickness = style.y;
|
||||
float rimBrightness = style.z;
|
||||
int window = (int)style.w;
|
||||
float bipolar = options.x;
|
||||
float bipolar = style.w;
|
||||
|
||||
float halfWidth = width * 0.5;
|
||||
float halfHeight = height * 0.5;
|
||||
@@ -37,12 +35,13 @@ float4 main(
|
||||
float2 local = scenePosition.xy;
|
||||
float antialias = max(max(fwidth(local.x), fwidth(local.y)), 0.5);
|
||||
|
||||
int nearest = (int)floor((local.x + halfWidth) / columnWidth);
|
||||
float density = 0.0;
|
||||
float2 gradient = float2(0.0, 0.0);
|
||||
|
||||
int first = max(nearest - window, 0);
|
||||
int last = min(nearest + window, count - 1);
|
||||
float firstReached = (local.x - radius + halfWidth) / columnWidth - 0.5;
|
||||
float lastReached = (local.x + radius + halfWidth) / columnWidth - 0.5;
|
||||
int first = (int)clamp(ceil(firstReached), 0.0, count - 1.0);
|
||||
int last = (int)clamp(floor(lastReached), -1.0, count - 1.0);
|
||||
|
||||
[loop]
|
||||
for (int index = first; index <= last; index++)
|
||||
|
||||
@@ -170,27 +170,6 @@ public sealed class MetaballSpectrumCustomEffectTests
|
||||
Assert.Equal(expected, Read(effect, PropertyIndex.RimBrightness));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-3f, 0f)]
|
||||
[InlineData(0f, 0f)]
|
||||
[InlineData(1f, 1f)]
|
||||
[InlineData(8f, 8f)]
|
||||
[InlineData(9f, 9f)]
|
||||
[InlineData(1000f, 1000f)]
|
||||
[InlineData((float)MaxWindow, (float)MaxWindow)]
|
||||
[InlineData(MaxWindow + 1024f, (float)MaxWindow)]
|
||||
[InlineData(float.MaxValue, (float)MaxWindow)]
|
||||
public void TheWindowIsNotCutOffBeforeTheShaderCapacity(float value, float expected)
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
using var effect = new MetaballSpectrumCustomEffect(context);
|
||||
|
||||
effect.Window = value;
|
||||
|
||||
Assert.Equal(expected, Read(effect, PropertyIndex.Window));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1f, 0f)]
|
||||
[InlineData(0.5f, 0.5f)]
|
||||
|
||||
@@ -24,7 +24,7 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
return MemoryMarshal.AsBytes(block.AsSpan()).ToArray();
|
||||
}
|
||||
|
||||
static void Configure(MetaballSpectrumCustomEffect effect, MetaballReference spec, int window, int? count = null)
|
||||
static void Configure(MetaballSpectrumCustomEffect effect, MetaballReference spec, int? count = null)
|
||||
{
|
||||
effect.FieldWidth = (float)spec.Width;
|
||||
effect.FieldHeight = (float)spec.Height;
|
||||
@@ -33,7 +33,6 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
effect.Threshold = (float)spec.Threshold;
|
||||
effect.RimThickness = (float)spec.RimThickness;
|
||||
effect.RimBrightness = (float)spec.RimBrightness;
|
||||
effect.Window = window;
|
||||
effect.Bipolar = spec.Bipolar ? 1f : 0f;
|
||||
effect.ColorR = (float)spec.Tint.R;
|
||||
effect.ColorG = (float)spec.Tint.G;
|
||||
@@ -42,7 +41,7 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
effect.Values = Packed(spec.Values);
|
||||
}
|
||||
|
||||
static Rendering Render(IGraphicsDevicesAndContext devices, MetaballReference spec, int window = 3, int? count = null)
|
||||
static Rendering Render(IGraphicsDevicesAndContext devices, MetaballReference spec, int? count = null)
|
||||
{
|
||||
var context = devices.DeviceContext;
|
||||
var halfWidth = (float)(spec.Width * 0.5 + spec.Radius + Margin);
|
||||
@@ -52,7 +51,7 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
using var clip = new Crop(context) { Rectangle = new Vector4(-halfWidth, -halfHeight, halfWidth, halfHeight) };
|
||||
using var floodOutput = flood.Output;
|
||||
effect.SetInput(0, floodOutput, true);
|
||||
Configure(effect, spec, window, count);
|
||||
Configure(effect, spec, count);
|
||||
using var effectOutput = effect.Output;
|
||||
clip.SetInput(0, effectOutput, true);
|
||||
using var output = clip.Output;
|
||||
@@ -82,7 +81,6 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
effect => effect.Threshold = 0.8f,
|
||||
effect => effect.RimThickness = 12f,
|
||||
effect => effect.RimBrightness = 0f,
|
||||
effect => effect.Window = 0f,
|
||||
effect => effect.Bipolar = 1f,
|
||||
effect => effect.ColorR = 0.8f,
|
||||
effect => effect.ColorG = 0.9f,
|
||||
@@ -99,7 +97,6 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
"Threshold",
|
||||
"RimThickness",
|
||||
"RimBrightness",
|
||||
"Window",
|
||||
"Bipolar",
|
||||
"ColorR",
|
||||
"ColorG",
|
||||
@@ -123,11 +120,11 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
using var live = new MetaballSpectrumCustomEffect(context);
|
||||
using var liveClip = new Crop(context.DeviceContext) { Rectangle = new Vector4(-120f, -80f, 120f, 80f) };
|
||||
live.SetInput(0, floodOutput, true);
|
||||
Configure(live, Base, 3);
|
||||
Configure(live, Base);
|
||||
using var fresh = new MetaballSpectrumCustomEffect(context);
|
||||
using var freshClip = new Crop(context.DeviceContext) { Rectangle = new Vector4(-120f, -80f, 120f, 80f) };
|
||||
fresh.SetInput(0, floodOutput, true);
|
||||
Configure(fresh, Base, 3);
|
||||
Configure(fresh, Base);
|
||||
change(fresh);
|
||||
|
||||
var before = Capture(context, live, liveClip);
|
||||
@@ -203,7 +200,7 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
using var context = devices.CreateContext();
|
||||
var spec = new MetaballReference(400d, 200d, 30d, 0.45, 4d, 0.6, false, Ramp(24), Blue);
|
||||
|
||||
var rendering = Render(context, spec, window: 4);
|
||||
var rendering = Render(context, spec);
|
||||
|
||||
Assert.Equal(0, spec.Mismatches(rendering, Tolerance));
|
||||
}
|
||||
@@ -215,7 +212,7 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
using var context = devices.CreateContext();
|
||||
var spec = new MetaballReference(400d, 200d, 30d, 0.45, 4d, 0.6, true, Wave(24), Blue);
|
||||
|
||||
var rendering = Render(context, spec, window: 4);
|
||||
var rendering = Render(context, spec);
|
||||
|
||||
Assert.Equal(0, spec.Mismatches(rendering, Tolerance));
|
||||
}
|
||||
@@ -230,7 +227,7 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
using var context = devices.CreateContext();
|
||||
var spec = new MetaballReference(400d, 200d, 30d, threshold, rim, brightness, false, Ramp(16), Blue);
|
||||
|
||||
var rendering = Render(context, spec, window: 4);
|
||||
var rendering = Render(context, spec);
|
||||
|
||||
Assert.Equal(0, spec.Mismatches(rendering, Tolerance));
|
||||
}
|
||||
@@ -255,7 +252,7 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
using var context = devices.CreateContext();
|
||||
var spec = new MetaballReference(400d, 200d, 30d, 0.45, 0d, 1d, false, Ramp(16), Blue);
|
||||
|
||||
var rendering = Render(context, spec, window: 4);
|
||||
var rendering = Render(context, spec);
|
||||
|
||||
Assert.All(rendering.Coordinates().Where(point => rendering[point.X, point.Y].Alpha == byte.MaxValue), point => Assert.Equal(Bgra.Opaque(255, 102, 32), rendering[point.X, point.Y]));
|
||||
}
|
||||
@@ -265,8 +262,8 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
var plain = Render(context, new MetaballReference(400d, 200d, 30d, 0.45, 6d, 0d, false, Ramp(16), Blue), window: 4);
|
||||
var bright = Render(context, new MetaballReference(400d, 200d, 30d, 0.45, 6d, 1d, false, Ramp(16), Blue), window: 4);
|
||||
var plain = Render(context, new MetaballReference(400d, 200d, 30d, 0.45, 6d, 0d, false, Ramp(16), Blue));
|
||||
var bright = Render(context, new MetaballReference(400d, 200d, 30d, 0.45, 6d, 1d, false, Ramp(16), Blue));
|
||||
|
||||
var whitened = bright.Coordinates().Count(point => bright[point.X, point.Y].Red > plain[point.X, point.Y].Red + 40);
|
||||
|
||||
@@ -280,11 +277,11 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
var spec = new MetaballReference(200d, 100d, 60d, 0.45, 4d, 0.6, false, Ramp(64), Blue);
|
||||
var needed = (int)Math.Ceiling(spec.Radius / (spec.Width / 64)) + 1;
|
||||
var reachedColumns = (int)Math.Ceiling(spec.Radius / (spec.Width / 64));
|
||||
|
||||
var rendering = Render(context, spec, window: needed);
|
||||
var rendering = Render(context, spec);
|
||||
|
||||
Assert.True(needed > 8);
|
||||
Assert.True(reachedColumns > 8);
|
||||
Assert.Equal(0, spec.Mismatches(rendering, Tolerance));
|
||||
}
|
||||
|
||||
@@ -295,8 +292,8 @@ public sealed class MetaballSpectrumRenderingTests
|
||||
using var context = devices.CreateContext();
|
||||
var spec = new MetaballReference(400d, 200d, 30d, 0.45, 4d, 0.6, true, Wave(24), Blue);
|
||||
|
||||
var first = Render(context, spec, window: 4);
|
||||
var second = Render(context, spec, window: 4);
|
||||
var first = Render(context, spec);
|
||||
var second = Render(context, spec);
|
||||
|
||||
Assert.True(first.SamePixelsAs(second));
|
||||
}
|
||||
|
||||
@@ -333,25 +333,6 @@ public sealed class MetaballSpectrumSourceTests
|
||||
Assert.True(after.SamePixelsAs(expected), setting);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ARadiusRaisedAfterTheFirstFrameWidensTheWindow()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
var spectrum = Enumerable.Range(0, 64).Select(index => (float)(0.1 + 0.9 * Math.Abs(Math.Sin(index * 0.7)))).ToArray();
|
||||
var parameter = Parameter(radius: 5d);
|
||||
using var source = parameter.CreateShapeSource(context);
|
||||
using var rebuilt = Parameter(radius: 60d).CreateShapeSource(context);
|
||||
|
||||
RenderFrame(context, source, 0, spectrum);
|
||||
parameter.BlobRadius.Values[0].Value = 60d;
|
||||
var after = RenderFrame(context, source, 0, spectrum);
|
||||
var expected = RenderFrame(context, rebuilt, 0, spectrum);
|
||||
|
||||
Assert.True(after.SamePixelsAs(expected));
|
||||
Assert.Equal(0, ReferenceOf(parameter, 0, spectrum).Mismatches(after, Tolerance));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AChangedSpectrumReachesTheNextFrame()
|
||||
{
|
||||
|
||||
@@ -20,11 +20,7 @@ public sealed partial class ShaderContractTests
|
||||
"Threshold",
|
||||
"RimThickness",
|
||||
"RimBrightness",
|
||||
"Window",
|
||||
"Bipolar",
|
||||
"Pad0",
|
||||
"Pad1",
|
||||
"Pad2",
|
||||
"ColorR",
|
||||
"ColorG",
|
||||
"ColorB",
|
||||
@@ -35,7 +31,6 @@ public sealed partial class ShaderContractTests
|
||||
{
|
||||
["field"] = "FieldWidth",
|
||||
["style"] = "Threshold",
|
||||
["options"] = "Bipolar",
|
||||
["tint"] = "ColorR",
|
||||
};
|
||||
|
||||
@@ -75,7 +70,7 @@ public sealed partial class ShaderContractTests
|
||||
{
|
||||
var declared = Declared();
|
||||
|
||||
Assert.Equal(4 * RegisterByteSize, Marshal.SizeOf(ConstantBuffer));
|
||||
Assert.Equal(3 * RegisterByteSize, Marshal.SizeOf(ConstantBuffer));
|
||||
Assert.Equal(Marshal.SizeOf(ConstantBuffer), declared["values"].Offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ internal sealed class MetaballSpectrumCustomEffect(IGraphicsDevicesAndContext de
|
||||
{
|
||||
public const int MaxValues = 256;
|
||||
public const int ValueByteSize = MaxValues * sizeof(float);
|
||||
public const int MaxWindow = 1 << 20;
|
||||
|
||||
internal enum PropertyIndex
|
||||
{
|
||||
@@ -20,7 +19,6 @@ internal sealed class MetaballSpectrumCustomEffect(IGraphicsDevicesAndContext de
|
||||
Threshold,
|
||||
RimThickness,
|
||||
RimBrightness,
|
||||
Window,
|
||||
Bipolar,
|
||||
ColorR,
|
||||
ColorG,
|
||||
@@ -36,7 +34,6 @@ internal sealed class MetaballSpectrumCustomEffect(IGraphicsDevicesAndContext de
|
||||
public float Threshold { set => SetValue((int)PropertyIndex.Threshold, value); }
|
||||
public float RimThickness { set => SetValue((int)PropertyIndex.RimThickness, value); }
|
||||
public float RimBrightness { set => SetValue((int)PropertyIndex.RimBrightness, value); }
|
||||
public float Window { set => SetValue((int)PropertyIndex.Window, value); }
|
||||
public float Bipolar { set => SetValue((int)PropertyIndex.Bipolar, value); }
|
||||
public float ColorR { set => SetValue((int)PropertyIndex.ColorR, value); }
|
||||
public float ColorG { set => SetValue((int)PropertyIndex.ColorG, value); }
|
||||
@@ -47,7 +44,7 @@ internal sealed class MetaballSpectrumCustomEffect(IGraphicsDevicesAndContext de
|
||||
[CustomEffect(1)]
|
||||
private sealed class EffectImpl : D2D1CustomShaderEffectImplBase<EffectImpl>
|
||||
{
|
||||
private const int HeaderByteSize = 64;
|
||||
private const int HeaderByteSize = 48;
|
||||
private const int ConstantBufferByteSize = HeaderByteSize + ValueByteSize;
|
||||
|
||||
private ConstantBuffer _cb;
|
||||
@@ -74,9 +71,6 @@ internal sealed class MetaballSpectrumCustomEffect(IGraphicsDevicesAndContext de
|
||||
[CustomEffectProperty(PropertyType.Float, (int)PropertyIndex.RimBrightness)]
|
||||
public float RimBrightness { get => _cb.RimBrightness; set { _cb.RimBrightness = Math.Clamp(value, 0f, 1f); UpdateConstants(); } }
|
||||
|
||||
[CustomEffectProperty(PropertyType.Float, (int)PropertyIndex.Window)]
|
||||
public float Window { get => _cb.Window; set { _cb.Window = Math.Clamp(value, 0f, MaxWindow); UpdateConstants(); } }
|
||||
|
||||
[CustomEffectProperty(PropertyType.Float, (int)PropertyIndex.Bipolar)]
|
||||
public float Bipolar { get => _cb.Bipolar; set { _cb.Bipolar = Math.Clamp(value, 0f, 1f); UpdateConstants(); } }
|
||||
|
||||
@@ -140,11 +134,7 @@ internal sealed class MetaballSpectrumCustomEffect(IGraphicsDevicesAndContext de
|
||||
public float Threshold;
|
||||
public float RimThickness;
|
||||
public float RimBrightness;
|
||||
public float Window;
|
||||
public float Bipolar;
|
||||
public float Pad0;
|
||||
public float Pad1;
|
||||
public float Pad2;
|
||||
public float ColorR;
|
||||
public float ColorG;
|
||||
public float ColorB;
|
||||
|
||||
@@ -82,24 +82,13 @@ internal sealed class MetaballSpectrumSource : IAudioSpectrumSource
|
||||
|
||||
var count = SpectrumResampler.Resample(spectrum, MemoryMarshal.Cast<byte, float>(_valueBytes.AsSpan()));
|
||||
|
||||
var fieldWidth = _parameter.FieldWidth.GetValue(frame, length, fps);
|
||||
var radius = _parameter.BlobRadius.GetValue(frame, length, fps);
|
||||
|
||||
var window = 0;
|
||||
if (count > 0)
|
||||
{
|
||||
var columnWidth = fieldWidth / count;
|
||||
window = (int)Math.Clamp(Math.Ceiling(radius / columnWidth) + 1, 1, MetaballSpectrumCustomEffect.MaxWindow);
|
||||
}
|
||||
|
||||
var parameters = new Parameters(
|
||||
(float)fieldWidth,
|
||||
(float)_parameter.FieldWidth.GetValue(frame, length, fps),
|
||||
(float)_parameter.FieldHeight.GetValue(frame, length, fps),
|
||||
(float)radius,
|
||||
(float)_parameter.BlobRadius.GetValue(frame, length, fps),
|
||||
(float)(_parameter.Threshold.GetValue(frame, length, fps) / 100.0),
|
||||
(float)_parameter.RimThickness.GetValue(frame, length, fps),
|
||||
(float)(_parameter.RimBrightness.GetValue(frame, length, fps) / 100.0),
|
||||
window,
|
||||
_parameter.IsBipolar ? 1f : 0f,
|
||||
color.R / 255f,
|
||||
color.G / 255f,
|
||||
@@ -118,8 +107,6 @@ internal sealed class MetaballSpectrumSource : IAudioSpectrumSource
|
||||
_effect.RimThickness = parameters.RimThickness;
|
||||
if (_isFirst || _parameters.RimBrightness != parameters.RimBrightness)
|
||||
_effect.RimBrightness = parameters.RimBrightness;
|
||||
if (_isFirst || _parameters.Window != parameters.Window)
|
||||
_effect.Window = parameters.Window;
|
||||
if (_isFirst || _parameters.Bipolar != parameters.Bipolar)
|
||||
_effect.Bipolar = parameters.Bipolar;
|
||||
if (_isFirst || _parameters.ColorR != parameters.ColorR)
|
||||
@@ -175,7 +162,6 @@ internal sealed class MetaballSpectrumSource : IAudioSpectrumSource
|
||||
float Threshold,
|
||||
float RimThickness,
|
||||
float RimBrightness,
|
||||
float Window,
|
||||
float Bipolar,
|
||||
float ColorR,
|
||||
float ColorG,
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする