Texture - Verge3D User Manual - Soft8Soft
Description: Learn how to use Texture in your interactive 3D apps made with Verge3D

# Texture

Create a texture to apply to a surface or as a reflection or refraction map.

After the initial use of a texture, its dimensions, format, and type cannot be changed. Instead, call .dispose() on the texture and instantiate a new one.

## Code Example

`// load a texture, set wrap mode to repeat const texture = new v3d.TextureLoader().load('mytexture.jpg'); texture.wrapS = v3d.RepeatWrapping; texture.wrapT = v3d.RepeatWrapping; texture.repeat.set(4, 4);`

## Constructor

### Texture(image : Image, mapping : Constant, wrapS : Constant, wrapT : Constant, magFilter : Constant, minFilter : Constant, format : Constant, type : Constant, anisotropy : Integer, encoding : Constant)

Refer to the properties below for the explanation of the constructor params meaning.

## Properties

### # .id : Integer

Readonly — unique number for this texture instance.

### # .isTexture : Boolean

Read-only flag to check if a given object is of type Texture.

### # .uuid : String

UUID of this object instance. This gets automatically assigned, so this shouldn't be edited.

### # .name : String

Optional name of the texture (doesn't need to be unique). Default is an empty string.

### # .image : Image

An image object, typically created using the TextureLoader.load method. This can be any image (e.g., PNG, JPG, WEBP, KTX2) or video (e.g., MP4, WEBM) type supported by Verge3D.

To use video as a texture you need to have a playing HTML5 video element as a source for your texture image and continuously update this texture as long as video is playing — the VideoTexture class handles this automatically.

### # .mipmaps : Array

Array of user-specified mipmaps (optional).

### # .mapping : Constant

How the image is applied to the object. An mapping type of v3d.UVMapping is the default, where the U,V coordinates are used to apply the map.

See the texture constants page for other mapping types.

### # .wrapS : Constant

This defines how the texture is wrapped horizontally and corresponds to U in UV mapping.

The default is v3d.ClampToEdgeWrapping, where the edge is clamped to the outer edge texels. The other two choices are v3d.RepeatWrapping and v3d.MirroredRepeatWrapping.

See the texture constants page for details.

### # .wrapT : Constant

This defines how the texture is wrapped vertically and corresponds to V in UV mapping. The same choices are available as for .wrapS.

NOTE: tiling of images in textures only functions if image dimensions are powers of two (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, ...) in terms of pixels. Individual dimensions need not be equal, but each must be a power of two. This is a limitation of WebGL, not Verge3D.

### # .magFilter : Constant

How the texture is sampled when a texel covers more than one pixel. The default is v3d.LinearFilter, which takes the four closest texels and bilinearly interpolates among them. The other option is v3d.NearestFilter, which uses the value of the closest texel.

See the texture constants page for details.

### # .minFilter : Constant

How the texture is sampled when a texel covers less than one pixel. The default is v3d.LinearMipmapLinearFilter, which uses mipmapping and a trilinear filter.

See the texture constants page for all possible choices.

### # .anisotropy : Integer

The number of samples taken along the axis through the pixel that has the highest density of texels. By default, this value is `1`. A higher value gives a less blurry result than a basic mipmap, at the cost of more texture samples being used. Use renderer.capabilities.getMaxAnisotropy() to find the maximum valid anisotropy value for the GPU.

### # .format : Constant

The default is v3d.RGBAFormat.

See the texture constants page for details of other formats.

### # .internalFormat : String

The default value is obtained using a combination of .format and .type.

The GPU format allows the developer to specify how the data is going to be stored on the GPU.

### # .type : Constant

This must correspond to the .format. The default is v3d.UnsignedByteType, which will be used for most texture formats.

See the texture constants page for details of other formats.

### # .generateMipmaps : Boolean

Whether to generate mipmaps (if possible) for a texture. True by default. Set this to false if you are creating mipmaps manually.

### # .premultiplyAlpha : Boolean

If set to `true`, the alpha channel, if present, is multiplied into the color channels when the texture is uploaded to the GPU. Default is `false`.

Note that this property has no effect for ImageBitmap. You need to configure on bitmap creation instead. See ImageBitmapLoader.

### # .flipY : Boolean

If set to `true`, the texture is flipped along the vertical axis when uploaded to the GPU. Default is `true`.

Note that this property has no effect for ImageBitmap. You need to configure on bitmap creation instead. See ImageBitmapLoader.

### # .unpackAlignment : Integer

4 by default. Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries). See glPixelStorei for more information.

### # .encoding : Constant

v3d.LinearEncoding is the default. See the texture constants page for details of other formats.

Note that if this value is changed on a texture after the material has been used, it is necessary to trigger a Material.needsUpdate for this value to be realized in the shader.

### # .version : Integer

This starts at `0` and counts how many times .needsUpdate is set to `true`.

### # .onUpdate : Function

A callback function, called when the texture is updated (e.g., when needsUpdate has been set to true and then the texture is used).

### # .needsUpdate : Boolean

Set this to `true` to trigger an update next time the texture is used. Particularly important for setting the wrap mode.

### # .userData : Object

An object that can be used to store custom data about the texture. It should not hold references to functions as these will not be cloned.

### # .source : Source

The data definition of a texture. A reference to the data source can be shared across textures. This is often useful in context of spritesheets where multiple textures render the same data but with different texture transformations.

## Methods

EventDispatcher methods are available on this class.

### # .clone() → Texture

Make copy of the texture. Note this is not a "deep copy", the image is shared. Besides, cloning a texture does not automatically mark it for a texture upload. You have to set .needsUpdate to `true` as soon as its image property (the data source) is fully loaded or ready.

### # .dispose()

Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.

## Source

For more info on how to obtain the source code of this module see this page.