warp.texture_sample#

warp.texture_sample(
tex: Texture1D,
u: float32,
dtype: Any,
lod: float32 = -1.0,
) → Any#
  • Kernel: true
  • Python: false
  • Differentiable: true

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, texel i at a mip level of width level_width is centered at (i + 0.5) / level_width. With normalized_coords=False, texel i of a single-level texture is centered at i + 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), or warp.vec4f (4). Use the type matching the texture’s num_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_mode is warp.TextureFilterMode.LINEAR; the coordinate is evaluated independently at each level used in the blend. Ignored for textures created with a single mip level. The lod adjoint is nonzero only for mipmapped textures with mip_filter_mode=TextureFilterMode.LINEAR and 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 to float32 without 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 as float32 channel 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; see warp.Texture. Currently, CUDA textures with unnormalized coordinates support only CLAMP and BORDER address modes. Use normalized coordinates with WRAP or MIRROR.

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.CLOSEST filtering 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(
tex: Texture2D,
uv: vec2f,
dtype: Any,
lod: float32 = -1.0,
) → Any
  • Kernel: true
  • Python: false
  • Differentiable: true

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. With normalized_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). With normalized_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), or warp.vec4f (4). Use the type matching the texture’s num_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_mode is warp.TextureFilterMode.LINEAR; the coordinates are evaluated independently at each level used in the blend. Ignored for textures created with a single mip level. The lod adjoint is nonzero only for mipmapped textures with mip_filter_mode=TextureFilterMode.LINEAR and 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 to float32 without 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 as float32 channel 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; see warp.Texture. Currently, CUDA textures with unnormalized coordinates support only CLAMP and BORDER address modes. Use normalized coordinates with WRAP or MIRROR.

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.CLOSEST filtering 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(
tex: Texture2D,
u: float32,
v: float32,
dtype: Any,
lod: float32 = -1.0,
) → Any
  • Kernel: true
  • Python: false
  • Differentiable: true

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 column i is centered at (i + 0.5) / level_width when normalized_coords=True. With unnormalized coordinates, its center is i + 0.5 in a single-level texture.

  • v – V coordinate. At a mip level of height level_height, texel row j is centered at (j + 0.5) / level_height when normalized_coords=True. With unnormalized coordinates, its center is j + 0.5 in 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), or warp.vec4f (4). Use the type matching the texture’s num_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_mode is warp.TextureFilterMode.LINEAR; the coordinates are evaluated independently at each level used in the blend. Ignored for textures created with a single mip level. The lod adjoint is nonzero only for mipmapped textures with mip_filter_mode=TextureFilterMode.LINEAR and 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 to float32 without 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 as float32 channel 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; see warp.Texture. Currently, CUDA textures with unnormalized coordinates support only CLAMP and BORDER address modes. Use normalized coordinates with WRAP or MIRROR.

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.CLOSEST filtering 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(
tex: Texture3D,
uvw: vec3f,
dtype: Any,
lod: float32 = -1.0,
) → Any
  • Kernel: true
  • Python: false
  • Differentiable: true

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. With normalized_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). With normalized_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), or warp.vec4f (4). Use the type matching the texture’s num_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_mode is warp.TextureFilterMode.LINEAR; the coordinates are evaluated independently at each level used in the blend. Ignored for textures created with a single mip level. The lod adjoint is nonzero only for mipmapped textures with mip_filter_mode=TextureFilterMode.LINEAR and 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 to float32 without 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 as float32 channel 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; see warp.Texture. Currently, CUDA textures with unnormalized coordinates support only CLAMP and BORDER address modes. Use normalized coordinates with WRAP or MIRROR.

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.CLOSEST filtering 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(
tex: Texture3D,
u: float32,
v: float32,
w: float32,
dtype: Any,
lod: float32 = -1.0,
) → Any
  • Kernel: true
  • Python: false
  • Differentiable: true

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 column i is centered at (i + 0.5) / level_width when normalized_coords=True. With unnormalized coordinates, its center is i + 0.5 in a single-level texture.

  • v – V coordinate. At a mip level of height level_height, texel row j is centered at (j + 0.5) / level_height when normalized_coords=True. With unnormalized coordinates, its center is j + 0.5 in a single-level texture.

  • w – W coordinate. At a mip level of depth level_depth, texel depth index k is centered at (k + 0.5) / level_depth when normalized_coords=True. With unnormalized coordinates, its center is k + 0.5 in 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), or warp.vec4f (4). Use the type matching the texture’s num_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_mode is warp.TextureFilterMode.LINEAR; the coordinates are evaluated independently at each level used in the blend. Ignored for textures created with a single mip level. The lod adjoint is nonzero only for mipmapped textures with mip_filter_mode=TextureFilterMode.LINEAR and 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 to float32 without 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 as float32 channel 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; see warp.Texture. Currently, CUDA textures with unnormalized coordinates support only CLAMP and BORDER address modes. Use normalized coordinates with WRAP or MIRROR.

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.CLOSEST filtering the sampled value is piecewise constant in the coordinates, so coordinate gradients are zero. Gradients are not propagated to the texture data itself.