---
title: "textureStore / imageStore: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "정수 좌표가 가리키는 텍셀 하나의 값을 바꿉니다. 컴퓨트 연산의 결과를 이미지에 기록할 때 사용합니다. 쓸 수 있는 스토리지 텍스처와 형식에 맞는 값이 필요합니다. 모델은 독립된 쓰기를 보여줍니다. 겹치는 쓰기는 경쟁이 없도록 별도로 설계해야 합니다."
url: https://typeshade.dev/ko/reference/functions/textureStore/
language: ko
---

# `textureStore`

함수

정수 좌표가 가리키는 텍셀 하나의 값을 바꿉니다.

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

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

- GLSL: `imageStore`

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

## 예제 비교

선택한 텍셀만 입력값으로 바뀝니다. 호출은 값을 반환하지 않으며, 화면에는 저장 전후의 텍셀이 표시됩니다.

**모델의 전제**`texture_storage_2d<"r32float", "write">; value = vec4(0.5, 0, 0, 1)`

**예제 1`textureStore(tex, vec2i(0, 0), value)`**

`0.75` `1` `0.5` `0.25`

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

**연산 전 저장값**

`0`

**반환값**

`void`

**연산 후 저장값**

`0.5`

**예제 2`textureStore(tex, vec2i(1, 0), value)`**

`0.75` `1` `0` `0.5`

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

**연산 전 저장값**

`0.25`

**반환값**

`void`

**연산 후 저장값**

`0.5`

**예제 3`textureStore(tex, vec2i(1, 1), value)`**

`0.75` `0.5` `0` `0.25`

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

**연산 전 저장값**

`1`

**반환값**

`void`

**연산 후 저장값**

`0.5`

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

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

Writes one texel to a storage texture at the integer `coord`, on a binding declared `"write"` or `"read_write"`; returns nothing.

## 구문

```ts
declare function textureStore<F extends StorageFormat, A extends 'write' | 'read_write'>(
  tex: texture_storage_2d<F, A>,
  coord: TexelCoord2,
  value: StorageTexel<F>,
): void
declare function textureStore<F extends StorageFormat, A extends 'write' | 'read_write'>(
  tex: texture_storage_2d_array<F, A>,
  coord: TexelCoord2,
  layer: number,
  value: StorageTexel<F>,
): void
```

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

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

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

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

**`TexelCoord2`**

`type TexelCoord2 = vec2i | vec2u`

**`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_storage_2d<F, A>``texture_storage_2d_array<F, A>`
- `coord` `TexelCoord2`
- `value` `StorageTexel<F>`
- `layer` 선택 사항 `number`

## 반환값

`void`

## 설명

The value is the texel the format decides: a `"…uint"` format stores a `vec4u`, a `"…sint"` one a `vec4i`, and every other one a `vec4`. Compiles to `textureStore` on WGSL; in a render entry its GLSL lowering is not supported yet ([Rule 10.5](https://typeshade.dev/ko/reference/rules/10-5/)), so a module using it emits WGSL alone, and on the CPU tier a store into a `CpuTexture` converts the value as the format decides while a store outside it, or into a texture not in that memory, is dropped ([Rule 11.7](https://typeshade.dev/ko/reference/rules/11-7/)).

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

## 대상별 출력

**WGSL**

`textureStore(a, b, c)`

**GLSL ES 3.00**

`textureStore` is not supported yet on the WebGL2 tier (Rule 10.5)

## 예제

- [`gallery/kernel-image-invert/kernel-image-invert.shade.ts`](https://typeshade.dev/ko/guide/examples/kernel-image-invert/)
- [`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)
