Unity Products:Amplify Shader Editor/Texture Sample
Texture Sample Node
The Texture Sample node ( shortcut: T key ) fetches and reads a texture to be used inside the shader, generally as a texture map that uses the model UVs. This node has various small options to make it easier to do simple and common operations with textures, as an example, besides using it to read an albedo or smoothness map you can also set it to read a normal map, which usually requires special treatment.
If you drag a texture into the editor graph a texture sample node with an automatic name will be created and the respective texture will be assigned to it, if that texture is marked as a normal map the node will also be set as normal map with an XYZ vector output port instead of an RGBA color port along side with a scale port that allows the normals to be scaled up and down in tangent space. This behavior is also true if you drag a texture into a pre-existing texture sample node.
NOTE 1: This node facilitates the use of textures which could lead you to believe it is a texture, when in fact it does two things, it fetches a texture and it reads the pixel colors of that texture in some fashion. Don't think of this node as much as being a texture but more as being the operation needed to read a single pixel of that texture (hence the name Sample). It's actually possible, and sometimes required, to read/sample the same texture more than once in which case you would need more of these nodes. For that purpose you would also need the Texture Object node connected to the Tex input port, this node might look similar but isn't, it only fetches the texture but doesn't do any explicit operation with it.
NOTE 2: Sampler States are only available on Unity 2018.1 or higher and the Use Sampling Macros flag must be turned on over the Master Node properties.
More info can be found over Unity's official documentation page
Nodes used:
Texture Sample
Node Parameter | Description | Default Value |
---|---|---|
Mode | Whether you want to use the texture directly or you want to reference an existing Texture Sample node.
|
Object |
UV Set | The UV channel used, also knows as UV Index in some applications. Set 2 is usually used for Lightmap UV coordinates.
|
1 |
Mip Mode | Sets the way mips work with the sampler. Texture must have mip maps turned on. More info about mip maps here.
|
Auto |
Unpack Normal Map | If toggled on it will use the texture as a normal map by unpacking and scaling the result into a normal vector in tangent space. | false |
Reference Sampler | Use sampler state from referenced texture sampler. Only used if no sampler state is set over the SS port. | <None> |
Parameters only visible if Mode set to Reference | ||
Reference | Points to an existing Texture Sample node
|
None |
Parameters only visible if Mode set to Object | ||
Type | A set of ways the value behaves in different situations.
|
Property |
Name | Name of the property holding the value. This is the name that will be shown in the material properties label, useful for organization purposes or to generate a Property Name. | Texture Sample # |
Property Name | This is the variable name that contains the value, this is automatically generated using the Name parameter, it's greyed out and not editable. The generation process removes special characters, whitespaces and adds an underscore at the beginning ( ie: "My Property Name" becomes "_MyPropertyName" ). Not editable to indicate what's the variable name to use when editing this value by script. | _TextureSample# |
Variable Mode | Defines if the current property/global variable is to be created on the current shader.
|
Create |
Default Texture | This is a fallback texture value that will be used if the default value is not set.
|
White |
Auto-Cast Mode | This option makes the node either adjust automatically from the input texture provided or lock it to a specific type
|
Auto |
Scale | This scales the normal map perpendicular to the surface. Effectively decreasing or increasing how bumpy the surface looks. Only available if Unpack Normal Map is checked and only visible is the respective port is not connected. | 1 |
Default Value | This is the value the shader currently holds. It's also the default value that is used when a new material is created with this shader. | None |
Material Value | This is the value the node the material currently holds. Only visible if the editor is open in material mode. | None |
Attributes | ||
Attributes | This group allows adding material property attributes that changes the visual and behavior of the property accordingly to the selected attribute. They can be dynamically added or removed with the plus and minus buttons.
|
None |
Input Port | Description | Type |
---|---|---|
Tex | This port accepts a Texture Object which allows the use of it's texture UV parameters in the material inspector. | Sampler2D |
UV | The UV coordinates to use when sampling the texture. If set overrides the texture tiling and offset parameters, otherwise it'll generated and use the model UVs. | Float2 [1] |
SS | External sampler state to be used on sampling texture. | Sampler State |
Other Parameters | ||
Level | Defines the mipmap level value to use. Only available if Mip Mode is set to Mip Level. | Float |
Bias | Defines the mip bias value to use. Only available if Mip Mode is set to Mip Bias. | Float |
Scale | This scales the normal map perpendicular to the surface. Effectively decreasing or increasing how bumpy the surface looks. Only available if Unpack Normal Map is checked. | Float |
DDX | The X derivative to use when doing sampling through derivatives. Only available if Mip Mode is set to Derivative. | Float2 [1] |
DDY | The Y derivative to use when doing sampling through derivatives. Only available if Mip Mode is set to Derivative. | Float2 [1] |
Output Port | Description | Type |
---|---|---|
RGBA | Returns the full RGBA color of the sampled texture. | Float4 |
R | Returns only the R component of the color value which corresponds to the X component of a Vector4 | Float |
G | Returns only the G component of the color value which corresponds to the Y component of a Vector4 | Float |
B | Returns only the B component of the color value which corresponds to the Z component of a Vector4 | Float |
A | Returns only the A component of the color value which corresponds to the W component of a Vector4 | Float |
if Unpack Normal Map is ON the output set changes to this | ||
XYZ | Returns the Unpacked and Scaled Normal in tangent space from the texture. | Float3 |
X | Returns only the X component of the normal vector | Float |
Y | Returns only the Y component of the normal vector | Float |
Z | Returns only the Z component of the normal vector | Float |
- ^ Port automatically adapts to selected cast mode into Float, Float2 or Float3.
Examples
Using a Texture Sample node to scale down a normal map. With Unpack Normal Map ON it gets a new scale input port and the output port changes to XYZ. Notice how the texture preview on the left panel has the common purple tones while the preview on the node is more blueish, this indicates the normal map was unpacked correctly.
Nodes used:
Float,
Texture Sample
Mixing the same texture using a Texture Object node with different UV tiling to produce detail colors at close range. Notice the little chain icon in the upper right corner of the node to indicate the referenced connection.
Nodes used:
Texture Object,
Texture Coordinates,
Float,
Multiply,
Texture Sample,
Blend Operations
Same example as before but now both the bottom gray Texture Sample node and the left Texture Coordinates reference the original directly from their properties.
Nodes used:
Texture Coordinates,
Float,
Multiply,
Texture Sample,
Blend Operations