Skip to content

Texture beta ​

A GPU texture created and managed at runtime. Construct one from an image or video source (Texture.image(...), Texture.video(...)), the live camera feed (Texture.cameraFeed()), or a compute kernel that writes its pixels (Texture.compute(...)).

For a compute-written texture the kernel writes the pixels and materials sample the same texture through the same handle, so updates show up in the next rendered frame without an explicit copy. Feed .read / .write tokens into a kernel's inputTextures / outputTextures maps.

Properties ​

depth read-only ​

  • Type: number
  • Depth (slices) for 3D textures, layer count for arrays. 1 for flat 2D / cubemap-face textures.

height read-only ​

  • Type: number

id read-only ​

  • Type: string
  • Texture id – matches dynamicTexture.id. Stable for the lifetime of the texture; surfaces in material TextureReference.dynamic references.

pixelFormat read-only ​

  • Type: string
  • Engine-agnostic pixel format name (e.g. "rgba32Float").

read read-only ​

  • Type: TextureBinding
  • Token tagged as "read into kernel" – pass to a kernel's inputTextures map.

textureType read-only ​

  • Type: string
  • Texture dimensionality: "2d", "3d", "cube", "2dArray", "cubeArray".

width read-only ​

  • Type: number

write read-only ​

  • Type: TextureBinding
  • Token tagged as "write from kernel" – pass to a kernel's outputTextures map.

Static Methods ​

background() ​

javascript
Texture.background(options?: Object): Promise<Texture>

The scene background as a sampleable texture: what is behind the scene, as a regular texture handle. Typical uses are first-person portal effects, augmented-reality color grading on detected planes, or piping the background into a compute kernel for a real-time filter.

In AR on iPhone and iPad it is the camera image. On Mac it is the scene's background, so a material sampling it at context.backgroundUV lines up with what is behind it; resize and filter settings and mipmaps do not apply there. Outside AR on iPhone and iPad it stays black. Not on visionOS. Always gate with environment.features.has('background').

Example:

javascript
if (!environment.features.has('background')) return;
const background = await Texture.background();
await entity.representation.setMaterial(Material.unlit({ map: background }));

Parameters:

  • options (Object) (optional)
  • options.semantic (string) (optional)
  • options.scale (number) (optional) - The picture's size as a fraction of the source's, as on Texture.image.
  • options.steps (Array<Object>) (optional) - Processing steps, as on Texture.image.

Returns: Promise<Texture>

cameraFeed() deprecated ​

Deprecated

Use Texture.background().

javascript
Texture.cameraFeed(options?: Object): Promise<Texture>

The scene background, under its earlier name.

Parameters:

  • options (Object) (optional)
  • options.semantic (string) (optional)

Returns: Promise<Texture>

compute() ​

javascript
Texture.compute(options: Object): Promise<Texture>

Allocate a GPU-only texture written by a compute kernel. Supports 2D, 3D, cube, and array textures with optional mipmap chains.

Async because the dynamic-texture asset-provider funnel allocates the underlying GPU resource and registers it in the runtime's manager cache (so material binding finds the same instance later). Authors await once at allocation; subsequent kernel dispatches are sync.

Example:

javascript
// 2D height map for a wave-grid kernel
const heightMap = await Texture.compute({
    pixelFormat: 'rgba32Float',
    width: 256,
    height: 256
});

// 3D scalar field for volumetric / marching-cubes work
const field = await Texture.compute({
    textureType: '3d',
    pixelFormat: 'r32Float',
    width: 64, height: 64, depth: 64
});

// Compute-driven normal map sampled by a PBR material
const normalMap = await Texture.compute({
    pixelFormat: 'rgba8Unorm',
    width: 512, height: 512,
    semantic: 'normal'
});

Parameters:

  • options (Object)
  • options.pixelFormat (string) - e.g. 'rgba32Float', 'rgba16Float', 'r32Float'.
  • options.textureType (string) (optional) - '2d' | '3d' | 'cube' | '2dArray' | 'cubeArray'.
  • options.width (number)
  • options.height (number)
  • options.depth (number) (optional) - Slice count for 3D textures.
  • options.arrayLength (number) (optional) - Layer count for arrays.
  • options.mipmapLevelCount (number) (optional) - Set > 1 + call texture.generateMipmaps() to populate.
  • options.semantic (string) (optional) - 'color' | 'normal' | 'scalar' | 'hdrColor' | 'raw'. Tells material binding how to sample (sRGB vs linear, etc.).
  • options.usage (Array<string>) (optional)

Returns: Promise<Texture>

fromAsset() ​

javascript
Texture.fromAsset(idOrName: string): Promise<Texture>

A texture from the experience's Library > Textures, by its id or its name. A texture its shader draws can be bound with .read and on materials; its .write is refused, since the shader owns its contents. Any other Library texture a kernel may also write. The texture belongs to the experience, so destroy() only drops this handle.

