---
title: "textureGather: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "샘플링 좌표 주변의 텍셀에서 한 채널씩 읽어 벡터로 돌려줍니다. 값들을 하나로 섞지 않습니다. 주변 샘플을 각각 다루는 사용자 정의 영상 필터를 만들 때 사용합니다. 모델은 기본 밉의 내부 영역을 읽습니다."
url: https://typeshade.dev/ko/reference/functions/textureGather/
language: ko
---

# `textureGather`

함수

샘플링 좌표 주변의 텍셀에서 한 채널씩 읽어 벡터로 돌려줍니다. 값들을 하나로 섞지 않습니다.

## 예제 비교

출력 성분은 격자의 왼쪽 위, 오른쪽 위, 오른쪽 아래, 왼쪽 아래 값에 대응합니다.

**모델의 전제**`channel = 0; uv = vec2(0.5, 0.5); level = 0`

**예제 1`textureGather(0, tex, smp, uv)`**

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

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

**결과**

`vec4(0.75, 1, 0.25, 0)`

**예제 2`textureGather(0, tex, smp, uv)`**

`1` `0` `0` `1`

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

**결과**

`vec4(1, 0, 1, 0)`

**예제 3`textureGather(0, tex, smp, uv)`**

`0.5` `0.5` `0.5` `0.5`

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

**결과**

`vec4(0.5, 0.5, 0.5, 0.5)`

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

## 활용

주변 샘플을 각각 다루는 사용자 정의 영상 필터를 만들 때 사용합니다.

## 입력 범위와 주의사항

모델은 기본 밉의 내부 영역을 읽습니다. 컬러 텍스처는 채널 선택자를 리터럴로 지정해야 합니다. 이 컴파일러의 대상 조합에서는 WebGPU에서만 지원됩니다.

셰이더의 입력 규칙과 정밀도는 [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의 컴파일러가 쓴 영어 원문입니다.

Reads one channel from the four texels a linear filter would blend at the coordinate on mip level 0, through the sampler `smp`, and returns them as a `vec4` in the order (umin,vmax), (umax,vmax), (umax,vmin), (umin,vmin), in any stage.

## 구문

```ts
declare function textureGather<E extends TextureElem = f32>(
  component: number,
  tex: texture_2d<E>,
  smp: sampler,
  uv: vec2,
): Vec4OfElem<E>
declare function textureGather<E extends TextureElem = f32>(
  component: number,
  tex: texture_2d_array<E>,
  smp: sampler,
  uv: vec2,
  layer: number,
): Vec4OfElem<E>
declare function textureGather<E extends TextureElem = f32>(
  component: number,
  tex: texture_cube<E>,
  smp: sampler,
  dir: vec3,
): Vec4OfElem<E>
declare function textureGather<E extends TextureElem = f32>(
  component: number,
  tex: texture_cube_array<E>,
  smp: sampler,
  dir: vec3,
  layer: number,
): Vec4OfElem<E>
declare function textureGather(tex: texture_depth_2d, smp: sampler, uv: vec2): vec4
declare function textureGather(tex: texture_depth_2d_array, smp: sampler, uv: vec2, layer: number): vec4
declare function textureGather(tex: texture_depth_cube, smp: sampler, dir: vec3): vec4
declare function textureGather(tex: texture_depth_cube_array, smp: sampler, dir: vec3, layer: number): vec4
```

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

## 매개변수

- `component` 선택 사항 `number`
- `tex` `texture_2d<E>``texture_2d_array<E>``texture_cube<E>``texture_cube_array<E>``texture_depth_2d``texture_depth_2d_array``texture_depth_cube``texture_depth_cube_array`
- `smp` `sampler`
- `uv` 선택 사항 `vec2`
- `dir` 선택 사항 `vec3`
- `layer` 선택 사항 `number`

## 반환값

`Vec4OfElem<E>``vec4`

## 설명

On a colour texture the first argument is the channel, a whole number from 0 to 3 written in the call; a depth texture has one channel and takes none; an array texture takes the layer after the coordinate. Compiles to `textureGather` on WGSL; 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.

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

## 대상별 출력

**WGSL**

`textureGather(a, b, c, d)`

**GLSL ES 3.00**

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

## 예제

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

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
- [내장 함수 표](https://typeshade.dev/ko/guide/language/builtins/#textures)
