-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix WebGL scaling of antialising by pixel ratio #13783
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## branch-3.5 #13783 +/- ##
===========================================
Coverage 92.65% 92.65%
===========================================
Files 326 326
Lines 20734 20734
===========================================
Hits 19211 19211
Misses 1523 1523 |
await display(row([plot("canvas"), plot("svg"), plot("webgl")])) | ||
}) | ||
|
||
it.dpr(3)("with devicePixelRatio == 3", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if just using .dpr(N)
is enough to produce a meaningful test. I think this needs scaling as well, but we don't have an API exposed for this currently, though it's possible at CDP (Chrome Devtools Protocol) level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd happily remove the new test and save the disk space. But if we keep it we can at least identify when it changes and it will lead us back here where there are instructions for a manual test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to keep this test, but I would also like to establish if we can make the difference more obvious. I did a little bit of exploration myself and there is a difference when comparing generated images between branch-3.5
and this PR, so this test is indeed valid, though hard on "the naked eye". I tried to enable scaling in CDP, but it doesn't seem to do anything useful. So I suppose this will have to do for now.
It looks to me like the test failures are unrelated. |
* Fix webgl handling of pixel ratio * Fix spelling mistake
Fixes #13692, the incorrect scaling of WebGL antialiasing by pixel ratio.
The
width
andheight
of the canvas used for WebGL rendering is scaled bypixel_ratio
:bokeh/bokehjs/src/lib/core/util/canvas.ts
Lines 71 to 72 in 78d71c2
whereas the
antialias
width is constant regardless ofpixel_ratio
. Following this through the WebGL rendering pipeline shows that this means the rendered antialiasing scales withpixel_ratio
, and so is too large forpixel_ratio > 1
such as for retina screen or zooming (which is implemented in chrome dev tools using a larger pixel ratio).The fix is to scale the antialiasing by dividing by
pixel_ratio
.Test code:
before the fix on a retina screen (pixel ratio 2) at zoom level 300% (so the pixel ratio seen is 6):
and after this fix:
The fix scales the antialising that is passed to the WebGL vertex shaders. It could be performed in the vertex shaders instead, but then the antialias would have to be a GLSL
attribute
rather thanuniform
. Whilst here I realised that thepixel_ratio
is passed to the shaders but only used to scale the canvas size, i.e. to remove thepixel_ratio
multiple added incanvas.ts
above. So I have moved this scaling toBaseGLGlyph
instead which means we no longer need to passpixel_ratio
into any of the shaders. It is not a big deal either way, but I think this implementation is a bit simpler and cleaner.