Difference between revisions of "Unity Products:Amplify Shader Editor/Static Switch"

From Amplify Creations Wiki
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
The Static Switch node creates and/or uses shader keywords through '''#if #elif/#else #endif''' directives. Its input [[#paramTrue|True]] will be used inside the '''#if''' directive body while the [[#paramFalse|False]] input will be used on the '''#else''' directive. If multiple keywords are defined on the [[#paramType|Type]] then an '''#elif''' directive will be created to each one of the middle items.
 
The Static Switch node creates and/or uses shader keywords through '''#if #elif/#else #endif''' directives. Its input [[#paramTrue|True]] will be used inside the '''#if''' directive body while the [[#paramFalse|False]] input will be used on the '''#else''' directive. If multiple keywords are defined on the [[#paramType|Type]] then an '''#elif''' directive will be created to each one of the middle items.
  
 +
'''NOTE:''' We recommend setting the keyword to local when working on Unity 2019.1 or newer. Unity has a limit of 384 global keywords which can be consumed very quickly across all shaders, including Unity native ones.<br/>
 +
The amount of local keywords is 64 so its always best use more local keywords and less global keywords in order to reduce total keyword count per shader.<br/>
 +
<br/><br/>
 
<img class="responsive-img" src="http://amplify.pt/NodeDetail/StaticSwitchNode.jpg">
 
<img class="responsive-img" src="http://amplify.pt/NodeDetail/StaticSwitchNode.jpg">
 
<br/><font size="1">Nodes used:  
 
<br/><font size="1">Nodes used:  
Line 17: Line 20:
 
|-
 
|-
 
! style="width: 10%;" | Node Parameter !! Description !! style="width: 10%;" | Default Value
 
! style="width: 10%;" | Node Parameter !! Description !! style="width: 10%;" | Default Value
|-
 
| id="paramType" | Type
 
| Defines the amount of variants and toggle default behavior when it's checked on
 
*'''Toggle''': Two variants are created and toggle is on when checked on
 
*'''Toggle Off''': Two variants are created and toggle is off when checked on
 
*'''Keyword Enum''': Up to 10 variants ( 9 keywords ) can be created.
 
| Toggle
 
 
|-
 
|-
 
| id="paramMode" | Mode
 
| id="paramMode" | Mode
 
| Specify if node creates the specified keyword or uses an already defined one
 
| Specify if node creates the specified keyword or uses an already defined one
 
* '''Create:''' Creates specified keywords
 
* '''Create:''' Creates specified keywords
* '''Fetch:''' Doesn't create keywords. The '''#if/#elif''' directives makes use of keywords assuming they're already created elsewhere.  
+
* '''Fetch:''' Doesn't create keywords. The '''#if/#elif''' directives makes use of keywords assuming they're already created elsewhere. `
 +
* '''Reference:''' Uses keyword created by another Static Switch node.  
 
|-
 
|-
 
| id="paramKeywordType" | Keyword Type
 
| id="paramKeywordType" | Keyword Type
Line 34: Line 31:
 
*'''Shader Feature Keyword:''' Unused variants wont be included into game build. Useful for keywords that will be set on the materials.
 
*'''Shader Feature Keyword:''' Unused variants wont be included into game build. Useful for keywords that will be set on the materials.
 
*'''Multi Compile Keyword:''' All variants will be included into game build regardless of its usage. Useful for keywords that will be set from code globally.
 
*'''Multi Compile Keyword:''' All variants will be included into game build regardless of its usage. Useful for keywords that will be set from code globally.
| Shader Feature Keyword
+
| Shader Feature
 +
|-
 +
| id="paramType" | Type
 +
| Defines the amount of variants and toggle default behavior when it's checked on
 +
*'''Toggle''': Two variants are created and toggle is on when checked on
 +
*'''Toggle Off''': Two variants are created and toggle is off when checked on
 +
*'''Keyword Enum''': Up to 10 variants ( 9 keywords ) can be created.
 +
| Toggle
 +
|-
 +
| id="paramIsLocal" | Is-Local
 +
| Sets the keyword to be local to this particular shader instead of global.'''(Only on Unity 2019.1 or newer)'''
 +
| True
 
|-
 
|-
 
| id="paramAutoRegister" | Auto-Register
 
| id="paramAutoRegister" | Auto-Register
Line 51: Line 59:
 
| Defines the default value for the Material Toggle property. This property is only visible if Material Toggle is turned on.
 
| Defines the default value for the Material Toggle property. This property is only visible if Material Toggle is turned on.
 
| False
 
| False
 +
|-
 +
| colspan="3" style="background:white; text-align: center; font-size: 11px;"| Reference
 +
|- style="background: #e5e5e5;" |
 +
| id="paramReference" | Reference
 +
| Static Switch to which to get keyword
 +
| <None>
 
|-
 
|-
 
| colspan="3" style="background:white; text-align: center; font-size: 11px;"| Keyword Enum
 
| colspan="3" style="background:white; text-align: center; font-size: 11px;"| Keyword Enum

Latest revision as of 16:06, 25 August 2021

Back to Node List

Static Node

The Static Switch node creates and/or uses shader keywords through #if #elif/#else #endif directives. Its input True will be used inside the #if directive body while the False input will be used on the #else directive. If multiple keywords are defined on the Type then an #elif directive will be created to each one of the middle items.

NOTE: We recommend setting the keyword to local when working on Unity 2019.1 or newer. Unity has a limit of 384 global keywords which can be consumed very quickly across all shaders, including Unity native ones.
The amount of local keywords is 64 so its always best use more local keywords and less global keywords in order to reduce total keyword count per shader.



Nodes used: Texture Sample, World Normal, Vertex To Fragment, Static Switch


Node Parameter Description Default Value
Mode Specify if node creates the specified keyword or uses an already defined one
  • Create: Creates specified keywords
  • Fetch: Doesn't create keywords. The #if/#elif directives makes use of keywords assuming they're already created elsewhere. `
  • Reference: Uses keyword created by another Static Switch node.
Keyword Type Type of keyword to be specified
  • Shader Feature Keyword: Unused variants wont be included into game build. Useful for keywords that will be set on the materials.
  • Multi Compile Keyword: All variants will be included into game build regardless of its usage. Useful for keywords that will be set from code globally.
Shader Feature
Type Defines the amount of variants and toggle default behavior when it's checked on
  • Toggle: Two variants are created and toggle is on when checked on
  • Toggle Off: Two variants are created and toggle is off when checked on
  • Keyword Enum: Up to 10 variants ( 9 keywords ) can be created.
Toggle
Is-Local Sets the keyword to be local to this particular shader instead of global.(Only on Unity 2019.1 or newer) True
Auto-Register If toggled on, keyword registry is done independently if node is connected to an output node. False
Material Toggle If activated, creates a Toggle property so keyword can be set via the material inspector. True
Material Value Selects current activated keyword. This can be either shown by a toggle or a multiple item dropdown depending on the selected Type. Off
Default Value Defines the default value for the Material Toggle property. This property is only visible if Material Toggle is turned on. False
Reference
Reference Static Switch to which to get keyword <None>
Keyword Enum
Amount Amount of keywords to generate 2
Item Name of the current keyword Key#
Shader Feature/Multi Compile
Name Name of the keyword that will be created and used by the node. Keyword #
Property Name This is the variable name that contains the value which is automatically generated from 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 Keyword Name" becomes "_MyKeywordName" ). _Keyword#
Keyword Name This is the generated keyword name which is automatically generated using the Name parameter, it's greyed out and not editable. The generation process removes special characters, whitespaces, adds an underscore(_) at the beginning, convert all characters to upper case and adds _ON at the end ( ie: "My Keyword Name" becomes "_MYKEYWORDNAME_ON" ). _Keyword#
Toggle with Fetch
Keyword Allows to select already existing Unity keywords or select a new custom new one. This list will continuously grow according to community needs/feedback.
  • Custom: Define a custom keyword to be used
  • ETC1_EXTERNAL_ALPHA
  • PIXELSNAP_ON
  • UNITY_PASS_FORWARDBASE
  • UNITY_PASS_FORWARDADD
  • UNITY_PASS_DEFERRED
  • UNITY_PASS_SHADOWCASTER
  • (More to come)
Custom
Custom Write custom keyword to be used. This property is only visible if Keyword property is set to Custom.
Custom Attributes
Attribute # Additional attributes can be added to the generated property created by this node.
Input Port Description Type
True Value to be outputted if selected keyword is being defined (#if body). Float [1]
False Value to be outputted if selected keyword is not being defined (#else body). Float [1]

  1. ^ Port automatically adapts to all connection types except Sampler types.

Back to Node List