Gather Texture 2D node
The Gather Texture 2D node samples the red channel of four neighboring pixels from a sample point. It returns a value of RRRR
, and takes each R
value from a different neighbor. Normal Texture sampling reads all four channels (RGBA) of a Texture.
This node is useful when you want to modify the bilinear interpolation between pixels, such as when you want to create custom blends.
This node uses the Gather HLSL intrinsic function. For platforms where this intrinsic function doesn't exist, Shader Graph uses an appropriate approximation, instead.
Note
When you use the Metal graphics API, the sample
, sample_compare
, gather
, and gather_compare
intrinsics use an integer (int2) offset
argument when sampling or gathering from a 2D Texture. The intrinsics apply this value to Texture coordinates before looking up each pixel. The offset
value must be in the range of -8
to +7
, or the Metal API clamps the offset
value.
The pixels that the Gather Texture 2D samples are always from the top mip level of the Texture, from a 2×2 block of pixels around the sample point. Rather than blending the 2×2 sample, it returns the sampled pixels in counter-clockwise order. It starts with the sample to the lower left of the query location:
Create Node menu category
The Gather Texture 2D node is under the Input > Texture category in the Create Node menu.
Compatibility
The Gather Texture 2D node is supported on the following render pipelines:
Built-In Render Pipeline | Universal Render Pipeline (URP) | High Definition Render Pipeline (HDRP) |
---|---|---|
Yes | Yes | Yes |
The Gather Texture 2D node can only be connected to a Block node in the Fragment Context. For more information on Block nodes and Contexts, refer to Master Stack.
Inputs
The Gather Texture 2D node has the following input ports:
Name | Type | Binding | Description |
---|---|---|---|
Texture | Texture 2D | None | The Texture to sample. |
UV | Vector 2 | UV | The UV coordinates to use to take the sample. |
Sampler | SamplerState | None | The Sampler State and its corresponding settings to use for the sample. |
Offset | Vector 2 | None | The pixel offset to apply to the sample's UV coordinates. The Offset value is in pixels, not UV space. |
Outputs
The Gather Texture 2D node has the following output ports:
Name | Type | Description |
---|---|---|
RGBA | Vector 4 | The sample value. This is the red channels of the 4 neighboring pixels from the specified sample position on the given Texture. |
R | Float | The first neighboring pixel's red channel. |
G | Float | The second neighboring pixel's red channel. |
B | Float | The third neighboring pixel's red channel. |
A | Float | The fourth neighboring pixel's red channel. |
Example graph usage
In the following example, a Gather Texture 2D node creates a blurred version of a Texture by averaging its 4 samples:
Then, the rest of the Shader Graph uses a Sample Texture 2D node to sample the Texture again, and uses a Lerp node to determine when to use the blurred Texture and when to use the regular Texture:
By changing the value provided to the T port on the Lerp node, you can change whether you want to blur or sharpen the Texture in your Shader Graph:
Related nodes
The following nodes are related or similar to the Gather Texture 2D node: