Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Weird error behaviour with CustomFunction node

Discussion in 'Shader Graph' started by PhilSA, Apr 19, 2019.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I decided to do a CustomFunction node "hello world" in order to get familiar with it, but I've run into a weird issue.

    I'm trying to start with a function that gets the direction of the main light in the LWRP. I do this by returning GetMainLight(), which is a function in LWRP's "Lighting.hlsl". So I created this HLSL file:
    Code (CSharp):
    1. void GetMainLightDir_float(out float3 lightDir)
    2. {
    3.     lightDir = GetMainLight().direction;
    4. }
    And then I made this graph to test it out:


    As you may notice, it gives me an error saying "undeclared identifier "GetMainLight"". I get that same error in the console too. However.... the weird thing is that it seems to work perfectly well even if there's an error:


    Now I have many questions:
    1. Why does it work and/or why is there an error?
    2. Why does it want my function to be named "GetMainLightDir_float" even though I said I wanted it to be named just "GetMainLightDir"?
    3. If I modify my .hlsl file with this include (where the GetMainLight() function is) in order to try to solve the error:
      Code (CSharp):
      1. #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
      2.  
      3. void GetMainLightDir_float(out float3 lightDir)
      4. {
      5.     lightDir = GetMainLight().direction;
      6. }
      ...it now gives me a new error: "redefinition of _Time", which I do not understand
     
    Last edited: Apr 19, 2019
  2. Sekia

    Sekia

    Joined:
    Aug 19, 2018
    Posts:
    1
    TIM截图20190419131053.png
    this now not an error ♪(^∀^●)ノ
     
    PhilSA likes this.
  3. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,237
    Custom Function nodes are currently broken when you use more than one referencing the same HLSL file, it will throw the "redefinition of" errors. There's a PR open that apparently fixes this: https://github.com/Unity-Technologies/ScriptableRenderPipeline/pull/3349

    I haven't tried this yet, but it may work to put your Custom Function node into a Sub Graph, then use that in your main graph instead.

    Edit: Doesn't work. Looks like every Custom Function needs to use a separate HLSL file until this is fixed, or use the string type and paste the function.
     
    Last edited: Apr 20, 2019