Hello, I try to recreate this kind of effect where text is masked and use three.js as a background. Here is some example from akaru
Since three.js’s actual output is just an image / canvas (WebGLRenderer.domElement to me more precise) - you could literally just render a frame, grab that domElement.toDataURL()
(docs, keep in mind this may be costly for high canvas resolutions) and set it as CSS background: url(...)
, then mask it with background-clip
.
Alternatively - you can draw three.js rendered frame onto another canvas (canvas2DContext.drawImage(renderer.domElement, 0, 0)
, and mask it manually (either by using .clip
, or just blending set to Multiply
- a bit more here.)
You can also do masking in three itself - using multiply blending combined with a masking plane placed right in front of the camera, or postprocessing.
If you’re using react-three-fiber
it may be even a bit easier and will allow you to create more flashy effects right in three - see this example by @drcmda (but I would be cautious about porting entire projects to react-three-fiber, if you haven’t already been using it - it works a bit different than vanilla three.)
Shader wizardry allows to turn this mask
into something funny
(pictures from two different runs)