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.

Official Strict shader variant matching

Discussion in '2022.1 Beta' started by aleksandrk, Sep 7, 2021.

  1. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,739
    Hello Unity alpha users!

    By default, when a shader variant is not found in the player build, Unity silently picks a "close enough" variant from the available ones. This has a potential to hide bugs in the keyword setup.
    Unity 2022.1 has a new checkbox in player settings, "Strict shader variant matching", that can be used to alter this behaviour. If this setting is enabled and a variant is not found by the player, an error is printed in the console, specifying the shader, subshader index, pass and keywords that were used for variant search, and error shader is used for rendering.
    This setting is intended as a simple validation layer that reveals keyword setup mistakes. By default it's disabled.

    Happy debugging! :)
     
  2. Kleptine

    Kleptine

    Joined:
    Dec 23, 2013
    Posts:
    211
    Hah! I discovered the 'fallback' earlier this year while tracking down a particularly nasty shader bug.
    https://uninomicon.com/shaderkeyword

    It'd be nice if the fallback mechanism were documented. How does it choose? Even better to have a warning like "Shader [Keywords] is missing. Falling back to Shader [Keywords]. Renderer [objectpath]". As is it's rather hard to identify when it happens.
     
    Jes28 likes this.
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,739
    That's not a fallback, it's a consequence of having global keywords.

    This is the second keyword system improvement (the first one is here). We want to introduce strict rules for resolving keyword conflicts, and make fixing keyword issues easier, but this will come later.
     
  4. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    44
    Great! Is there any plan to give this feature to 2020.3.x LTS?
     
  5. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,739
    No.
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Here's a thought - can we specify an "error shader" of our own? Having that control over default fallback is an even safer way to manage this new option. A use case scenario is that the developer wants to manage it strictly but one falls through the net. The dev can identify it but the gamer just thinks "oh, generic wall".

    Revenue unaffected, everyone happy and it's silently fixed by the dev in the know.
     
    Peter77 and ImpossibleRobert like this.
  7. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,739
    I tried this recently for Hybrid... turns out it's not as easy as it sounds :)
    Error shader is quite special, and is treated by the code as such.
     
    hippocoder likes this.