How to use the fitted data

# Overview

In http://www-evasion.imag.fr/Membres/Antoine.Bouthors/research/phd/thesis/tables/ you will find the following files:

- Matlab files (fit_*.mat) containing the fitted parameters for the simulation data, see below

- Text files (Mie*.txt) containing the phase function used.

- Mie0.txt represents the chopped peak of the Mie phase function, i.e., Ppeak(Θ) (equation A.1 in the thesis)
- MiePF3.txt represents the chopped Mie phase function, i.e., Pchopped(Θ) in RGB format (equation A.3 in the thesis)

I am not sure whether these functions are normalized or not. I advise you to re-generate them using MiePlot, with the parameters described in appendix A.

- The other text files are simply interpolated values of the fitted parameters contained in the matlab files. I won't describe them here, I suggest you regenerate these as you see fit from the matlab files (see below)

# Fitted parameters

Here is what the matlab files contain in detail:

- The files fit_o*.mat contain the fitted parameters for the BSDF, i.e., the equations in §5.4 of the thesis.
- The files fitXZ8_o*.mat contain the fitted parameters for the moments of the spatial distribution, i.e., the equations in §5.3 of the thesis.
- The numbers in the file names corresponds to the orders of scattering that where fitted (under the form n+1). fit_o1.mat contains the fitted parameters for order 2. fitXZ8_o6-8.mat contains the fitted parameters for the orders [7,9]. fit_o15p.mat contains the fitted parameters for the orders [16,∞], etc.

## BSDF parameters

When you open the matlab files for the BSDF parameters (fit_o*.mat), you will find the following variables in the workspace. All the variables follow the same "table of control points" format.

### Peak value

- The variable 'a' contains the fitted values for A1(n, z1, θ) (used in equation 5.48 in the thesis). It the I3D paper, it corresponds to A(t, μV). It is a table of control points. Each row of the table is a control point. Each control point has 3 values:

- z1 (in meters)
- θ (under the form -cos(θ) I believe, i.e., μV in the I3D paper)
- A1

For example if you open fit_o2.mat, and read [50,-0.6,0.039801] in the 3rd row, that means A1( n=3, z1=50m, θ=cos-1(0.6) ) = 0.039801. And so on.
Note there is a discontinuity around θ=90°. That is normal and expected.

- The variable 'x' contains the fitted values for A2(n, z1, θ') (used in equation 5.48 in the thesis). It the I3D paper, it corresponds to X(t, μL). Each control point has 3 values:

- z1 (in meters)
- θ' (under the form cos(θ') I believe, i.e., μL in the I3D paper)
- A2

For example if you open fit_o2.mat, and read [50,0.2,1.904] in the 3rd row, that means A2( n=3, z1=50m, θ'=cos-1(0.2) ) = 1.904. And so on.
Note that A2 is normalized so that A2(n, z1, 0) = 1, as explained in the thesis. Also, θ' ranges from 0° to 90° (whereas θ ranges from 0° to 180°), which is normal since the slab can only be lit from above.

### Peak location

- The variable 'b1' contains the fitted values for B1(n, z1, θ) (used in equation 5.49 in the thesis). It the I3D paper, it corresponds to B1(t, μV). Each control point has 3 values:

- z1 (in meters)
- θ (under the form -cos(θ) I believe, i.e., μV in the I3D paper)
- B1

For example if you open fit_o2.mat, and read [50,-0.6,9.2099] in the 3rd row, that means B1( n=3, z1=50m, θ=cos-1(0.6) ) = 9.2099. And so on.

- The variable 'b2' contains the fitted values for B2(n, z1, θ') (used in equation 5.49 in the thesis). It the I3D paper, it corresponds to B2(t, μL). Each control point has 3 values:

- z1 (in meters)
- θ' (under the form cos(θ') I believe, i.e., μL in the I3D paper)
- B2

For example if you open fit_o2.mat, and read [50,0.2,26.066] in the 3rd row, that means B2( n=3, z1=50m, θ=cos-1(0.2) ) = 26.066. And so on.

### Broadness

- The variable 'c' contains the fitted values for C(n, z1, θ) (used in equation 5.50 in the thesis). It the I3D paper, it corresponds to C(t, μV). Each control point has 3 values:

- z1 (in meters)
- θ (under the form -cos(θ) I believe, i.e., μV in the I3D paper)
- C

For example if you open fit_o2.mat, and read [50,-0.6,18.529] in the 3rd row, that means C( n=3, z1=50m, θ=cos-1(0.6) ) = 18.529. And so on.

### Logarithmic behavior

- The variable 'd' contains the fitted values for D(n, z1, θ) (used in equation 5.51 in the thesis). It the I3D paper, it corresponds to D(t, μV). Each control point has 3 values:

- z1 (in meters)
- θ (under the form -cos(θ) I believe, i.e., μV in the I3D paper)
- D

For example if you open fit_o2.mat, and read [50,-0.6,631.07] in the 3rd row, that means D( n=3, z1=50m, θ=cos-1(0.6) ) = 631.07. And so on.

