---
title: "vec3: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점 | TypeShade"
description: "vec3는 성분 3개를 벡터로 묶습니다. 스칼라 하나를 주면 모든 성분에 같은 값을 넣습니다. 좌표, 방향, 색상 또는 같은 형식의 독립된 값들을 표현할 때 사용합니다. 생성자는 방향을 정규화하지 않습니다."
url: https://typeshade.dev/ko/reference/functions/vec3/
language: ko
---

# `vec3`

함수

`vec3`는 성분 3개를 벡터로 묶습니다. 스칼라 하나를 주면 모든 성분에 같은 값을 넣습니다.

## 예제 비교

스칼라 입력은 모든 성분에 반복됩니다. 성분별 입력은 나열한 순서대로 들어갑니다. 숫자 벡터는 영으로, 불리언 벡터는 거짓으로 채울 수 있습니다.

**예제 1`vec3(1.)`**

`1` `1` `1`

이 예제의 성분

**결과**

`[1,1,1]`

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

`1` `2` `3`

이 예제의 성분

**결과**

`[1,2,3]`

**예제 3`vec3(0.)`**

`0` `0` `0`

이 예제의 성분

**결과**

`[0,0,0]`

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

## 활용

좌표, 방향, 색상 또는 같은 형식의 독립된 값들을 표현할 때 사용합니다.

## 입력 범위와 주의사항

생성자는 방향을 정규화하지 않습니다. 정수·불리언·부동소수점 벡터의 성분 형식은 서로 다릅니다. 이 컴파일러는 `f64` 벡터를 소프트웨어로 구현합니다.

셰이더의 입력 규칙과 정밀도는 [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)에서 규정합니다.

## 관련 함수

