Fixed gradient, more cleanup

This commit is contained in:
Samuele Lorefice
2025-04-03 18:48:50 +02:00
parent 3b319da80b
commit 925e4c9989
3 changed files with 12 additions and 12 deletions

View File

@@ -129,7 +129,7 @@ public class Program {
sw.Stop();
Console.WriteLine(
$"\nEdge pixels: {maskData.Edges.Count} | {maskData.Edges.Count / (sw.ElapsedMilliseconds + 1)} pixels/s\n Time: {sw.Elapsed.TotalSeconds:F4}s");
$"\nEdge pixels: {maskData.Edges.Count} | {width*height / (sw.ElapsedMilliseconds + 1)} pixels/s\n Time: {sw.Elapsed.TotalSeconds:F4}s");
}
static Vector3[,] Gradient(TransitionMaskData mask, SDFData sdfA, SDFData sdfB) {
@@ -160,9 +160,7 @@ public class Program {
});*/
kernels.Gradient(mask.Mask, sdfA.SDF, sdfB.SDF, out var temp);
Console.WriteLine(
$"Gradient Time: {sw.Elapsed.TotalSeconds:N4}s ({iterCount / (float)sw.Elapsed.TotalSeconds:N0} pixels/s)");
//Console.WriteLine($"Min: {min} | Max: {max}");
Console.WriteLine($"Gradient Time: {sw.Elapsed.TotalSeconds:N4}s ({width*height / (float)sw.Elapsed.TotalSeconds:N0} pixels/s)");
return temp;
}
@@ -173,7 +171,7 @@ public class Program {
kernels.Sdf(mask.Edges.ToArray(), (int)width, (int)height, out var temp);
Console.WriteLine($"\nSDF Generation Time: {sw.Elapsed.TotalSeconds:N4}s ({iterCount / sw.Elapsed.TotalSeconds:N0} pixels/s)");
Console.WriteLine($"\nSDF Generation Time: {sw.Elapsed.TotalSeconds:N4}s ({width*height / sw.Elapsed.TotalSeconds:N0} pixels/s)");
return new(temp);
}
@@ -196,7 +194,7 @@ public class Program {
where T : INumber<T>, IMultiplyOperators<T, float, T>, IAdditionOperators<T, T, T>
=> a * (1 - t) + b * t;
static T Remap<T>(T value, T min, T max, T newMin, T newMax)
public static T Remap<T>(T value, T min, T max, T newMin, T newMax)
where T : INumber<T>, ISubtractionOperators<T, T, T>, IMultiplyOperators<T, T, T>, IAdditionOperators<T, T, T>
=> (value - min) / (max - min) * (newMax - newMin) + newMin;
}

View File

@@ -76,8 +76,10 @@ public partial class SdfKernels {
ArrayView2D<Vector3, Stride2D.DenseX> sdfb,
ArrayView2D<Vector3, Stride2D.DenseX> gradient
) { //early exit if not on mask
if(mask[index].X == 0f || mask[index].Y == 0f) return;
float a = sdfa[index].X; float b = sdfb[index].X;
gradient[index] = new (a / (a + b));
if(mask[index].X == 0f || mask[index].Y > 0f) return;
float a = sdfa[index].X;
float b = sdfb[index].X;
float result = a / (a + b);
gradient[index] = new (result);
}
}

View File

@@ -158,7 +158,7 @@ public partial class SdfKernels {
accelerator.Synchronize();
gradient = bufferMask.GetAsArray2D();
gradient = bufferGradient.GetAsArray2D();
}
private static string GetInfoString(Accelerator a)