Example:

javascript
// Read the clouds a texture shader draws, in a kernel of your own
const clouds = await Texture.fromAsset('Clouds');
kernel.run({ inputTextures: { clouds: clouds.read }, outputTextures: { output: target.write } });

Parameters:

  • idOrName (string) - The texture's id, or its name when no other Library texture shares it.

Returns: Promise<Texture>

image() ​

javascript
Texture.image(urlOrId: string, options?: Object): Promise<Texture>

Static image-asset texture. Reads an image asset (PNG / JPG / etc.) from the experience's asset library or an absolute URL and binds it as a sampleable texture – typical use is a hand-painted normal map or albedo map fed to Material.pbr({ normalMap: tex }).

Example:

javascript
const normalMap = await Texture.image('rocks-normal.png', { semantic: 'normal' });
await entity.representation.setMaterial(Material.pbr({
    map: 'rocks-color.png',
    normalMap: normalMap
}));

// A softened, half-size poster for a glow
const glow = await Texture.image('poster.png', { scale: 0.5, steps: [{ blur: 12 }, { thresholdToZero: 0.2 }] });

Parameters:

  • urlOrId (string) - HTTPS URL or asset id from the project library.
  • options (Object) (optional)
  • options.semantic (string) (optional) - 'color' | 'normal' | 'scalar' | 'hdrColor' | 'raw'. Tells material binding how to sample (sRGB vs linear).
  • options.scale (number) (optional) - The picture's size as a fraction of the source's, more than 0 and at most 1, such as 0.5 for half.
  • options.steps (Array<Object>) (optional) - Processing steps, run in order: { blur: radius } in pixels, { thresholdToZero: value } from 0 to 1, { radialZoomBlur: amount } from 0 to 1, or { shader: assetId } for a texture shader.

Returns: Promise<Texture>

video() ​

javascript
Texture.video(urlOrId: string, options?: Object): Promise<Texture>

Video-asset texture. Plays a video file (mp4 / mov) as a sampleable texture and binds it to a material – typical use is a looping background, an animated diorama, or a UI-overlay video sticker.

The video starts playing automatically by default. Pass { autoplays: false } and call videoTexture.play() later when the entity becomes visible.

Example:

javascript
const intro = await Texture.video('intro-loop.mp4', { loops: true, volume: 0.3 });
await entity.representation.setMaterial(Material.unlit({ map: intro }));

Parameters:

  • urlOrId (string) - HTTPS URL or asset id from the project library.
  • options (Object) (optional)
  • options.semantic (string) (optional) - 'color' | 'normal' | 'scalar' | 'hdrColor' | 'raw'.
  • options.loops (boolean) (optional) - Restart from frame 0 on end.
  • options.autoplays (boolean) (optional) - Start playback as soon as the asset is ready.
  • options.volume (number) (optional) - Linear gain (0..1). Unset = system default.
  • options.streamContent (boolean) (optional) - HTTP streaming vs. download-then-play.
  • options.isShared (boolean) (optional) - SharePlay sync – when true, playback time syncs across session participants.
  • options.scale (number) (optional) - The picture's size as a fraction of the source's, as on Texture.image.
  • options.steps (Array<Object>) (optional) - Processing steps, as on Texture.image.

Returns: Promise<Texture>

Methods ​

destroy() ​

javascript
destroy(): void

Release the texture's GPU memory immediately.

Textures clean up automatically when the proxy goes out of scope. Call destroy() only for early termination in hot allocation / teardown loops where JSC's GC delay matters. Subsequent kernel dispatches binding this texture warn and abort, since a skipped binding would shift every later texture into the wrong slot.

Returns: void

generateMipmaps() ​

javascript
generateMipmaps(): void

Generate the mipmap chain. Runs a synchronous GPU mipmap-generation pass against the texture's command queue. Requires the texture was allocated with mipmapLevelCount > 1. No-op on textures without a mip chain.

Returns: void

setParameter() ​

javascript
setParameter(name: string, value: any, typeHint?: any): Texture

Sets a setting of the shader that draws a Library texture, on the running copy only: the texture in Library > Textures keeps its value. Converts the value as Material.setParameter does, and replaces a setting bound to a variable. A texture whose shader runs once runs once more with the new value.

Example:

javascript
const ripples = await Texture.fromAsset('Ripples');
ripples.setParameter('speed', 2).setParameter('tint', '#33CCFF', { type: 'color' });

Parameters:

  • name (string) - The setting's name, as the shader's settings panel shows it.
  • value (any) - Number, boolean, string, array (vector2/3/4), Vector3, or a color ('#RRGGBB', Color).
  • typeHint (any) (optional) - Overrides the inferred type: { type: "float" | "int" | "vector2" | "vector3" | "vector4" | "color" | "bool" | "string" }.

Returns: Texture