---
title: "resource(): TypeShade 셰이더 API의 레이아웃 분류 함수 참조 문서"
description: "resource, TypeShade API의 레이아웃 분류에 속하는 함수입니다. 구조체가 아닌 바인딩 리소스를 선언합니다. 텍스처나 샘플러가 여기에 해당합니다."
url: https://typeshade.dev/ko/api/resource/
language: ko
---

# `resource()`

함수, 레이아웃 분류

구조체가 아닌 바인딩 리소스를 선언합니다. 텍스처나 샘플러가 여기에 해당합니다.

`import { resource } from 'typeshade/core/ir'`

설명은 커밋 af54ddad5의 검토된 컴파일러 문서를 번역한 것입니다. 시그니처와 예제 코드는 원문을 따르며, 필요한 경우 설명에 편집상 수정이 반영됩니다.

## 구문

```ts
function resource<T extends ShaderType>(
  name: string,
  type: T,
  at: { group: number; binding: number; space?: AddressSpace },
): Resource<T>
```

## 매개변수

**`name` `string`**

생성되는 바인딩 이름입니다. 호스트가 바인딩할 때도 이 이름을 씁니다.

**`type` `T extends ShaderType`**

리소스의 타입입니다. 예: `texture2dfT`, `texture2dArrayfT`, `samplerT`.

**`at` `{ group: number; binding: number; space?: AddressSpace }`**

`group`과 `binding` 슬롯, 그리고 선택 사항인 주소 공간(`space`)입니다.

## 반환값

`Resource<T>`

[`Resource`](https://typeshade.dev/ko/api/resource-interface/) 핸들입니다. `.binding`과 `.node`를 가집니다.

## 설명

바인딩 선언과 접근 노드를 이 호출 하나에서 얻습니다.

`.node`는 넘긴 타입의 구체적인 키를 유지한다: `Node<'texture_2d<f32>'>`, `Node<'sampler'>`, `Node<'texture_2d_array<u32>'>`. 이 덕분에 텍스처 호출은 작성하는 줄에서 타입 검사를 받습니다. [`textureSample`](https://typeshade.dev/ko/api/texturesample/)은 샘플링할 2D 텍스처와 샘플러를 이 순서로 받으므로, 둘을 바꿔 쓰면 tsc 오류가 납니다. 필터링이 의미를 갖지 않는 자리에서는 정수 텍스처가 거부되며, 배열 텍스처는 레이어 인자를 반드시 요구합니다.

`.binding`은 `module({ bindings })`에 넣거나 `uses`에 핸들을 넘길 때 씁니다. 주소 공간의 기본값은 `'uniform'`이며, 이는 텍스처와 샘플러의 관례입니다.

## 예제

### 예제

```ts
import { resource, textureSample, texture2dfT, samplerT } from 'typeshade/core/ir'

const tex = resource('tex', texture2dfT, { group: 0, binding: 1 })
const smp = resource('tex_sampler', samplerT, { group: 0, binding: 2 })
const c = textureSample(tex.node, smp.node, uv)
```

## 함께 보기

- [`textureSample`](https://typeshade.dev/ko/api/texturesample/)
- [`Resource`](https://typeshade.dev/ko/api/resource-interface/)
- [`textureLoad`](https://typeshade.dev/ko/api/textureload/)
- [`storageBuffer`](https://typeshade.dev/ko/api/storagebuffer/)
- [`array`](https://typeshade.dev/ko/api/array/)

## 소스

[`src/core/sot.ts`, 855행](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/sot.ts#L855), 커밋 af54ddad5 기준
