You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
4.9 KiB
74 lines
4.9 KiB
2 years ago
|
# 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](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-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
|
||
|
|
||
|
[!include[nodes-compatibility-all](./snippets/nodes-compatibility-all.md)] <!-- ALL PIPELINES INCLUDE -->
|
||
|
|
||
|
[!include[nodes-fragment-only](./snippets/nodes-fragment-only.md)] <!-- FRAGMENT ONLY INCLUDE -->
|
||
|
|
||
|
## Inputs
|
||
|
|
||
|
[!include[nodes-inputs](./snippets/nodes-inputs.md)] <!-- MULTIPLE INPUT PORTS INCLUDE -->
|
||
|
|
||
|
| **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
|
||
|
|
||
|
[!include[nodes-outputs](./snippets/nodes-outputs.md)] <!-- MULTIPLE OUTPUT PORTS INCLUDE -->
|
||
|
|
||
|
| **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
|
||
|
|
||
|
[!include[nodes-related](./snippets/nodes-related.md)]
|
||
|
|
||
|
- [Sample Texture 2D node](Sample-Texture-2D-Node.md)
|
||
|
- [Sample Texture 2D LOD node](Sample-Texture-2D-LOD-Node.md)
|
||
|
- [Sampler State node](Sampler-State-Node.md)
|
||
|
- [Texture 2D Asset node](Texture-2D-Asset-Node.md)
|