Unity Products:Amplify Shader Editor/Texture Sample

From Amplify Creations Wiki
Jump to navigation Jump to search

Back to Node List

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: Turns off referencing altogether
  • Reference: Turns on referencing.
UV Set The UV channel used, also knows as UV Index in some applications. Set 2 is usually used for Lightmap UV coordinates.
  • [1,8]: Changes set to specified number from set 1 to set 8. Please that Unity 2018.1 and below only allows from 1 to 4.
Mip Mode Sets the way mips work with the sampler. Texture must have mip maps turned on. More info about mip maps here.
  • Auto: Manages mip levels automatically.
  • Mip Level: Lets you specify an exact mip level to sample from.
  • Mip Bias: Lets you use an offset value to increase or decrease the automatic mip level.
  • Derivative: Lets you specify the X and Y derivatives to the sampler.
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: Not referencing anything.
  • Option #: All other options are dynamically generated and point to all the available Texture Sample nodes in Object Mode contained in the shader graph
Parameters only visible if Mode set to Object
Type A set of ways the value behaves in different situations.
  • Property: the value becomes available in the properties of the material that uses the shader and can be changed in the material inspector or by script.
  • Global: the value can only be set by script and this defines a static variable that is shared between all shaders that use it. It's useful to change a value globally.
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: Property and/or global variable is created in the shader
  • Fetch: No variable nor property is registered on shader, useful when p.e. there's need to using global variables declared over a included cginc
Default Texture This is a fallback texture value that will be used if the default value is not set.
  • White: Uses Unity's built-in white texture. RGBA( 1, 1, 1, 1).
  • Black: Uses Unity's built-in black texture. RGBA( 0, 0, 0, 0).
  • Gray: Uses Unity's built-in gray texture. RGBA( 0.5, 0.5, 0.5, 0.5).
  • Bump: Uses Unity's built-in bump texture. RGBA( 0.5, 0.5, 1, 0.5).
Auto-Cast Mode This option makes the node either adjust automatically from the input texture provided or lock it to a specific type
  • Auto: Detects and uses any type of texture changing input ports accordingly.
  • Locked To Texture 1D: Locks to only accept 1D textures (in unity these are actually normal 2D textures)
  • Locked To Texture 2D: Locks to only accept regular 2D textures
  • Locked To Texture 3D: Locks to only accept 3D textures
  • Locked To Cube: Locks to only accept Cube map textures
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 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.
  • Hide in Inspector: The property is created but tells the material inspector to not draw it.
  • HDR: Marks the property as being an HDR element that accepts linear values outside of the [0,1] range and warns the user when the selected property is not supported.
  • Gamma: Indicates that a property is specified as sRGB value, and possibly needs conversion according to color space used.
  • Per Rendered Data: Indicates that a property will be coming from per-renderer data in the form of a MaterialPropertyBlock. Material inspector changes the texture slot UI for these properties.
  • No Scale Offset: Hides the scale and offset value properties besides a texture property and if ASE custom material inspector is being used it will also turn it into a mini thumbnail texture property.
  • Normal: Tells the inspector to expect the texture property to be a normal map which warns the user when that's not the case.
  • Single Line Texture: Texture property is represented by a smaller one line UI over the material inspector ( Tiling and Offset are not shown )
  • Custom: Allows adding custom attributes directly on a textfield

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

  1. ^ Port automatically adapts to selected cast mode into Float, Float2 or Float3.


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

Back to Node List