Search Unity

Feature Request Idea: Readonly Variable node.

Discussion in 'Shader Graph' started by cubrman, Jan 24, 2021.

  1. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Readonly Variable node.

    One of the worst parts of the Shader Graph experience is the cases, when you use a single value in multiple places and are forced to follow the lines to see what kind of value that is. Yes this can be partially mitigated by planning your layout, but I personally find it almost impossible to create a layout for a large shader graph that will completely prevent the confusion that these lines tend to create.

    I propose an idea to introduce a Readonly Variable node which will work the following way:
    1. Each Readonly Variable node is unique and forcibly has a unique name, which can be changed by the user, as long as it does not clash with other Readonly Variable node names or input property names.
    2. A Readonly Variable node can be assigned any value, but it can only be assigned it ONCE.
    3. A Readonly Variable node has a reading state and the assigning state. These reading state can be used to read a value from it and to assign it to any other node's value slot. There can be as many reading parts of the node as the user wants, but there can only be ONE assigning part.
    4. Once added to the Shader Graph, a Readonly Variable node will have:
    a) both assign value and read value slots, if it has never been assigned a value before. In this case, once the user connects a line to any of the slots of the node the other slot will immediatly hide;
    b) only the read value slot, if the node already had its value assigned in this Shader Graph.
    5. If a Readonly Variable node is used to read a value from it, but it has never had its value assigned to it, it must have a yellow triangle appear next to it, to show the user that this node has a default value at this moment.
    6. In general, the reading part of the Readonly Variable node should function like an input property node, but have a distinct look.
    7. If the user hovers their mouse over the reading part of the Readonly Variable node, the assigning part of the node must be highlighted and vise-versa: if the user hovers their mouse over the assigning part of the node, ALL the reading parts should be highlighted.
    8. If the user clicks on the reading part of the node with the middle mouse - they should be transported to the assigning part of the node.
    9. The reading part of the node should be visually distinct from the assigning part of the node.
     
    Ninquiet and bgolus like this.
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Last edited: Jan 24, 2021
  3. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    412
    Well my problem with the word "variable" was that it can bring confusion as a variable can be assigned multiple times and that would mean you don't really know what value it holds when you read it as Shader Graph is not code and it is non-linear. If you can't assign the variable multiple times it's not really technically a variable. I did not want to use this word at all and first opted for the word "constant" but at the end settled on "readonly variable" as in c# readonly variables work precisely like that: one assignment, multiple reads.

    I don't really care about the name - I just want to have this functionality.
     
  4. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
  5. corjn

    corjn

    Joined:
    Feb 6, 2014
    Posts:
    168
    +1, can't imagine dropping Amplify Shader for Shader Graph, just because of this feature. It basically removes spaghetti graphs.

    And you can already do that in Bolt / Unity visual scripting, so it would make sense to add it on shader graph too.
     
  6. Ninquiet

    Ninquiet

    Joined:
    Sep 21, 2015
    Posts:
    10
    Totally support this request +1