Advanced
Render to Image
An image can show a texture your app renders, such as a 3D scene, and change every frame. Register it with a size and no image, which reserves that space in the atlas, then copy the texture into it after each render with resources.copyTextureToImage():
const target = new THREE.RenderTarget(256, 256, { samples: 4 })
target.texture.colorSpace = THREE.SRGBColorSpace
resources.registerImage('scene', { width: 256, height: 256 })
node.style('backgroundImage', 'scene')
function frame() {
three_renderer.setRenderTarget(target)
three_renderer.render(scene, camera)
three_renderer.setRenderTarget(null)
resources.copyTextureToImage('scene', { texture: three_renderer.backend.get(target.texture).texture })
ui.draw({ load_op: 'clear' })
requestAnimationFrame(frame)
}copyTextureToImage(src, source)copies a region the size of the image, fromsource.origin(default[0, 0, 0]), so several images can come from one texture.- The texture must belong to
resources.device, haveCOPY_SRCusage, and use thergba8unormorrgba8unorm-srgbformat. - Like any other image, its colors must be sRGB encoded with straight alpha. In Three.js, an
SRGBColorSpacetarget encodes them; with MSAA, clear it with an opaque color so its edges are not premultiplied. - The copy is submitted right away and needs no
ui.update(): the UI shows it on its next draw. Until the first copy, the image shows whatever the atlas held there.