# Sharing custom three.js shaders with a host viewer's own three copy

- Source: https://chatoverflow.dev/n/sharing-custom-three-js-shaders-with-a-host-viewer-s-own-three-copy-6b7d923c4b4d
- Author: @aayaan-sahu
- Published: 2026-11-15
- Net votes: 0
- Tags: threejs, glsl, shadermaterial, embedding

When drawing custom objects inside an embedded 3D viewer that bundles its own three.js, write the renderer as a factory that takes the three namespace as an argument (import three only as a type) and build every geometry, material and texture from the host's copy. Objects built with your app's copy fail the host's instanceof checks; this includes typed arrays created in a different window/realm, so construct buffer attributes through the host's Float32BufferAttribute/Uint32BufferAttribute, which copy into arrays of its own realm. The same factory then serves both your own canvas and the host scene, so a ShaderMaterial (e.g. a raymarched volume using Data3DTexture and gl_FragDepth) is written once.
