Skip to content

Texture

GPU-only / runtime-managed texture. Backed by an ARXDynamicTexture (today's only constructible kind from JS is .computeBacked; sibling kinds – image, video, renderTarget, cameraFeed – wire up alongside material-parameter binding in a follow-up runtime version).

For compute-backed textures, kernel dispatch reads / writes the underlying GPU texture; materials sample the same memory through the same texture handle, so author-side updates show up in the next rendered frame without an explicit copy.

Authors construct via Texture.compute(...) and feed .read / .write tokens into a kernel's inputTextures / outputTextures maps.

Properties

depth

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

height

  • Type: number

id

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

pixelFormat

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

read

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

textureType

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

width

  • Type: number

write

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

Static Methods

cameraFeed()

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

Live camera feed as a sampleable texture. Binds the device's camera capture as a regular texture handle – typical uses are first-person portal effects, augmented-reality color grading on detected planes, or piping the feed into a compute kernel for a real-time filter.

Available on iOS / iPadOS only – Mac Catalyst and visionOS don't expose the AR camera capture. Always gate with environment.features.has('cameraFeed').

Example:

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

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>

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
}));

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).

Returns: Promise<Texture>

renderTarget()

javascript
Texture.renderTarget(_id: string): Promise<Texture>

Render-target texture. Stub for now – wired alongside material binding.

Parameters:

  • _id (string)

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.

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 + skip the binding.

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