Skip to content

Commit 0f4c6ea

Browse files
committed
Improve coverage quality with weighted blending and gamma correction
1 parent be37983 commit 0f4c6ea

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

528 Bytes
Binary file not shown.

src/Forme.MonoGame/Shaders/FormeShader.fx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ float FormeRender(float2 renderCoord, float4 bandTransform, float4 glyphTexInfo)
195195

196196
// Loop over all curves in the horizontal band.
197197
float xcov = 0.0;
198+
float xwgt = 0.0;
198199

199200
float2 hBandHeader = FetchBandTexel(bandTexSize, glyphBaseTexel + bandIndexY);
200201
float hCurveCount = hBandHeader.r;
@@ -215,14 +216,15 @@ float FormeRender(float2 renderCoord, float4 bandTransform, float4 glyphTexInfo)
215216
{
216217
float2 r = SolveHorizPoly(p12, p3) * pixelsPerEm.x;
217218

218-
if (elig.x > 0.5) xcov += saturate(r.x + 0.5);
219-
if (elig.y > 0.5) xcov -= saturate(r.y + 0.5);
219+
if (elig.x > 0.5) { xcov += saturate(r.x + 0.5); xwgt = max(xwgt, saturate(1.0 - abs(r.x) * 2.0)); }
220+
if (elig.y > 0.5) { xcov -= saturate(r.y + 0.5); xwgt = max(xwgt, saturate(1.0 - abs(r.y) * 2.0)); }
220221
}
221222
}
222223

223224
// Loop over all curves in the vertical band. Swap x and y to reuse the
224225
// horizontal solver and eligibility logic.
225226
float ycov = 0.0;
227+
float ywgt = 0.0;
226228

227229
float2 vBandHeader = FetchBandTexel(bandTexSize, glyphBaseTexel + bandCount + bandIndexX);
228230
float vCurveCount = vBandHeader.r;
@@ -247,20 +249,21 @@ float FormeRender(float2 renderCoord, float4 bandTransform, float4 glyphTexInfo)
247249
{
248250
float2 r = SolveHorizPoly(p12, p3) * pixelsPerEm.y;
249251

250-
if (elig.x > 0.5) ycov += saturate(r.x + 0.5);
251-
if (elig.y > 0.5) ycov -= saturate(r.y + 0.5);
252+
if (elig.x > 0.5) { ycov += saturate(r.x + 0.5); ywgt = max(ywgt, saturate(1.0 - abs(r.x) * 2.0)); }
253+
if (elig.y > 0.5) { ycov -= saturate(r.y + 0.5); ywgt = max(ywgt, saturate(1.0 - abs(r.y) * 2.0)); }
252254
}
253255
}
254256

255-
float covX = min(abs(xcov), 1.0);
256-
float covY = min(abs(ycov), 1.0);
257+
float coverage = max(
258+
abs(xcov * xwgt + ycov * ywgt) / max(xwgt + ywgt, 0.0001),
259+
min(abs(xcov), abs(ycov)));
257260

258-
return saturate((covX + covY) * 0.5);
261+
return sqrt(saturate(coverage));
259262
}
260263

261264
float4 PS_Main(VSOutput input) : COLOR0
262265
{
263-
float coverage = FormeRender(input.texcoord, input.banding, input.glyphLoc);
266+
float coverage = FormeRender(input.texcoord, input.banding, input.glyphLoc);
264267
return float4(input.color.rgb * coverage, coverage * input.color.a);
265268
}
266269

741 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)