textureSampleGrad
함수
호출자가 제공한 좌표 변화량으로 텍스처의 세부 수준을 선택합니다.
다른 언어의 관련 이름
관련 연산은 인수, 지원 범위와 의미가 다를 수 있습니다. 다른 언어의 이름을 TypeShade 별칭으로 사용할 수는 없습니다. 지원하는 형태와 제한은 대상 언어에 따라 다릅니다.
- GLSL:
textureGrad
예제 비교
같은 좌표에서도 좌표 변화량이 크면 더 넓은 영역을 대표하는 거친 밉이 선택됩니다.
모델의 전제uv = vec2(0.25, 0.25); filter = linear; mip = nearest; levels = [2 × 2, 1 × 1]
예제 1ddx = vec2(0.5, 0); ddy = vec2(0, 0.5)
0.75100.25 - 결과
0
예제 2ddx = vec2(1, 0); ddy = vec2(0, 1)
0.5 - 결과
0.5
예제 3ddx = vec2(0.25, 0); ddy = vec2(0, 0.25)
0.75100.25 - 결과
0
예제는 설명용 계산 모델이며 GPU를 실행하지 않습니다. 정확한 호출 형식은 아래 컴파일러 참고 자료에서 설명합니다. 소수 결과는 표시할 때 반올림했습니다. 각 예제는 명시한 전제를 따릅니다. 실제 셰이더의 결과는 대상 언어의 정밀도와 실행 규칙에 따릅니다.
활용
좌표가 반복되거나 분기 안에서 바뀌더라도 원래의 매끄러운 좌표 변화량으로 필터링해야 할 때 사용합니다.
입력 범위와 주의사항
모델은 정사각형 텍스처에 등방성 변화량을 적용하고 가장 가까운 밉을 고릅니다. 실제 필터링은 샘플러와 읽는 범위의 비등방성에도 영향을 받습니다.
셰이더의 입력 규칙과 정밀도는 WGSL과 GLSL ES 3.00에서 규정합니다.
관련 함수
- WGSL
textureSampleGrad(a, b, c, d, e)- GLSL ES 3.00
textureGrad(a, c, d, e)
시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 af54ddad5의 컴파일러가 쓴 영어 원문입니다.
Samples a float texture through the sampler smp with the explicit gradients ddx and ddy, which have the width of the coordinate, in any stage.
구문
declare function textureSampleGrad( tex: texture_2d<f32>, smp: sampler, uv: vec2, ddx: vec2, ddy: vec2,): vec4declare function textureSampleGrad( tex: texture_2d_array<f32>, smp: sampler, uv: vec2, layer: number, ddx: vec2, ddy: vec2,): vec4declare function textureSampleGrad( tex: texture_cube<f32>, smp: sampler, dir: vec3, ddx: vec3, ddy: vec3,): vec4declare function textureSampleGrad( tex: texture_3d<f32>, smp: sampler, coord: vec3, ddx: vec3, ddy: vec3,): vec4declare function textureSampleGrad( tex: texture_cube_array<f32>, smp: sampler, dir: vec3, layer: number, ddx: vec3, ddy: vec3,): vec4매개변수나 반환 위치에 쓰인 number는 스칼라가 들어갈 자리입니다. 앰비언트 파일은 GPU 스칼라를 브랜드가 붙은 number로 선언하고 그 브랜드는 선택이라서, 리터럴도 브랜드가 붙은 스칼라도 이 자리에 들어갑니다.
type f32 = number & { readonly [f32Tag]?: true }
타입으로 쓴 number는 쓰이는 곳을 보고 추론하며, f32, i32, u32는 너비를 고정합니다. 그 행과 컴파일러가 낸 결과는 TypeScript에서 페이지에 있습니다.
매개변수
-
textexture_2d<f32>texture_2d_array<f32>texture_cube<f32>texture_3d<f32>texture_cube_array<f32> -
smpsampler -
uv선택 사항vec2 -
dir선택 사항vec3 -
coord선택 사항vec3 -
ddxvec2vec3 -
layer선택 사항number -
ddyvec2vec3
반환값
설명
On a texture_2d_array the layer comes before the gradients. Compiles to textureSampleGrad on WGSL and textureGrad on GLSL.
대상별 출력
- WGSL
-
textureSampleGrad(a, b, c, d, e) - GLSL ES 3.00
-
textureGrad(a, c, d, e)