Compare commits
8 Commits
dfa2cf3f31
...
ILGpu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c65346aeec | ||
|
|
a74ae1167e | ||
|
|
d7d2091d64 | ||
|
|
ea28738280 | ||
|
|
2faab96a7d | ||
|
|
8c5ca2ce21 | ||
|
|
d0fbd31c1d | ||
|
|
5cf8612699 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ obj/
|
|||||||
/packages/
|
/packages/
|
||||||
riderModule.iml
|
riderModule.iml
|
||||||
/_ReSharper.Caches/
|
/_ReSharper.Caches/
|
||||||
|
publish/
|
||||||
6
.run/Release Build Linux-x64.run.xml
Normal file
6
.run/Release Build Linux-x64.run.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Release Build Linux-x64" type="DotNetFolderPublish" factoryName="Publish to folder">
|
||||||
|
<riderPublish configuration="Release" delete_existing_files="true" include_native_libs_for_self_extract="true" platform="Any CPU" produce_single_file="true" runtime="linux-x64" target_folder="$PROJECT_DIR$/SDFMapCreator/publish/linux-x64" target_framework="net8.0" uuid_high="-7972981449231152312" uuid_low="-5206031561210231144" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
6
.run/Release Build Win-x64.run.xml
Normal file
6
.run/Release Build Win-x64.run.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Release Build Win-x64" type="DotNetFolderPublish" factoryName="Publish to folder">
|
||||||
|
<riderPublish configuration="Release" delete_existing_files="true" include_native_libs_for_self_extract="true" platform="Any CPU" produce_single_file="true" runtime="win-x64" target_folder="$PROJECT_DIR$/SDFMapCreator/publish/win-x64" target_framework="net8.0" uuid_high="-7972981449231152312" uuid_low="-5206031561210231144" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -12,4 +12,8 @@
|
|||||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_NESTED_FOR_STMT/@EntryValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_NESTED_FOR_STMT/@EntryValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_ARROW_WITH_EXPRESSIONS/@EntryValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_ARROW_WITH_EXPRESSIONS/@EntryValue">True</s:Boolean>
|
||||||
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">151</s:Int64>
|
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">151</s:Int64>
|
||||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE/@EntryValue">WRAP_IF_LONG</s:String></wpf:ResourceDictionary>
|
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_OBJECT_AND_COLLECTION_INITIALIZER_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
@@ -29,12 +29,14 @@ public static class Program {
|
|||||||
Console.WriteLine("Debug mode enabled.");
|
Console.WriteLine("Debug mode enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var imagesPath = "images";
|
var imagesPath = "images";
|
||||||
for (var i = 0; i < 8; i++) {
|
for (var i = 0; i < 8; i++) {
|
||||||
var pixels = ImageUtil.LoadImage<Vector3>($"./{imagesPath}{Path.DirectorySeparatorChar}{i + 1:00}.png");
|
var pixels = ImageUtil.LoadImage<Vector3>($"./{imagesPath}{Path.DirectorySeparatorChar}{i + 1:00}.png");
|
||||||
Images.Add(new(pixels, pixels.GetLength(0), pixels.GetLength(1)));
|
Images.Add(new(pixels, pixels.GetLength(0), pixels.GetLength(1)));
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
/*
|
||||||
var pixels = ImageUtil.LoadImage<Vector3>($"./sphereempty.png");
|
var pixels = ImageUtil.LoadImage<Vector3>($"./sphereempty.png");
|
||||||
Images.Add(new(pixels, pixels.GetLength(0), pixels.GetLength(1)));
|
Images.Add(new(pixels, pixels.GetLength(0), pixels.GetLength(1)));
|
||||||
pixels = ImageUtil.LoadImage<Vector3>($"./spherehalf.png");
|
pixels = ImageUtil.LoadImage<Vector3>($"./spherehalf.png");
|
||||||
@@ -54,6 +56,22 @@ public static class Program {
|
|||||||
width = (uint)Images[0].Width;
|
width = (uint)Images[0].Width;
|
||||||
height = (uint)Images[0].Height;
|
height = (uint)Images[0].Height;
|
||||||
|
|
||||||
|
// sum all images together
|
||||||
|
if(debug) Images[0].Pixels.SaveImage("Debug/Sum0.png");
|
||||||
|
|
||||||
|
for (int i = 1; i < Images.Count; i++) {
|
||||||
|
for (int x = 0; x < Images[i].Width; x++) {
|
||||||
|
for (int y = 0; y < Images[i].Height; y++) {
|
||||||
|
Images[i].Pixels[x, y].X = MathF.Min(Images[i - 1].Pixels[x, y].X + Images[i].Pixels[x, y].X, MAX);
|
||||||
|
Images[i].Pixels[x, y].Y = MathF.Min(Images[i - 1].Pixels[x, y].Y + Images[i].Pixels[x, y].X, MAX);
|
||||||
|
Images[i].Pixels[x, y].Z = MathF.Min(Images[i - 1].Pixels[x, y].Z + Images[i].Pixels[x, y].X, MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(debug)Images[i].Pixels.SaveImage($"Debug/Sum{i}.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("Creating masks...");
|
Console.WriteLine("Creating masks...");
|
||||||
for (var i = 0; i < Images.Count; i++) { //for each image pair, create a mask
|
for (var i = 0; i < Images.Count; i++) { //for each image pair, create a mask
|
||||||
var selfMask = SelfMask(Images[i].Pixels);
|
var selfMask = SelfMask(Images[i].Pixels);
|
||||||
@@ -95,9 +113,10 @@ public static class Program {
|
|||||||
var currStep = 0f;
|
var currStep = 0f;
|
||||||
var stepIncrement = MAX / Gradients.Count;
|
var stepIncrement = MAX / Gradients.Count;
|
||||||
|
|
||||||
|
|
||||||
for (var x = 0; x < width; x++)
|
for (var x = 0; x < width; x++)
|
||||||
for (var y = 0; y < height; y++)
|
for (var y = 0; y < height; y++)
|
||||||
finalImage[x, y] = new(Images[0].Pixels[x, y].X);
|
finalImage[x, y] = new(ImageMasks[0].Mask[x, y].X != 0 || ImageMasks[0].Mask[x, y].Y > 0 ? MAX : MIN);
|
||||||
|
|
||||||
for (var i = 0; i < Gradients.Count; i++) {
|
for (var i = 0; i < Gradients.Count; i++) {
|
||||||
var mask = ImageMasks[i + 1];
|
var mask = ImageMasks[i + 1];
|
||||||
@@ -105,7 +124,7 @@ public static class Program {
|
|||||||
Console.WriteLine($"Applying gradient {i}..., {currStep} -> {currStep + stepIncrement}");
|
Console.WriteLine($"Applying gradient {i}..., {currStep} -> {currStep + stepIncrement}");
|
||||||
for (var x = 0; x < mask.Mask.GetLength(0); x++) {
|
for (var x = 0; x < mask.Mask.GetLength(0); x++) {
|
||||||
for (var y = 0; y < mask.Mask.GetLength(1); y++) {
|
for (var y = 0; y < mask.Mask.GetLength(1); y++) {
|
||||||
if (gradient[x, y].X == 0) continue;
|
if (mask.Mask[x,y].X == 0) continue;
|
||||||
var pixel = new Vector3(Remap(gradient[x, y].X, MIN, MAX, 1.0f - currStep,
|
var pixel = new Vector3(Remap(gradient[x, y].X, MIN, MAX, 1.0f - currStep,
|
||||||
1.0f - (currStep + stepIncrement)));
|
1.0f - (currStep + stepIncrement)));
|
||||||
if (pixel.X > finalImage[x, y].X) finalImage[x, y] = pixel;
|
if (pixel.X > finalImage[x, y].X) finalImage[x, y] = pixel;
|
||||||
@@ -114,17 +133,21 @@ public static class Program {
|
|||||||
currStep += stepIncrement;
|
currStep += stepIncrement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finalImage.SaveImage("Debug/Final.png");
|
||||||
|
|
||||||
// apply directional blur
|
// apply directional blur
|
||||||
var iterations = 10;
|
var iterations = 1;
|
||||||
var radius = 3f;
|
var radius = 100f;
|
||||||
var step = .5f;
|
var step = .5f;
|
||||||
var sigma = 1f;
|
var sigma = 1f;
|
||||||
|
var totalMask = SelfMask(Images[^1].Pixels);
|
||||||
|
totalMask.SaveImage("Debug/TotalMask.png");
|
||||||
for (var i = 0; i < iterations; i++) {
|
for (var i = 0; i < iterations; i++) {
|
||||||
Console.WriteLine($"Applying directional blur {i + 1}/{iterations}...");
|
Console.WriteLine($"Applying directional blur {i + 1}/{iterations}...");
|
||||||
finalImage = DirectionalBlur(finalImage, ImageMasks[0].Mask, radius, step, sigma);
|
finalImage = DirectionalBlur(finalImage, totalMask, radius, step, sigma);
|
||||||
}
|
}
|
||||||
|
|
||||||
finalImage.SaveImage("final.png");
|
finalImage.SaveImage("finalBlur.png");
|
||||||
Console.WriteLine("Done!");
|
Console.WriteLine("Done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,8 +211,7 @@ public static class Program {
|
|||||||
if (pixel.X > absMax) absMax = pixel.X;
|
if (pixel.X > absMax) absMax = pixel.X;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parallel.For(0, width * height, parallelOptions, (i) =>
|
Parallel.For(0, width * height, parallelOptions, (i) => {
|
||||||
{
|
|
||||||
//convert 1D index to 2D index
|
//convert 1D index to 2D index
|
||||||
var x = (int)(i % width);
|
var x = (int)(i % width);
|
||||||
var y = (int)(i / width);
|
var y = (int)(i / width);
|
||||||
@@ -198,7 +220,7 @@ public static class Program {
|
|||||||
sw.Stop();
|
sw.Stop();
|
||||||
|
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
$"SDF Normalization Time: {sw.Elapsed.TotalSeconds:N4}s ({width*height / sw.Elapsed.TotalSeconds:N0} pixels/s)");
|
$"SDF Normalization Time: {sw.Elapsed.TotalSeconds:N4}s ({width * height / sw.Elapsed.TotalSeconds:N0} pixels/s)");
|
||||||
|
|
||||||
return new(temp);
|
return new(temp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public partial class SdfKernels {
|
|||||||
var valueB = B[x, y];
|
var valueB = B[x, y];
|
||||||
var lumaA = valueA.X;
|
var lumaA = valueA.X;
|
||||||
var lumaB = valueB.X;
|
var lumaB = valueB.X;
|
||||||
var r = lumaA > LUMA_THRESHOLD || lumaB > LUMA_THRESHOLD ? 1f : 0f;
|
var r = lumaB - lumaA > LUMA_THRESHOLD ? 1f : 0f;
|
||||||
mask[x, y] = new(r, 0f, 0f);
|
mask[x, y] = new(r, 0f, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,10 @@ public partial class SdfKernels {
|
|||||||
var x = index.X;
|
var x = index.X;
|
||||||
var y = index.Y;
|
var y = index.Y;
|
||||||
//if we are on the edge of the image, return false
|
//if we are on the edge of the image, return false
|
||||||
if (x == 0 || y == 0 || x == width - 1 || y == height - 1) return;
|
if (x == 0 || y == 0 || x == width - 1 || y == height - 1) {
|
||||||
|
mask[index].Y = 1f; //set the edge flag
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//check the 3x3 kernel
|
//check the 3x3 kernel
|
||||||
for (var xi = x - 1; xi <= x + 1; xi++) {
|
for (var xi = x - 1; xi <= x + 1; xi++) {
|
||||||
@@ -78,12 +81,33 @@ public partial class SdfKernels {
|
|||||||
ArrayView2D<Vector3, Stride2D.DenseX> sdfb,
|
ArrayView2D<Vector3, Stride2D.DenseX> sdfb,
|
||||||
ArrayView2D<Vector3, Stride2D.DenseX> gradient
|
ArrayView2D<Vector3, Stride2D.DenseX> gradient
|
||||||
) { //early exit if not on mask
|
) { //early exit if not on mask
|
||||||
if (mask[index].X == 0f || mask[index].Y > 0f) return;
|
if (mask[index].X == 0f) return;
|
||||||
var a = sdfa[index].X;
|
var a = sdfa[index].X;
|
||||||
var b = sdfb[index].X;
|
var b = sdfb[index].X;
|
||||||
gradient[index] = new(a / (a + b));
|
gradient[index] = new(a / (a + b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Vector3 SampleBilinear(ArrayView2D<Vector3, Stride2D.DenseX> image, float x, float y) {
|
||||||
|
int width = image.IntExtent.X;
|
||||||
|
int height = image.IntExtent.Y;
|
||||||
|
|
||||||
|
var x0 = (int)x;
|
||||||
|
var y0 = (int)y;
|
||||||
|
var x1 = x0 + 1;
|
||||||
|
var y1 = y0 + 1;
|
||||||
|
|
||||||
|
if (x0 < 0 || x1 >= width || y0 < 0 || y1 >= height) return Vector3.Zero;
|
||||||
|
|
||||||
|
var a = new Vector2(x - x0, y - y0);
|
||||||
|
var b = new Vector2(1f - a.X, 1f - a.Y);
|
||||||
|
|
||||||
|
return Vector3.Lerp(
|
||||||
|
Vector3.Lerp(image[x0, y0], image[x1, y0], a.X),
|
||||||
|
Vector3.Lerp(image[x0, y1], image[x1, y1], a.X),
|
||||||
|
a.Y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static void DirectionalBlurKernel(Index2D index,
|
static void DirectionalBlurKernel(Index2D index,
|
||||||
ArrayView2D<Vector3, Stride2D.DenseX> image,
|
ArrayView2D<Vector3, Stride2D.DenseX> image,
|
||||||
ArrayView2D<Vector3, Stride2D.DenseX> mask,
|
ArrayView2D<Vector3, Stride2D.DenseX> mask,
|
||||||
@@ -102,13 +126,19 @@ public partial class SdfKernels {
|
|||||||
|
|
||||||
var gradient = Vector2.Zero;
|
var gradient = Vector2.Zero;
|
||||||
|
|
||||||
for (var dx = -1; dx <= 1; dx++) {
|
// calculate the gradient
|
||||||
for (var dy = -1; dy <= 1; dy++) {
|
for (int i = -1; i <= 1; i++) {
|
||||||
if (x + dx < 0 || x + dx >= width || y + dy < 0 || y + dy >= height) continue;
|
if (x + i < 0 || x + i >= width || y + i < 0 || y + i >= height) continue;
|
||||||
gradient += new Vector2(dx, dy) * image[x + dx, y + dy].X;
|
gradient.X += i * image[x + i, y].X;
|
||||||
}
|
gradient.Y += i * image[x, y + i].X;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
output[x, y] = new Vector3(float.Abs((gradient.X * 0.5f) + 0.5f),
|
||||||
|
float.Abs((gradient.Y * 0.5f) + 0.5f), 0.5f);
|
||||||
|
return;
|
||||||
|
*/
|
||||||
|
|
||||||
if (gradient == Vector2.Zero) {
|
if (gradient == Vector2.Zero) {
|
||||||
output[x, y] = value;
|
output[x, y] = value;
|
||||||
return;
|
return;
|
||||||
@@ -119,19 +149,19 @@ public partial class SdfKernels {
|
|||||||
|
|
||||||
// now we follow the direction line and sample the image for length;
|
// now we follow the direction line and sample the image for length;
|
||||||
for (var l = -radius; l <= radius; l += step) {
|
for (var l = -radius; l <= radius; l += step) {
|
||||||
var xOffset = (int)(gradient.X * l);
|
var xOffset = (gradient.X * l);
|
||||||
var yOffset = (int)(gradient.Y * l);
|
var yOffset = (gradient.Y * l);
|
||||||
var xSample = x + xOffset;
|
var xSample = x + xOffset;
|
||||||
var ySample = y + yOffset;
|
var ySample = y + yOffset;
|
||||||
|
|
||||||
if (xSample < 0 || xSample >= width || ySample < 0 || ySample >= height) continue;
|
if (xSample < 0 || xSample >= width || ySample < 0 || ySample >= height) continue;
|
||||||
|
|
||||||
var sampleValue = image[xSample, ySample];
|
var sampleValue = SampleBilinear(image, xSample, ySample);
|
||||||
var weight = MathF.Exp(-l * l / (2f * sigma * sigma));
|
var weight = MathF.Exp(-(l * l) / (2f * sigma * sigma));
|
||||||
output[x, y] += sampleValue * weight;
|
output[x, y] += sampleValue * weight;
|
||||||
sum += weight;
|
sum += weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
output[x, y] /= sum;
|
output[x, y] = output[x, y] / sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user