---
title: "textureLoad / texelFetch: 셰이더 함수 사용법, 계산 예제와 입력 범위·주의점"
description: "정수 좌표에 저장된 텍셀 하나를 읽습니다. 샘플러로 주변 값을 보간하지 않습니다. 영상 처리 커널이나 조회 테이블에서 정확한 값을 읽거나, 멀티샘플의 개별 값을 확인할 때 사용합니다. 예제는 기본 밉의 유효한 텍셀을 읽습니다."
url: https://typeshade.dev/ko/reference/functions/textureLoad/
language: ko
---

# `textureLoad`

함수

정수 좌표에 저장된 텍셀 하나를 읽습니다. 샘플러로 주변 값을 보간하지 않습니다.

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

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

- GLSL: `texelFetch`
- GLSL: `imageLoad`

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

## 예제 비교

정수 좌표가 가리키는 칸의 값이 그대로 나옵니다. 이웃 텍셀의 값은 섞이지 않습니다.

**모델의 전제**`texture_2d<f32>; level = 0`

**예제 1`textureLoad(tex, vec2i(0, 0), 0).r`**

`0.75` `1` `0` `0.25`

텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.

**결과**

`0`

**예제 2`textureLoad(tex, vec2i(1, 0), 0).r`**

`0.75` `1` `0` `0.25`

텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.

**결과**

`0.25`

**예제 3`textureLoad(tex, vec2i(1, 1), 0).r`**

`0.75` `1` `0` `0.25`

텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.

**결과**

`1`

