Search Unity

Question Baking lights and custom shaders

Discussion in 'Global Illumination' started by agus_r, Sep 20, 2022.

  1. agus_r

    agus_r

    Joined:
    Oct 8, 2020
    Posts:
    15
    Hi, I have been writing my own shaders that are basically modifications of the standard shaders, nothing fancy, but I combine noise with textures so that walls in the environment look dirty, etc. I also bake the lighting, so I wonder, how does Unity deal with custom shaders when baking light?
    My understanding is that in order to get the right lighting, when determining the light bounces on the different objects, you need the information of the albedo, normals, smoothness, metallicity, etc. of the material the light is bouncing on, at that specific location. So you'll need to compute the shader there, is this actually computed during the baking process? or does Unity use default values of smoothness, and other parameters? What about if I modify the vertex shader so that the triangle changes its location? this is going to mess with the triangle tree optimizations, is the vertex shader also taken into account?
    And if I use an interior mapping shader, is the baked lighting going to look right?
    Thanks in advance
     
  2. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    328
    Custom Shaders can provide inputs to the lighting system via a special shader pass known as the 'Meta Pass'. It affects both fully baked and realtime GI. The pass determines how the shaded object will look from the light bakers point of view. Relevant doc page is here https://docs.unity3d.com/Manual/MetaPass.html

    For shadows (rendering to the camera's depth buffer) those are handled in the 'ShadowCaster' pass. Example near the bottom of this page https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html