Search Unity

Question How to set a single environmental lightprobe?

Discussion in 'Global Illumination' started by joze05, Sep 30, 2021.

  1. joze05

    joze05

    Joined:
    Jun 24, 2019
    Posts:
    5
    I'm working on an algorithm which estimates the environmental lighting of a real world scene. The algorithm returns back the 27 values SphericalHarmonicsL2 probe.
    How can I use these values, to light a virtual scene?
    I have already removed all of the world lighting (skybox,...) in the Windows->Rendering->Lighting window.
     
  2. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    328
    Hey there,

    You should be able to set
    RenderSettings.ambientProbe
    to your desired SphericalHarmonicsL2 object. You'll probably also want to set
    RenderSettings.ambientMode
    to
    AmbientMode.Custom
    to avoid issues related to the skybox.

    That should work fine in playmode, but might seem to 'flicker' in the editor. That's a known issue, and if you run into it you should be able to solve it by just baking lighting once (Window > Rendering > Lighting > Generate Lighting).

    Let me know if this helps :)
     
  3. joze05

    joze05

    Joined:
    Jun 24, 2019
    Posts:
    5
    Thank you so much for the reply.
    In the meantime I ended up writing my own shader, where I set the vertex light (color) from the environment probe and the per-vertex-probe (which is also calculated during the light estimation).

    Anyway...setting the ambientProbe is possible during runtime? Could one also set multiple light probes, similar to light probe groups. I have to add, this is for an AR app running on Android, where I want to achieve coherent rendering of the virtually added objects in my RL-scene.
     
  4. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    328
    There is just one ambient probe, and that can indeed be changed dynamically. For light probe groups, you can change the SH coefficients by accessing
    LightmapSettings.lightProbes.bakedProbes
    which is just an array of SphericalHarmonicsL2.
     
    joze05 likes this.