textureSampleCompareLevel
이 페이지에서

textureSampleCompareLevel

함수

비교 샘플러로 기준 깊이와 저장된 깊이를 비교합니다. 필터링은 비교 결과를 섞어 가시성을 구합니다.

예제 비교

기준 깊이가 높아질수록 이하 비교를 통과하는 텍셀이 줄어듭니다. 기본 밉에서 얻은 비교 결과를 선형 필터링합니다.

모델의 전제depth = [[0.75, 1], [0, 0.25]]; compare = less-equal; filter = linear; level = 0; uv = vec2(0.5, 0.5)

예제 1textureSampleCompareLevel(tex, smp, uv, 0.2)
truetruefalsetrue
텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.
결과
0.75
예제 2textureSampleCompareLevel(tex, smp, uv, 0.5)
truetruefalsefalse
텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.
결과
0.5
예제 3textureSampleCompareLevel(tex, smp, uv, 0.8)
falsetruefalsefalse
텍셀 격자입니다. 위쪽 행의 세로 텍스처 좌표가 더 큽니다. 값은 한 채널을 나타내며 비교 격자는 통과 여부를 보여줍니다.
결과
0.25

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

활용

그림자를 판정할 때 사용합니다. 표면의 깊이를 광원에서 기록한 가장 가까운 깊이와 비교합니다.

입력 범위와 주의사항

먼저 각 깊이와 기준값을 비교한 뒤 필터링합니다. 평균 깊이와 한 번 비교하면 결과가 달라집니다. 이 호출은 밉 레벨 영을 사용합니다.

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

WGSL
textureSampleCompareLevel(a, b, c, d)
GLSL ES 3.00
textureLod(a, vec3(c, d), 0.0)

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

Compares the reference depth ref against the shadow map at uv through the comparison sampler smp at mip level 0, in any stage; returns an f32, how much of the filter footprint passed.

구문

declare function textureSampleCompareLevel(
tex: texture_depth_2d,
smp: sampler_comparison,
uv: vec2,
ref: number,
): f32
declare function textureSampleCompareLevel(
tex: texture_depth_2d_array,
smp: sampler_comparison,
uv: vec2,
layer: number,
ref: number,
): f32
declare function textureSampleCompareLevel(
tex: texture_depth_cube,
smp: sampler_comparison,
dir: vec3,
ref: number,
): f32
declare function textureSampleCompareLevel(
tex: texture_depth_cube_array,
smp: sampler_comparison,
dir: vec3,
layer: number,
ref: number,
): f32

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

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

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

매개변수

반환값

f32

설명

On a texture_depth_2d_array the layer comes before the reference, and on a texture_depth_cube the coordinate is a vec3 direction. Compiles to textureSampleCompareLevel on WGSL and to textureLod at level zero on a sampler2DShadow on GLSL, where the reference folds into the coordinate.

대상별 출력

WGSL
textureSampleCompareLevel(a, b, c, d)
GLSL ES 3.00
textureLod(a, vec3(c, d), 0.0)

예제

함께 보기

이 페이지 편집 문제 보고