There’s something going on either in Three.js (seems unlikely in this case, but still a possibility), or with discrepancies between browsers (seems more likely).
Finally, open it in any Chrome/Blink-based browser including Chrome Android, Edge Android, Opera Android, and Samsung Internet Android, and it will be broken presumably because they all use the same browser engine. The position of the object will be off, and the object will be stretched (as if it were scaled on Y or similar). Here are those four browsers on Android, respectively:
The three.js APIs you are using here do not have dedicated code paths for Android devices. It may be worth trying to recreate this with just Canvas 2D API instead of three.js. You may want to measure and log the sizes, aspect ratios, etc. on the device as well.
I saw that the pixel sizes for the canvas differ by about 0.25px between mobile and desktop (when desktop is set to the identical size as mobile in the device emulator in devtools). F.e. XXX.5 on desktop and XXX.24567 or similar on mobile. Not sure that it would have any effect on the internal drawing of the canvas though.
You’re sounding alarms that the Three.js team needs to investigate this bug, when it’s you who’s using very unorthodox and conflicting methods of sizing your canvas. You’re using hard values (1851), .setSize() then overriding it with styles. I recommend you plug in your Android to your computer via USB then use this method to debug your own device to see what your code is doing to your canvas.
When debugging, I noticed that you’re setting a height of sceneH = 1851 then using renderer.setPixelRatio(window.devicePixelRatio). A lot of Android devices have a pixel ratio of 3, which makes your scene height 1851 * 3 = 5553. This seems to be the root of your problem.
If you set renderer.setPixelRatio(2), then the stretching goes away. My guess is that you’re reaching some dimension limit, since window.innerHeight is typically less than 1851px on an Android. Mine is 1232px.
Thanks, I appreciate the feedback. I’m already doing that remote debugging. The desktop Chrome inspector (connected to my Android device) shows the same result as I see on Android (scene content erroneously distorted).
i.e. The above screenshots of Android Chrome show the same result as when I view through the inspector. I believe Android simply pipes the screen data to the inspector, so inspecting with desktop Chrome has no effect on the result.
This should have no effect on the scene contents, it would only effect the resolution of the scene, but it should not stretch anything in the scene because the aspect ratio is always the same. Everything in the scene should be drawn using a WebGL viewport height of 2, and width of 2, regardless of the resolution, and regardless of the aspect ratio.
Given that the aspect ratio is the same on all devices, the rendering should be proportionally the same on all devices.
There’s nothing unorthodox in the way I’m sizing the canvas. It should not be distorting anything in the way I’ve rendered it.
It works on all devices, except Android Chrome (and derivatives Edge, Opera, Samsung Internet on Android), which definitely implies something (not sure what yet).
If this in fact turns out to be the problem (it shouldn’t be causing the problem), then the question would be is it Three.js or Chrome that the issue is coming from?
Here is iPhone Safari, with the correct result (hence all derivative browsers on iOS have the correct result because they all use Safari web views):
I’m pretty certain it’s a Chrome issue. I really do think you’re reaching some sort of maximum canvas or buffer size limit. But if you really want to pursue this further, you could re-create the bug using another WebGL library to rule out the possibility. TWGL.js is a very low-level lib that’s a very thin layer above WebGL. You could recreate your dimensions with this demo and compare:
It isn’t visible in the images, but the distortion happens along along all axes including Z towards the camera, so if we rotate the camera around the object (f.e. with OrbitControls) the object appears to be translated forward on Z. Strange.
They surely don’t need to. If I was core member of Three.js (I’m not), I certainly would want to. IMO, no harm sharing what I did.
I think if you’re going to report a bug to any library it’s your responsibility to have done some reasonable research to ensure it’s actually a bug with the library but you haven’t shown that, yet. Three.js maintainers have enough to work on without spending time trying to get to the bottom of every users misunderstanding of WebGL limitations and three.js implementation. You may disagree but you have understand that people may start taking your reports less seriously as a consequence.
At first brush here if this works on nearly every other device but one or two browser / device combos then you can be fairly sure that it’s not a three.js implementation issue. And if you do a little searching online you can see that there are canvas size limitations per device. If you’d like to see the limitations of your device you can run the following on the remote console:
c = document.createElement( 'canvas' );
ctx = c.getContext( 'webgl2' );
ctx.getParameter( ctx.MAX_VIEWPORT_DIMS );
// returns [ 32767, 32767 ] on Windows 10, Chrome, RTX 2070
// returns [ 16384, 16384 ] on Android Pixel 3, Chrome
You haven’t posted your device information but it’s possible you’re limited to a 4k canvas on your device which could be the source of the issue.
If I understand correctly, the width and height attributes dictate the canvas drawing size. The physical dimensions of the canvas on screen are 980*3.5 by 1851*3.5, or 3430 x 6478, which is what the canvas size is set to, and those are lower than the limit.
It’s odd to me that your newer 2021 pixel device has a lower limit than my 2018 pixel 3 one…
If I understand correctly, the width and height attributes dictate the canvas drawing size.
These are values you can request the canvas size to be but there’s no guarantee the device can provide them. You can query these values to get the current drawing buffer size which will be clamped based on device capability. For some reason these seem to max out before hitting the MAX_VIEWPORT_DIMS values: