Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback Shader Graph Custom Function node Subgraph Access?

Discussion in 'Graphics Experimental Previews' started by URocks, Feb 17, 2020.

  1. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    Imagine that I have subgraph which is creating star shape (or whatever else) made of dozen nodes...
    Then in the Custom function node, I want to create a lot of these stars inside for loop, but there is no access to my subgraph in the custom function node.
    I am Imagining the subgraph can be represented as a method with inputs and outputs (we have blackboard of inputs and output node inside subgraph), so there should be a way how to access is from the custom function node.

    Or is there a way how to do it right now, maybe somehow with hlsl include or something any ideas?

    But if you dismiss this idea of accessing subgraphs from custom function nodes please create some visual for loop nodes because this is so limiting, not have access to subgraph inside custom function node
     
    Last edited: Feb 17, 2020
    NotaNaN, bobbaluba and Jawsarn like this.
  2. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    Same problem here, want to use a for loop and call a subgraph.
     
    NotaNaN, bobbaluba and URocks like this.
  3. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    @alexandral_unity There must be lot of us, is there a chance to add this possibility?
     
    NotaNaN, bobbaluba and youri_ssk like this.
  4. xOrfe

    xOrfe

    Joined:
    Apr 21, 2013
    Posts:
    31
    Same issue, any idea? :D
     
  5. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    I also wanted to do this. Sadly, I ended up porting most of my shader graphs to hlsl and now I only use shader graph for very simple top-level stuff.

    Some of the things I wanted it for:

    - 3D fractional brownian motion with a configurable number of octaves
    - Other fractal noise functions (hybrid multifractal, ridged multifractal, turbulence etc.)
    - Raymarching SDFs (I want to define the model as a shader graph and do a custom number of iterations on it in a raymarcher.

    I'm sure there are less esoteric use-cases as well.
     
    NotaNaN and URocks like this.
  6. NotaNaN

    NotaNaN

    Joined:
    Dec 14, 2018
    Posts:
    325
    @alexandral_unity, is there anything on this?

    Can we please have For Loop nodes, While Loop nodes, or at least have the ability to do limited sub-graph recursion?
     
  7. Prokhpav

    Prokhpav

    Joined:
    Jul 11, 2020
    Posts:
    2
    I found a way to use SubGraph in CustomNode

    1) First, you need to find the name of the subgraph function

    You need to create a separate node of the SubGraph, right-click on it and select "Show Generated Code". In this code, you need to find function named "SG_[name of SubGraph]_[a lot of random symbols]". Right above this function should be a structure "struct Bindings_[name of SubGraph]_[a lot of random symbols] {};".

    2) SubGraph initialization

    In order for the SubGraph function to be created before the CustomNode function, it is necessary that the CustomNode node is located strictly after the SubGraph node. The best way to do this is to add an unused variable to the Input CustomNode and connect it to the output from the SubGraph.

    3) Using the SubGraph function in CustomNode

    The arguments of the SubGraph function consist of three parts: void func([Inputs], Binding, [out Outputs]) . The SubGraph function doesn't return anything, it writes results into the given Output variables. Therefore, the use of the function looks like this:

    Outputs initialization;
    [name of Binding struct] Binding;
    [name of SubGraph function](Input1, Input2, ... , InputN, Binding, Output1, ... , OutputN);
     

    Attached Files:

  8. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159

    Hi @Prokhpav nice work looks like a good start, but do you think is possible to use a subgraph inside for loop in custom node. Imagine that your subgraph doing a simple circle where you can change the position, size, and color of the circle in subgraph parameters. And when you use it inside custom node For Loop you can duplicate these circles with different colors positions and size and the custom node should output result with all different circles with different colors sizes and positions
     
  9. Prokhpav

    Prokhpav

    Joined:
    Jul 11, 2020
    Posts:
    2
    You can use SubGraphs and other CustomFunctions in any way (certainly, within the capabilities of the programming language)). Random circles shader below (The names of the SubGraph and Binding will most likely change during import, you should replace them with names from the Generated Code)
     

    Attached Files:

    apkdev and URocks like this.
  10. URocks

    URocks

    Joined:
    May 1, 2014
    Posts:
    159
    Amazing job @Prokhpav ! Thank you so much for your findings. Thats exactly what I need! :)
     
  11. wengyhong

    wengyhong

    Joined:
    May 19, 2021
    Posts:
    6
    This doesnt seem to work anymore? I am using Unity 2021.3.1f1 and I have replaced the names in the custom function