方式ごとに分けたシェーダーで64ステップの描画と初回描画を速くする
・直線、放射、回転の方式ごとにコンパイルしたシェーダーを選んで使うよう変更-M
このコミットが含まれているのは:
6ファイル変更
+105
-42
検索条件に一致するファイルはありません
@@ -228,7 +228,7 @@ internal sealed class SpectrumColorShiftCustomEffect : D2D1CustomShaderEffectBas
|
||||
{
|
||||
_cb.SpreadScale = ShiftGeometry.Spread(_mode, _cb.Distance, _cb.Radius);
|
||||
|
||||
var shader = StepShaders.Select(_physical, _steps);
|
||||
var shader = StepShaders.Select(_physical, _mode, _steps);
|
||||
if (shader != _shader)
|
||||
{
|
||||
drawInformation.SetPixelShader(shader, PixelOptions.None);
|
||||
|
||||
@@ -11,13 +11,15 @@ internal static class StepShaders
|
||||
private static readonly Variants Legacy = new(LegacyName);
|
||||
private static readonly Variants Physical = new(PhysicalName);
|
||||
|
||||
public static IEnumerable<int> Counts => Enumerable.Range(0, Variants.Length).Select(CountAt);
|
||||
public static IEnumerable<int> Counts => Enumerable.Range(0, Variants.CountLength).Select(Variants.CountAt);
|
||||
|
||||
public static byte[] DefaultBytes => Legacy.Bytes(Spectrum.DefaultSteps);
|
||||
public static IEnumerable<ShiftMode> Modes => Variants.Modes;
|
||||
|
||||
public static string ResourceName(bool physical, int count) => (physical ? Physical : Legacy).ResourceName(count);
|
||||
public static byte[] DefaultBytes => Legacy.Bytes(ShiftMode.Linear, Spectrum.DefaultSteps);
|
||||
|
||||
public static Guid Select(bool physical, int steps) => (physical ? Physical : Legacy).Id(steps);
|
||||
public static string ResourceName(bool physical, ShiftMode mode, int count) => (physical ? Physical : Legacy).ResourceName(mode, count);
|
||||
|
||||
public static Guid Select(bool physical, ShiftMode mode, int steps) => (physical ? Physical : Legacy).Id(mode, steps);
|
||||
|
||||
public static void Load(ID2D1EffectContext effectContext)
|
||||
{
|
||||
@@ -25,32 +27,44 @@ internal static class StepShaders
|
||||
Physical.Load(effectContext);
|
||||
}
|
||||
|
||||
private static int CountAt(int index) => Spectrum.MinSteps + index * Spectrum.StepQuantum;
|
||||
|
||||
private sealed class Variants(string name)
|
||||
private sealed class Variants
|
||||
{
|
||||
public static int Length { get; } = (Spectrum.MaxSteps - Spectrum.MinSteps) / Spectrum.StepQuantum + 1;
|
||||
public static ShiftMode[] Modes { get; } = Enum.GetValues<ShiftMode>();
|
||||
|
||||
private readonly Guid[] _ids = [.. Enumerable.Range(0, Length).Select(_ => Guid.NewGuid())];
|
||||
private readonly Lazy<byte[]>[] _bytes = [.. Enumerable.Range(0, Length).Select(index => new Lazy<byte[]>(() => Read(name, CountAt(index))))];
|
||||
public static int CountLength { get; } = (Spectrum.MaxSteps - Spectrum.MinSteps) / Spectrum.StepQuantum + 1;
|
||||
|
||||
public string ResourceName(int count) => $"{name}{count}";
|
||||
private readonly string _name;
|
||||
private readonly Guid[] _ids;
|
||||
private readonly Lazy<byte[]>[] _bytes;
|
||||
|
||||
public Guid Id(int steps) => _ids[IndexOf(steps)];
|
||||
public Variants(string name)
|
||||
{
|
||||
_name = name;
|
||||
_ids = [.. Enumerable.Range(0, Modes.Length * CountLength).Select(_ => Guid.NewGuid())];
|
||||
_bytes = [.. Enumerable.Range(0, Modes.Length * CountLength).Select(index => new Lazy<byte[]>(() => Read(index)))];
|
||||
}
|
||||
|
||||
public byte[] Bytes(int steps) => _bytes[IndexOf(steps)].Value;
|
||||
public static int CountAt(int index) => Spectrum.MinSteps + index * Spectrum.StepQuantum;
|
||||
|
||||
public string ResourceName(ShiftMode mode, int count) => $"{_name}{mode}{count}";
|
||||
|
||||
public Guid Id(ShiftMode mode, int steps) => _ids[IndexOf(mode, steps)];
|
||||
|
||||
public byte[] Bytes(ShiftMode mode, int steps) => _bytes[IndexOf(mode, steps)].Value;
|
||||
|
||||
public void Load(ID2D1EffectContext effectContext)
|
||||
{
|
||||
for (var index = 0; index < Length; index++)
|
||||
for (var index = 0; index < _ids.Length; index++)
|
||||
{
|
||||
var bytes = _bytes[index].Value;
|
||||
effectContext.LoadPixelShader(_ids[index], bytes, bytes.Length);
|
||||
}
|
||||
}
|
||||
|
||||
private static int IndexOf(int steps) => (Spectrum.Padded(steps) - Spectrum.MinSteps) / Spectrum.StepQuantum;
|
||||
private static int IndexOf(ShiftMode mode, int steps)
|
||||
=> Array.IndexOf(Modes, mode) * CountLength + (Spectrum.Padded(steps) - Spectrum.MinSteps) / Spectrum.StepQuantum;
|
||||
|
||||
private static byte[] Read(string name, int count) => PackResourceReader.ReadAllBytes(ShaderResourceUri.Get($"{name}{count}"));
|
||||
private byte[] Read(int index)
|
||||
=> PackResourceReader.ReadAllBytes(ShaderResourceUri.Get(ResourceName(Modes[index / CountLength], CountAt(index % CountLength))));
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする