warp.texture_sample#
- warp.texture_sample( ) Any#
Kernel
Sample the 1D texture at the given U coordinate.
Experimental
The texture API is experimental and subject to change. See
warp.Texture.- Parameters:
tex – The 1D texture to sample.
u – U coordinate. With
normalized_coords=True, texeliat a mip level of widthlevel_widthis centered at(i + 0.5) / level_width. Withnormalized_coords=False, texeliof a single-level texture is centered ati + 0.5on both backends. For a mipmapped texture on the CPU backend, coordinates remain in base-level texel space and the center is(i + 0.5) * base_width / level_width. CUDA mipmapped textures require normalized coordinates. Coordinates and filtering footprints beyond the texture are handled by its address mode.dtype – The return type, which selects how many channels are read:
float(1 channel),warp.vec2f(2), orwarp.vec4f(4). Use the type matching the texture’snum_channels. The CPU backend normalizes unsigned integer data to[0, 1]and signed integer data to[-1, 1]. The CUDA backend does the same for 8- and 16-bit integer formats but does not promote 32-bit ones, so anint32oruint32texture yields neither a normalized nor a numerically converted value there; use an 8- or 16-bit or a floating-point format instead. Floating-point texture data is returned asfloat32channel values without normalization.lod – Mipmap level-of-detail as a float. When omitted or negative, mip level 0 is sampled. Nonnegative values are clamped to the texture’s available mip-level range. Fractional values blend between neighbouring mip levels when
mip_filter_modeiswarp.TextureFilterMode.LINEAR; the coordinate is evaluated independently at each level used in the blend. Ignored for textures created with a single mip level.
- Returns:
The sampled value of the specified
dtype.
The filtering mode (
warp.TextureFilterMode) and the addressing of out-of-range coordinates (warp.TextureAddressMode) are those set when the texture was created; seewarp.Texture. On CUDA,WRAPandMIRRORare treated asCLAMPwhennormalized_coords=False(the CPU sampler honors them).Example
@wp.kernel def sample(t1: wp.Texture1D, t2: wp.Texture2D, t3: wp.Texture3D, out: wp.array[wp.float32]): out[0] = wp.texture_sample(t1, 1.0, dtype=float) # halfway between texels 0 and 1 out[1] = wp.texture_sample(t2, wp.vec2(1.5, 0.5), dtype=float) # texel (col 1, row 0) out[2] = wp.texture_sample(t3, wp.vec3(1.5, 0.5, 0.5), dtype=float) # texel (col 1, row 0, slice 0) data_1d = np.array([0.0, 10.0, 20.0, 30.0], dtype=np.float32) tex_1d = wp.Texture1D(data_1d, filter_mode=wp.TextureFilterMode.LINEAR, normalized_coords=False) data_2d = np.array([[0.0, 1.0], [2.0, 3.0]], dtype=np.float32) tex_2d = wp.Texture2D(data_2d, filter_mode=wp.TextureFilterMode.CLOSEST, normalized_coords=False) data_3d = np.arange(8, dtype=np.float32).reshape(2, 2, 2) tex_3d = wp.Texture3D(data_3d, filter_mode=wp.TextureFilterMode.CLOSEST, normalized_coords=False) out = wp.zeros(3, dtype=wp.float32) wp.launch(sample, dim=1, inputs=[tex_1d, tex_2d, tex_3d], outputs=[out]) r = out.numpy() print(round(float(r[0]), 1), round(float(r[1]), 1), round(float(r[2]), 1))
5.0 1.0 1.0
- warp.texture_sample( ) Any
Kernel
Sample the 2D texture at the given UV coordinates.
Experimental
The texture API is experimental and subject to change. See
warp.Texture.- Parameters:
tex – The 2D texture to sample.
uv – UV coordinates as a
warp.vec2f. Withnormalized_coords=True, texel(i, j)at a mip level of size(level_width, level_height)is centered at((i + 0.5) / level_width, (j + 0.5) / level_height). Withnormalized_coords=False, texel(i, j)of a single-level texture is centered at(i + 0.5, j + 0.5)on both backends. For a mipmapped texture on the CPU backend, coordinates remain in base-level texel space and the center is((i + 0.5) * base_width / level_width, (j + 0.5) * base_height / level_height). CUDA mipmapped textures require normalized coordinates. Coordinates and filtering footprints beyond the texture are handled by its per-axis address modes.dtype – The return type, which selects how many channels are read:
float(1 channel),warp.vec2f(2), orwarp.vec4f(4). Use the type matching the texture’snum_channels. The CPU backend normalizes unsigned integer data to[0, 1]and signed integer data to[-1, 1]. The CUDA backend does the same for 8- and 16-bit integer formats but does not promote 32-bit ones, so anint32oruint32texture yields neither a normalized nor a numerically converted value there; use an 8- or 16-bit or a floating-point format instead. Floating-point texture data is returned asfloat32channel values without normalization.lod – Mipmap level-of-detail as a float. When omitted or negative, mip level 0 is sampled. Nonnegative values are clamped to the texture’s available mip-level range. Fractional values blend between neighbouring mip levels when
mip_filter_modeiswarp.TextureFilterMode.LINEAR; the coordinates are evaluated independently at each level used in the blend. Ignored for textures created with a single mip level.
- Returns:
The sampled value of the specified
dtype.
The filtering mode (
warp.TextureFilterMode) and the addressing of out-of-range coordinates (warp.TextureAddressMode) are those set when the texture was created; seewarp.Texture. On CUDA,WRAPandMIRRORare treated asCLAMPwhennormalized_coords=False(the CPU sampler honors them).
- warp.texture_sample( ) Any
Kernel
Sample the 2D texture at the given UV coordinates.
Experimental
The texture API is experimental and subject to change. See
warp.Texture.- Parameters:
tex – The 2D texture to sample.
u – U coordinate. At a mip level of width
level_width, texel columniis centered at(i + 0.5) / level_widthwhennormalized_coords=True. With unnormalized coordinates, its center isi + 0.5in a single-level texture on both backends; for a mipmapped texture on the CPU backend, its center is(i + 0.5) * base_width / level_width.v – V coordinate. At a mip level of height
level_height, texel rowjis centered at(j + 0.5) / level_heightwhennormalized_coords=True. With unnormalized coordinates, its center isj + 0.5in a single-level texture on both backends; for a mipmapped texture on the CPU backend, its center is(j + 0.5) * base_height / level_height. CUDA mipmapped textures require normalized coordinates. Coordinates and filtering footprints beyond the texture are handled by its per-axis address modes.dtype – The return type, which selects how many channels are read:
float(1 channel),warp.vec2f(2), orwarp.vec4f(4). Use the type matching the texture’snum_channels. The CPU backend normalizes unsigned integer data to[0, 1]and signed integer data to[-1, 1]. The CUDA backend does the same for 8- and 16-bit integer formats but does not promote 32-bit ones, so anint32oruint32texture yields neither a normalized nor a numerically converted value there; use an 8- or 16-bit or a floating-point format instead. Floating-point texture data is returned asfloat32channel values without normalization.lod – Mipmap level-of-detail as a float. When omitted or negative, mip level 0 is sampled. Nonnegative values are clamped to the texture’s available mip-level range. Fractional values blend between neighbouring mip levels when
mip_filter_modeiswarp.TextureFilterMode.LINEAR; the coordinates are evaluated independently at each level used in the blend. Ignored for textures created with a single mip level.
- Returns:
The sampled value of the specified
dtype.
The filtering mode (
warp.TextureFilterMode) and the addressing of out-of-range coordinates (warp.TextureAddressMode) are those set when the texture was created; seewarp.Texture. On CUDA,WRAPandMIRRORare treated asCLAMPwhennormalized_coords=False(the CPU sampler honors them).
- warp.texture_sample( ) Any
Kernel
Sample the 3D texture at the given UVW coordinates.
Experimental
The texture API is experimental and subject to change. See
warp.Texture.- Parameters:
tex – The 3D texture to sample.
uvw – UVW coordinates as a
warp.vec3f. Withnormalized_coords=True, texel(i, j, k)at a mip level of size(level_width, level_height, level_depth)is centered at((i + 0.5) / level_width, (j + 0.5) / level_height, (k + 0.5) / level_depth). Withnormalized_coords=False, texel(i, j, k)of a single-level texture is centered at(i + 0.5, j + 0.5, k + 0.5)on both backends. For a mipmapped texture on the CPU backend, coordinates remain in base-level texel space and the center is((i + 0.5) * base_width / level_width, (j + 0.5) * base_height / level_height, (k + 0.5) * base_depth / level_depth). CUDA mipmapped textures require normalized coordinates. Coordinates and filtering footprints beyond the texture are handled by its per-axis address modes.dtype – The return type, which selects how many channels are read:
float(1 channel),warp.vec2f(2), orwarp.vec4f(4). Use the type matching the texture’snum_channels. The CPU backend normalizes unsigned integer data to[0, 1]and signed integer data to[-1, 1]. The CUDA backend does the same for 8- and 16-bit integer formats but does not promote 32-bit ones, so anint32oruint32texture yields neither a normalized nor a numerically converted value there; use an 8- or 16-bit or a floating-point format instead. Floating-point texture data is returned asfloat32channel values without normalization.lod – Mipmap level-of-detail as a float. When omitted or negative, mip level 0 is sampled. Nonnegative values are clamped to the texture’s available mip-level range. Fractional values blend between neighbouring mip levels when
mip_filter_modeiswarp.TextureFilterMode.LINEAR; the coordinates are evaluated independently at each level used in the blend. Ignored for textures created with a single mip level.
- Returns:
The sampled value of the specified
dtype.
The filtering mode (
warp.TextureFilterMode) and the addressing of out-of-range coordinates (warp.TextureAddressMode) are those set when the texture was created; seewarp.Texture. On CUDA,WRAPandMIRRORare treated asCLAMPwhennormalized_coords=False(the CPU sampler honors them).
- warp.texture_sample( ) Any
Kernel
Sample the 3D texture at the given UVW coordinates.
Experimental
The texture API is experimental and subject to change. See
warp.Texture.- Parameters:
tex – The 3D texture to sample.
u – U coordinate. At a mip level of width
level_width, texel columniis centered at(i + 0.5) / level_widthwhennormalized_coords=True. With unnormalized coordinates, its center isi + 0.5in a single-level texture on both backends; for a mipmapped texture on the CPU backend, its center is(i + 0.5) * base_width / level_width.v – V coordinate. At a mip level of height
level_height, texel rowjis centered at(j + 0.5) / level_heightwhennormalized_coords=True. With unnormalized coordinates, its center isj + 0.5in a single-level texture on both backends; for a mipmapped texture on the CPU backend, its center is(j + 0.5) * base_height / level_height.w – W coordinate. At a mip level of depth
level_depth, texel depth indexkis centered at(k + 0.5) / level_depthwhennormalized_coords=True. With unnormalized coordinates, its center isk + 0.5in a single-level texture on both backends; for a mipmapped texture on the CPU backend, its center is(k + 0.5) * base_depth / level_depth. CUDA mipmapped textures require normalized coordinates. Coordinates and filtering footprints beyond the texture are handled by its per-axis address modes.dtype – The return type, which selects how many channels are read:
float(1 channel),warp.vec2f(2), orwarp.vec4f(4). Use the type matching the texture’snum_channels. The CPU backend normalizes unsigned integer data to[0, 1]and signed integer data to[-1, 1]. The CUDA backend does the same for 8- and 16-bit integer formats but does not promote 32-bit ones, so anint32oruint32texture yields neither a normalized nor a numerically converted value there; use an 8- or 16-bit or a floating-point format instead. Floating-point texture data is returned asfloat32channel values without normalization.lod – Mipmap level-of-detail as a float. When omitted or negative, mip level 0 is sampled. Nonnegative values are clamped to the texture’s available mip-level range. Fractional values blend between neighbouring mip levels when
mip_filter_modeiswarp.TextureFilterMode.LINEAR; the coordinates are evaluated independently at each level used in the blend. Ignored for textures created with a single mip level.
- Returns:
The sampled value of the specified
dtype.
The filtering mode (
warp.TextureFilterMode) and the addressing of out-of-range coordinates (warp.TextureAddressMode) are those set when the texture was created; seewarp.Texture. On CUDA,WRAPandMIRRORare treated asCLAMPwhennormalized_coords=False(the CPU sampler honors them).