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

Shader Graph / Custom Function Node - how to have 2+ functions inside HLSL File?

Discussion in 'Graphics Experimental Previews' started by _watcher_, Jul 31, 2019.

  1. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    261
    SPOILER: Question to this thread was answered below (in EDIT2), in this same post. Newbie mistake. This thread can be closed, or remain here for other people like me, that don't have basic knowledge of HLSL and are searching for similar answers.

    ---------

    Hello

    TRIVIA
    I come here from a Shader Graph's Custom Function Node support thread which got phased out, due to being beta-19.1-related. It discussed documentation for Shader Graph's Custom Function Node, which was recently implemented and does have documentation here. Im posting here in hopes i can get my question on the CustomFunction HLSL file structure answered here, as the docs are rather recent, and dont (clearly) answer it.

    DOCS
    The documentation states:
    QUESTION
    When ShaderGraph's CustomNode's HLSL file needs multiple functions, how to name and reference them via other functions?

    I tried (which doesnt work):
    Example1:
    Code (CSharp):
    1. void MyTestMult1_float(float4 A, float4 B, out float4 Out)
    2. {
    3.     Out = MyTestMult2(A, B); // <--- this never gets called
    4. }
    5.  
    6. float4 MyTestMult2(float4 A, float4 B)
    7. {
    8.     return A * B;
    9. }
    10.  
    Result1:
    Code (CSharp):
    1. Undeclared identifier 'MyTestMult2'
    Example2:
    Code (CSharp):
    1. void MyTestMult1_float(float4 A, float4 B, out float4 Out)
    2. {
    3.     Out = MyTestMult2_float (A, B); // <--- this never gets called
    4. }
    5.  
    6. float4 MyTestMult2_float(float4 A, float4 B)
    7. {
    8.     return A * B;
    9. }
    Result2:
    Code (CSharp):
    1. Undeclared identifier 'MyTestMult2_float'
    Example3:
    Code (CSharp):
    1. v
    2. void MyTestMult1_float(float4 A, float4 B, out float4 Out)
    3. {
    4.    Out = MyTestMult2 (A, B); // <--- this never gets called
    5. }
    6.  
    7. float4 MyTestMult2_float(float4 A, float4 B)
    8. {
    9.    return A * B;
    10. }
    Result3:
    Code (CSharp):
    1. Undeclared identifier 'MyTestMult2'
    Maybe i'm just really bad at this. Should be simple for anyone who did this before to help.

    EDIT: I just noticed the docs do have multiple-function example, which, in-fact, is similar to to my Example2. But my Example2 throws the above error. I also tested the docs example, it works. So its my mistake. Hmm..

    EDIT2: I found out the problem. It was the function order. Apparently (and most of you probably know this, but i didnt!) functions in HLSL need to be declared in sequence, where later functions only can reference prior functions. I really should start learning some HLSL basics first x).
     
    Last edited: Jul 31, 2019
    R_Chris_D likes this.
  2. R_Chris_D

    R_Chris_D

    Joined:
    Sep 28, 2016
    Posts:
    3
    thank you! I've been asking myself what am I doing wrong.
     
    _watcher_ likes this.