Search Unity

Feature Request Reference Nodes

Discussion in 'Shader Graph' started by xzodia, May 21, 2021.

  1. xzodia

    xzodia

    Joined:
    Jan 24, 2013
    Posts:
    50
    In an effort to reduce spaghetti graphs, I suggest creating a node which stores a given value (like a variable in code) which can then be reused elsewhere in the graph.
    Hopefully, this would enable nicer looking / easier to understand graphs.

    Example:
    Example.png
     
    MirzaBeig, Qriva and florianBrn like this.
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    You can create custom sub graphs, and reuse them many times over as nodes.
     
  3. beevik_

    beevik_

    Joined:
    Sep 27, 2020
    Posts:
    101
    Subgraphs are great, but they are not a solution to all the problems that "reference nodes" can solve.

    The original poster's "reference node" idea would be really useful for high fan-out (or fan-in) situations, where a single output from one node is fed into the inputs of several other nodes. Such situations rapidly lead to spaghetti. "Reference nodes" would clean up this spaghetti by replacing the branching wires with proximal reference nodes.

    The use of subgraphs would not help much in this situation, because you'd still have the same amount of fan-out and therefore the same number of branching wires.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    You can solve spaghetti code, with correctly made sub graphs, of the spaghettis nodes itself.
    Then you use input as your reference.

    Initial state

    upload_2021-6-12_13-58-8.png

    Refined state

    upload_2021-6-12_13-58-21.png
     
  5. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    @Antypodish

    Subgraphs are neat but I agree that a 'store value' or like a 'register local variable' is very much needed just like they have in amplify shader editor.

    For example in my water shader I use the 'depth' of the water many times throughout the graph. This depth is calculated in a subgraph but when using that subgraph in my main graph, I have basically 2 options right now.

    1. Have an instance of that subgraph + its inputs each time in the main graph where I use the water depth.

    this has the following issues:
    - afaik this is a hit on performance since the subgraph is evaluated multiple times essentially for the same output?
    - I have the same node + inputs multiple times in the main graph, this is messy and redundant

    2. Have a single instance of that subgraph and connect it to each part of the main graph where the output value is used.

    this has the following issue:
    - very messy with a lot of connection wires going over other nodes

    A 'register local variable' would solve this. I would just use the 'depth calculation' subgraph + input once in my graph and register it to a local variable. Then I can connect that local variable (which would ideally take up as little space as a normal property) wherever I need in the main graph. This way the graph stays super clean and I can be 100% sure that the depth value is only calculated one single time.

    Some drawings to make my point clear. (Pictures are blurry but you should get the idea)


    situation 1: messy due to wires crossing over main graph


    situation 2: less messy but subgraph is evaluated multiple times (I think?) and having the same subgraph node + its input 3 times is redundancy


    situation 3: a local variable would solve the issues: the graph is clean and there is clearly only a single evaluation of the subgraph
     
    Last edited: Jun 13, 2021
    MirzaBeig and florianBrn like this.
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    If you call node multiple times, then yes GPU processes it multiple times. So it is no ideal.

    And all get what you all saying. Agree that ref would be nice.

    However with current sub graphs it is not end of the world, as you can have decent solution at current state. As per my description few post above.

    Possibly forces you to have cleaner graph, with fewer tangling wires.

    Hence you got at least 3, not two options.
     
  7. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
  8. Mariusz-Born7

    Mariusz-Born7

    Joined:
    Sep 4, 2015
    Posts:
    40
    Come on Unity! It is so needed feature...
     
  9. Blackfire-Studio

    Blackfire-Studio

    Joined:
    Dec 17, 2013
    Posts:
    185
  10. MirzaBeig

    MirzaBeig

    Joined:
    Dec 27, 2014
    Posts:
    602
    +1 for register/get local node, like Amplify Shader Editor.
    It's one of the features I miss most when jumping to Shader Graph.
     
  11. FredMoreau

    FredMoreau

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    168
    Hi there,

    we actually had this card internally, just not on the public roadmap.
    Here it is.
    I'm taking note of the above input. Thanks everyone!