Search Unity

Question How can I use If or is NULL statement in Shader Graph? [LWRP - Universal - HDRP]

Discussion in 'Shader Graph' started by siberhecy, Sep 2, 2019.

  1. siberhecy

    siberhecy

    Joined:
    Aug 1, 2016
    Posts:
    21
    Hello, I searched but didn't found anything good. Maybe I searched wrong terms, anyways.
    My question is how can I use If statement in Shader Graph?
    For example, I have 2 texture and 1 color property. (_Texture_1, _Normal, _Color)
    If I use anything in _Normal texture property I want to use this texture as normal map in my PBR master.
    Also If I pick any color except White I want to assign this color to my PBR master.
    Hope you understand what I mean, thanks waiting for your answers :)
    Have a nice day.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    There is no such thing as a null in a shader. Well, there is, but it just crashes the GPU if it exists.

    Instead Unity makes sure the is always a valid texture assigned to any texture slot when the GPU renders the shader. For something like a normal texture, you should make sure that texture property is set to use the default "bump" normal texture if none is assigned.

    Now materials themselves can obviously have no texture assigned, and for Unity's custom shaders they use shader #if compilation switches with keywords set using custom material inspectors, but Shader Graph does not currently support those.

    As for the color. You can absolutely test to see if the color is white or not in the shader graph, but realistically it'll be faster to just always multiply the texture by the color value, and use a white default texture.
     
  3. siberhecy

    siberhecy

    Joined:
    Aug 1, 2016
    Posts:
    21
    Thanks for answer, looks like I will create more shaders like; this shader for models which is not have bump map blah blah blah..
     
  4. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    Eons ago and the functionality i will refer might not have existed then. But you could test the Vector 4 from a sample texture node with Any logic and branch based on whether the result is 0 or not (if using default white/grey channel subtract 1 / 0.5 from the vector 4 first then do Any test branching on that)
     
    NightmareS likes this.