Search Unity

Use the META pass in skybox shader

Discussion in 'Shaders' started by djancool, Aug 27, 2021.

  1. djancool

    djancool

    Joined:
    May 1, 2016
    Posts:
    6
    Hello all,

    I am using a custom skybox shader and is it possible to use the meta pass for the skybox so the lightbaker could use different settings etc. for baking.

    thanks in advanced for any help!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    It is not possible, no.

    You can however set the skybox to whatever you want it to be during baking, then swap the skybox to something else at runtime. You just can't use the auto generate option in the lighting panel as changing the skybox will restart the light baking.

    Alternatively you could override the skybox with a script component during play mode, which won't restart the lightmap baking. But it means it'll be using the "baking" skybox while you're editing the scene.
    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ReplaceSkybox : MonoBehaviour
    6. {
    7.     public Material skyboxReplacementMaterial;
    8.  
    9.     void OnEnable()
    10.     {
    11.         if (skyboxReplacementMaterial != null)
    12.             RenderSettings.skybox = skyboxReplacementMaterial;
    13.     }
    14. }