### Anisotropy

- The variable 'p' contains the fitted values for P(n, Θ) (used in equation 5.52 in the thesis). It the I3D paper, it corresponds to P(θ). Each control point has 3 values:

- z1 (in meters)
- Θ (under the form cos(Θ) I believe)
- P

Note there is an inconsistency here: although in the thesis and paper we say that P does not depend on z1, we have z1 as a parameter in the tables. This is simply due to the fact that the fitting was done per slab thickness. If you observe the data, you will note that the values for P are actually almost identical for a given Θ, regardless of z1. This is a nice validation of our assumption that P does not depend on z1. In consequence, to read the value for P, you can either read the values of P for an arbitrary z1, or read P for all values of z1 and take the average. I think we did the latter.
For example if you open fit_o2.mat, and read

- [50, -0.5, 2.2514] in the 3rd row,
- [100, -0.5, 2.0483] in the 12th row,
- [200, -0.5, 2.0575] in the 21st row,
- [250, 0.5, 2.0711] in the 30th row,
- [300, -0.5, 2.0132] in the 39th row,
- [400, -0.5, 2.0722] in the 48th row and
- [500, -0.5, 2.0974] in the 57th row,

that means P( n=3, Θ=cos-1(0.5) ) = 2.0873. And so on.
Finally, note that there is no data for P(n=[16,∞], Θ). This is normal: these orders are isotropic, therefore P(n=[16,∞], Θ)=1 everywhere, as explained in the thesis.

## Spatial distribution parameters

### Notes

- The matlab files for the spatial distribution parameters (fitXZ8_o*.mat) follow the exact same "table of control points" style as for the BSDF. I will therefore be more concise here.

- The main issues in using this data are

- The names of the parameters differ between the matlab variables, thesis functions and I3D functions. Serious headache in perspective.

- The functions for the second moment in the thesis and I3D paper are wrong.
- Some of the data is missing in the matlab files (thus I have written it in this document).

- I would also like to remind you that z' is the viewpoint depth: z'=z1-z (thesis p. 114).

- Finally, bear in mind that P(n) (equation 5.26) is not at all the same function than P(n, Θ) (equation 5.52). Similarly, g in equations 5.11 and 5.17 is not the assymetry parameter of the phase function. This is just the result of a poor naming convention.

### First moment

Matlab variable | Thesis function equivalent | Control points | I3D paper function equivalent
b | O(n, μ, μ') (eq.5.24) | Column 1&2: -μ (i.e., μV in the I3D paper), Column 3: μ', Column 4: O | N(μV, μL)
c | I(n, μ) (eq.5.19) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: I | I(μV)
d | M(n, μ) (eq.5.23) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: M | M(μV)
e | E(n, μ) (eq.5.15) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: E | E(μV)
j | G(n, μ) (eq.5.20) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: G | G(μV)
k | F(n, μ) (eq.5.16) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: F | F(μV)
l | H(n, μ) (eq.5.18) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: H | H(μV)
u | K(n, μ) (eq.5.21) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: K | K(μV)
v | L(n, μ) (eq.5.22) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: L | L(μV)
w | J(n, μ) (eq.5.20) | Column 1: -μ (i.e., μV in the I3D paper), Column 2: J | J(μV)

### Second moment

The equation 5.25 in the thesis should be
σ(n, z1, z, θ, ψ, θ') = p + q z1 log(1 + rz') + s log(1 + tz1), n=[16,∞]
σ(n, z1, z, θ, ψ, θ') = Sa + Sb log(1 + Sc z'), n<16
With these equations, the data for n=[16,∞] is not present in the matlab files. Here are the values:
P(n=[16,∞]) = 171.0
Q(n=[16,∞]) = 0.1645
R(n=[16,∞]) = 0.002321
S(n=[16,∞]) = 504.6956
T(n=[16,∞]) = 0.00096153
For n<16, the parameters Sa, Sb, Sc are defined by the scalar variables sa, sb, and sc in the matlab files.

# Values outside the control points

The parameters have been fitted only for the given control points. To compute the value of a parameter outside the control points, you have to interpolate. The choice of the interpolation method is important, as it will give different results. We used the linspace() matlab function to sample uniformly the domain, then interpolated using interp1() for 1D data and griddata() for 2D data. Although it is tempting to use a cubic or spline interpolation method to get smooth variations, these are bad choices as they result in overshoots. Thus we interpolated all the data using the linear method, which gave satisfactory results. Care must be taken to interpolate finely enough so that the discontinuities are not smoothed out.
The data in the .txt files was directly created from the matlab files by interpolation. The files *Params*.txt contain the min and max bounds of the domain over which we did the interpolation. I advise you to re-create your own tables, though.
The program used to create the videos directly reads these text files and converts them into OpenGL textures. The equations are then computed in a GLSL shader, using the textures. I strongly advise you to validate your code against a basic slab before trying it out on other shapes.
Antoine Bouthors