docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Sample Texture 2D Array node

    The Sample Texture 2D Array node samples a Texture 2D Array asset and returns a Vector 4 color value. You can specify the UV coordinates for a texture sample and use a Sampler State node to define a specific Sampler State. The node's Index input port specifies which index of a Texture 2D Array to sample.

    For more information about Texture 2D Arrays, see Texture Arrays in the Unity User manual.

    Note

    If you experience texture sampling errors for this node in a graph with Custom Function Nodes or Sub Graphs, upgrade to Shader Graph version 10.3 or later.

    An image that displays the Graph window with a Sample Texture 2D Array node.

    Create Node menu category

    The Sample Texture 2D Array node is under the Input > Texture category in the Create Node menu.

    Compatibility

    The Sample Texture 3D node is supported on the following render pipelines:

    Built-In Render Pipeline Universal Render Pipeline (URP) High Definition Render Pipeline (HDRP)
    Yes Yes Yes

    With its default settings, this node can only connect to a Block node in the Fragment Context of a Shader Graph. To sample a Texture for the Vertex Context of a Shader Graph, set the Mip Sampling Mode to LOD.

    Inputs

    The Sample Texture 3D node has the following input ports:

    Name Type Binding Description
    Texture Array Texture 2D Array None The Texture 2D Array asset to sample.
    Index Float None The index of the specific Texture in the Texture array to sample. The index value is the Texture's location in the Texture array. The index values in an array always start at 0. An array with four textures would have locations 0, 1, 2, and 3.
    UV Vector 2 None UV coordinates to use to sample the Texture.
    Sampler Sampler State Default Sampler State The Sampler State and settings to use to sample the texture.
    LOD Float LOD NOTE: The LOD Input port only displays if Mip Sampling Mode is LOD. For more information, refer to Additional node settings. The specific mip to use when sampling the Texture.
    UV Vector 2 UV The UV coordinates to use to sample the texture.
    Sampler Sampler State Default Sampler State The Sampler State and settings to use to sample the texture.
    LOD Float LOD The specific mip to use when sampling the Texture. NOTE The LOD Input port only displays if Mip Sampling Mode is LOD. For more information, refer to Additional node settings.
    Bias Float Bias NOTE: The Bias Input port only displays if Mip Sampling Mode is Bias. For more information, refer to Additional node settings. If Use Global Mip Bias is enabled, Unity adds this Bias amount to the Global Mip Bias for a texture's mip calculation. If Global Mip Bias is disabled, Unity uses this Bias amount instead of the Global Mip Bias.
    DDX Float DDY NOTE: The DDX Input port only displays if Mip Sampling Mode is Gradient. For more information, refer to Additional node settings. The specific DDX value to use to calculate the texture's mip when sampling. For more information on DDX values for mipmaps, refer to Mipmaps introduction in the Unity User Manual.
    DDY Float DDY NOTE The DDY Input port only displays if Mip Sampling Mode is Gradient. For more information, refer to Additional node settings. The specific DDY value to use to calculate the texture's mip when sampling. For more information on DDY values for mipmaps, refer to Mipmaps introduction> in the Unity User Manual.

    Additional node settings

    The Sample Texture 3D node has some additional settings that you can access from the Graph Inspector:

    Name Type Option Description
    Use Global Mip Bias Toggle N/A Enable Use Global Mip Bias to use the render pipeline's Global Mip Bias. This bias adjusts the percentage of texture information taken from a specific mip when sampling. For more information on mip bias, refer to Mipmaps introduction in the Unity User Manual.
    N/A N/A Enabled Shader Graph uses the render pipeline's Global Mip Bias to adjust the texture information taken when sampling.
    N/A N/A Disabled Shader Graph doesn't use the render pipeline's Global Mip Bias to adjust texture information when sampling.
    Mip Sampling Mode Dropdown N/A Choose the sampling mode to use to calculate the mip level of the texture.
    N/A N/A Standard The render pipeline calculates and automatically selects the mip for the texture.
    N/A N/A LOD The render pipeline lets you set an explicit mip for the texture on the node. The texture will always use this mip, regardless of the DDX or DDY calculations between pixels. Set the Mip Sampling Mode to LOD to connect the node to a Block node in the Vertex Context. For more information on Block nodes and Contexts, refer to Master Stack.
    N/A N/A Gradient The render pipeline lets you set the DDX and DDY values to use for its mip calculation, instead of using the values calculated from the texture's UV coordinates. For more information on DDX and DDY values, refer to Mipmaps introduction in the User Manual.
    N/A N/A Bias The render pipeline lets you set a bias to adjust the calculated mip for a texture up or down. Negative values bias the mip to a higher resolution. Positive values bias the mip to a lower resolution. The render pipeline can add this value to the value of the Global Mip Bias, or use this value instead of its Global Mip Bias. For more information on mip bias, refer to Mipmaps introduction in the User Manual.

    Outputs

    The Sample Texture 3D node has the following output ports:

    Name Type Description
    RGBA Vector 4 The full RGBA Vector 4 color value of the texture sample.
    R Float The Red channel or X component of the texture sample.
    G Float The Green channel or Y component of the texture sample.
    B Float The Blue channel or Z component of the texture sample.
    A Float The Alpha channel or W component of the texture sample.

    Example graph usage

    In the following example, the Sample Texture 2D Array node samples a Texture array that has 4 different cloth normal maps. Change the number given to the Index port as an input, and the Sample Texture 2D Array node can sample a specific normal map from the array. The Index value changes the output the node sends to the Normal Unpack node, and the Normal (Tangent Space) Block node in the Master Stack.

    An image of the Graph window, that displays a Sample Texture 2D Array node. The node has a Sampler State node attached as an input and sends its RGBA output to the Normal Unpack node. The Normal Unpack node's Out output port connects to the Normal (Tangent Space) Block node in the Master Stack. The Index is set to 2, which makes the sphere in the Main Preview window render with a leather-like Texture.

    An image of the Graph window, that displays a Sample Texture 2D Array node. The node has a Sampler State node attached as an input and sends its RGBA output to the Normal Unpack node. The Normal Unpack node's Out output port connects to the Normal (Tangent Space) Block node in the Master Stack. The Index is set to 0, which makes the sphere in the Main Preview window render with a ridged fabric Texture.

    Generated code example

    The following code represents this node in Unity's shader code:

    float4 _SampleTexture2DArray_RGBA = SAMPLE_TEXTURE2D_ARRAY(Texture, Sampler, UV, Index);
    float _SampleTexture2DArray_R = _SampleTexture2DArray_RGBA.r;
    float _SampleTexture2DArray_G = _SampleTexture2DArray_RGBA.g;
    float _SampleTexture2DArray_B = _SampleTexture2DArray_RGBA.b;
    float _SampleTexture2DArray_A = _SampleTexture2DArray_RGBA.a;
    

    Related nodes

    The following nodes are related or similar to the Sample Texture 3D node:

    • Sample Texture 2D node
    • Sample Texture 3D node
    • Sampler State node

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Create Node menu category
    • Compatibility
    • Inputs
    • Additional node settings
    • Outputs
    • Example graph usage
    • Generated code example
    • Related nodes
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)