TextureArray

Inherits: TextureLayered < Resource < Reference < Object

存储在单个基元中的纹理数组。

描述

TextureArrays store an array of Images in a single Texture primitive. Each layer of the texture array has its own mipmap chain. This makes it is a good alternative to texture atlases. See also Texture3D.

TextureArrays must be displayed using shaders. After importing your file as a TextureArray and setting the appropriate Horizontal and Vertical Slices, display it by setting it as a uniform to a shader, for example (2D):

  1. shader_type canvas_item;
  2. uniform sampler2DArray tex;
  3. uniform int index;
  4. void fragment() {
  5. COLOR = texture(tex, vec3(UV.x, UV.y, float(index)));
  6. }

Set the integer uniform “index” to show a particular part of the texture as defined by the Horizontal and Vertical Slices in the importer.

Note: When sampling an albedo texture from a texture array in 3D, the sRGB -> linear conversion hint (hint_albedo) should be used to prevent colors from looking washed out:

  1. shader_type spatial;
  2. uniform sampler2DArray tex : hint_albedo;
  3. uniform int index;
  4. void fragment() {
  5. ALBEDO = texture(tex, vec3(UV.x, UV.y, float(index)));
  6. }

Note: TextureArrays can only be sampled in shaders in the GLES3 backend. In GLES2, their data can be accessed via scripting, but there is no way to render them in a hardware-accelerated manner.

方法

void

create ( int width, int height, int depth, Format format, int flags=7 )

方法说明

以指定的widthheightdepth创建TextureArray。参阅Formatformat选项。参阅Flags枚举器的flags选项。