• Stars
    star
    251
  • Rank 161,077 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Adds 'Register Variable' and 'Get Variable' nodes to Shader Graph, allowing you to link sections of a graph without connection wires. <3

Shader Graph Variables

  • Requires Shader Graph v10+
  • Tested with Unity 2020.3.0f1, Shader Graph v10.3.2 (URP, but should work in HDRP too)
  • Should also work with newer Unity versions. If there's any errors/problems, let me know by opening an issue (if one doesn't already exist)

Main Feature :

  • Adds Register Variable and Get Variable nodes to Shader Graph, allowing you to link sections of a graph without connection wires
    • These nodes (technically subgraphs) include a TextField where you can enter a variable name (not case sensitive)
    • They automatically link up with invisible connections/wires/edges
    • These variables are local to the graph - they won't be shared between other graphs or subgraphs
  • Supports Vector and Float types
    • Vector2/3 will be promoted to Vector4. After Get Variable, can Split and re-Combine after if required
    • If a float is connected the port will automatically change. However note that DynamicVector/DynamicValue slots (used by most math nodes) currently default to the Vector4 port instead. If you require float, put the value through a Float node before connecting
  • The variable names are serialized using the node's "synonyms" field, which is unused by the graph (only used for nodes in the Add Node menu). The field was added in v10 so is one main reason why the tool wouldn't work properly on previous versions (the SubGraphs also likely won't load)
  • Note that if the tool is removed, any graphs that used it should still load correctly. However since it does use a few SubGraphs, if they don't exist anymore it will cause the graph to error and you'll need to remove those nodes, reinstall the tool, or at least include the SubGraphs from the tool in your Assets to fix it
  • For setup & usage instructions, see below

Extra Features :

  • Group Colors
    • Right-click group name and select "Edit Group Color" to show Color Picker to edit background/border colour (inc. alpha)
    • Uses a hidden Color node & synonyms for serialization. It can't be moved so try to move the group as a whole rather than the nodes in it

  • 'Port Swap' Hotkey (Default : S)
    • Swaps ports on selected nodes
    • Enabled for nodes : Add, Subtract, Multiply, Divide, Maximum, Minimum, Lerp, Inverse Lerp, Step and Smoothstep

  • 'Add Node' Hotkeys (Default : Alpha Number keys, 1 to 0)
    • 10 hotkeys for quickly adding nodes at the mouse position. Defaults are :
      • 1 : Add
      • 2 : Subtract
      • 3 : Multiply
      • 4 : Lerp
      • 5 : Split
      • 6 : One Minus
      • 7 : Negate
      • 8 : Absolute
      • 9 : Step
      • 0 : Smoothstep
    • To change nodes : Tools β†’ SGVariables β†’ ExtraFeatures β†’ Rebind Node Bindings
  • To edit keybindings : Edit β†’ Shortcuts (search for SGVariables)
    • Note, try to avoid conflicts with SG's hotkeys (mainly A, F and O) as those can't be rebound

Setup:

  • Install via Package Manager β†’ Add package via git URL : https://github.com/Cyanilux/ShaderGraphVariables.git
  • Alternatively, download and put the folder in your Assets
  • Note these methods won't update automatically, so please check back if you have any problems. If there's any important fixes or additional features added, I'll likely post about it on twitter too!

Usage :

  1. Add Node β†’ Register Variable
    • The node has a Text Field in the place of it's output port where you can type a variable name
    • Attach a Float/Vector to the input port
  2. Add Node β†’ Get Variable
    • Again, it has a Text Field but this time for the input port. Type the same variable name
    • Variable names aren't case sensitive. "Example" would stil link to "EXAMPLE" or "eXaMpLe" etc.
    • When the variable name matches, the input port value (e.g. (0,0,0,0)) should disappear and the preview will change
    • A connection/edge may blink temporarily, but then is hidden to keep the graph clean (kinda the whole point of the tool)
    • You can now use the output of that node as you would usually

Authors :

Known Issues :

  • If a 'Get Variable' node is connected to the vertex stage and then a name is entered, it can cause shader errors if fragment-only nodes are used by the variable (e.g. cannot map expression to vs_5_0 instruction set)
  • If a node uses a DynamicVector/DynamicValue slot (Most math nodes) it currently will default to Vector4. If you want Float, pass the value through the Float node before connecting!

More Repositories

1

URP_BlitRenderFeature

Blit Render Feature for Universal RP's Forward Renderer. Set specific source/destination via camera source, ID string or RenderTexture asset. Also options for _InverseView matrix and _CameraNormalsTexture generation.
C#
565
star
2

URP_ShaderGraphCustomLighting

Some custom lighting functions/sub-graphs for Shader Graph, Universal Render Pipeline
HLSL
524
star
3

URP_ShaderCodeTemplates

A few shader code templates/examples for Unity, Universal Render Pipeline (URP v10 / Unity 2020.3). ShaderLab & HLSL.
ShaderLab
267
star
4

URP_WatercolourShaders

A few experiments with watercolour-like shader effects made using Shader Graph. Unity 2020.1.2f1, URP 8.2.0
C#
180
star
5

BakeShader

Unity editor tool for baking shaders to textures. Texture2D, Texture3D, Flipbook, or MeshRenderer (uses model UV)
C#
163
star
6

URP_RetroCRTShader

A shader graph which replicates some retro tv/monitor effects. CRT (cathode-ray tube) warping, scanlines, static, distortion, etc.
C#
141
star
7

Cards

A few scripts which controls interactions for a hand of cards. Card model, shadergraph and example setup included.
C#
128
star
8

ShaderGraphToPNG

Screenshots a Shader Graph in multiple sections, stitches them together and saves the result as a PNG
C#
117
star
9

ToDo

Unity in-editor to-do list, attached as a component and uses a custom inspector based on ReorderableList. Also see branches for ScriptableObject / cross-scene reference version.
C#
81
star
10

URP_GrassGeometryShader

Example of a Grass Geometry Shader for Unity, Universal Render Pipeline. Based on https://github.com/IronWarrior/UnityGrassGeometryShader
HLSL
63
star
11

cyanilux.github.io

Tutorial/blog site, generated using Hugo
HTML
2
star