Search Unity

Help Wanted Global variables in the Shader Graph (URP/LWRP)

Discussion in 'Shader Graph' started by RedMattis, Feb 1, 2020.

  1. RedMattis

    RedMattis

    Joined:
    Apr 18, 2015
    Posts:
    28
    I'm trying to figure out how to get global variables to work within URP.

    I've tried setting a variable in the Shader Graph and then setting the reference name doing something like this:
    Code (CSharp):
    1. Shader.SetGlobalFloat("Vector1_71B9E5F1", currentFloor);
    Nothing seems to happen though, so I'm guessing that would have to be done on the actual material instance?

    I've also tried something like
    Code (CSharp):
    1. Shader.SetGlobalFloat("_GLOBAL_FLOOR", currentFloor);
    , and then setting it in .hlsl code (something I'm not very familiar with). But if that is the way, then I don't think I know the correct syntax. I've tried a bunch of variants of the below without success:

    upload_2020-2-1_22-12-13.png

    I've also tried changing the reference string of a property to _GLOBAL_FLOOR, but that just made unity instantly crash to desktop when I pressed 'enter' in the field.

    I'm running out of ideas, and I haven't been able to find any solution that seems to be Shader Graph compatible.
     
    Last edited: Feb 1, 2020
  2. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    119
    When you were trying to set the property using the reference name from the blackboard, did you have the "exposed" toggle enabled? You need that disabled to properly set variables from script.
     
  3. RedMattis

    RedMattis

    Joined:
    Apr 18, 2015
    Posts:
    28
    I tried both. I'll give it another try though.

    Should I ever change the reference reference ids? (Vector1_71B9E5F1, f.ex.). I did try changing them before (to EnvironmentAlbedo f.ex.), but it resulted in my editor-chain-crashing until I manually edited the graph file to remove the input and all references to it within that file.

    When I set the property, do I have to set it on a specific GameObject, or can I set it globally for all of Unity? I'd prefer to do the later, because my gut feeling is that running Update loops on every single game object with a material (to set the variable on it) would be terrible for performance.

    With all that said, while I'll probably need global variables later regardless, this particular problem might be better solved with some sort of occlusion. What I was really trying to to was:
    A) Hide roofs/floors/above of buildings when the player enters them (3rd top-down person game) / hide ground, etc. when going into a basement.
    B) Black-out or perhaps cull the world based on whether or not it was visible to the player object (not the main camera, the main camera is a top-down one)
     
unityunity