From 8485e471f3fb23890375efcaebfcadcb58f98714 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 19 Aug 2019 00:54:11 +0200 Subject: [PATCH] Kernel creation and normalization --- samples/ComputeSharp.BokehBlur/Program.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/samples/ComputeSharp.BokehBlur/Program.cs b/samples/ComputeSharp.BokehBlur/Program.cs index 91111902..b79c1105 100644 --- a/samples/ComputeSharp.BokehBlur/Program.cs +++ b/samples/ComputeSharp.BokehBlur/Program.cs @@ -44,6 +44,27 @@ namespace ComputeSharp.BokehBlur } }); + Console.WriteLine(">> Creating kernel"); + int diameter = Radius * 2 + 1; + float[] kernel = new float[diameter * diameter]; + int ones = 0; + for (int i = 0; i < diameter; i++) + { + for (int j = 0; j < diameter; j++) + { + if (MathF.Sqrt(MathF.Pow(j - Radius, 2) + MathF.Pow(i - Radius, 2)) - 0.1f <= Radius) + { + kernel[i * diameter + j] = 1; + ones++; + } + } + } + + Console.WriteLine(">> Normalizing kernel"); + for (int i = 0; i < diameter; i++) + for (int j = 0; j < diameter; j++) + kernel[i * diameter + j] /= ones; + // Apply the effect Console.WriteLine(">> Applying effect"); Vector4[] resultArray = new Vector4[height * width];