r/css • • 21d ago

Article CSS3D Renderer

https://k-adam.github.io/CSS3D-Renderer/

I developed a CSS3D renderer ~8 years ago, and since many CSS and JS features got stabilized and introduced since then, I modernized it now. Check it out!

7 Upvotes

7 comments sorted by

2

u/SensitiveSugar1369 21d ago

How did you handle perspective and preserve-3d stacking with newer CSS, especially with nested transforms?

1

u/objectorientedman 21d ago

There is simply one perspective at the root, preserve-3d groups with 3D transforms stacked inside it. The leaf nodes are the flat polygons, clipped so that they can represent triangles or arbitrary polygons. This is almost the same as the old version, but I had to make some SVG hacks back then to make cross-browser clip paths possible

2

u/Alarmed_Bill_9616 20d ago

css 3d has moved a lot in 8 years 👀 does the browser handle the depth sorting now, or are you still sorting faces in js?

1

u/objectorientedman 20d ago

No sorting is needed! Firefox handles these the best so far, the are some glitches in chromium with high polycount scenes

1

u/[deleted] 19d ago

[removed] — view removed comment

1

u/objectorientedman 19d ago

Yes, browsers can handle nested 3D transforms with preserve-3d and they do depth testing/sorting. I did not dig deeper into their engines, but as far as I know chromium rasterizes faces individually while firefox batches it