This class extends the Texture class specifically to handle external sources such as images, videos or canvases. It can be used with ComputePass and/or any kind of Mesh.

Can also handle texture transformations using a Mat3 if the useTransform parameter has been set to true upon creation.

If you use transformations, the modelMatrix will be available in the shaders using texturesMatrices.${texture.options.name}.matrix.

The library provide a convenient helpers in the shaders to help you compute the transformed UV:

// assuming 'uv' is a valid vec2f containing the original UV and the texture name is 'meshTexture'
uv = getUVCover(uv, texturesMatrices.meshTexture.matrix);
// assuming 'renderer' is a valid GPURenderer

// create a simple media texture
const mediaTexture = new MediaTexture(renderer, {
label: 'Media texture',
name: 'mediaTexture',
})

mediaTexture.loadImage('path/to/image.jpg')

// create a cube map texture
const cubeMapTexture = new MediaTexture(renderer, {
label: 'Cube map texture',
name: 'cubeMapTexture',
viewDimension: 'cube',
})

cubeMapTexture.loadImages([
'path/to/positive-x.jpg',
'path/to/negative-x.jpg',
'path/to/positive-y.jpg',
'path/to/negative-y.jpg',
'path/to/positive-z.jpg',
'path/to/negative-z.jpg',
])

Hierarchy (View Summary)

Constructors

Properties

externalTexture: GPUExternalTexture

The GPUExternalTexture used if any.

The MediaTexture sources to use if any.

Size of the texture source, usually our sources first element size (since for cube maps, all sources must have the same size).

Options used to create this MediaTexture.

videoFrameCallbackIds: Map<number, number>

Array of requestVideoFrameCallback returned ids if used.

offset: Vec2

Vec2 offset to apply to the Texture if useTransform parameter has been set to true.

scale: Vec2

Vec2 scale to apply to the Texture if useTransform parameter has been set to true.

transformOrigin: Vec2

Vec2 transformation origin to use when applying the transformations to the Texture if useTransform parameter has been set to true. A value of (0.5, 0.5) corresponds to the center of the texture. Default is (0, 0), the upper left.

modelMatrix: Mat3

Mat3 transformation matrix to apply to the Texture if useTransform parameter has been set to true.

transformBinding?: BufferBinding

BufferBinding to send the transformation matrix to the shaders if useTransform parameter has been set to true.

renderer: Renderer

renderer used by this Texture.

type: string

The type of the Texture.

uuid: string

The universal unique id of this Texture.

texture: GPUTexture

The GPUTexture used.

Array of bindings that will actually only hold one texture binding.

Accessors

Methods

  • Upload a source to the GPU and use it for our texture.

    Parameters

    • parameters: {
          source: GPUCopyExternalImageSource;
          width?: number;
          height?: number;
          depth?: number;
          origin?: GPUOrigin3D;
          colorSpace?: PredefinedColorSpace;
      }

      parameters used to upload the source.

      • source: GPUCopyExternalImageSource

        source to use for our texture.

      • Optionalwidth?: number

        source width.

      • Optionalheight?: number

        source height.

      • Optionaldepth?: number

        source depth.

      • Optionalorigin?: GPUOrigin3D
      • OptionalcolorSpace?: PredefinedColorSpace

    Returns void

  • Use data as the texture source and upload it to the GPU.

    Parameters

    • parameters: {
          width?: number;
          height?: number;
          depth?: number;
          origin?: GPUOrigin3D;
          data?: Float32Array;
      }

      parameters used to upload the source.

    Returns void