Skip to content

Commit b638106

Browse files
committed
some tidy up
1 parent 17de319 commit b638106

File tree

8 files changed

+32
-68
lines changed

8 files changed

+32
-68
lines changed

examples/assets/fonts/Arial-429/Arial.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
-55.9 KB
Binary file not shown.
-51.4 KB
Binary file not shown.
-36.6 KB
Binary file not shown.
-39.7 KB
Binary file not shown.

examples/user-interface/text-outline.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
text.element.fontAsset = fontAsset;
9393
});
9494

95-
var fontAsset2 = new pc.Asset('Arial.json', "font", {url: "../assets/fonts/Arial-429/Arial.json"});
95+
var fontAsset2 = new pc.Asset('Arial.json', "font", {url: "../assets/fonts/Arial-v4/Arial.json"});
9696
fontAsset2.on('load', function () {
9797
// Apply the font to the text element
9898
text2.element.fontAsset = fontAsset2;

src/framework/components/element/text-element.js

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ Object.assign(pc, function () {
44
ALL_IN_ONE: 0,
55
TEXT: 1,
66
OUTLINE: 2,
7-
OUTLINE_AA: 3,
8-
DROP_SHADOW: 4,
9-
DROP_SHADOW_AA: 5,
10-
EDGE_AA: 6,
11-
STENCIL_CLEAR: 7
7+
DROP_SHADOW: 3,
8+
EDGE_AA: 4,
9+
STENCIL_CLEAR: 5
1210
};
1311

1412
var MeshInfo = function () {
@@ -256,44 +254,25 @@ Object.assign(pc, function () {
256254
if (multiPassNeeded) {
257255
if (this._shadowOffset.x != 0 && this._shadowOffset.y != 0 && this._shadowColor.a > 0) {
258256
// with drop shadow
259-
if (true || this._outlineColor.a < 1 || this._shadowColor.a < 1) {
260-
// with edge AA pass
261-
passes.length = 5;
262-
passes[0] = RenderPass.TEXT;
263-
passes[1] = RenderPass.OUTLINE;
264-
passes[2] = RenderPass.DROP_SHADOW;
265-
passes[3] = RenderPass.EDGE_AA;
266-
passes[4] = RenderPass.STENCIL_CLEAR;
267-
} else {
268-
// no edge AA pass
269-
passes.length = 4;
270-
passes[0] = RenderPass.TEXT;
271-
passes[1] = RenderPass.OUTLINE_AA;
272-
passes[2] = RenderPass.DROP_SHADOW_AA;
273-
passes[3] = RenderPass.STENCIL_CLEAR;
274-
}
257+
passes.length = 5;
258+
passes[0] = RenderPass.TEXT;
259+
passes[1] = RenderPass.OUTLINE;
260+
passes[2] = RenderPass.DROP_SHADOW;
261+
passes[3] = RenderPass.EDGE_AA;
262+
passes[4] = RenderPass.STENCIL_CLEAR;
275263
} else {
276264
// no drop shadow
277-
if (true || this._outlineColor.a < 1 ) {
278-
// with edge AA pass
279-
passes.length = 4;
280-
passes[0] = RenderPass.TEXT;
281-
passes[1] = RenderPass.OUTLINE;
282-
passes[2] = RenderPass.EDGE_AA;
283-
passes[3] = RenderPass.STENCIL_CLEAR;
284-
} else {
285-
// no edge AA pass
286-
passes.length = 3;
287-
passes[0] = RenderPass.TEXT;
288-
passes[1] = RenderPass.OUTLINE_AA;
289-
passes[2] = RenderPass.STENCIL_CLEAR;
290-
}
265+
passes.length = 4;
266+
passes[0] = RenderPass.TEXT;
267+
passes[1] = RenderPass.OUTLINE;
268+
passes[2] = RenderPass.EDGE_AA;
269+
passes[3] = RenderPass.STENCIL_CLEAR;
291270
}
292271
}
293272

294-
var mesh_infos_num_needed = (multiPassNeeded) ? passes.length * this._font.textures[0].length : this._font.textures[0].length;
273+
var numMeshInfosNeeded = (multiPassNeeded) ? passes.length * this._font.textures[0].length : this._font.textures[0].length;
295274

296-
for (i = 0; i < mesh_infos_num_needed; i++) {
275+
for (i = 0; i < numMeshInfosNeeded; i++) {
297276
var ti = i % this._font.textures[0].length;
298277
var p = (i - ti) / this._font.textures[0].length;
299278

@@ -326,7 +305,7 @@ Object.assign(pc, function () {
326305

327306
// destroy any excess mesh instances
328307
var removedModel = false;
329-
for (i = mesh_infos_num_needed; i < this._meshInfo.length; i++) {
308+
for (i = numMeshInfosNeeded; i < this._meshInfo.length; i++) {
330309
if (this._meshInfo[i].meshInstance) {
331310
if (!removedModel) {
332311
// remove model from scene so that excess mesh instances are removed
@@ -338,8 +317,8 @@ Object.assign(pc, function () {
338317
}
339318
}
340319

341-
if (mesh_infos_num_needed < this._meshInfo.length) {
342-
this._meshInfo.splice(mesh_infos_num_needed, this._meshInfo.length - mesh_infos_num_needed);
320+
if (numMeshInfosNeeded < this._meshInfo.length) {
321+
this._meshInfo.splice(numMeshInfosNeeded, this._meshInfo.length - numMeshInfosNeeded);
343322
this._element.addModelToLayers(this._model);
344323
}
345324

@@ -1299,13 +1278,11 @@ Object.assign(pc, function () {
12991278
});
13001279
mi.stencilBack = mi.stencilFront;
13011280
break;
1302-
case RenderPass.OUTLINE_AA: // second pass (just border, use stencil and set stencil)
1303-
case RenderPass.DROP_SHADOW_AA: // third pass (just drop shadow, use stencil and set stencil)
13041281
case RenderPass.EDGE_AA: // forth pass (just edge AA, use stencil and set stencil)
13051282
mi.stencilFront = new pc.StencilParameters({
13061283
ref: stencilParams.ref,
13071284
func: pc.FUNC_EQUAL,
1308-
zpass: pc.STENCILOP_INCREMENT
1285+
zpass: pc.STENCILOP_KEEP
13091286
});
13101287
mi.stencilBack = mi.stencilFront;
13111288
break;
@@ -1334,8 +1311,6 @@ Object.assign(pc, function () {
13341311
});
13351312
mi.stencilBack = mi.stencilFront;
13361313
break;
1337-
case RenderPass.OUTLINE_AA: // second pass (just border, use stencil and set stencil)
1338-
case RenderPass.DROP_SHADOW_AA: // third pass (just drop shadow, use stencil and set stencil)
13391314
case RenderPass.EDGE_AA: // forth pass (just edge AA, use stencil and set stencil)
13401315
mi.stencilFront = new pc.StencilParameters({
13411316
ref: 42,

src/graphics/program-lib/chunks/msdf.frag

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ vec4 applyMsdf(vec4 color) {
4545
float t_font_pxrange = font_pxrange;
4646

4747
#ifdef MSDFA
48-
float num = float(sigDist<0.5)*clamp((outline_thickness-0.2)*5.0,0.0,1.0);
48+
float alpha = float(sigDist<0.5)*clamp((outline_thickness-0.2)*5.0,0.0,1.0);
4949

5050
float tsamplea = texture2D(texture_msdfMapA, vUv0).r;
5151
float ssamplea = texture2D(texture_msdfMapA, uvShdw).r;
5252

53-
sigDist=mix(sigDist, tsamplea, num);
54-
sigDistShdw=mix(sigDistShdw, ssamplea, num);
53+
sigDist=mix(sigDist, tsamplea, alpha);
54+
sigDistShdw=mix(sigDistShdw, ssamplea, alpha);
5555

56-
t_outline_thickness=mix(outline_thickness, outline_thickness*0.25+0.02, num);
57-
t_font_pxrange=mix(font_pxrange, font_pxrange*4.0, num);
56+
t_outline_thickness=mix(outline_thickness, outline_thickness*0.25+0.02, alpha); // 0.02 is fudge factor needed probably due to rounding differences in msdf and sdf generation?
57+
t_font_pxrange=mix(font_pxrange, font_pxrange*4.0, alpha);
5858
#endif
5959

6060
#ifdef USE_FWIDTH
@@ -86,40 +86,30 @@ vec4 applyMsdf(vec4 color) {
8686
vec4 tcolor = mix(scolor, color, inside);
8787

8888
#ifdef MSDFA
89-
if (render_pass==1.0 && inside==0.0) //text
89+
if (render_pass==5.0) //stencil clear
9090
{
91-
discard;
92-
}
93-
94-
if (render_pass==2.0 && outline<1.0) //outline
95-
{
96-
discard;
91+
return vec4(0.0);
9792
}
9893

99-
if (render_pass==3.0 && outline==0.0) //outline_aa
94+
if (render_pass==1.0 && inside==0.0) //text
10095
{
10196
discard;
10297
}
10398

104-
if (render_pass==4.0 && shadow<1.0) //drop_shadow
99+
if (render_pass==2.0 && outline<1.0) //outline
105100
{
106101
discard;
107102
}
108103

109-
if (render_pass==5.0 && shadow==0.0) //drop_shadow_aa
104+
if (render_pass==3.0 && shadow<1.0) //drop_shadow
110105
{
111106
discard;
112107
}
113108

114-
if (render_pass==6.0 && tcolor.a==0.0) //edge aa
109+
if (render_pass==4.0 && tcolor.a==0.0) //edge aa
115110
{
116111
discard;
117112
}
118-
119-
if (render_pass==7.0) //stencil clear
120-
{
121-
return vec4(0.0);
122-
}
123113
#endif
124114

125115
return vec4(tcolor.rgb,tcolor.a);

0 commit comments

Comments
 (0)