예제는 설명용 계산 모델이며 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/)
- [`textureSampleLevel`](https://typeshade.dev/ko/reference/functions/textureSampleLevel/)
- [`textureSampleBias`](https://typeshade.dev/ko/reference/functions/textureSampleBias/)
- [`textureSampleGrad`](https://typeshade.dev/ko/reference/functions/textureSampleGrad/)
- [`textureGather`](https://typeshade.dev/ko/reference/functions/textureGather/)

**WGSL**

`textureLoad(a, b, c)`

**GLSL ES 3.00**

`texelFetch(a, b, int(c))`

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

Reads one texel at the integer `coord` and mip `level` without filtering, by a `vec2i` on a `texture_2d`, a `vec3i` on a `texture_3d` and one integer on a `texture_1d`; a cube texture has no texel fetch on either target.

## 구문

```ts
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_2d<E>,
  coord: TexelCoord2,
  level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_2d_array<E>,
  coord: TexelCoord2,
  layer: number,
  level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_3d<E>,
  coord: TexelCoord3,
  level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_1d<E>,
  coord: number,
  level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
  tex: texture_multisampled_2d<E>,
  coord: TexelCoord2,
  sampleIndex: number,
): Vec4OfElem<E>
declare function textureLoad(tex: texture_depth_multisampled_2d, coord: TexelCoord2, sampleIndex: number): f32
declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>(
  tex: texture_storage_2d<F, A>,
  coord: TexelCoord2,
): StorageTexel<F>
declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>(
  tex: texture_storage_2d_array<F, A>,
  coord: TexelCoord2,
  layer: number,
): StorageTexel<F>
```

매개변수나 반환 위치에 쓰인 `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`

**`Vec4OfElem`**

`type Vec4OfElem<E> = typeof u32Tag extends keyof E ? vec4u : typeof i32Tag extends keyof E ? vec4i : vec4`

**`TexelCoord2`**

`type TexelCoord2 = vec2i | vec2u`

**`TexelCoord3`**

`type TexelCoord3 = vec3i | vec3u`

**`StorageFormat`**

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

**`StorageTexel`**

``type StorageTexel<F extends StorageFormat> = F extends `${string}uint` ? vec4u : F extends `${string}sint` ? vec4i : vec4``

## 매개변수

- `tex` `texture_2d<E>``texture_2d_array<E>``texture_3d<E>``texture_1d<E>``texture_multisampled_2d<E>``texture_depth_multisampled_2d``texture_storage_2d<F, A>``texture_storage_2d_array<F, A>`
- `coord` `TexelCoord2``TexelCoord3``number`
- `level` 선택 사항 `number`
- `layer` 선택 사항 `number`
- `sampleIndex` 선택 사항 `number`

## 반환값

`Vec4OfElem<E>``f32``StorageTexel<F>`

## 설명

On a `texture_2d_array` the layer comes before the level, and on a `texture_multisampled_2d` or `texture_depth_multisampled_2d` the third argument is the sample index instead of a level. Compiles to `textureLoad` on WGSL and `texelFetch` on GLSL, where the lowering of a multisampled texture is not supported yet ([Rule 10.5](https://typeshade.dev/ko/reference/rules/10-5/)), so a module loading one emits WGSL alone.

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

## 대상별 출력

**WGSL**

`textureLoad(a, b, c)`

**GLSL ES 3.00**

`texelFetch(a, b, int(c))`

작성자는 어느 텍스처에든 같은 호출을 쓰고, 컴파일러가 타깃마다 필요한 형태를 씁니다. GLSL ES 3.00의 `texelFetch`는 부호 있는 좌표만 받고, 배열 레이어를 좌표 안에 넣으며, 1d 텍스처와 멀티샘플 텍스처가 없다.

텍스처 작성하는 코드 WGSL GLSL ES 3.00

```wgsl
texture_2d<f32>
```

```ts
textureLoad(t, vec2i(1, 2), 0)
```

```wgsl
textureLoad(t, vec2<i32>(1, 2), 0u)
```

```glsl
texelFetch(t, ivec2(1, 2), int(0u))
```

```wgsl
texture_2d<f32>
```

```ts
textureLoad(t, vec2u(1, 2), 0)
```

```wgsl
textureLoad(t, vec2<u32>(1u, 2u), 0u)
```

```glsl
texelFetch(t, ivec2(uvec2(1u, 2u)), int(0u))
```

```wgsl
texture_3d<f32>
```

```ts
textureLoad(t, vec3i(1, 2, 3), 0)
```

```wgsl
textureLoad(t, vec3<i32>(1, 2, 3), 0u)
```

```glsl
texelFetch(t, ivec3(1, 2, 3), int(0u))
```

```wgsl
texture_3d<f32>
```

```ts
textureLoad(t, vec3u(1, 2, 3), 0)
```

```wgsl
textureLoad(t, vec3<u32>(1u, 2u, 3u), 0u)
```

```glsl
texelFetch(t, ivec3(uvec3(1u, 2u, 3u)), int(0u))
```

```wgsl
texture_2d_array<f32>
```

```ts
textureLoad(t, vec2i(1, 2), 3, 0)
```

```wgsl
textureLoad(t, vec2<i32>(1, 2), 3, 0u)
```

```glsl
texelFetch(t, ivec3(ivec2(1, 2), int(3)), int(0u))
```

```wgsl
texture_2d_array<f32>
```

```ts
textureLoad(t, vec2u(1, 2), 3, 0)
```

```wgsl
textureLoad(t, vec2<u32>(1u, 2u), 3, 0u)
```

```glsl
texelFetch(t, ivec3(ivec2(uvec2(1u, 2u)), int(3)), int(0u))
```

```wgsl
texture_1d<f32>
```

```ts
textureLoad(t, 1, 0)
```

```wgsl
textureLoad(t, 1, 0u)
```

이 대상에는 형태가 없습니다.

```wgsl
texture_multisampled_2d<f32>
```

```ts
textureLoad(t, vec2i(1, 2), 0)
```

```wgsl
textureLoad(t, vec2<i32>(1, 2), 0u)
```

이 대상에는 형태가 없습니다.

```wgsl
texture_depth_multisampled_2d
```

```ts
textureLoad(t, vec2i(1, 2), 0)
```

```wgsl
textureLoad(t, vec2<i32>(1, 2), 0u)
```

이 대상에는 형태가 없습니다.

## 예제

- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/ko/guide/examples/cube-env/)
- [`gallery/feedback-trail/feedback-trail.shade.ts`](https://typeshade.dev/ko/guide/examples/feedback-trail/)
- [`gallery/kernel-image-invert/kernel-image-invert.shade.ts`](https://typeshade.dev/ko/guide/examples/kernel-image-invert/)
- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/ko/guide/examples/msaa-resolve/)
- [`gallery/storage-texture/storage-texture.shade.ts`](https://typeshade.dev/ko/guide/examples/storage-texture/)

## 함께 보기

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