---
title: "array: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점 | TypeShade"
description: "같은 형식의 값을 정해진 개수만큼 묶습니다. 짧은 커널, 조회 테이블, 샘플 집합을 저장할 때 사용합니다. 생성자 원소 수는 고정 길이와 같아야 합니다. 인수가 없는 생성자는 원소 형식의 영으로 채웁니다. 단위행렬이나 임의의 기본값을 넣지 않습니다."
url: https://typeshade.dev/ko/reference/functions/array/
language: ko
---

# `array`

함수

같은 형식의 값을 정해진 개수만큼 묶습니다.

## 예제 비교

나열한 원소가 입력 순서대로 배열에 들어갑니다. 인수 없는 생성자는 각 원소를 영으로 채웁니다.

**예제 1`array(1., 2., 3.)`**

**결과**

`[1, 2, 3]`

**예제 2`array<f32, 3>()`**

**결과**

`[0, 0, 0]`

**예제 3`array(vec2(1., 0.), vec2(0., 1.))`**

**결과**

`[[1, 0], [0, 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)에서 규정합니다.

## 관련 함수

- [`fill`](https://typeshade.dev/ko/reference/functions/fill/)
- [`zip`](https://typeshade.dev/ko/reference/functions/zip/)

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

Builds an `array<T, N>` from exactly N values of type T.

## 구문

```ts
declare function array<V extends readonly unknown[]>(...values: V): array<[(V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never)] extends [never] ? V[number] : (V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never), V['length']>
declare function array<T, N extends number>(...values: readonly T[]): array<T, N>
```

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

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

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

## 매개변수

- `...values` `V``readonly T[]`

## 반환값

`array<[(V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never)] extends [never] ? V[number] : (V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never), V['length']>``array<T, N>`

## 설명

Without type arguments, `array(v1, v2, ..., vN)` reads T and N off the values, as WGSL does; `array<T, N>(v1, ..., vN)` names them, and `array<T, N>()` is the zero value, every element the zero of its type. An array has the methods `map`, `forEach`, `some`, `every` and `reduce`, each a counted loop over its elements that calls the function it is handed with the element, its `i32` index and the array.

## 예제

- [`path/palette/palette.shade.ts`](https://typeshade.dev/ko/guide/examples/palette/)
- [`path/double-array/double-array.shade.ts`](https://typeshade.dev/ko/guide/examples/double-array/)
- [`path/image-blur/image-blur.shade.ts`](https://typeshade.dev/ko/guide/examples/image-blur/)
- [`path/sum-array/sum-array.shade.ts`](https://typeshade.dev/ko/guide/examples/sum-array/)
- [`path/parallel-sum/parallel-sum.shade.ts`](https://typeshade.dev/ko/guide/examples/parallel-sum/)
- [`path/histogram/histogram.shade.ts`](https://typeshade.dev/ko/guide/examples/histogram/)
- [`gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts`](https://typeshade.dev/ko/guide/examples/capsule-corp-namek-class/)
- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/ko/guide/examples/path-tracer/)
- [`gallery/array-length/array-length.shade.ts`](https://typeshade.dev/ko/guide/examples/array-length/)
- [`gallery/array-literal-ramp/array-literal-ramp.shade.ts`](https://typeshade.dev/ko/guide/examples/array-literal-ramp/)
- [`gallery/array-methods/array-methods.shade.ts`](https://typeshade.dev/ko/guide/examples/array-methods/)
- [`gallery/atomic-histogram/atomic-histogram.shade.ts`](https://typeshade.dev/ko/guide/examples/atomic-histogram/)
- [`gallery/bare-position/bare-position.shade.ts`](https://typeshade.dev/ko/guide/examples/bare-position/)
- [`gallery/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/ko/guide/examples/bit-bump/)
- [`gallery/bool-select/bool-select.shade.ts`](https://typeshade.dev/ko/guide/examples/bool-select/)
- [`gallery/clip-planes/clip-planes.shade.ts`](https://typeshade.dev/ko/guide/examples/clip-planes/)
- [`gallery/closures/closures.shade.ts`](https://typeshade.dev/ko/guide/examples/closures/)
- [`gallery/compute-reduction-twin/compute-reduction-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/compute-reduction-twin/)
- [`gallery/compute-sync/compute-sync.shade.ts`](https://typeshade.dev/ko/guide/examples/compute-sync/)
- [`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/default-args/default-args.shade.ts`](https://typeshade.dev/ko/guide/examples/default-args/)
- [`gallery/generic-class/generic-class.shade.ts`](https://typeshade.dev/ko/guide/examples/generic-class/)
- [`gallery/generic-helpers/generic-helpers.shade.ts`](https://typeshade.dev/ko/guide/examples/generic-helpers/)
- [`gallery/gpu-console/gpu-console.shade.ts`](https://typeshade.dev/ko/guide/examples/gpu-console/)
- [`gallery/higher-order/higher-order.shade.ts`](https://typeshade.dev/ko/guide/examples/higher-order/)
- [`gallery/id-pick/id-pick.shade.ts`](https://typeshade.dev/ko/guide/examples/id-pick/)
- [`gallery/integer-math/integer-math.shade.ts`](https://typeshade.dev/ko/guide/examples/integer-math/)
- [`gallery/kernel-array-methods/kernel-array-methods.shade.ts`](https://typeshade.dev/ko/guide/examples/kernel-array-methods/)
- [`gallery/kernel-push/kernel-push.shade.ts`](https://typeshade.dev/ko/guide/examples/kernel-push/)
- [`gallery/kernel-set-unique/kernel-set-unique.shade.ts`](https://typeshade.dev/ko/guide/examples/kernel-set-unique/)
- [`gallery/loop-kernel/loop-kernel.shade.ts`](https://typeshade.dev/ko/guide/examples/loop-kernel/)
- [`gallery/loop-on-cpu/loop-on-cpu.shade.ts`](https://typeshade.dev/ko/guide/examples/loop-on-cpu/)
- [`gallery/loop-reduction/loop-reduction.shade.ts`](https://typeshade.dev/ko/guide/examples/loop-reduction/)
- [`gallery/loop-struct-array/loop-struct-array.shade.ts`](https://typeshade.dev/ko/guide/examples/loop-struct-array/)
- [`gallery/loops-over-data/loops-over-data.shade.ts`](https://typeshade.dev/ko/guide/examples/loops-over-data/)
- [`gallery/mixin-surface/mixin-surface.shade.ts`](https://typeshade.dev/ko/guide/examples/mixin-surface/)
- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/ko/guide/examples/msaa-resolve/)
- [`gallery/null-values/null-values.shade.ts`](https://typeshade.dev/ko/guide/examples/null-values/)
- [`gallery/optional-fields/optional-fields.shade.ts`](https://typeshade.dev/ko/guide/examples/optional-fields/)
- [`gallery/optional-values/optional-values.shade.ts`](https://typeshade.dev/ko/guide/examples/optional-values/)
- [`gallery/orbit-inout/orbit-inout.shade.ts`](https://typeshade.dev/ko/guide/examples/orbit-inout/)
- [`gallery/packed-bytes/packed-bytes.shade.ts`](https://typeshade.dev/ko/guide/examples/packed-bytes/)
- [`gallery/packing-bitcast/packing-bitcast.shade.ts`](https://typeshade.dev/ko/guide/examples/packing-bitcast/)
- [`gallery/palette-const/palette-const.shade.ts`](https://typeshade.dev/ko/guide/examples/palette-const/)
- [`gallery/particle-step/particle-step.shade.ts`](https://typeshade.dev/ko/guide/examples/particle-step/)
- [`gallery/pick-composite/pick-composite.shade.ts`](https://typeshade.dev/ko/guide/examples/pick-composite/)
- [`gallery/ray-class/ray-class.shade.ts`](https://typeshade.dev/ko/guide/examples/ray-class/)
- [`gallery/reference-parameters/reference-parameters.shade.ts`](https://typeshade.dev/ko/guide/examples/reference-parameters/)
- [`gallery/shadow-compare/shadow-compare.shade.ts`](https://typeshade.dev/ko/guide/examples/shadow-compare/)
- [`gallery/shape-inheritance/shape-inheritance.shade.ts`](https://typeshade.dev/ko/guide/examples/shape-inheritance/)
- [`gallery/subgroup-reduce/subgroup-reduce.shade.ts`](https://typeshade.dev/ko/guide/examples/subgroup-reduce/)
- [`gallery/tuple-and-brand/tuple-and-brand.shade.ts`](https://typeshade.dev/ko/guide/examples/tuple-and-brand/)
- [`gallery/uniform-array/uniform-array.shade.ts`](https://typeshade.dev/ko/guide/examples/uniform-array/)
- [`gallery/workgroup-override/workgroup-override.shade.ts`](https://typeshade.dev/ko/guide/examples/workgroup-override/)
- [`gallery/workgroup-reduce/workgroup-reduce.shade.ts`](https://typeshade.dev/ko/guide/examples/workgroup-reduce/)
- [`gallery/workgroup-scratch/workgroup-scratch.shade.ts`](https://typeshade.dev/ko/guide/examples/workgroup-scratch/)
- [`gallery/workgroup-tile-2d/workgroup-tile-2d.shade.ts`](https://typeshade.dev/ko/guide/examples/workgroup-tile-2d/)

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
