Changes

Jump to: navigation, search

TeamDS

1,380 bytes added, 23:39, 4 April 2017
Why I chose this
=== Why I chose this ===
I chose SDF image conversion because it has lots of potential for parallelization. Since all the operations of a pixel are independent of each other and reads data from one single array, this allows for massive gains when using GPU multi-threading.
 
 
=== The code ===
void Generate(const float src[], float dst[], int width, int height, int spread)
{
int spreadSize = spread * spread;
int size = width * height;
for (int i = 0; i < size; i++)
{
Vector2 localVec(i - ((i / width) * width), i / width);
float shortestDist = MAX_FLOAT_VALUE;
float pixelVal = src[i];
if (pixelVal > 0) // It's an inside pixel
{
// Find closest outside pixel
for (int j = 0; j < size; j++)
{
float pixelVal2 = src[j];
if (pixelVal2 == 0)// Outside pixel
{
// Calculate distance
Vector2 targetVec(j - ((j / width) * width), j / width);
float dist = localVec.CalcDistance(targetVec);
if (dist < shortestDist) shortestDist = dist;
}
 
}
 
float spread01 = (shortestDist / spread);
if (spread01 > 1) spread01 = 1; // clamp it
dst[i] = (spread01 * .5f) + 0.5f;
}
else // It's an outisde pixel
{
// Find closest inside pixel
for (int j = 0; j < size; j++)
{
float pixelVal2 = src[j];
if (pixelVal2 > 0)// Inside pixel
{
// Calculate distance
Vector2 targetVec(j - ((j / width) * width), j / width);
float dist = localVec.CalcDistance(targetVec);
if (dist < shortestDist) shortestDist = dist;
}
}
 
float spread01 = (shortestDist / spread);
if (spread01 > 1) spread01 = 1; // clamp it
dst[i] = (1 - spread01) *.5f;
}
}
}
=== Assignment 2 ===
=== Assignment 3 ===
116
edits

Navigation menu