Skip to content

Commit bf767d7

Browse files
Renamed Texel Size node to Texture Size and added texel size outputs (#6315)
* Renamed the Texel Size node to Texture Size and added texel size output ports Previously, the Texel Size node was actually returning the texture size - so I've renamed the node to reflect that. I also added two new output ports to the node so that in addition to outputing the texture size, it also outputs the texel size. * Changed file name of Texel Size Node to Texture Size Node and made some consistency changes. * Updated the documentation based on Chris's feedback Made Chris's suggested changes to the documentation * Updated node thumbnail and removed an extra period from the documentation * Added the definition of Texel to the documentation Co-authored-by: sarah.welton <[email protected]>
1 parent 4dccee7 commit bf767d7

File tree

7 files changed

+62
-35
lines changed

7 files changed

+62
-35
lines changed

com.unity.shadergraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2626
### Changed
2727
- Changed the title suffix on old nodes and properties rom "Deprecated" to "Legacy".
2828
- Updated searcher package dependency version to 4.9.1
29+
- Renamed the Shader Graph Texel Size node to Texture Size and added two additional output ports that actually output the texel size in addition to the texture size.
2930

3031
### Fixed
3132
- Fixed a usability issue where in some cases searcher would suggest one collapsed category of results that user would have to manually expand anyway

com.unity.shadergraph/Documentation~/Input-Nodes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
|[**Sample Texture 3D**](Sample-Texture-3D-Node.md)| [**Sample Virtual Texture**](Sample-Virtual-Texture-Node.md) |
108108
|![Image](images/SampleTexture3DNodeThumb.png)| ![image](images/SampleVirtualTextureNodeThumb.png) |
109109
|Samples a Texture 3D and returns a color value for use in the shader.| Samples a Virtual Texture and returns color values for use in the shader.|
110-
|[**Sampler State**](Sampler-State-Node.md)|[**Texel Size**](Texel-Size-Node.md)|
111-
|![Image](images/SamplerStateNodeThumb.png)|![Image](images/TexelSizeNodeThumb.png)|
110+
|[**Sampler State**](Sampler-State-Node.md)|[**Texture Size**](Texture-Size-Node.md)|
111+
|![Image](images/SamplerStateNodeThumb.png)|![Image](images/TexelSizeNodeThumb.png) <!-- Add updated image -->|
112112
|Defines a Sampler State for sampling textures.|Returns the Width and Height of the texel size of Texture 2D input.|
113113
|[**Texture 2D Array Asset**](Texture-2D-Array-Asset-Node.md)|[**Texture 2D Asset**](Texture-2D-Asset-Node.md)|
114114
|![Image](images/Texture2DArrayAssetNodeThumb.png)|![Image](images/Texture2DAssetNodeThumb.png)|

com.unity.shadergraph/Documentation~/TableOfContents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@
137137
* [Sample Virtual Texture](Sample-Virtual-Texture-Node)
138138
* [Sampler State](Sampler-State-Node)
139139
* [Split Texture Transform](Split-Texture-Transform-Node)
140-
* [Texel Size](Texel-Size-Node)
141140
* [Texture 2D Array Asset](Texture-2D-Array-Asset-Node)
142141
* [Texture 2D Asset](Texture-2D-Asset-Node)
143142
* [Texture 3D Asset](Texture-3D-Asset-Node)
143+
* [Texture Size](Texture-Size-Node)
144144
* [Math](Math-Nodes)
145145
* Advanced
146146
* [Absolute](Absolute-Node)

com.unity.shadergraph/Documentation~/Texel-Size-Node.md

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Texture Size Node
2+
3+
The Texture Size node takes a Texture 2D input and returns the width and height texel resolution of the texture. It also returns the width and height size of each texel of the texture. The node uses the built in variable `{texturename}_TexelSize` to access the special properties of the given Texture 2D input.
4+
5+
The term "texel" is short for "texture element" or "texture pixel." It represents a single pixel in the texture. So, for example, if Texture resolution is 512x512 texels, the texture is sampled over the range [0-1] in UV space, so each texel is 1/512 x 1/512 in size in UV coordinates.
6+
7+
<!-- ![](images/) Add image of node-->
8+
9+
If you experience texture sampling errors while using this node in a graph which includes Custom Function Nodes or Sub Graphs, you can resolve them by upgrading your version of Shader Graph to version 10.3 or later.
10+
11+
> [!NOTE]
12+
> Don't use the default input to reference your **Texture 2D**, as this affects the performance of your graph. Connect a [Texture 2D Asset Node](Texture-2D-Asset-Node.md) to the Texture Size node's Texture input port and re-use this definition for sampling.
13+
14+
## Create Node menu category
15+
16+
The Texture Size node is under the **Input** &gt; **Texture** category in the Create Node menu.
17+
18+
## Compatibility
19+
20+
The Texture Size node is compatible with all render pipelines.
21+
22+
## Ports
23+
24+
| Name | Direction | Type | Binding | Description |
25+
|:------------ |:----------|:---------|:--------|:------------|
26+
| Texture | Input | Texture | None | The Texture 2D asset to measure. |
27+
| Width | Output | Float | None | The width of the Texture 2D asset in texels. |
28+
| Height | Output | Float | None | The height of the Texture 2D asset in texels. |
29+
| Texel Width | Output | Float | None | The texel width of the Texture 2D asset in UV coordinates. |
30+
| Texel Height | Output | Float | None | The texel height of the Texture 2D asset in UV coordinates. |
31+
32+
33+
<!-- ## Example graph usage -->
34+
35+
<!-- Add example usage of node -->
36+
37+
## Generated Code Example
38+
39+
The following example code represents one possible outcome of this node.
40+
41+
```
42+
float _TexelSize_Width = Texture_TexelSize.z;
43+
float _TexelSize_Height = Texture_TexelSize.w;
44+
```
Lines changed: 2 additions & 2 deletions
Loading

com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/TexelSizeNode.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,46 @@
66

77
namespace UnityEditor.ShaderGraph
88
{
9-
[Title("Input", "Texture", "Texel Size")]
9+
[Title("Input", "Texture", "Texture Size")]
1010
class Texture2DPropertiesNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
1111
{
1212
public const int OutputSlotWId = 0;
1313
public const int OutputSlotHId = 2;
14+
public const int OutputSlotTWId = 3;
15+
public const int OutputSlotTHId = 4;
1416
public const int TextureInputId = 1;
1517
const string kOutputSlotWName = "Width";
1618
const string kOutputSlotHName = "Height";
19+
const string kOutputSlotTWName = "Texel Width";
20+
const string kOutputSlotTHName = "Texel Height";
1721
const string kTextureInputName = "Texture";
1822

1923
public override bool hasPreview { get { return false; } }
2024

2125
public Texture2DPropertiesNode()
2226
{
23-
name = "Texel Size";
24-
synonyms = new string[] { "texture size" };
27+
name = "Texture Size";
28+
synonyms = new string[] { "texel size" };
2529
UpdateNodeAfterDeserialization();
2630
}
2731

2832
public sealed override void UpdateNodeAfterDeserialization()
2933
{
3034
AddSlot(new Vector1MaterialSlot(OutputSlotWId, kOutputSlotWName, kOutputSlotWName, SlotType.Output, 0, ShaderStageCapability.All));
3135
AddSlot(new Vector1MaterialSlot(OutputSlotHId, kOutputSlotHName, kOutputSlotHName, SlotType.Output, 0, ShaderStageCapability.All));
36+
AddSlot(new Vector1MaterialSlot(OutputSlotTWId, kOutputSlotTWName, kOutputSlotTWName, SlotType.Output, 0, ShaderStageCapability.All));
37+
AddSlot(new Vector1MaterialSlot(OutputSlotTHId, kOutputSlotTHName, kOutputSlotTHName, SlotType.Output, 0, ShaderStageCapability.All));
3238
AddSlot(new Texture2DInputMaterialSlot(TextureInputId, kTextureInputName, kTextureInputName));
33-
RemoveSlotsNameNotMatching(new[] { OutputSlotWId, OutputSlotHId, TextureInputId });
39+
RemoveSlotsNameNotMatching(new[] { OutputSlotWId, OutputSlotHId, OutputSlotTWId, OutputSlotTHId, TextureInputId });
3440
}
3541

3642
// Node generations
3743
public virtual void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
3844
{
3945
sb.AppendLine(string.Format("$precision {0} = {1}.texelSize.z;", GetVariableNameForSlot(OutputSlotWId), GetSlotValue(TextureInputId, generationMode)));
4046
sb.AppendLine(string.Format("$precision {0} = {1}.texelSize.w;", GetVariableNameForSlot(OutputSlotHId), GetSlotValue(TextureInputId, generationMode)));
47+
sb.AppendLine(string.Format("$precision {0} = {1}.texelSize.x;", GetVariableNameForSlot(OutputSlotTWId), GetSlotValue(TextureInputId, generationMode)));
48+
sb.AppendLine(string.Format("$precision {0} = {1}.texelSize.y;", GetVariableNameForSlot(OutputSlotTHId), GetSlotValue(TextureInputId, generationMode)));
4149
}
4250

4351
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)

0 commit comments

Comments
 (0)