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:
- 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.
- 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.