Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Right way to disable and skip "Specular Highlights" and "Environment Reflections" on custom shaders?

Discussion in 'Shader Graph' started by Ben_at_Work, Jul 28, 2022.

  1. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    58
    Many of Unity's built in shaders, like the URP/Lit shader, have checkboxes to entirely disable Specular Highlights and Environment Reflections and I'd like to know if Shader Graph can prune those two features to the same degree. Intuitively, zeroing values out would seem like something that could be detected and pruned at build-time, but I'd rather be certain.

    toggleSpecular.PNG

    It's easy enough to set the smoothness, specular, and metallic parameters to zero, or even to delete the nodes from the fragment shader displayed on the graph, but which if either of these will definitively cut those layers from the shader? If zeroing is enough, will it still be recognized with a boolean attached even if it's passing the same zeroed value?

    So to rephrase the question, when, if ever, will Shader Graph entirely skip its specular and reflection layers? Is environment reflection accessible in the same way to begin with?
     
  2. Shaggy21

    Shaggy21

    Joined:
    Oct 2, 2014
    Posts:
    21
    also interested
     
  3. bnmguy

    bnmguy

    Joined:
    Oct 31, 2020
    Posts:
    125
    You can use shader keywords:
    _SPECULARHIGHLIGHTS_OFF
    _ENVIRONMENTREFLECTIONS_OFF
    as boolean keywords. Set them as local shader features in fragment and make sure to check the "exposed" checkbox to allow toggling in the editor. Note enabling these keywords actually turns these features off.
    They don't need to exist in the graph itself, just in the properties panel.
     
    Last edited: Aug 11, 2022
  4. melos_han_tani

    melos_han_tani

    Joined:
    Jan 11, 2018
    Posts:
    77
    I've done this in a shadergraph (in 2021.3.20f1) , but sometimes it seems like a material will ignore one of the settings and randomly flip it. (The inspector for the material will show "Environment Reflections Off" as checked, but reflections will show. Is there some way other scripts/materials could be interfering with this? (There are no scripts on my end that would be setting either keyword). Maybe skybox stuff?
     
    acur97 likes this.
  5. bnmguy

    bnmguy

    Joined:
    Oct 31, 2020
    Posts:
    125
    Check the generated shader code and see what keywords are being set. I'd start there.
     
  6. Ben_at_Work

    Ben_at_Work

    Joined:
    Mar 16, 2022
    Posts:
    58
    For clarity, here's the pattern I use in Shadergraph. The keyword reference may fall out of sync with your display name so double check that those are identical to what was posted above. I use negative tense names to match the actual toggle state.

    lightChannel_01.PNG lightChannel_02.PNG