Create a new Texture instance.
The graphics device used to manage this texture.
Optionaloptions: {Object for passing optional arguments.
OptionaladdressU?: numberThe repeat mode to use in the U direction. Defaults to ADDRESS_REPEAT.
OptionaladdressV?: numberThe repeat mode to use in the V direction. Defaults to ADDRESS_REPEAT.
OptionaladdressW?: numberThe repeat mode to use in the W direction. Defaults to ADDRESS_REPEAT.
Optionalanisotropy?: numberThe level of anisotropic filtering to use. Defaults to 1.
OptionalarrayLength?: numberSpecifies whether the texture is to be a 2D texture array. When passed in as undefined or < 1, this is not an array texture. If >= 1, this is an array texture. Defaults to undefined.
OptionalcompareFunc?: numberComparison function when compareOnRead is enabled. Can be:
Defaults to FUNC_LESS.
OptionalcompareOnRead?: booleanWhen enabled, and if texture format is PIXELFORMAT_DEPTH or PIXELFORMAT_DEPTHSTENCIL, hardware PCF is enabled for this texture, and you can get filtered results of comparison using texture() in your shader. Defaults to false.
Optionalcubemap?: booleanSpecifies whether the texture is to be a cubemap. Defaults to false.
Optionaldepth?: numberThe number of depth slices in a 3D texture.
OptionalflipY?: booleanSpecifies whether the texture should be flipped in the Y-direction. Only affects textures with a source that is an image, canvas or video element. Does not affect cubemaps, compressed textures or textures set from raw pixel data. Defaults to false.
Optionalformat?: numberThe pixel format of the texture. Can be:
Defaults to PIXELFORMAT_RGBA8.
Optionalheight?: numberThe height of the texture in pixels. Defaults to 4.
Optionallevels?: Array of Uint8Array or other supported browser interface; or a two-dimensional array of Uint8Array if options.arrayLength is defined and greater than zero.
OptionalmagFilter?: numberThe magnification filter type to use. Defaults to FILTER_LINEAR.
OptionalminFilter?: numberThe minification filter type to use. Defaults to FILTER_LINEAR_MIPMAP_LINEAR.
Optionalmipmaps?: booleanWhen enabled try to generate or use mipmaps for this texture. Default is true.
Optionalname?: stringThe name of the texture. Defaults to null.
OptionalnumLevels?: numberSpecifies the number of mip levels to generate. If not specified, the number is calculated based on the texture size. When this property is set, the mipmaps property is ignored.
OptionalpremultiplyAlpha?: booleanIf true, the alpha channel of the texture (if present) is multiplied into the color channels. Defaults to false.
Optionalprojection?: stringThe projection type of the texture, used when the texture represents an environment. Can be:
Defaults to TEXTUREPROJECTION_CUBE if options.cubemap is true, otherwise TEXTUREPROJECTION_NONE.
Optionalstorage?: booleanDefines if texture can be used as a storage texture by a compute shader. Defaults to false.
Optionaltype?: stringSpecifies the texture type. Can be:
Defaults to TEXTURETYPE_DEFAULT.
Optionalvolume?: booleanSpecifies whether the texture is to be a 3D volume. Defaults to false.
Optionalwidth?: numberThe width of the texture in pixels. Defaults to 4.
// Create a 8x8x24-bit texture
const texture = new pc.Texture(graphicsDevice, {
width: 8,
height: 8,
format: pc.PIXELFORMAT_RGB8
});
// Fill the texture with a gradient
const pixels = texture.lock();
const count = 0;
for (let i = 0; i < 8; i++) {
for (let j = 0; j < 8; j++) {
pixels[count++] = i * 32;
pixels[count++] = j * 32;
pixels[count++] = 255;
}
}
texture.unlock();
Protected_Protected_Protected_Protected_Protected_Protected_ProtectedidThe name of the texture.
Gets the addressing mode to be applied to the texture horizontally.
Sets the addressing mode to be applied to the texture horizontally. Can be:
Gets the addressing mode to be applied to the texture vertically.
Sets the addressing mode to be applied to the texture vertically. Can be:
Gets the addressing mode to be applied to the 3D texture depth.
Sets the addressing mode to be applied to the 3D texture depth. Can be:
Gets the integer value specifying the level of anisotropy to apply to the texture.
Sets the integer value specifying the level of anisotropy to apply to the texture. The value ranges from 1 (no anisotropic filtering) to the maximum anisotropy supported by the graphics device (see GraphicsDevice#maxAnisotropy).
Returns true if this texture is a 2D texture array and false otherwise.
Returns the number of textures inside this texture if this is a 2D array texture or 0 otherwise.
Gets the comparison function when compareOnRead is enabled.
Sets the comparison function when compareOnRead is enabled. Possible values:
Gets whether you can get filtered results of comparison using texture() in your shader.
When enabled, and if texture format is PIXELFORMAT_DEPTH or PIXELFORMAT_DEPTHSTENCIL, hardware PCF is enabled for this texture, and you can get filtered results of comparison using texture() in your shader.
Returns true if this texture is a cube map and false otherwise.
The number of depth slices in a 3D texture.
Gets whether the texture should be flipped in the Y-direction.
Sets whether the texture should be flipped in the Y-direction. Only affects textures with a source that is an image, canvas or video element. Does not affect cubemaps, compressed textures or textures set from raw pixel data. Defaults to true.
The pixel format of the texture. Can be:
The height of the texture in pixels.
Gets the magnification filter to be applied to the texture.
Sets the magnification filter to be applied to the texture. Can be:
Gets the minification filter to be applied to the texture.
Sets the minification filter to be applied to the texture. Can be:
Gets whether the texture should generate/upload mipmaps.
Sets whether the texture should generate/upload mipmaps.
Gets the number of mip levels.
Returns true if all dimensions of the texture are power of two, and false otherwise.
Returns true if the texture is stored in an sRGB format, meaning it will be converted to linear space when sampled. Returns false if the texture is stored in a linear format.
Defines if texture can be used as a storage texture by a compute shader.
Returns true if this texture is a 3D volume and false otherwise.
The width of the texture in pixels.
Frees resources associated with this texture.
Get the pixel data of the texture. If this is a cubemap then an array of 6 images will be returned otherwise a single image.
OptionalmipLevel: number = 0A non-negative integer specifying the image level of detail. Defaults to 0, which represents the base image source. A level value of N, that is greater than 0, represents the image source for the Nth mipmap reduction level.
The source image of this texture. Can be null if source not assigned for specific image level.
Locks a miplevel of the texture, returning a typed array to be filled with pixel data.
Optionaloptions: { face?: number; level?: number; mode?: number } = {}Optional options object. Valid properties are as follows:
Optionalface?: numberIf the texture is a cubemap, this is the index of the face to lock.
Optionallevel?: numberThe mip level to lock with 0 being the top level. Defaults to 0.
Optionalmode?: numberThe lock mode. Can be:
A typed array containing the pixel data of the locked mip level.
Set the pixel data of the texture from a canvas, image, video DOM element. If the texture is a cubemap, the supplied source must be an array of 6 canvases, images or videos.
A canvas, image or video element, or an array of 6 canvas, image or video elements.
OptionalmipLevel: number = 0A non-negative integer specifying the image level of detail. Defaults to 0, which represents the base image source. A level value of N, that is greater than 0, represents the image source for the Nth mipmap reduction level.
Unlocks the currently locked mip level and uploads it to VRAM.
Forces a reupload of the textures pixel data to graphics memory. Ordinarily, this function is called by internally by setSource and unlock. However, it still needs to be called explicitly in the case where an HTMLVideoElement is set as the source of the texture. Normally, this is done once every frame before video textured geometry is rendered.
Represents a texture, which is typically an image composed of pixels (texels). Textures are fundamental resources for rendering graphical objects. They are commonly used by Materials and sampled in Shaders (usually fragment shaders) to define the visual appearance of a 3D model's surface. Beyond storing color images, textures can hold various data types like normal maps, environment maps (cubemaps), or custom data for shader computations. Key properties control how the texture data is sampled, including filtering modes and coordinate wrapping.
Note on HDR texture format support:
As textures:
As renderable textures that can be used as color buffers in a RenderTarget: