Skip to content
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

WebGL rect glyph with hatch pattern #11159

Merged
merged 7 commits into from Apr 13, 2021
Merged

WebGL rect glyph with hatch pattern #11159

merged 7 commits into from Apr 13, 2021

Conversation

ianthomas23
Copy link
Member

This PR implements WebGL rect glyph rendering comprising fill, optional hatch pattern, and line with line joins. Lines are rendered on top of the fill/hatch, as occurs in canvas and svg backends, but this is accomplished in a single pass, i.e. each pixel of each rect is only rendered once in the fragment shader. Implemented using ReGL instanced rendering in the usual manner.

Things not done (which are silently ignored):

  • Dashed lines, which need full support in LineGL before they can be added here.
  • Hatching using user-specified images, which needs generic WebGL Image support to be written first.

Here is the new test image:
webgl__should_support_rect
Fully supports hatch color, alpha, scale and weight, although I haven't added explicit tests for these.

This code will form the basis for WebGL rendering of many glyph classes, all the ones that are of defined shape and are rendered within a (scaled and rotated) quad. This includes quad, hbar, vbar, circle, ellipse and all the scatter markers. To do this it will need to be expanded to support glyph size being 1D or 2D, presence or not of angle property, and whether glyph size is specified in data or canvas coordinates.

I have reorganised some of the shared code into a new file webgl_utils.ts. There is some duplication of code in regl_wrap.ts and between webgl/rect.ts and webgl\markers.ts which I should be able to reduce/remove as I proceed with the unification mentioned above.

@ianthomas23
Copy link
Member Author

Rebased with respect to branch-2.4 to avoid merge conflicts.

@ianthomas23
Copy link
Member Author

✗ js/bokeh.legacy.min.js 1153 kB > 1150 kB

CI is failing on size of legacy js bundle. Is it OK for me to bump up this limit a few more kb in the short term?

@mattpap
Copy link
Contributor

mattpap commented Apr 12, 2021

CI is failing on size of legacy js bundle. Is it OK for me to bump up this limit a few more kb in the short term?

Yes, just add another 50k.

@mattpap
Copy link
Contributor

mattpap commented Apr 12, 2021

Hatching using user-specified images, which needs generic WebGL Image support to be written first.

I'm wondering if hatch patterns shouldn't be handled as textures in general? Does this make sense at all?

@bryevdv
Copy link
Member

bryevdv commented Apr 12, 2021

cc @jsignell @jrbourbeau just an FYI, webgl rects may be of interest for the dask dashboard

@ianthomas23
Copy link
Member Author

I'm wondering if hatch patterns shouldn't be handled as textures in general? Does this make sense at all?

Hatch patterns could be implemented as textures, but the results will be lower quality and the code more complicated than using distance functions.

Lower quality because texture interpolation is bilinear, so essentially cartesian. This is fine for axis-aligned patterns, but for curved ones like dot, ring and spiral the cartesian interpolation does not correctly determine the distance from the curve whereas distance functions do. So the texture solution will effectively have different antialiasing width as you move around the curve.

More complicated because you cannot just have a single texture per hatch pattern as we allow the hatch scale and weight to be changed independently. A texture for a particular hatch scale and weight can be reused for other scales but only if the scale-to-weight ratio is the same. To support all possible scale and weight combinations we'd have to create textures on the fly as they are required. To create the patterns here we'd have to draw on the textures which could be done using canvas but of course I would do so using webgl and the very same distance functions already written here!

The distance functions give very accurate results and are very simple; the most complicated ones are only 7 lines of code in the fragment shader.

@ianthomas23
Copy link
Member Author

I've made a number of changes following review, and also switched the shader files from 4 to 2-space indents to save a few bytes.

@bryevdv
Copy link
Member

bryevdv commented Apr 13, 2021

@ianthomas23 IIUC I've moved this to ready (please let me know if I misunderstood)

@mattpap
Copy link
Contributor

mattpap commented Apr 13, 2021

(...) and also switched the shader files from 4 to 2-space indents to save a few bytes.

We will have to minify shaders at some point, but this is still a good change for the sake of consistency across bokehjs.

@mattpap mattpap added this to the 2.4 milestone Apr 13, 2021
@mattpap mattpap merged commit fbf1d4f into bokeh:branch-2.4 Apr 13, 2021
@bryevdv
Copy link
Member

bryevdv commented Apr 13, 2021

Thanks @ianthomas23 !

@ianthomas23 ianthomas23 deleted the webgl_rect branch May 15, 2021 22:51
bryevdv pushed a commit that referenced this pull request Dec 13, 2021
* WebGL rect basic implementation of fill and line

* WebGL rect line joins

* Hatch patterns

* Add test

* Add macos and windows test images

* Changes following review comments

* Use 2-space indents in rect shaders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants