Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Invalid light probe cells and minimum light probe distance

Discussion in 'Global Illumination' started by olejuer, Oct 21, 2021.

  1. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    210
    Hi everybody,

    I have some troubles setting up light probes. The result I get are jumpy transitions in lighting and light probes that are entirely ignored. I am looking for advice and more information. Thanks!

    I have observed two things I don't understand:

    Grid and minimum distance
    It seems there is a kind of grid with a spacing of 0.01 units on which light probes are placed. Below a distance of 0.06 units, light probes seem to disappear. I could not find any documentation on this and whether it is possible to change this behavior . My project has a small scale and requires precise placement of light probes.
    I can reproduce this in Unity 2020.1 and 2021.1

    Invalid cells
    Under certain circumstances, light probe cells become invalid and the cell is displayed with red lines. In the lighting window we can toggle this in the workflow settings. The tooltip says that these cells cannot be used for interpolation. I don't understand the conditions under which a cell becomes invalid and what exactly the consequences are and I could not find any documentation on this. It seems to happen for particularly small cell volumes.
    I can reproduce this in Unity 2020.1, but not in 2021.1

    upload_2021-10-21_10-58-19.png
    Screenshot 1: Light probe gizmos show the configured positions. The rendered light probes differ: One is missing and one is moved to snap to a grid. The red lines hint at an invalid light probe cell


    upload_2021-10-21_10-51-52.png
    Screenshot 2: the red lines in the light probe cell highlight an invalid cell which is apparently not suited for interpolation. This seems to happen when the cell is very thin or elongated.
     
    Last edited: Oct 21, 2021
    AntonioModer likes this.
  2. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    1,080
    Hello! I would suggest reading through the following thread regarding probe positioning issues: https://forum.unity.com/threads/objects-pick-wrong-light-probes.964250/

    As for the Highlight Invalid Cells option not working; I suspect that this is a bug with the visualization, as opposed to probe tetrahedralization. Could you please submit a bug report so that we could investigate? Thanks!
     
  3. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    210
    Hi @kristijonas_unity

    thanks for your response!
    I read through the thread and I don't think it is relevant, because it covers the selection of baked lightprobes. Here, lightprobes that are too close to each other are discarded during baking.

    Also the grid snapping still eludes me.

    About the invalid cells, I don't think it's a bug. I think the cells are in fact invalid because of their small volume. I just would like to learn about the underlying logic.

    So my questions are
    1. Can I change the minimum distance that lightprobes must have to be baked?
    2. Can I change the spacing of the grid to which lightprobes are snapped when being baked?
    3. When exactly are lightprobe cells considered to be invalid?
    4. Should I prevent having any invalid lightprobe cells, or is it okay as long as they are surrounded by valid cells?

    I ask these questions because there is no mentioning of these aspects in the documentation nor could I find anything about this in the forums.

    Thanks!
     
  4. rasmusn

    rasmusn

    Unity Technologies

    Joined:
    Nov 23, 2017
    Posts:
    99
    Those are great questions. I had to think for a while and look through our code but I think I now have the answers.

    First, a little background. As you probably know Unity (like most engines) use a floating point representation to represent real numbers (e.g. coordinates for probes). As you may also already know, a problem with the floating point representation is that it gets less accurate the farther you go from 1 (loosely formulated). For example, 1.0 + 2.0 has high accuracy but 0.00001 + 0.00002 and 10000000.0 + 20000000.0 does not. This is not due to bad code, it is simply a consequence of the representation. In general there are various ways to deal with this, but one commonly used approach in games is simply to avoid tiny and/or huge numbers in the first place. Please forgive me if you already knew this, I just had to make sure we were on the same page.

    Another Unity and probe specific thing to be aware of is that Unity quantizes probe positions, i.e. snaps them to a very fine grid as you mention yourself. This is because the procedure we use to calculate the tetrahedralization (the structure used for interpolation) doesn't deal well with tiny differences in coordinates. The reason for this that this procedure uses floating point numbers as well and these don't work well with small numbers (as explained above). So Unity's solution for now is to quantise probe positions so you ensure some minimum distance between probes. If you follow the general advice that you should try to avoid tiny or huge numbers, then this approach works fine.

    1. Can I change the minimum distance that lightprobes must have to be baked?
    2. Can I change the spacing of the grid to which lightprobes are snapped when being baked?

    Since snapping happens as part of baking I think it makes sense to answer both of these at once.

    No, you cannot. And I'd like to stress that this is primarily because of the fundamental limitation of floating point numbers. Theoretically there are ways around it (using more bits to increase precision, using fixed point representation, etc.) but these would entail other drawbacks (e.g. bad performance).

    What you can do however, is to avoid tiny numbers in the first place. This is not ideal, I know.

    3. When exactly are lightprobe cells considered to be invalid?
    Based on my understanding of the Unity source code, a tetrahedron (i.e. "a 4 probe pyramid") is invalid if its volume is very small (approximately less 0.001). This situation can happen if some or all of the involved probes are really close together. Again, this is very much related to the inaccurate nature of small numbers represented with floating point. For example, imagine you are calculating the volume of the tetrahedron spanned by the 4 nearby probes. This involves mathematical computation (multiplication, addition, etc.). Since all these operations become more and more inaccurate for smaller and smaller numbers, that means there must be a given threshold below which the calculation is so inaccurate that it is no longer meaningful. Therefore we must have a limit like this (as long as we are using floating point representation at least).

    You can find more information in the presentation below but it is somewhat technical and I cannot guarantee you that everything is up to date with the current implementation.
    https://ubm-twvideo01.s3.amazonaws.com/o1/vault/gdc2012/slides/Programming Track/Cupisz_Robert_Light_Probe_Interpolation.pdf

    4. Should I prevent having any invalid lightprobe cells, or is it okay as long as they are surrounded by valid cells?
    It is OK in the sense that you will be able to sample something from the probe structure. However, generally it is a red flag which suggest that lighting quality will suffer and you should try to fix it.

    My advice to you would be:
    1. Find a way to avoid tiny numbers. Instead of regarding Unity coordinates as meters, perhaps think of them as milli or micrometers. That allows you scale up your entire scene and this avoids tiny numbers. Try to pick the unit that matches whatever it is that you are modelling such that you end up working in the ranges of 0.01 - 10000.
    2. Avoid oblong or flat tetrahedra. You can do this by avoiding to place probes very close together.
    If you follow this advice I think your issues will go away. I hope this advice works for you.
     
    Last edited: Oct 29, 2021
    JKort, olejuer and kristijonas_unity like this.
  5. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    210
    Hi @rasmusn ,

    thank you so much for this expansive explanation!
    I am aware of floating point precision and can absolutely understand that this leads to the limitations you mention. I just didn't expect to encounter this already at values of 0.01. But since the tetrahedralization will further divide the distances for interpolation it does make sense.
    I think technically it would be possible to make the engine use a scaling factor internally before baking. But I understand that it wouldn't be an easy task to implement this. I was just hoping there might already be such a thing.

    It feels like I simply chose a bad scaling for my project. It is a VR project and the distances I describe arise naturally from the setting: a tabletop game world. Such a scene easily spans a broad range of distances, from millimeters to several meters, so it's a challenge to find the right units of measurement for the project. In this case, centimeteres would have been a better choice than meters.

    Unfortunately, increasing the scale of the project at this late stage is quite difficult to do. Many things do not behave nicely when it comes to rescaling, such as particle systems, shadows and quality settings, custom scripts, plugins, ...

    I will just have to take extra care with the lightprobe placement to make it work. Your information will help with this, so thanks again!
     
    rasmusn likes this.