---
title: "textureNumLayers: WGSL·GLSL 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "텍스처 배열은 독립적으로 선택할 수 있는 이미지 레이어를 담습니다. 이 함수는 레이어 수를 구합니다. 레이어 선택자의 범위를 정하거나 이미지 배열을 순회할 때 사용합니다. 배열 텍스처가 필요합니다."
url: https://typeshade.dev/ko/reference/functions/textureNumLayers/
language: ko
---

# `textureNumLayers`

함수

텍스처 배열은 독립적으로 선택할 수 있는 이미지 레이어를 담습니다. 이 함수는 레이어 수를 구합니다.

## 예제 비교

반환값은 배열의 레이어 수입니다. 큐브 배열에서는 개별 면이 아니라 큐브 수를 셉니다.

**예제 1`texture_2d_array: layers = 1`**

**결과**

`1`

**예제 2`texture_2d_array: layers = 4`**

**결과**

`4`

**예제 3`texture_cube_array: cubes = 3`**

**결과**

`3`

예제는 설명용 계산 모델이며 GPU를 실행하지 않습니다. 정확한 호출 형식은 아래 컴파일러 참고 자료에서 설명합니다. 소수 결과는 표시할 때 반올림했습니다. 각 예제는 명시한 전제를 따릅니다. 실제 셰이더의 결과는 대상 언어의 정밀도와 실행 규칙에 따릅니다.

## 활용

레이어 선택자의 범위를 정하거나 이미지 배열을 순회할 때 사용합니다.

## 입력 범위와 주의사항

배열 텍스처가 필요합니다. 마지막 유효 레이어 인덱스는 레이어 수보다 하나 작습니다.

셰이더의 입력 규칙과 정밀도는 [WGSL](https://www.w3.org/TR/WGSL/)과 [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf)에서 규정합니다.

## 관련 함수

- [`textureSample`](https://typeshade.dev/ko/reference/functions/textureSample/)
- [`textureLoad`](https://typeshade.dev/ko/reference/functions/textureLoad/)
- [`textureSampleLevel`](https://typeshade.dev/ko/reference/functions/textureSampleLevel/)
- [`textureSampleBias`](https://typeshade.dev/ko/reference/functions/textureSampleBias/)
- [`textureSampleGrad`](https://typeshade.dev/ko/reference/functions/textureSampleGrad/)

**WGSL**

`textureNumLayers(a)`

**GLSL ES 3.00**

`uint(textureSize(a, 0).z)`

시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 af54ddad5의 컴파일러가 쓴 영어 원문입니다.

Returns the number of layers of a `texture_2d_array` or a `texture_cube_array` as a `u32`.

## 구문

```ts
declare function textureNumLayers<E extends TextureElem = f32>(tex: texture_cube_array<E>): u32
declare function textureNumLayers(tex: texture_depth_cube_array): u32
declare function textureNumLayers(tex: texture_depth_2d_array): u32
declare function textureNumLayers<E extends TextureElem = f32>(tex: texture_2d_array<E>): u32
declare function textureNumLayers<F extends StorageFormat, A extends StorageAccess>(
  tex: texture_storage_2d_array<F, A>,
): u32
```

시그니처에는 앰비언트 파일이 스스로 쓰려고 선언한 타입이 나올 수 있습니다. 아래가 그 선언입니다.

**`TextureElem`**

`type TextureElem = f32 | i32 | u32`

**`StorageFormat`**

`type StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm'`

**`StorageAccess`**

`type StorageAccess = 'write' | 'read' | 'read_write'`

## 매개변수

- `tex` `texture_cube_array<E>``texture_depth_cube_array``texture_depth_2d_array``texture_2d_array<E>``texture_storage_2d_array<F, A>`

## 반환값

`u32`

## 설명

A texture with no layers is refused.

CPU 오라클에는 텍스처 메모리도 이웃 프래그먼트도 없습니다. `{ gpuStubs: true }`로 컴파일한 모듈이 아니면 호출이 예외를 던집니다. 그 옵션을 주면 자리를 채우는 값이 돌아옵니다.

## 대상별 출력

**WGSL**

`textureNumLayers(a)`

**GLSL ES 3.00**

`uint(textureSize(a, 0).z)`

## 예제

- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/ko/guide/examples/cube-array-gather/)
- [`gallery/shadow-compare/shadow-compare.shade.ts`](https://typeshade.dev/ko/guide/examples/shadow-compare/)

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
- [내장 함수 표](https://typeshade.dev/ko/guide/language/builtins/#textures)
- [`typeshade/core/ir`의 `textureNumLayers()`](https://typeshade.dev/ko/api/texturenumlayers/)
