Hi.
I saw this project earlier in the day and had a quick go porting the shader while dinner was cooking. I’m adding it here in case it might be of use to anybody:
local kernel = { category = "filter", group = "msdf", name = "draw" } kernel.vertexData = { -- Background colors (use fill color for foreground) { default = 0, name = "back\_r", min = 0, max = 1, index = 0 }, { default = 0, name = "back\_g", min = 0, max = 1, index = 1 }, { default = 0, name = "back\_b", min = 0, max = 1, index = 2 } } kernel.fragment = [[#ifdef GL\_OES\_standard\_derivatives #extension GL\_OES\_standard\_derivatives : enable #endif P\_POSITION float median (P\_COLOR float r, P\_COLOR float g, P\_COLOR float b) { return max(min(r, g), min(max(r, g), b)); } P\_COLOR vec4 FragmentKernel (P\_UV vec2 uv) { P\_COLOR vec3 sample = texture2D(CoronaSampler0, uv).rgb; P\_UV float sig\_dist = median(sample.r, sample.g, sample.b) - 0.5; #ifdef GL\_OES\_standard\_derivatives P\_UV float dsd = fwidth(sig\_dist); #else P\_UV float dsd = CoronaTexelSize.x; #endif P\_UV float opacity = clamp(sig\_dist / dsd + 0.5, 0.0, 1.0); return vec4(mix(CoronaVertexUserData.xyz, CoronaColorScale(1.).xyz, opacity), 1.); }]] graphics.defineEffect(kernel)
with example usage being:
local m = display.newImageRect("msdf.png", 200, 200) m.x, m.y = display.contentCenterX, display.contentCenterY m.fill.effect = "filter.msdf.draw" m.fill.effect.back\_r = .8 m:setFillColor(0, 0, 1)
I’ve not even remotely put it through its paces. The above image is the “M” output generated from the sample at the end of the Console Commands section, using the executable included with the project. (I’ve barely looked at the code, so don’t know if it’d be an easy port outside Windows.)
Anyhow, like I said, just putting it out there.