Created
March 17, 2021 14:20
-
-
Save GuyInGrey/6d551ff84a9cd39c34b4b0ae4a17f6ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Drawing; | |
using ComputeSharp; | |
using Windows.Devices.SmartCards; | |
namespace EDStatistics_Core | |
{ | |
public readonly struct HeatmapImageGenerationShader : IComputeShader | |
{ | |
public readonly ReadWriteBuffer<int> density; | |
public readonly ReadWriteBuffer<int> image; | |
public readonly int width; | |
public readonly float maxDensity; | |
public HeatmapImageGenerationShader( | |
ReadWriteBuffer<int> density, | |
ReadWriteBuffer<int> image, | |
int width, | |
float maxDensity | |
) { | |
this.density = density; | |
this.image = image; | |
this.width = width; | |
this.maxDensity = maxDensity; | |
} | |
public void Execute(ThreadIds ids) | |
{ | |
var y = ids.X; | |
for (var x = 0; x < width; x++) | |
{ | |
var j = (x + (y * width)) * 4; | |
var value = density[x + (y * width)] / (float)maxDensity; | |
if (value > 1f) { value = 1f; } | |
if (value < 0f) { value = 0f; } | |
var v = value - 1; | |
value = v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v * v; | |
value = -value + 1; | |
image[j] = image[j + 1] = (int)(value * 255); | |
image[j + 2] = 0; | |
image[j + 3] = 255; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment