Created
August 3, 2018 13:31
-
-
Save hb3p8/c886a103323ab78ffc63f35bd0f9e43e to your computer and use it in GitHub Desktop.
This file contains 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
vec4 StepJFA (in vec2 fragCoord, in float level) | |
{ | |
level = clamp(level-1.0, 0.0, c_maxSteps); | |
float stepwidth = floor(exp2(c_maxSteps - level)+0.5); | |
float bestDistance = 9999.0; | |
vec2 bestCoord = vec2(0.0); | |
vec3 bestColor = vec3(0.0); | |
for (int y = -1; y <= 1; ++y) { | |
for (int x = -1; x <= 1; ++x) { | |
vec2 sampleCoord = fragCoord + vec2(x,y) * stepwidth; | |
vec4 data = texture( iChannel0, sampleCoord / iChannelResolution[0].xy); | |
vec2 seedCoord; | |
vec3 seedColor; | |
DecodeData(data, seedCoord, seedColor); | |
float dist = length(seedCoord - fragCoord); | |
if ((seedCoord.x != 0.0 || seedCoord.y != 0.0) && dist < bestDistance) | |
{ | |
bestDistance = dist; | |
bestCoord = seedCoord; | |
bestColor = seedColor; | |
} | |
} | |
} | |
return EncodeData(bestCoord, bestColor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment