---
title: "textureDimensions / textureSize: 셰이더 함수 설명과 예제, 입력 범위 및 주의점"
description: "텍스처 크기는 이미지의 범위를 나타내며 색상 값과는 다릅니다. 텍셀 단위의 이동량을 정규화된 좌표 변화량으로 바꿀 때 사용합니다. 배열 레이어 수와 샘플 수는 별도로 조회합니다. 큐브 텍스처에서는 한 면의 크기를 돌려줍니다."
url: https://typeshade.dev/ko/reference/functions/textureDimensions/
language: ko
---

# `textureDimensions`

함수

텍스처 크기는 이미지의 범위를 나타내며 색상 값과는 다릅니다.

**다른 언어의 관련 이름**

관련 연산은 인수, 지원 범위와 의미가 다를 수 있습니다. 다른 언어의 이름을 TypeShade 별칭으로 사용할 수는 없습니다. 지원하는 형태와 제한은 대상 언어에 따라 다릅니다.

- GLSL: `textureSize`

[대상별 출력](https://typeshade.dev/ko/reference/functions/textureDimensions/#targets)

## 예제 비교

반환 벡터의 각 성분은 해당 축의 텍셀 수입니다. 큐브의 면 수는 크기 벡터에 포함되지 않습니다.

**예제 1`texture_2d: 8 × 4`**

**결과**

`vec2u(8, 4)`

**예제 2`texture_3d: 8 × 4 × 2`**

**결과**

`vec3u(8, 4, 2)`

**예제 3`texture_cube: 4 × 4 × 6`**

**결과**

`vec2u(4, 4)`

예제는 설명용 계산 모델이며 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**

`textureDimensions(a)`

**GLSL ES 3.00**

`uvec2(textureSize(a, 0))`

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

Returns the size of the texture's base mip level: width and height as a `vec2u`, width, height and depth as a `vec3u` on a `texture_3d`, or the width alone as a `u32` on a `texture_1d`.

## 구문

```ts
declare function textureDimensions<E extends TextureElem = f32>(
  tex: texture_2d<E> | texture_2d_array<E>,
  level?: number,
): vec2u
declare function textureDimensions<E extends TextureElem = f32>(
  tex: texture_cube<E> | texture_cube_array<E>,
  level?: number,
): vec2u
declare function textureDimensions<E extends TextureElem = f32>(
  tex: texture_3d<E>,
  level?: number,
): vec3u
declare function textureDimensions<E extends TextureElem = f32>(tex: texture_1d<E>, level?: number): u32
declare function textureDimensions<E extends TextureElem = f32>(tex: texture_multisampled_2d<E>): vec2u
declare function textureDimensions(
  tex:
    | texture_depth_2d
    | texture_depth_2d_array
    | texture_depth_cube
    | texture_depth_cube_array
    | texture_depth_multisampled_2d,
  level?: number,
): vec2u
declare function textureDimensions<F extends StorageFormat, A extends StorageAccess>(
  tex: texture_storage_2d<F, A> | texture_storage_2d_array<F, A>,
): vec2u
```

매개변수나 반환 위치에 쓰인 `number`는 스칼라가 들어갈 자리입니다. 앰비언트 파일은 GPU 스칼라를 브랜드가 붙은 number로 선언하고 그 브랜드는 선택이라서, 리터럴도 브랜드가 붙은 스칼라도 이 자리에 들어갑니다.

`type f32 = number & { readonly [f32Tag]?: true }`

타입으로 쓴 `number`는 쓰이는 곳을 보고 추론하며, `f32`, `i32`, `u32`는 너비를 고정합니다. 그 행과 컴파일러가 낸 결과는 [TypeScript에서](https://typeshade.dev/ko/guide/language/from-typescript/) 페이지에 있습니다.

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

**`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_2d<E> | texture_2d_array<E>``texture_cube<E> | texture_cube_array<E>``texture_3d<E>``texture_1d<E>``texture_multisampled_2d<E>``| texture_depth_2d | texture_depth_2d_array | texture_depth_cube | texture_depth_cube_array | texture_depth_multisampled_2d``texture_storage_2d<F, A> | texture_storage_2d_array<F, A>`
- `level` 선택 사항 `number`

## 반환값

`vec2u``vec3u``u32`

## 설명

On a cube texture it is the size of one face.

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

## 대상별 출력

**WGSL**

`textureDimensions(a)`

**GLSL ES 3.00**

`uvec2(textureSize(a, 0))`

## 예제

- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/ko/guide/examples/cube-array-gather/)
- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/ko/guide/examples/cube-env/)
- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/ko/guide/examples/msaa-resolve/)
- [`gallery/shadow-compare/shadow-compare.shade.ts`](https://typeshade.dev/ko/guide/examples/shadow-compare/)
- [`gallery/storage-texture/storage-texture.shade.ts`](https://typeshade.dev/ko/guide/examples/storage-texture/)
- [`gallery/textured-quad/textured-quad.shade.ts`](https://typeshade.dev/ko/guide/examples/textured-quad/)

## 함께 보기

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