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

Question Setting RendererSettings.ambientProbe changes its value

Discussion in 'Global Illumination' started by waxx, Nov 18, 2022.

  1. waxx

    waxx

    Joined:
    Apr 1, 2013
    Posts:
    48
    Pretty much what the subject line says.

    This code:

    Code (CSharp):
    1. Debug.Log($"Probe[0, 0] = {RenderSettings.ambientProbe[0, 0]}");
    2. var oldProbe = RenderSettings.ambientProbe;
    3. Debug.Log($"Probe[0, 0] = {oldProbe[0, 0]}");
    4. RenderSettings.ambientProbe = oldProbe;
    5. Debug.Log($"Probe[0, 0] = {RenderSettings.ambientProbe[0, 0]}");
    Produces the following results:

    I'm on URP 12.1.7. Why? I'm trying to serialize and pre-bake my ambientProbes for a couple of skyboxes we're using in-game so I don't have to update GI.
     
  2. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    248
    Hmm, I took a look at the code behind RenderSettings.ambientProbe, and the current behavior is indeed pretty unintuitive:

    When using
    RenderSettings.ambientMode == AmbientMode.Skybox
    :
    If you set
    RenderSettings.ambientProbe = myProbe;
    , the value you will read back from
    RenderSettings.ambientProbe
    is given by
    myProbe * GammaToLinearSpace(RenderSettings.ambientIntensity)
    , where
    GammaToLinearSpace
    is a conversion from gamma to linear color space.

    When using
    RenderSettings.ambientMode == AmbientMode.Custom
    :
    If you set
    RenderSettings.ambientProbe = myProbe;
    , the value you will read back from
    RenderSettings.ambientProbe
    is exactly
    myProbe
    .

    In other words, this strange behavior should only be happening if you have
    RenderSettings.ambientIntensity
    set to a value that isn't exactly 1 (since 1 is the same in gamma and linear space), and you have
    RenderSettings.ambientMode
    set to
    AmbientMode.Skybox
    . Could you verify that this is the case? If the behavior you observe doesn't match what I've written here, it's probably down to difference between Unity versions. Please note which version of Unity you are using. The solution is probably to use
    AmbientMode.Custom
    .

    I'd consider this a bug, and will report it internally.
     
  3. waxx

    waxx

    Joined:
    Apr 1, 2013
    Posts:
    48
    That is indeed the setup I'm running. Thank you for looking into this and shedding some light (pun not intended) on the issue!
     
    Pema-Malling likes this.