warp.texture_sample#
- warp.texture_sample( ) Any#
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.5. Mipmapped textures should use normalized coordinates. Unnormalized coordinates for mipmapped textures are currently accepted only on the CPU backend and may be unsupported in a future release. 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.lod – Mipmap level-of-detail as a float. The default selects mip level 0. Currently, any negative value also selects mip level 0. 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. Thelodadjoint is nonzero only for mipmapped textures withmip_filter_mode=TextureFilterMode.LINEARand an unclamped, nonnegative LOD. At an unclamped integer LOD, the mip-blend derivative may differ on either side. Warp uses the derivative toward increasing LOD values. The LOD gradient is zero when the LOD is clamped.
- Returns:
The sampled value of the specified
dtype. The backends normalize unsigned 8- and 16-bit integer data to[0, 1]and signed 8- and 16-bit integer data to[-1, 1]. Signed and unsigned 32-bit integer data is converted numerically tofloat32without normalization and requires closest filtering within and between mip levels. Integers outside[-2**24, 2**24]may round during conversion. Floating-point texture data is returned asfloat32channel values without normalization.
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. Currently, CUDA textures with unnormalized coordinates support onlyCLAMPandBORDERaddress modes. Use normalized coordinates withWRAPorMIRROR.The backward pass propagates gradients to the sampling coordinates wherever the sample is locally linear. At interpolation-cell and address-mode boundaries the mathematical derivative is not unique, so Warp follows the branch selected by the forward sampler. With
warp.TextureFilterMode.CLOSESTfiltering the sampled value is piecewise constant in the coordinates, so coordinate gradients are zero. Gradients are not propagated to the texture data itself.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
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). Mipmapped textures should use normalized coordinates. Unnormalized coordinates for mipmapped textures are currently accepted only on the CPU backend and may be unsupported in a future release. 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.lod – Mipmap level-of-detail as a float. The default selects mip level 0. Currently, any negative value also selects mip level 0. 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. Thelodadjoint is nonzero only for mipmapped textures withmip_filter_mode=TextureFilterMode.LINEARand an unclamped, nonnegative LOD. At an unclamped integer LOD, the mip-blend derivative may differ on either side. Warp uses the derivative toward increasing LOD values. The LOD gradient is zero when the LOD is clamped.
- Returns:
The sampled value of the specified
dtype. The backends normalize unsigned 8- and 16-bit integer data to[0, 1]and signed 8- and 16-bit integer data to[-1, 1]. Signed and unsigned 32-bit integer data is converted numerically tofloat32without normalization and requires closest filtering within and between mip levels. Integers outside[-2**24, 2**24]may round during conversion. Floating-point texture data is returned asfloat32channel values without normalization.
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. Currently, CUDA textures with unnormalized coordinates support onlyCLAMPandBORDERaddress modes. Use normalized coordinates withWRAPorMIRROR.The backward pass propagates gradients to the sampling coordinates wherever the sample is locally linear. At interpolation-cell and address-mode boundaries the mathematical derivative is not unique, so Warp follows the branch selected by the forward sampler. With
warp.TextureFilterMode.CLOSESTfiltering the sampled value is piecewise constant in the coordinates, so coordinate gradients are zero. Gradients are not propagated to the texture data itself.
- warp.texture_sample( ) Any
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.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. Mipmapped textures should use normalized coordinates. Unnormalized coordinates for mipmapped textures are currently accepted only on the CPU backend and may be unsupported in a future release. 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.lod – Mipmap level-of-detail as a float. The default selects mip level 0. Currently, any negative value also selects mip level 0. 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. Thelodadjoint is nonzero only for mipmapped textures withmip_filter_mode=TextureFilterMode.LINEARand an unclamped, nonnegative LOD. At an unclamped integer LOD, the mip-blend derivative may differ on either side. Warp uses the derivative toward increasing LOD values. The LOD gradient is zero when the LOD is clamped.
- Returns:
The sampled value of the specified
dtype. The backends normalize unsigned 8- and 16-bit integer data to[0, 1]and signed 8- and 16-bit integer data to[-1, 1]. Signed and unsigned 32-bit integer data is converted numerically tofloat32without normalization and requires closest filtering within and between mip levels. Integers outside[-2**24, 2**24]may round during conversion. Floating-point texture data is returned asfloat32channel values without normalization.
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. Currently, CUDA textures with unnormalized coordinates support onlyCLAMPandBORDERaddress modes. Use normalized coordinates withWRAPorMIRROR.The backward pass propagates gradients to the sampling coordinates wherever the sample is locally linear. At interpolation-cell and address-mode boundaries the mathematical derivative is not unique, so Warp follows the branch selected by the forward sampler. With
warp.TextureFilterMode.CLOSESTfiltering the sampled value is piecewise constant in the coordinates, so coordinate gradients are zero. Gradients are not propagated to the texture data itself.
- warp.texture_sample( ) Any
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). Mipmapped textures should use normalized coordinates. Unnormalized coordinates for mipmapped textures are currently accepted only on the CPU backend and may be unsupported in a future release. 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.lod – Mipmap level-of-detail as a float. The default selects mip level 0. Currently, any negative value also selects mip level 0. 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. Thelodadjoint is nonzero only for mipmapped textures withmip_filter_mode=TextureFilterMode.LINEARand an unclamped, nonnegative LOD. At an unclamped integer LOD, the mip-blend derivative may differ on either side. Warp uses the derivative toward increasing LOD values. The LOD gradient is zero when the LOD is clamped.
- Returns:
The sampled value of the specified
dtype. The backends normalize unsigned 8- and 16-bit integer data to[0, 1]and signed 8- and 16-bit integer data to[-1, 1]. Signed and unsigned 32-bit integer data is converted numerically tofloat32without normalization and requires closest filtering within and between mip levels. Integers outside[-2**24, 2**24]may round during conversion. Floating-point texture data is returned asfloat32channel values without normalization.
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. Currently, CUDA textures with unnormalized coordinates support onlyCLAMPandBORDERaddress modes. Use normalized coordinates withWRAPorMIRROR.The backward pass propagates gradients to the sampling coordinates wherever the sample is locally linear. At interpolation-cell and address-mode boundaries the mathematical derivative is not unique, so Warp follows the branch selected by the forward sampler. With
warp.TextureFilterMode.CLOSESTfiltering the sampled value is piecewise constant in the coordinates, so coordinate gradients are zero. Gradients are not propagated to the texture data itself.
- warp.texture_sample( ) Any
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.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.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. Mipmapped textures should use normalized coordinates. Unnormalized coordinates for mipmapped textures are currently accepted only on the CPU backend and may be unsupported in a future release. 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.lod – Mipmap level-of-detail as a float. The default selects mip level 0. Currently, any negative value also selects mip level 0. 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. Thelodadjoint is nonzero only for mipmapped textures withmip_filter_mode=TextureFilterMode.LINEARand an unclamped, nonnegative LOD. At an unclamped integer LOD, the mip-blend derivative may differ on either side. Warp uses the derivative toward increasing LOD values. The LOD gradient is zero when the LOD is clamped.
- Returns:
The sampled value of the specified
dtype. The backends normalize unsigned 8- and 16-bit integer data to[0, 1]and signed 8- and 16-bit integer data to[-1, 1]. Signed and unsigned 32-bit integer data is converted numerically tofloat32without normalization and requires closest filtering within and between mip levels. Integers outside[-2**24, 2**24]may round during conversion. Floating-point texture data is returned asfloat32channel values without normalization.
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. Currently, CUDA textures with unnormalized coordinates support onlyCLAMPandBORDERaddress modes. Use normalized coordinates withWRAPorMIRROR.The backward pass propagates gradients to the sampling coordinates wherever the sample is locally linear. At interpolation-cell and address-mode boundaries the mathematical derivative is not unique, so Warp follows the branch selected by the forward sampler. With
warp.TextureFilterMode.CLOSESTfiltering the sampled value is piecewise constant in the coordinates, so coordinate gradients are zero. Gradients are not propagated to the texture data itself.