Skip to content
Snippets Groups Projects
Commit e709b1bf authored by Alexander Rose's avatar Alexander Rose
Browse files

better text border rendering

parent 06f9578c
No related branches found
No related tags found
No related merge requests found
...@@ -74,7 +74,7 @@ export namespace Text { ...@@ -74,7 +74,7 @@ export namespace Text {
...FontAtlasParams, ...FontAtlasParams,
sizeFactor: PD.Numeric(1, { min: 0, max: 10, step: 0.1 }), sizeFactor: PD.Numeric(1, { min: 0, max: 10, step: 0.1 }),
borderWidth: PD.Numeric(0, { min: 0, max: 1, step: 0.01 }), borderWidth: PD.Numeric(0, { min: 0, max: 0.5, step: 0.01 }),
borderColor: PD.Color(ColorNames.grey), borderColor: PD.Color(ColorNames.grey),
offsetX: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }), offsetX: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }),
offsetY: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }), offsetY: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }),
......
...@@ -32,17 +32,11 @@ void main(){ ...@@ -32,17 +32,11 @@ void main(){
if (vTexCoord.x > 1.0) { if (vTexCoord.x > 1.0) {
gl_FragColor = vec4(uBackgroundColor, uBackgroundOpacity); gl_FragColor = vec4(uBackgroundColor, uBackgroundOpacity);
} else { } else {
// TODO nicer border
// retrieve signed distance // retrieve signed distance
float sdf = texture2D(tFont, vTexCoord).a + uBorderWidth; float sdf = texture2D(tFont, vTexCoord).a + uBorderWidth;
// perform adaptive anti-aliasing of the edges // perform adaptive anti-aliasing of the edges
float w = clamp( float w = clamp(smoothness * (abs(dFdx(vTexCoord.x)) + abs(dFdy(vTexCoord.y))), 0.0, 0.5);
smoothness * (abs(dFdx(vTexCoord.x)) + abs(dFdy(vTexCoord.y))),
0.0,
0.5
);
float a = smoothstep(0.5 - w, 0.5 + w, sdf); float a = smoothstep(0.5 - w, 0.5 + w, sdf);
// gamma correction for linear attenuation // gamma correction for linear attenuation
...@@ -51,8 +45,10 @@ void main(){ ...@@ -51,8 +45,10 @@ void main(){
if (a < 0.5) discard; if (a < 0.5) discard;
material.a *= a; material.a *= a;
if (uBorderWidth > 0.0 && sdf < (0.5 + uBorderWidth)) { // add border
material.xyz = uBorderColor; float t = 0.5 + uBorderWidth;
if (uBorderWidth > 0.0 && sdf < t) {
material.xyz = mix(uBorderColor, material.xyz, smoothstep(t - w, t, sdf));
} }
gl_FragColor = material; gl_FragColor = material;
......
...@@ -33,8 +33,8 @@ function textRepr() { ...@@ -33,8 +33,8 @@ function textRepr() {
...PD.getDefaultValues(Text.Params), ...PD.getDefaultValues(Text.Params),
attachment: 'middle-center', attachment: 'middle-center',
fontSize: 96, fontSize: 96,
fontWeight: 'bold', fontWeight: 'normal',
background: true borderWidth: 0.3
} }
const textBuilder = TextBuilder.create(props, 1, 1) const textBuilder = TextBuilder.create(props, 1, 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment