two.js icon indicating copy to clipboard operation
two.js copied to clipboard

[Bug] WebGL Renderer Blurry

Open benz2012 opened this issue 1 year ago • 4 comments

Describe the bug Using the WebGL renderer in my conditions produces far blurrier output shapes than with the Canvas renderer or SVG renderer. I wouldn't be surprised if Retina magic (or lack thereof) is at play here.

To Reproduce Steps to reproduce the behavior:

  1. Head to any of the "Drawing Your First Shapes" examples
  2. Add type: Two.Types.webgl to the params object
  3. Observe the shapes (especially their strokes)

Expected behavior The WebGL renderer should produce the same or near the same image sharpness as the other two renderers.

Desktop:

  • Device: MacBook Pro (13-inch, 2018, Four Thunderbolt 3 Ports)
  • OS: MacOS 12.6.5
  • Browser: Google Chrome 112.0.5615.137

Screenshots all3

benz2012 avatar Apr 29 '23 01:04 benz2012

To make it even easier, simply navigate to the Rendering Types example codepen to see the differences as well

benz2012 avatar Apr 30 '23 22:04 benz2012

Thanks for posting. Yes, this has to do with retina displays. The way the WebGL Renderer works is that textures are created of each individual path. These textures are uploaded to WebGL and then rendered on quads. The WebGL canvas takes into account the DPI, but the canvas that generates each texture isn't. I'll have to address this, though I'm not sure what performance hit this will create yet.

jonobr1 avatar May 01 '23 19:05 jonobr1

It could also have to do with how the textures are filtered: https://github.com/jonobr1/two.js/blob/dev/src/renderers/webgl.js#L1418-L1420

jonobr1 avatar May 01 '23 20:05 jonobr1

@jonobr1 I played around with the filters and using nearest with MAG eliminates the blurriness. Changing MIN didn't seem to have any effect.

However, once the blurriness was gone, it became apparent that the root cause was still present -- so I think your first hunch might be correct. Pixelation was present.

rendering types with  mag nearest

benz2012 avatar May 02 '23 01:05 benz2012

This will be published on NPM by the end of the week. Thanks for reporting!

jonobr1 avatar Feb 22 '24 06:02 jonobr1