-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve text rendering #40
Comments
Interestingly, if you hover over the character, things are rendered correctly: @Breja Sorry to ping you, but I've been reading through the webgl code and yet cannot seem to figure out what causes the text to render correctly when the cursor is above it. Do you have any idea what could be causing the above to happen? It seems to be related to the background color, but other than that I'm lost as to what makes the text render right/wrong. |
The cursor char is rendered as a HTML/DOM node. It's a z-index thing because I was too lazy to implement the cursor in WebGL. Line 20 in cab0b08
I think I might start looking in uivonim/src/render/webgl-utils.ts Line 91 in cab0b08
|
@Breja Thank you for the quick response! After taking a look at the code for the font atlas, it appears that @romgrk If you get the chance, could you try 6244541 and see if it fixes the font issues for you? |
What do you have |
|
Interesting, I can't seem to replicate that, looks fine on my system. Maybe it could be config-related somehow? I'm not sure. |
Is the canvas rendering taking into account the device pixel ratio? Is it possible to test rendering to the canvas at higher resolutions? |
Yep, here are the main places it's used: https://github.com/smolck/uivonim/search?q=devicePixelRatio
Not sure I understand the question, you mean for me to test it, or just in general? |
For me to check if it makes a difference. I guess I can set |
Interesting, thank you for the detailed response! As far as I know, it could be an issue with (a) the font texture atlas (so see uivonim/src/render/webgl-utils.ts Lines 91 to 104 in cab0b08
I don't really know how I could test this on my system, so here's a diff you could try @romgrk (note that this is a complete shot in the dark, just a change to be more like code I saw in a tutorial on text rendering in webgl; I'm not really sure what it does, and I don't really expect it to fix anything): Diffdiff --git a/src/render/webgl-utils.ts b/src/render/webgl-utils.ts
index b5743a75..b8c0a223 100644
--- a/src/render/webgl-utils.ts
+++ b/src/render/webgl-utils.ts
@@ -94,8 +94,7 @@ const create = (options?: WebGLContextAttributes) => {
) => {
gl.activeTexture(textureUnit)
gl.bindTexture(gl.TEXTURE_2D, gl.createTexture())
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
// @ts-ignore typings are wrong, see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/pixelStorei#Pixel_storage_parameters I'm guessing it's more likely that something isn't right about how the font is scaled to the device pixel ratio; if I'm correct it'll probably be something in this code or in the code around it: uivonim/src/render/font-texture-atlas.ts Lines 52 to 75 in fe510ee
But I really don't know what exactly the issue is here. |
I doubt #255 improved anything here (if anything it seems to have gotten worse on low-res monitors), but maybe? Assuming not, my plan to fix this is to use MSDFs generated with msdf-atlas-gen (via a native node module). Using MSDFs, for one, would allow for proper anti-aliasing in the shader (instead of in the font atlas texture), hopefully improving the text quality (significantly?), and might remove the need to re-generate the atlas as much (since text can be scaled and not look blurry w/MSDFs iiuc). |
Currently, text rendering seems to be ok only for specific font-sizes. Examples:
h12
h15
h16
The rendering is probably not handling non-integer pixel value incorrectly. It should probably round them to the neared integer value. h16 works because
16 / 1.333333.. == 12
(point to pixel conversion) but other values dont, eg15 / 1.33333... == 11.25
.Edit: this seems to contain decent hints how to improve things: https://stackoverflow.com/questions/25956272/better-quality-text-in-webgl
The text was updated successfully, but these errors were encountered: