A game about forced loneliness, made by TACStudios
1# Sample Texture 2D Array node
2
3The 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](Sampler-State-Node.md) to define a specific Sampler State. The node's **Index** input port specifies which index of a Texture 2D Array to sample.
4
5For more information about Texture 2D Arrays, see [Texture Arrays](https://docs.unity3d.com/Manual/class-Texture2DArray.html) in the Unity User manual.
6
7[!include[nodes-sample-errors](./snippets/sample-nodes/nodes-sample-errors.md)]
8
9
10
11## Create Node menu category
12
13The Sample Texture 2D Array node is under the **Input** > **Texture** category in the Create Node menu.
14
15## Compatibility
16
17The Sample Texture 3D [!include[nodes-compatibility-all](./snippets/nodes-compatibility-all.md)]
18
19[!include[nodes-sample-fragment-lod](./snippets/sample-nodes/nodes-sample-fragment-lod.md)]
20
21## Inputs
22
23The Sample Texture 3D [!include[nodes-inputs](./snippets/nodes-inputs.md)]
24
25| **Name** | **Type** | **Binding** | **Description** |
26|--|--|--|--|
27| **Texture Array** | Texture 2D Array | None | The Texture 2D Array asset to sample. |
28| **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. |
29| **UV** | Vector 2 | None | UV coordinates to use to sample the Texture. |
30| **Sampler** | Sampler State | Default Sampler State | The Sampler State and settings to use to sample the texture. |
31| **LOD** | Float | LOD | **NOTE**: The **LOD** Input port only displays if **Mip Sampling Mode** is **LOD**. For more information, refer to [Additional node settings](#additional-node-settings). The specific mip to use when sampling the Texture. |
32| **UV** | Vector 2 | UV | The UV coordinates to use to sample the texture. |
33| **Sampler** | Sampler State | Default Sampler State | The Sampler State and settings to use to sample the texture.|
34| **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](#additional-node-settings). |
35| **Bias** | Float | Bias | **NOTE**: The **Bias** Input port only displays if **Mip Sampling Mode** is **Bias**. For more information, refer to [Additional node settings](#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. |
36| **DDX** | Float | DDY | **NOTE**: The **DDX** Input port only displays if **Mip Sampling Mode** is **Gradient**. For more information, refer to [Additional node settings](#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](https://docs.unity3d.com/Documentation/Manual/texture-mipmaps-introduction.html) in the Unity User Manual. |
37| **DDY** | Float | DDY | **NOTE** The **DDY** Input port only displays if **Mip Sampling Mode** is **Gradient**. For more information, refer to [Additional node settings](#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](https://docs.unity3d.com/Documentation/Manual/texture-mipmaps-introduction.html)> in the Unity User Manual. |
38
39
40## Additional node settings
41
42The Sample Texture 3D [!include[nodes-additional-settings](./snippets/nodes-additional-settings.md)]
43
44[!include[nodes-sample-mip-bias-sample-mode-table](./snippets/sample-nodes/nodes-sample-mip-bias-sample-mode-table.md)]
45
46## Outputs
47
48The Sample Texture 3D [!include[nodes-outputs](./snippets/nodes-outputs.md)]
49
50[!include[nodes-sample-rgba-output-table](./snippets/sample-nodes/nodes-sample-rgba-output-table.md)]
51
52## Example graph usage
53
54In 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.
55
56
57
58
59
60
61## Generated code example
62
63[!include[nodes-generated-code](./snippets/nodes-generated-code.md)]:
64
65```
66float4 _SampleTexture2DArray_RGBA = SAMPLE_TEXTURE2D_ARRAY(Texture, Sampler, UV, Index);
67float _SampleTexture2DArray_R = _SampleTexture2DArray_RGBA.r;
68float _SampleTexture2DArray_G = _SampleTexture2DArray_RGBA.g;
69float _SampleTexture2DArray_B = _SampleTexture2DArray_RGBA.b;
70float _SampleTexture2DArray_A = _SampleTexture2DArray_RGBA.a;
71```
72
73## Related nodes
74
75[!include[nodes-related](./snippets/nodes-related.md)] Sample Texture 3D node:
76
77- [Sample Texture 2D node](Sample-Texture-2D-Node.md)
78- [Sample Texture 3D node](Sample-Texture-3D-Node.md)
79- [Sampler State node](Sampler-State-Node.md)