warp.texture\_sample ==================== .. function:: warp._src.lang.texture_sample(tex: Texture1D, u: float32, dtype: Any, lod: float32) -> Any .. hlist:: :columns: 8 * Kernel Sample the 1D texture at the given U coordinate. .. admonition:: Experimental The texture API is experimental and subject to change. See :class:`warp.Texture`. :param tex: The 1D texture to sample. :param 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. :param dtype: The return type, which selects how many channels are read: ``float`` (1 channel), :class:`warp.vec2f` (2), or :class:`warp.vec4f` (4). Use the type matching the texture's :attr:`~warp.Texture.num_channels`. :param 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 :attr:`warp.TextureFilterMode.LINEAR`; the coordinate is evaluated independently at each level used in the blend. The ``lod`` argument is ignored for textures created with a single mip level. :returns: The sampled value of the specified ``dtype``. The CPU backend normalizes unsigned integer data to ``[0, 1]`` and signed integer data to ``[-1, 1]``. On CUDA devices, normalized integer sampling is supported only for 8- and 16-bit formats; use an 8- or 16-bit integer or floating-point texture. Floating-point texture data is returned as ``float32`` channel values without normalization. The filtering mode (:class:`warp.TextureFilterMode`) and the addressing of out-of-range coordinates (:class:`warp.TextureAddressMode`) are those set when the texture was created; see :class:`warp.Texture`. Currently, CUDA textures with unnormalized coordinates support only ``CLAMP`` and ``BORDER`` address modes. Use normalized coordinates with ``WRAP`` or ``MIRROR``. .. rubric:: Example .. testcode:: @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)) .. testoutput:: 5.0 1.0 1.0 .. function:: warp._src.lang.texture_sample(tex: Texture2D, uv: vec2f, dtype: Any, lod: float32) -> Any :noindex: .. hlist:: :columns: 8 * Kernel Sample the 2D texture at the given UV coordinates. .. admonition:: Experimental The texture API is experimental and subject to change. See :class:`warp.Texture`. :param tex: The 2D texture to sample. :param uv: UV coordinates as a :class:`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. :param dtype: The return type, which selects how many channels are read: ``float`` (1 channel), :class:`warp.vec2f` (2), or :class:`warp.vec4f` (4). Use the type matching the texture's :attr:`~warp.Texture.num_channels`. :param 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 :attr:`warp.TextureFilterMode.LINEAR`; the coordinates are evaluated independently at each level used in the blend. The ``lod`` argument is ignored for textures created with a single mip level. :returns: The sampled value of the specified ``dtype``. The CPU backend normalizes unsigned integer data to ``[0, 1]`` and signed integer data to ``[-1, 1]``. On CUDA devices, normalized integer sampling is supported only for 8- and 16-bit formats; use an 8- or 16-bit integer or floating-point texture. Floating-point texture data is returned as ``float32`` channel values without normalization. The filtering mode (:class:`warp.TextureFilterMode`) and the addressing of out-of-range coordinates (:class:`warp.TextureAddressMode`) are those set when the texture was created; see :class:`warp.Texture`. Currently, CUDA textures with unnormalized coordinates support only ``CLAMP`` and ``BORDER`` address modes. Use normalized coordinates with ``WRAP`` or ``MIRROR``. .. function:: warp._src.lang.texture_sample(tex: Texture2D, u: float32, v: float32, dtype: Any, lod: float32) -> Any :noindex: .. hlist:: :columns: 8 * Kernel Sample the 2D texture at the given UV coordinates. .. admonition:: Experimental The texture API is experimental and subject to change. See :class:`warp.Texture`. :param tex: The 2D texture to sample. :param 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. :param 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. :param dtype: The return type, which selects how many channels are read: ``float`` (1 channel), :class:`warp.vec2f` (2), or :class:`warp.vec4f` (4). Use the type matching the texture's :attr:`~warp.Texture.num_channels`. :param 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 :attr:`warp.TextureFilterMode.LINEAR`; the coordinates are evaluated independently at each level used in the blend. The ``lod`` argument is ignored for textures created with a single mip level. :returns: The sampled value of the specified ``dtype``. The CPU backend normalizes unsigned integer data to ``[0, 1]`` and signed integer data to ``[-1, 1]``. On CUDA devices, normalized integer sampling is supported only for 8- and 16-bit formats; use an 8- or 16-bit integer or floating-point texture. Floating-point texture data is returned as ``float32`` channel values without normalization. The filtering mode (:class:`warp.TextureFilterMode`) and the addressing of out-of-range coordinates (:class:`warp.TextureAddressMode`) are those set when the texture was created; see :class:`warp.Texture`. Currently, CUDA textures with unnormalized coordinates support only ``CLAMP`` and ``BORDER`` address modes. Use normalized coordinates with ``WRAP`` or ``MIRROR``. .. function:: warp._src.lang.texture_sample(tex: Texture3D, uvw: vec3f, dtype: Any, lod: float32) -> Any :noindex: .. hlist:: :columns: 8 * Kernel Sample the 3D texture at the given UVW coordinates. .. admonition:: Experimental The texture API is experimental and subject to change. See :class:`warp.Texture`. :param tex: The 3D texture to sample. :param uvw: UVW coordinates as a :class:`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. :param dtype: The return type, which selects how many channels are read: ``float`` (1 channel), :class:`warp.vec2f` (2), or :class:`warp.vec4f` (4). Use the type matching the texture's :attr:`~warp.Texture.num_channels`. :param 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 :attr:`warp.TextureFilterMode.LINEAR`; the coordinates are evaluated independently at each level used in the blend. The ``lod`` argument is ignored for textures created with a single mip level. :returns: The sampled value of the specified ``dtype``. The CPU backend normalizes unsigned integer data to ``[0, 1]`` and signed integer data to ``[-1, 1]``. On CUDA devices, normalized integer sampling is supported only for 8- and 16-bit formats; use an 8- or 16-bit integer or floating-point texture. Floating-point texture data is returned as ``float32`` channel values without normalization. The filtering mode (:class:`warp.TextureFilterMode`) and the addressing of out-of-range coordinates (:class:`warp.TextureAddressMode`) are those set when the texture was created; see :class:`warp.Texture`. Currently, CUDA textures with unnormalized coordinates support only ``CLAMP`` and ``BORDER`` address modes. Use normalized coordinates with ``WRAP`` or ``MIRROR``. .. function:: warp._src.lang.texture_sample(tex: Texture3D, u: float32, v: float32, w: float32, dtype: Any, lod: float32) -> Any :noindex: .. hlist:: :columns: 8 * Kernel Sample the 3D texture at the given UVW coordinates. .. admonition:: Experimental The texture API is experimental and subject to change. See :class:`warp.Texture`. :param tex: The 3D texture to sample. :param 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. :param 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. :param 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. :param dtype: The return type, which selects how many channels are read: ``float`` (1 channel), :class:`warp.vec2f` (2), or :class:`warp.vec4f` (4). Use the type matching the texture's :attr:`~warp.Texture.num_channels`. :param 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 :attr:`warp.TextureFilterMode.LINEAR`; the coordinates are evaluated independently at each level used in the blend. The ``lod`` argument is ignored for textures created with a single mip level. :returns: The sampled value of the specified ``dtype``. The CPU backend normalizes unsigned integer data to ``[0, 1]`` and signed integer data to ``[-1, 1]``. On CUDA devices, normalized integer sampling is supported only for 8- and 16-bit formats; use an 8- or 16-bit integer or floating-point texture. Floating-point texture data is returned as ``float32`` channel values without normalization. The filtering mode (:class:`warp.TextureFilterMode`) and the addressing of out-of-range coordinates (:class:`warp.TextureAddressMode`) are those set when the texture was created; see :class:`warp.Texture`. Currently, CUDA textures with unnormalized coordinates support only ``CLAMP`` and ``BORDER`` address modes. Use normalized coordinates with ``WRAP`` or ``MIRROR``.