question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS objects get pixelated when using CSS3DRenderer with PerspectiveCamera

See original GitHub issue
Description of the problem

I’ve made a demo to demonstrate the problem, I tried to remove all the code that’s unnecessary.

Use your mouse wheel to zoom in / out. You can probably see, that on the right, the SVG becomes pixelated, as if it was a low-resolution jpeg, or something. Given the fact that SVG uses vector graphics, it should remain crystal clear and razor sharp, no matter how far I zoom in (like it does with OrthographicCamera - on the left).

What I’ve tried:

  • Different browsers. All the major browsers seem to be affected, some of them are worse than others. Chrome seems to be the best, but it’s still very far from perfect: Capture
  • Dolly instead of changing the camera’s zoom property. Well, it doesn’t really matter if I change the perspective camera’s position, or its zoom property, the effect seems to be the same.

What I can think of…:

  • Maybe the browsers can’t handle some specific transform attributes well, but they can handle others very well…? I’ve noticed that the camera’s div (generated by the CSS3DRenderer) has translateZ when I use PerspectiveCamera, but it has scale when I use OrthographicCamera. Although I’ve tried manually changing it and it didn’t improve anything, so I’m not sure…

Any ideas, anyone?

https://jsfiddle.net/soadzoor/jkn2eugs/6/

UPDATE: After some digging, I’ve figured out that if I remove the perspective: XXXpx; attribute, then it becomes sharp, and also: if I add the perspective: XXXpx; attribute to the one with the orthographic camera, it becomes blurry. So the question: can we replace this attribute to something else (like a transform matrix), to get the same perspective effect minus the blurriness?

UPDATE2: I’ve tried replacing perspective with transform: perspective (the former needs to be added to the parent, the latter needs to be added to the child), and also recreated the effect with matrix3d, based on this: https://stackoverflow.com/questions/8029605/what-is-the-math-behind-webkit-perspective/8029819#8029819 All of these approaches get me to the same blurry image… I’m starting to give up on this, it’s probably a browser limitation that can’t be solved as of now…

Three.js version
  • Dev
  • r109
  • < r109
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yomotsucommented, Oct 3, 2019

FYI: Once you apply CSS-Transform3D, the element will be rasterized at the initial size, and not a vector image anymore, because of GPU-acceleration. prepare a bigger element, then apply 3D, and then scale it down.

0reactions
soadzoorcommented, Oct 18, 2019

On macOS Chrome, this improves the quality a lot:

 const svgSize = {
    x: 16,
    y: 16
  };

Wow, I’ve just tried it, and it does make a significant difference on windows-chrome, too! I’m wondering why…? It doesn’t really make any sense, does it…? Smaller size should give us an even blurrier result…?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SVG becomes blurry ONLY when it is too close to camera
It looks like there is a similar issue here: CSS objects get pixelated when using CSS3DRenderer with PerspectiveCamera · Issue #17641 · mrdoob/three.js...
Read more >
CSS3DRenderer disable scaling - javascript - Stack Overflow
The only way to stop the scaling is by projecting the 3D positions to 2D with the Vector3.project() method. Take a look at...
Read more >
Getting started with the CSS 3D renderer | Three.js Cookbook
CSS3DRenderer object, we can directly access these CSS 3D features and transform an arbitrary HTML element in 3D space. Getting ready. To use...
Read more >
image-rendering - CSS: Cascading Style Sheets | MDN
The image is scaled with the nearest-neighbor algorithm. pixelated. Using the nearest-neighbor algorithm, the image is scaled up to the next ...
Read more >
Test- cssRenderer & webglRenderer together. - Plunker
Vector3(); var te = this.object.matrix.elements; // get X column of ... don't use screenWidth, since perspective camera is fixed to screen height scope....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found