写真モードで水平線に隠れた部分を横にぼかして埋める
このコミットが含まれているのは:
6ファイル変更
+84
-10
検索条件に一致するファイルはありません
+34
-2
@@ -19,6 +19,10 @@ static const float HalfTexel = 0.5;
|
||||
static const float MinimumDepth = 1e-4;
|
||||
static const float MinimumShift = 1e-9;
|
||||
static const int MaximumTaps = 16;
|
||||
static const float FillRadiusFraction = 0.006;
|
||||
static const int FillHalfTaps = 4;
|
||||
static const float FillTaps = 9.0;
|
||||
static const float FillThreshold = 0.5;
|
||||
static const float MaximumSine = 0.1;
|
||||
|
||||
float ArcSine(float value)
|
||||
@@ -37,6 +41,16 @@ float ReadShift(float elevation)
|
||||
return MapTexture.SampleLevel(MapSampler, mapUv, 0).x;
|
||||
}
|
||||
|
||||
float ReadFill(float elevation)
|
||||
{
|
||||
float position = (elevation - mapStart) / mapSpan;
|
||||
if (position < 0.0 || position > 1.0)
|
||||
return 0.0;
|
||||
|
||||
float2 mapUv = float2((position * (mapWidth - 1.0) + HalfTexel) / mapWidth, HalfTexel);
|
||||
return MapTexture.SampleLevel(MapSampler, mapUv, 0).y;
|
||||
}
|
||||
|
||||
float4 main(
|
||||
float4 position : SV_POSITION,
|
||||
float4 scenePosition : SCENE_POSITION,
|
||||
@@ -61,6 +75,7 @@ float4 main(
|
||||
float sinAzimuth = direction.x / horizontal;
|
||||
float cosAzimuth = worldForward / horizontal;
|
||||
float pixelAngle = 1.0 / focalLength;
|
||||
float fillStep = FillRadiusFraction * (inputBounds.z - inputBounds.x) / FillHalfTaps;
|
||||
|
||||
float lowShift = ReadShift(elevation - 0.5 * pixelAngle);
|
||||
float highShift = ReadShift(elevation + 0.5 * pixelAngle);
|
||||
@@ -85,8 +100,25 @@ float4 main(
|
||||
float seenForward = cosAzimuth * cosSeen;
|
||||
float3 seenDirection = float3(sinAzimuth * cosSeen, seenDown * pitchCosine + seenForward * pitchSine, -seenDown * pitchSine + seenForward * pitchCosine);
|
||||
float2 seenPosition = center + focalLength * seenDirection.xy / max(seenDirection.z, MinimumDepth);
|
||||
float2 clamped = clamp(seenPosition, inputBounds.xy + HalfTexel, inputBounds.zw - HalfTexel);
|
||||
sum += SourceTexture.SampleLevel(SourceSampler, uv0.xy + (clamped - scenePosition.xy) * uv0.zw, 0);
|
||||
float2 lowerBound = inputBounds.xy + HalfTexel;
|
||||
float2 upperBound = inputBounds.zw - HalfTexel;
|
||||
if (ReadFill(sampled) > FillThreshold)
|
||||
{
|
||||
float4 blurred = float4(0.0, 0.0, 0.0, 0.0);
|
||||
[unroll]
|
||||
for (int offset = -FillHalfTaps; offset <= FillHalfTaps; offset++)
|
||||
{
|
||||
float2 shifted = clamp(seenPosition + float2(offset * fillStep, 0.0), lowerBound, upperBound);
|
||||
blurred += SourceTexture.SampleLevel(SourceSampler, uv0.xy + (shifted - scenePosition.xy) * uv0.zw, 0);
|
||||
}
|
||||
|
||||
sum += blurred / FillTaps;
|
||||
}
|
||||
else
|
||||
{
|
||||
float2 clamped = clamp(seenPosition, lowerBound, upperBound);
|
||||
sum += SourceTexture.SampleLevel(SourceSampler, uv0.xy + (clamped - scenePosition.xy) * uv0.zw, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return lerp(source, sum / taps, amount);
|
||||
|
||||
@@ -54,6 +54,7 @@ public sealed class MirageEffectProcessorTests
|
||||
double Value(Animation animation) => animation.GetValue(frame, Length, EffectDescriptions.Fps);
|
||||
var eyeHeight = Math.Clamp(Value(effect.EyeHeight), MirageSettings.MinimumEyeHeightMeters, MirageSettings.MaximumEyeHeightMeters);
|
||||
float[] shifts;
|
||||
float[]? fill = null;
|
||||
if (effect.Kind == MirageKind.Inferior)
|
||||
{
|
||||
shifts = MirageTable.BuildInferior(eyeHeight, Value(effect.HeatDifference), Value(effect.HeatThickness));
|
||||
@@ -61,11 +62,12 @@ public sealed class MirageEffectProcessorTests
|
||||
else
|
||||
{
|
||||
var distance = Value(effect.Distance) * MirageSettings.MetersPerKilometer;
|
||||
shifts = MirageTable.BuildSuperior(eyeHeight, Value(effect.InversionDifference), Value(effect.InversionHeight), Value(effect.InversionThickness), distance, effect.Source, MirageTable.BuildStandard(eyeHeight, distance));
|
||||
shifts = MirageTable.BuildSuperior(eyeHeight, Value(effect.InversionDifference), Value(effect.InversionHeight), Value(effect.InversionThickness), distance, effect.Source, MirageTable.BuildStandard(eyeHeight, distance), out var unseen);
|
||||
fill = unseen;
|
||||
}
|
||||
|
||||
var pitch = Value(effect.CameraPitch) * MirageSettings.RadiansPerDegree;
|
||||
shader = new MirageShaderModel(width, height, source, MirageTable.ToTexels(shifts), MirageSettings.GetHalfFieldOfViewTangent(Value(effect.FieldOfView)), (float)Math.Cos(pitch), (float)Math.Sin(pitch), (float)(Value(effect.Amount) / 100.0));
|
||||
shader = new MirageShaderModel(width, height, source, MirageTable.ToTexels(shifts, fill), MirageSettings.GetHalfFieldOfViewTangent(Value(effect.FieldOfView)), (float)Math.Cos(pitch), (float)Math.Sin(pitch), (float)(Value(effect.Amount) / 100.0));
|
||||
}
|
||||
|
||||
public Bgra Expected(int x, int y) => shader.Shade(x, y);
|
||||
|
||||
@@ -8,6 +8,9 @@ internal sealed class MirageShaderModel(int width, int height, Func<int, int, Bg
|
||||
const float MinimumShift = 1e-9f;
|
||||
const int MaximumTaps = 16;
|
||||
const float MaximumSine = 0.1f;
|
||||
const float FillThreshold = 0.5f;
|
||||
const int FillHalfTaps = 4;
|
||||
const float FillTaps = 9f;
|
||||
|
||||
readonly Vector4[] pixels = Premultiplied(width, height, source);
|
||||
|
||||
@@ -26,7 +29,7 @@ internal sealed class MirageShaderModel(int width, int height, Func<int, int, Bg
|
||||
return values;
|
||||
}
|
||||
|
||||
float ReadShift(float elevation)
|
||||
float Read(float elevation, int channel)
|
||||
{
|
||||
var position = (elevation - (float)MirageSettings.GetMapStartRadians()) / (float)MirageSettings.GetMapSpanRadians();
|
||||
if (position < 0f || position > 1f)
|
||||
@@ -34,11 +37,15 @@ internal sealed class MirageShaderModel(int width, int height, Func<int, int, Bg
|
||||
|
||||
var x = position * (MirageSettings.MapWidth - 1f);
|
||||
var index = Math.Min((int)MathF.Floor(x), MirageSettings.MapWidth - 2);
|
||||
var low = texels[index * MirageSettings.TexelChannels];
|
||||
var high = texels[(index + 1) * MirageSettings.TexelChannels];
|
||||
var low = texels[index * MirageSettings.TexelChannels + channel];
|
||||
var high = texels[(index + 1) * MirageSettings.TexelChannels + channel];
|
||||
return low + (high - low) * (x - index);
|
||||
}
|
||||
|
||||
float ReadShift(float elevation) => Read(elevation, 0);
|
||||
|
||||
float ReadFill(float elevation) => Read(elevation, 1);
|
||||
|
||||
Vector4 Sample(Vector2 position)
|
||||
{
|
||||
var x = Math.Clamp(position.X - 0.5f, 0f, width - 1f);
|
||||
@@ -85,6 +92,9 @@ internal sealed class MirageShaderModel(int width, int height, Func<int, int, Bg
|
||||
var stretch = MathF.Abs(pixelAngle + highShift - lowShift) / pixelAngle;
|
||||
var taps = Math.Clamp(MathF.Ceiling(stretch), 1f, MaximumTaps);
|
||||
var (sinAzimuth, cosAzimuth) = MathF.SinCos(azimuth);
|
||||
var fillStep = (float)MirageSettings.FillRadiusFraction * width / FillHalfTaps;
|
||||
var lowerBound = new Vector2(0.5f, 0.5f);
|
||||
var upperBound = new Vector2(width - 0.5f, height - 0.5f);
|
||||
var sum = Vector4.Zero;
|
||||
for (var tap = 0; tap < MaximumTaps && tap < taps; tap++)
|
||||
{
|
||||
@@ -95,7 +105,18 @@ internal sealed class MirageShaderModel(int width, int height, Func<int, int, Bg
|
||||
var seenForward = cosAzimuth * cosSeen;
|
||||
var seenDirection = new Vector3(sinAzimuth * cosSeen, seenDown * pitchCosine + seenForward * pitchSine, -seenDown * pitchSine + seenForward * pitchCosine);
|
||||
var position = center + focal * new Vector2(seenDirection.X, seenDirection.Y) / MathF.Max(seenDirection.Z, MinimumDepth);
|
||||
sum += Sample(Vector2.Clamp(position, new Vector2(0.5f, 0.5f), new Vector2(width - 0.5f, height - 0.5f)));
|
||||
if (ReadFill(sampled) > FillThreshold)
|
||||
{
|
||||
var blurred = Vector4.Zero;
|
||||
for (var offset = -FillHalfTaps; offset <= FillHalfTaps; offset++)
|
||||
blurred += Sample(Vector2.Clamp(position + new Vector2(offset * fillStep, 0f), lowerBound, upperBound));
|
||||
|
||||
sum += blurred / FillTaps;
|
||||
}
|
||||
else
|
||||
{
|
||||
sum += Sample(Vector2.Clamp(position, lowerBound, upperBound));
|
||||
}
|
||||
}
|
||||
|
||||
return ToBgra(Vector4.Lerp(original, sum / taps, amount));
|
||||
|
||||
@@ -88,7 +88,8 @@ internal sealed class MirageEffectProcessor(IGraphicsDevicesAndContext devices,
|
||||
_standardKey = standardKey;
|
||||
}
|
||||
|
||||
return MirageTable.ToTexels(MirageTable.BuildSuperior(key.EyeHeight, key.InversionDifference, key.InversionHeight, key.InversionThickness, distanceMeters, key.Source, _standard));
|
||||
var shifts = MirageTable.BuildSuperior(key.EyeHeight, key.InversionDifference, key.InversionHeight, key.InversionThickness, distanceMeters, key.Source, _standard, out var fill);
|
||||
return MirageTable.ToTexels(shifts, fill);
|
||||
}
|
||||
|
||||
private void WriteMap(float[] texels)
|
||||
|
||||
@@ -46,6 +46,8 @@ internal static class MirageSettings
|
||||
public const double MinimumSlope = 1e-4;
|
||||
public const int MaximumSteps = 2_000_000;
|
||||
public const int MaximumTaps = 16;
|
||||
public const double FillRadiusFraction = 0.006;
|
||||
public const int FillTaps = 9;
|
||||
|
||||
public static readonly float MinimumHalfFieldTangent = GetHalfFieldOfViewTangent(MinimumFieldOfViewDegrees);
|
||||
public static readonly float MaximumHalfFieldTangent = GetHalfFieldOfViewTangent(MaximumFieldOfViewDegrees);
|
||||
|
||||
+17
-1
@@ -16,9 +16,14 @@ internal static class MirageTable
|
||||
}
|
||||
|
||||
public static float[] BuildSuperior(double eyeHeight, double difference, double height, double thickness, double distanceMeters, MirageSource source, double[] standard)
|
||||
=> BuildSuperior(eyeHeight, difference, height, thickness, distanceMeters, source, standard, out _);
|
||||
|
||||
public static float[] BuildSuperior(double eyeHeight, double difference, double height, double thickness, double distanceMeters, MirageSource source, double[] standard, out float[] fill)
|
||||
{
|
||||
var atmosphere = new Atmosphere(AtmosphereLayer.Inversion, difference, height, thickness);
|
||||
var shifts = new float[MirageSettings.MapWidth];
|
||||
var unseen = new float[MirageSettings.MapWidth];
|
||||
var (gapLow, gapHigh) = HiddenCoordinates(standard);
|
||||
Parallel.For(0, MirageSettings.MapWidth, index =>
|
||||
{
|
||||
var angle = MirageSettings.GetMapAngleRadians(index);
|
||||
@@ -26,10 +31,19 @@ internal static class MirageTable
|
||||
var coordinate = Coordinate(result, distanceMeters);
|
||||
var seen = source == MirageSource.Photo ? StandardElevation(standard, coordinate) : GeometricElevation(coordinate, eyeHeight, distanceMeters);
|
||||
shifts[index] = (float)(seen - angle);
|
||||
if (source == MirageSource.Photo && coordinate > gapLow && coordinate < gapHigh)
|
||||
unseen[index] = 1f;
|
||||
});
|
||||
fill = unseen;
|
||||
return shifts;
|
||||
}
|
||||
|
||||
public static (double Low, double High) HiddenCoordinates(double[] standard)
|
||||
{
|
||||
var first = Array.FindIndex(standard, coordinate => coordinate >= 0.0);
|
||||
return first > 0 ? (standard[first - 1], standard[first]) : (double.NaN, double.NaN);
|
||||
}
|
||||
|
||||
public static float[] BuildInferior(double eyeHeight, double difference, double thickness)
|
||||
{
|
||||
var heated = new Atmosphere(AtmosphereLayer.Heated, difference, 0.0, thickness);
|
||||
@@ -97,12 +111,14 @@ internal static class MirageTable
|
||||
return values[low] + fraction * (values[high] - values[low]);
|
||||
}
|
||||
|
||||
public static float[] ToTexels(float[] shifts)
|
||||
public static float[] ToTexels(float[] shifts, float[]? fill = null)
|
||||
{
|
||||
var texels = new float[shifts.Length * MirageSettings.TexelChannels];
|
||||
for (var index = 0; index < shifts.Length; index++)
|
||||
{
|
||||
texels[index * MirageSettings.TexelChannels] = shifts[index];
|
||||
if (fill is not null)
|
||||
texels[index * MirageSettings.TexelChannels + 1] = fill[index];
|
||||
texels[index * MirageSettings.TexelChannels + 3] = 1f;
|
||||
}
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする