Unity Products:Amplify Shader Editor/Custom Expression

From Amplify Creations Wiki
Jump to: navigation, search

Back to Node List

Custom Expression Node

The Custom Expression Node allows shader code to be directly injected into the graph. It will either write inline or create a function according to how code is written on its Code text area. If a return function is detected on the text area then a function will be created. Also in function mode each instruction line must end with a ;. If no return function is detected them an expression will be generated and used directly on the vertex/frag body. On Expression mode a ; is not required on the end of an instruction line.


Nodes used: Texture Sample, Float, Custom Expression

Node Parameter Description Default Value
Name Custom Expression name. It will be used to internally name the variable or function generated. My Custom Expression
Mode Determines on how use the code placed over the Code text area.
  • Create: The result of what is placed over the coding area and connected to the inputs will be directly assigned to the output port.
  • Call: Instructions placed over the code area are placed inline over the shader body and they are not assigned to anything. This is particularly useful for calling functions declared over another part of the shader or on an included cginc.

With Call Mode active, a special input port In is added, which acts as a relay passing what is connected to it directly to the node output port.

Create
Precision Precision used when declaring the node internal variables.

Defines the amount of bytes the variable can hold, effectively defining how precise the value is. It's usefulness is bond by the hardware specifications necessary. Lowest precision is slightly faster but might produce errors and artifacts.

  • Float: Highest precision, useful for values that can be very high or very low in value (ie: positions, coordinates, etc)
  • Half: Medium precision, in most cases is as good as Float but at half of it's precision
Float
Code Text area on which the custom expression or function is written. Creates a function or a custom expression depending if it contains a return statement on its body. False
Set Unique If toggled on, a unique id will be appended to the function/variable name. This allows different Custom Expressions to have the same name.

If, for example, a user wants a function to be generated over the Custom Expression and used by others then it should be toggled off in order to maintain the original name.

True
Auto-Register Register functions generated by the Custom Expression even when no connection exists with an output node. False
Output Type Variable type of the newly created expression or return type of the newly created function. Only visible when Call Mode is turned off. Float
Dependencies Allows the user to select other Custom Expressions on which it depends on, in order to guarantee they are written first. -
Inputs Allows adding (+) or removing (-) Input ports. Input ports can be used inside the code area by directly calling their names. 0
Qualifier Specifies type qualifier for current input parameters on function mode. When on this mode, a function is created with each Input Port set as a function input parameter using its assigned qualifier.
  • In - Value assigned to parameter will be copied into it when the function is called. It can be modified inside function as it will not affect original one.
  • Out - Value not initialized by the function caller. The function is responsible for initializing this parameter, all changes done on top if it will also be copied to the original variable set on the function calling.
  • InOut - Combines previous qualifiers, value will be set to the one passed by the function call but also all changes done to it inside the function body will be copied to the original one.
In
Type Data Type for the input port
  • int - Int data type
  • float - Float data type
  • float2 - Vector2 data type
  • float3 - Vector3 data type
  • float4 - Vector4 data type
  • float3x3 - Matrix3x3 data type
  • float4x4 - Matrix4x4 data type
  • sampler1D - Sampler1D data type
  • sampler2D - Sampler2D data type
  • sampler3D - Sampler3D data type
  • samplerCUBE - SamplerCUBE data type
float
Name Input name, also used internally as a variable or function parameter name. In#
Value Input current value. Only visible if the respective input port is not connected. 0


Input Port Description Type
In# The amount and type of input ports is given by the node configuration. Each input port corresponds to the node input parameter with the same name and order at the Node Properties. Float

Back to Node List