Search Unity

Questions about Unity Standard shader code

Discussion in 'Shaders' started by ArachnidAnimal, Nov 21, 2017.

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,813
    I'm trying to understand shaders and have some questions.
    Here is the the Unity standard specular shader:
    Code (csharp):
    1.  
    2. Shader "Standard (Specular setup)"
    3.   SubShader
    4.     {
    5.         Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
    6.         LOD 300
    7.  
    8.         // ------------------------------------------------------------------
    9.         //  Base forward pass (directional light, emission, lightmaps, ...)
    10.         Pass
    11.         {
    12.             Name "FORWARD"
    13.         }
    14.         // ------------------------------------------------------------------
    15.         //  Additive forward pass (one light per pass)
    16.         Pass
    17.         {
    18.             Name "FORWARD_DELTA"
    19.         }
    20.         // ------------------------------------------------------------------
    21.         //  Shadow rendering pass
    22.         Pass
    23.         {
    24.             Name "ShadowCaster"
    25.         }
    26.          // ------------------------------------------------------------------
    27.         //  Deferred pass
    28.         Pass
    29.         {
    30.             Name "DEFERRED"
    31.         }
    32.  
    33.         // ------------------------------------------------------------------
    34.         // Extracts information for lightmapping, GI (emission, albedo, ...)
    35.         // This pass it not used during regular rendering.
    36.         Pass
    37.         {
    38.             Name "META"
    39.         }
    40. }//end subshader
    41.  
    In the "META" pass, the code comment says "This pass it not used during regular rendering.".
    What is considered "regular" rendering? Isn't this code automatically executed? If it isn't, what prevents the META pass from being executed?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Technically the names don’t do anything for rendering, they’re there for convenience of code readability, and for UsePass. What maters is each pass’s LightMode tag.

    https://docs.unity3d.com/Manual/SL-PassTags.html

    Each of those named passes has a different LightMode, specifically ForwardBase, ForwardAdd, ShadowCaster, Deferred, and Meta, in that order. The page above describes what each LightMode type is used for. Curiously Meta is not listed on the above page, but is instead documented here:
    https://docs.unity3d.com/Manual/MetaPass.html

    Basically the Meta Pass is not used by the main rendering pipeline, and is generally only used when baking lightmap data in the editor. It’s possible it might get used at runtime for some uncommon situations for Enlighten’s realtime precomputed GI, I don’t know for sure, but certainly not for the average use cases.
     
    ArachnidAnimal likes this.
  3. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,813
    Thanks. Now I understand.