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

Maintaining marker size with various pixelRatio values #20

Merged
merged 9 commits into from
Aug 21, 2020

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Mar 18, 2019

Added new option constPointSize to help maintain marker sizes with different pixelRatio values.

Fix for issue plotly/plotly.js#3246.
Kindly visit PR plotly/plotly.js#3637 for more information.
@dy
cc: @etpinard

marker-vert.glsl Outdated
@@ -38,7 +38,7 @@ void main() {
float size = size * maxSize / 255.;
float borderSize = borderSize * maxSize / 255.;

gl_PointSize = 2. * size * pixelRatio;
gl_PointSize = 2. * size * 2.;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not fixing pixel ratio from uniforms side?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dy for looking at this.
It seems to be used in one other place in the shader:

fragPointSize = size * pixelRatio;
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But fragPointSize is different from gl_PointSize. Can you possibly add a test-case for the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not fixing pixel ratio from uniforms side?

pixelRatio could be set as a constant of 2 here:

pixelRatio: regl.context('pixelRatio'),
; but I thought it may be more consistent e.g. with other gl-vis/3d modules where other pixelRatio values are possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be done as a separate option if you want to make some default value. Here https://github.com/gl-vis/regl-scatter2d/blob/master/scatter.js#L199

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand. Why not avoiding passing plotGlPixelRatio as pixelRatio at all?
The cases mentioned in the codepen make sure the point size is consisted in devices with various pixelRatio. If you want to pass "fake" pixelRatio - the point size will be increased, that's what expected. Am I getting it wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Plotly.js plotGlPixelRatio is the same as pixelRatio. Here is another codepen example comparing scatter, scattergl & scatter3d with different pixelRatio values lines and markers. The only module which treat pixelRatio differently seems to be this module. When passing different pixelRatio values we don't expect a change in point sizes but slightly higher render quality.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered that on the devices with another default pixelRatio? The point size is likely smaller there, other gl- components don’t consider that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codepens on different devices appear to be rendered OK with this fix.
@etpinard what's your thoughts here.
Should we consider another fix something like this? https://github.com/plotly/plotly.js/compare/markersize-second-approach

Copy link
Member

@etpinard etpinard Apr 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your hard work @archmoj - your patch appears to make scattergl consistent with how markers are drawn in scatter3d so 👌

As this repo remains in @dy 's hands, we could perhaps make this new/consistent pixelRatio behaviour an opt-in e.g. by adding a boolean flag to regl-scatter2d that we would turn on upon instantiating in plotly.js

marker-vert.glsl Outdated
@@ -38,7 +38,7 @@ void main() {
float size = size * maxSize / 255.;
float borderSize = borderSize * maxSize / 255.;

gl_PointSize = 2. * size * pixelRatio;
gl_PointSize = 2. * size * 2.;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But fragPointSize is different from gl_PointSize. Can you possibly add a test-case for the issue?

@archmoj
Copy link
Contributor Author

archmoj commented Apr 1, 2019

@dy @etpinard OK. The tests are tweaked with half sizes and passed noting that we should maintain sizes identical to (the old use of) pixelRatio=2 in plotly.js baselines. If all is good we may publish a minor and include these changes in the next plotly.js minor.

@archmoj
Copy link
Contributor Author

archmoj commented Apr 5, 2019

@dy Possibly any updates on this?
If you still think that this is not the right fix, please let me know. Maybe we could find another way to tweak the API on the plotly.js side?
Thank you in advance.

@dy
Copy link
Member

dy commented Apr 8, 2019

@archmoj I did not mean to delay, sorry. Yes, I think that now pixelRatio is handled correctly - it scales points up depending on the device or passed pixelRatio. If we remove that support, the regl-scatter2d will render points with 1:1 pixels binding, which makes pixelRatio option useless.
If you want to fix pixelRatio to some value, you can do that externally, that option is exactly for that.

@archmoj
Copy link
Contributor Author

archmoj commented Apr 8, 2019

@dy Thank you very much for the follow ups.
In fact we prefer not to pass a constant value there.
Here is another codepen comparing pixelRatio values equal to 1 and 2 that uses current regl-line2d & regl-scatter2d modules. The line widths are identical but the marker sizes are not.

@dy
Copy link
Member

dy commented Apr 11, 2019

Yep, the problem is on the regl-line2d side. It just doesn't account for pixelRatio. regl-scatter2d works as intended.

revert sizes in tests
@archmoj
Copy link
Contributor Author

archmoj commented Apr 11, 2019

Thanks for your hard work @archmoj - your patch appears to make scattergl consistent with how markers are drawn in scatter3d so

As this repo remains in @dy 's hands, we could perhaps make this new/consistent pixelRatio behaviour an opt-in e.g. by adding a boolean flag to regl-scatter2d that we would turn on upon instantiating in plotly.js

Great idea @etpinard.
Applied in 9c0933a.

@dy this should be good to go as tested on plotly side as well as here without any changes to the tests.
Would you mind reviewing it again?
Thanks in advance.

@archmoj archmoj requested a review from dy April 12, 2019 14:13
@dy
Copy link
Member

dy commented Apr 14, 2019

Gentlemen, I can't understand - why passing plotly's pixelRatio at all, if you need that constant? Just initialize regl-scatter2d with {pixelRatio: 2} from any trace and we're good to go, it will behave the same way as the other gl components. It is also shorter than {pixelRatio: plotlyPixelRatio, constantPixelRatio: true}.

@etpinard
Copy link
Member

, I can't understand - why passing plotly's pixelRatio at all, if you need that constant?

We offer that option to users on static exports (example) - which can make a appreciable difference in the quality of the exported images.

@dy
Copy link
Member

dy commented Apr 16, 2019

@etpinard that's great option, but no need to pass it to regl-scatter, pass {pixelRatio: constant} instead and that's it. Eg. here
https://github.com/plotly/plotly.js/blob/225521271f2eb7f5803713a28d8a7e0ef16ccc57/src/traces/scattergl/index.js#L116
just add an extra-line

// fix pixel ratio to accommodate other gl-components api
opts.marker.pixelRatio = 2.

@archmoj
Copy link
Contributor Author

archmoj commented Apr 16, 2019

@dy Thanks for the suggestion.
Unfortunately it does not seem to help fix the issue : (
Here is a codepen based on the fix you suggested.
Please notice how the markers are getting bigger with greater pixelRatio values.

@archmoj archmoj merged commit d9784d9 into master Aug 21, 2020
@archmoj archmoj deleted the fix3246-glPixelRatio-change-marker-size branch August 21, 2020 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants