textureLoad
이 페이지에서

textureLoad

함수

정수 좌표에 저장된 텍셀 하나를 읽습니다. 샘플러로 주변 값을 보간하지 않습니다.

다른 언어의 관련 이름

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

  • GLSL: texelFetch
  • GLSL: imageLoad

대상별 출력

예제 비교

정수 좌표가 가리키는 칸의 값이 그대로 나옵니다. 이웃 텍셀의 값은 섞이지 않습니다.

모델의 전제texture_2d<f32>; level = 0

예제 1textureLoad(tex, vec2i(0, 0), 0).r
0.75100.25
텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.
결과
0
예제 2textureLoad(tex, vec2i(1, 0), 0).r
0.75100.25
텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.
결과
0.25
예제 3textureLoad(tex, vec2i(1, 1), 0).r
0.75100.25
텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.
결과
1

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

활용

영상 처리 커널이나 조회 테이블에서 정확한 값을 읽거나, 멀티샘플의 개별 값을 확인할 때 사용합니다.

입력 범위와 주의사항

예제는 기본 밉의 유효한 텍셀을 읽습니다. 멀티샘플 텍스처에서는 밉 레벨 대신 샘플 인덱스를 지정합니다. 좌표는 유효 범위를 벗어나면 안 됩니다.

셰이더의 입력 규칙과 정밀도는 WGSL과 GLSL ES 3.00에서 규정합니다.

WGSL
textureLoad(a, b, c)
GLSL ES 3.00
texelFetch(a, b, int(c))

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

Reads one texel at the integer coord and mip level without filtering, by a vec2i on a texture_2d, a vec3i on a texture_3d and one integer on a texture_1d; a cube texture has no texel fetch on either target.

구문

declare function textureLoad<E extends TextureElem = f32>(
tex: texture_2d<E>,
coord: TexelCoord2,
level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
tex: texture_2d_array<E>,
coord: TexelCoord2,
layer: number,
level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
tex: texture_3d<E>,
coord: TexelCoord3,
level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
tex: texture_1d<E>,
coord: number,
level: number,
): Vec4OfElem<E>
declare function textureLoad<E extends TextureElem = f32>(
tex: texture_multisampled_2d<E>,
coord: TexelCoord2,
sampleIndex: number,
): Vec4OfElem<E>
declare function textureLoad(tex: texture_depth_multisampled_2d, coord: TexelCoord2, sampleIndex: number): f32
declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>(
tex: texture_storage_2d<F, A>,
coord: TexelCoord2,
): StorageTexel<F>
declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>(
tex: texture_storage_2d_array<F, A>,
coord: TexelCoord2,
layer: number,
): StorageTexel<F>

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

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

타입으로 쓴 number는 쓰이는 곳을 보고 추론하며, f32, i32, u32는 너비를 고정합니다. 그 행과 컴파일러가 낸 결과는 TypeScript에서 페이지에 있습니다.

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

TextureElem
type TextureElem = f32 | i32 | u32
Vec4OfElem
type Vec4OfElem<E> = typeof u32Tag extends keyof E ? vec4u : typeof i32Tag extends keyof E ? vec4i : vec4
TexelCoord2
type TexelCoord2 = vec2i | vec2u
TexelCoord3
type TexelCoord3 = vec3i | vec3u
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

매개변수

반환값

Vec4OfElem<E>f32StorageTexel<F>

설명

On a texture_2d_array the layer comes before the level, and on a texture_multisampled_2d or texture_depth_multisampled_2d the third argument is the sample index instead of a level. Compiles to textureLoad on WGSL and texelFetch on GLSL, where the lowering of a multisampled texture is not supported yet (Rule 10.5), so a module loading one emits WGSL alone.

대상별 출력

WGSL
textureLoad(a, b, c)
GLSL ES 3.00
texelFetch(a, b, int(c))

작성자는 어느 텍스처에든 같은 호출을 쓰고, 컴파일러가 타깃마다 필요한 형태를 씁니다. GLSL ES 3.00의 texelFetch는 부호 있는 좌표만 받고, 배열 레이어를 좌표 안에 넣으며, 1d 텍스처와 멀티샘플 텍스처가 없다.

텍스처작성하는 코드WGSLGLSL ES 3.00
texture_2d<f32>
textureLoad(t, vec2i(1, 2), 0)
textureLoad(t, vec2<i32>(1, 2), 0u)
texelFetch(t, ivec2(1, 2), int(0u))
texture_2d<f32>
textureLoad(t, vec2u(1, 2), 0)
textureLoad(t, vec2<u32>(1u, 2u), 0u)
texelFetch(t, ivec2(uvec2(1u, 2u)), int(0u))
texture_3d<f32>
textureLoad(t, vec3i(1, 2, 3), 0)
textureLoad(t, vec3<i32>(1, 2, 3), 0u)
texelFetch(t, ivec3(1, 2, 3), int(0u))
texture_3d<f32>
textureLoad(t, vec3u(1, 2, 3), 0)
textureLoad(t, vec3<u32>(1u, 2u, 3u), 0u)
texelFetch(t, ivec3(uvec3(1u, 2u, 3u)), int(0u))
texture_2d_array<f32>
textureLoad(t, vec2i(1, 2), 3, 0)
textureLoad(t, vec2<i32>(1, 2), 3, 0u)
texelFetch(t, ivec3(ivec2(1, 2), int(3)), int(0u))
texture_2d_array<f32>
textureLoad(t, vec2u(1, 2), 3, 0)
textureLoad(t, vec2<u32>(1u, 2u), 3, 0u)
texelFetch(t, ivec3(ivec2(uvec2(1u, 2u)), int(3)), int(0u))
texture_1d<f32>
textureLoad(t, 1, 0)
textureLoad(t, 1, 0u)

이 대상에는 형태가 없습니다.

texture_multisampled_2d<f32>
textureLoad(t, vec2i(1, 2), 0)
textureLoad(t, vec2<i32>(1, 2), 0u)

이 대상에는 형태가 없습니다.

texture_depth_multisampled_2d
textureLoad(t, vec2i(1, 2), 0)
textureLoad(t, vec2<i32>(1, 2), 0u)

이 대상에는 형태가 없습니다.

예제

함께 보기

이 페이지 편집 문제 보고