- [`length`](https://typeshade.dev/ko/reference/functions/length/)
- [`normalize`](https://typeshade.dev/ko/reference/functions/normalize/)
- [`dot`](https://typeshade.dev/ko/reference/functions/dot/)

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

Builds a `vec3` from three scalars, a `vec2` and a scalar, or broadcasts a single scalar to all three components.

## 구문

```ts
declare function vec3<T = f32>(): VecFor3<T>
declare function vec3<T = f32>(x: number, y: number, z: number): VecFor3<T>
declare function vec3<T = f32>(v: vec2, z: number): VecFor3<T>
declare function vec3<T = f32>(x: number, v: vec2): VecFor3<T>
declare function vec3<T = f32>(scalar: number): VecFor3<T>
declare function vec3<T = f32>(v: vec3): VecFor3<T>
declare function vec3<T>(x: bool, y: bool, z: bool): VecFor3<T>
declare function vec3<T>(scalar: bool): VecFor3<T>
declare function vec3<T = f32>(v: vec3i): VecFor3<T>
declare function vec3<T = f32>(v: vec3u): VecFor3<T>
declare function vec3<T = f32>(v: vec3b): VecFor3<T>
declare function vec3(v: vec3f64): vec3
```

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

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

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

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

**`VecFor3`**

`type VecFor3<T> = VecElemOf<T, vec3u, vec3i, vec3f64, vec3b, vec3>`

## 매개변수

- `x` 선택 사항 `number``bool`
- `v` 선택 사항 `vec2``vec3``vec3i``vec3u``vec3b``vec3f64`
- `scalar` 선택 사항 `number``bool`
- `y` 선택 사항 `number``bool`
- `z` 선택 사항 `number``bool`

## 반환값

`VecFor3<T>``vec3`

## 예제

- [`path/palette/palette.shade.ts`](https://typeshade.dev/ko/guide/examples/palette/)
- [`path/ray-tracer/ray-tracer.shade.ts`](https://typeshade.dev/ko/guide/examples/ray-tracer/)
- [`gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts`](https://typeshade.dev/ko/guide/examples/capsule-corp-namek-class/)
- [`gallery/domain-warp-twin/domain-warp-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/domain-warp-twin/)
- [`gallery/hillshade-twin/hillshade-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/hillshade-twin/)
- [`gallery/julia-twin/julia-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/julia-twin/)
- [`gallery/kaleidoscope-twin/kaleidoscope-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/kaleidoscope-twin/)
- [`gallery/mandelbrot-twin/mandelbrot-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/mandelbrot-twin/)
- [`gallery/ocean-twin/ocean-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/ocean-twin/)
- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/ko/guide/examples/path-tracer/)
- [`gallery/plasma-twin/plasma-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/plasma-twin/)
- [`gallery/rt-renderer-class/rt-renderer-class.shade.ts`](https://typeshade.dev/ko/guide/examples/rt-renderer-class/)
- [`gallery/starfield-twin/starfield-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/starfield-twin/)
- [`gallery/tunnel-twin/tunnel-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/tunnel-twin/)
- [`gallery/voronoi-twin/voronoi-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/voronoi-twin/)
- [`gallery/fp64-burning-ship-twin/fp64-burning-ship-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-burning-ship-twin/)
- [`gallery/fp64-cancellation-twin/fp64-cancellation-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-cancellation-twin/)
- [`gallery/fp64-checker-plane-twin/fp64-checker-plane-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-checker-plane-twin/)
- [`gallery/fp64-clock-twin/fp64-clock-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-clock-twin/)
- [`gallery/fp64-julia-twin/fp64-julia-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-julia-twin/)
- [`gallery/fp64-lane-stripes/fp64-lane-stripes.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-lane-stripes/)
- [`gallery/fp64-loran-twin/fp64-loran-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-loran-twin/)
- [`gallery/fp64-mandelbrot-de-twin/fp64-mandelbrot-de-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-mandelbrot-de-twin/)
- [`gallery/fp64-newton-twin/fp64-newton-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-newton-twin/)
- [`gallery/fp64-rtc-twin/fp64-rtc-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-rtc-twin/)
- [`gallery/fp64-sine-sweep-twin/fp64-sine-sweep-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-sine-sweep-twin/)
- [`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/bit-bump/bit-bump.shade.ts`](https://typeshade.dev/ko/guide/examples/bit-bump/)
- [`gallery/bitfield-bands/bitfield-bands.shade.ts`](https://typeshade.dev/ko/guide/examples/bitfield-bands/)
- [`gallery/block-scope/block-scope.shade.ts`](https://typeshade.dev/ko/guide/examples/block-scope/)
- [`gallery/bool-select/bool-select.shade.ts`](https://typeshade.dev/ko/guide/examples/bool-select/)
- [`gallery/class-builder/class-builder.shade.ts`](https://typeshade.dev/ko/guide/examples/class-builder/)
- [`gallery/class-parts/class-parts.shade.ts`](https://typeshade.dev/ko/guide/examples/class-parts/)
- [`gallery/class-syntax/class-syntax.shade.ts`](https://typeshade.dev/ko/guide/examples/class-syntax/)
- [`gallery/closures/closures.shade.ts`](https://typeshade.dev/ko/guide/examples/closures/)
- [`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/cutout/cutout.shade.ts`](https://typeshade.dev/ko/guide/examples/cutout/)
- [`gallery/default-args/default-args.shade.ts`](https://typeshade.dev/ko/guide/examples/default-args/)
- [`gallery/feedback-trail/feedback-trail.shade.ts`](https://typeshade.dev/ko/guide/examples/feedback-trail/)
- [`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/higher-order/higher-order.shade.ts`](https://typeshade.dev/ko/guide/examples/higher-order/)
- [`gallery/imported-noise/imported-noise.shade.ts`](https://typeshade.dev/ko/guide/examples/imported-noise/)
- [`gallery/inferred-returns/inferred-returns.shade.ts`](https://typeshade.dev/ko/guide/examples/inferred-returns/)
- [`gallery/mixin-surface/mixin-surface.shade.ts`](https://typeshade.dev/ko/guide/examples/mixin-surface/)
- [`gallery/normal-matrix/normal-matrix.shade.ts`](https://typeshade.dev/ko/guide/examples/normal-matrix/)
- [`gallery/null-values/null-values.shade.ts`](https://typeshade.dev/ko/guide/examples/null-values/)
- [`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/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/rng-method/rng-method.shade.ts`](https://typeshade.dev/ko/guide/examples/rng-method/)
- [`gallery/separable-blur/separable-blur.shade.ts`](https://typeshade.dev/ko/guide/examples/separable-blur/)
- [`gallery/shape-inheritance/shape-inheritance.shade.ts`](https://typeshade.dev/ko/guide/examples/shape-inheritance/)
- [`gallery/textured-quad/textured-quad.shade.ts`](https://typeshade.dev/ko/guide/examples/textured-quad/)

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
- [`typeshade/core/ir`의 `vec3()`](https://typeshade.dev/ko/api/vec3/)
