Преглед изворни кода

Canvas2D: fix text rendering issue

When the text was white over white background the render was inaccurate, artifacts occurred. Problem solved.
nockawa пре 8 година
родитељ
комит
36b044066b

+ 3 - 2
canvas2D/src/Engine/babylon.fontTexture.ts

@@ -478,7 +478,7 @@
 
             this._currentFreePosition = Vector2.Zero();
 
-            // Add the basic ASCII based characters
+            // Add the basic ASCII based characters                                                               
             for (let i = 0x20; i < 0x7F; i++) {
                 var c = String.fromCharCode(i);
                 this.getChar(c);
@@ -602,11 +602,12 @@
                 // Premul Alpha manually
                 let id = this._context.getImageData(curPosXMargin, curPosYMargin, width, this._lineHeightSuper);
                 for (let i = 0; i < id.data.length; i += 4) {
-                    let v = id.data[i+3];
+                    let v = id.data[i + 3];
                     if (v > 0 && v < 255) {
                         id.data[i + 0] = v;
                         id.data[i + 1] = v;
                         id.data[i + 2] = v;
+                        id.data[i + 3] = v;
                     }
 
                 }

+ 4 - 0
canvas2D/src/Engine/babylon.text2d.ts

@@ -140,6 +140,7 @@
         static TEXT2D_MAINPARTID = 1;
 
         static TEXT2D_CATEGORY_SDF = "SignedDistanceField";
+        static TEXT2D_CATEGORY_FONTTEXTURE = "FontTexture";
 
         public static fontProperty: Prim2DPropInfo;
         public static defaultFontColorProperty: Prim2DPropInfo;
@@ -571,6 +572,9 @@
             if (this._fontSDF) {
                 cat.push(Text2D.TEXT2D_CATEGORY_SDF);
             }
+            if (this._fontTexture instanceof FontTexture) {
+                cat.push(Text2D.TEXT2D_CATEGORY_FONTTEXTURE);
+            }
             return cat;
         }
 

+ 4 - 0
canvas2D/src/shaders/text2d.fragment.fx

@@ -25,7 +25,11 @@ void main(void) {
 	if (color.a == 0.0) {
 		discard;
 	}
+#ifdef FontTexture
+	gl_FragColor = vec4(color.xxxx)*vColor;
+#else
 	gl_FragColor = color*vColor;
 #endif
+#endif
 
 }