How to create Sketchfab like annotations with Three.js?

What you can do:

  • enable a depth rendering of the scene
  • create a shader material to apply to the hotspot:
    • enable alpha blending
    • set depth test to false to always render the hotspot / disable depth write
    • in the shader, compare the current depth with the one in the zbuffer (thanks to the depth rendering): set the alpha value of the final color depending on the test (for eg, 1.0 if current depth < z in zbuffer, else 0.3)

Here’s an example. It’s not done in threejs, but it should be easy to port the code.

If the depth in the depth rendering is stored as a linear depth (I don’t know how Threejs does it), here’s a modified sample.

3 Likes