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

CSS3DRenderer: Force canvas size to be even #20069

Closed
wants to merge 1 commit into from

Conversation

WestLangley
Copy link
Collaborator

@WestLangley WestLangley commented Aug 13, 2020

Possible approach to addressing #19854. Posting as a DRAFT.

CSS3DRenderer translates by half-width, so this PR prevents fractional pixels.

It appears to work for every example I have tried.

Note that there is no three.js requirement that the passed-in canvas dimensions are whole numbers. This can happen, for example, if the user splits the screen.

/ping @JohannesDeml Can you please test this PR on all your examples?

@WestLangley WestLangley added this to the rXXX milestone Aug 13, 2020
@JohannesDeml
Copy link
Contributor

Yes, making everything even does work, that's also the route I took in my project, since it also fixes the perspective camera problem (which I had). I went on to have the same resolution for the webgl renderer and the css renderer (so both would always be even). I'm not sure if that is necessary, but I think it might help with having cutouts fitting to the css renderer as clean as possible (so the antialiased line of the webgl renderer matching the css element).

I think it is a good solution for now, since it consistently fixes the problem, but it still would be interesting to understand why the problem occurs in the first place.

@WestLangley
Copy link
Collaborator Author

WestLangley commented Aug 14, 2020

In CSS3DRenderer, when replacing

var style = cameraCSSMatrix + 'translate(' +  _widthHalf + 'px,' +  _heightHalf + 'px)';

with

var style = cameraCSSMatrix + 'translate(' + Math.round( _widthHalf ) + 'px,' + Math.round( _heightHalf ) + 'px)';

I observe the same artifacts in Chrome and Firefox as appear in Safari.

Consequently, my hypothesis is Safari is rounding during the "translate" step, but in fact, should be rounding only after the entire matrix expression is evaluated.

//

I think I would prefer to not worry about this, and assume Safari will fix it at some point.

In the mean time, users can pass in even-valued canvas dimensions at the app level and avoid these artifacts.

//

EDIT: macOS Safari 13.1.2 test case: https://threejs.org/examples/css3d_sandbox.html.

  1. scroll the mouse to zoom in
  2. resize the window

Screen Shot 2020-08-28 at 4 16 40 PM

@yomotsu
Copy link
Contributor

yomotsu commented Aug 15, 2020

users can pass in even-valued canvas dimensions at the app level

Should we notice it in the documentation?

@JohannesDeml
Copy link
Contributor

Consequently, my hypothesis is Safari is rounding during the "translate" step, but in fact, should be rounding only after the entire matrix expression is evaluated.

Ah, that does make a lot of sense! Thanks for your in depth analysis!

users can pass in even-valued canvas dimensions at the app level

Should we notice it in the documentation?

I think that would be the best solution. What do you think @WestLangley ?

@WestLangley
Copy link
Collaborator Author

Should we notice it in the documentation?

We do not document browser bugs in the documentation.

I suggest we do nothing unless this becomes a serious user issue.

@WestLangley WestLangley removed this from the rXXX milestone Aug 17, 2020
@WestLangley WestLangley deleted the dev_css3d_make_even branch August 17, 2020 22:56
@mrdoob
Copy link
Owner

mrdoob commented Aug 18, 2020

https://bugs.webkit.org/show_bug.cgi?id=215590

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.

4 participants