1

I'm trying to render a fairly complex lamp using Three.js: https://sayduck.com/3d/xhcn

Render preview

The product is split up in multiple meshes similar to this one: Mesh preview

The main issue is that I also need to use transparent PNG textures (in order to achieve the complex shape while keeping polygon counts low) like this: Texture preview

As you can see from the live demo, this gives really weird results, especially when rotating the camera around the lamp - I believe due to z-ordering of the meshes.

I've been reading answers to similar questions on SO, like https://stackoverflow.com/a/15995475/5974754 or https://stackoverflow.com/a/37651610/5974754 to get an understanding of the underlying mechanism of how transparency is handled in Three.js and WebGL.

I think that in theory, what I need to do is, each frame, explicitly define a renderOrder for each mesh with a transparent texture (because the order based on distance to camera changes when moving around), so that Three.js knows which pixel is currently closest to the camera.

However, even ignoring for the moment that explicitly setting the order each frame seems far from trivial, I am not sure I understand how to set this order theoretically. My meshes have fairly complex shapes and are quite intertwined, which means that from a given camera angle, some part of mesh A can be closer to the camera than some part of mesh B, while somewhere else, part of mesh B are closer. In this situation, it seems impossible to define a closer mesh, and thus a proper renderOrder.

Have I understood correctly, and this is basically reaching the limits of what WebGL can handle?

Otherwise, if this is doable, is the approach with two render scenes (one for opaque meshes first, then one for transparent ones ordered back to front) the right one? How should I go about defining the back to front renderOrder the way that Three.js expects?

Thanks a lot for your help!

gman
  • 100,619
  • 31
  • 269
  • 393
Silvain
  • 399
  • 4
  • 20
  • 2
    It sounds like what you're looking for is a true-depth or occlusion-based solution, which can be expensive. You could use a depth texture to try to find which shapes are further from the camera, or you could do some form of ray-tracing. Both of those would be very process-intensive, and your render would run even slower than it does now. – TheJim01 Aug 15 '17 at 14:48
  • 2
    You might be interested in [this](https://github.com/mrdoob/three.js/issues/9977). – gman Aug 16 '17 at 02:09

0 Answers0