A small program that fits Linearly Transformed Cosine parameters to GGX BRDF. Largely inspired by Eric Heitz's LTC research.
Also accounts for implementation caveats mentioned in the lecture Real-Time Area Lighting: a Journey from Research to Production by Stephen Hill.
For implementation details checkout this blog post.
LCTFit.exe [OPTIONS] SUBCOMMAND
OPTIONS:
-h, --help Print this help message and exit
-d, --output-dir TEXT:DIR [./build/out]
output directory
SUBCOMMANDS:
dist-ggx Print values of GGX BRDF on upper hemisphere to a file
dist-lct Print values of LCT BRDF on upper hemisphere to a file
dist Print values of LCT and GGX on upper hemisphere to files
gen_luts write M matrix and albedo to textures
LCTFit.exe dist-ggx [OPTIONS]
OPTIONS:
-h, --help Print this help message and exit
-r, --res INT [256] sampling resolution of theta and phi
-t, --theta-multiplier FLOAT REQUIRED
theta multiplier. Viewing angle theta_v = multiplier * 0.5 * pi
-u, --roughness FLOAT REQUIRED
roughness
-o, --output TEXT [ggx.dat]
name of output data file
LCTFit.exe dist-lct [OPTIONS]
OPTIONS:
-h, --help Print this help message and exit
-r, --res INT [256] sampling resolution of theta and phi
-m, --m-params FLOAT x 3 REQUIRED
Matrix M parameters. x-scale, x-z shear, y scale
-y, --y-angle FLOAT [0]
Angle of rotation around +y axis, in degrees
-a, --albedo FLOAT [1] albedo parameter
-o, --output TEXT [lct.dat]
name of output data file
LCTFit.exe gen_luts [OPTIONS]
OPTIONS:
-h, --help Print this help message and exit
-t, --theta-multiplier [INT,FLOAT,FLOAT] [64, 0.0, 0.99]
range of theta multiplier: <resolution> <min> <max>
-r, --roughness [INT,FLOAT,FLOAT] [64, 0.03, 1.0]
range of roughness: <resolution> <min> <max>
Data stored in each channel of each texture:
| Description | R | G | B | A | |
|---|---|---|---|---|---|
lut_m.exr |
|
||||
lut_b.exr |
|
||||
lut_bm_0.exr |
|
||||
lut_bm_1.exr |
|
||||
lut_inv_0.exr |
|||||
lut_inv_1.exr |
|||||
lut_norm_inv.exr |
Refer to the blog post for detailed descriptions of these parameters.
LCTFit.exe sample_luts -h sample textures containing M parameters
C:\Users\Liyao\Sources\lct_fitting\build\Release\LCTFit.exe sample_luts [OPTIONS] input_0 input_1
POSITIONALS:
input_0 TEXT:FILE REQUIRED LUT texture containing first 3 parameters of matrix M
input_1 TEXT:FILE REQUIRED LUT texture containing last 2 parameters of matrix M and albedo
OPTIONS:
-h, --help Print this help message and exit
-r, --res INT [256] sampling resolution of theta and phi
-t, --theta-multiplier FLOAT REQUIRED
theta multiplier. Viewing angle theta_v = multiplier * 0.5 * pi
-u, --roughness FLOAT REQUIRED
roughness
-l, --lct-filename TEXT [lct.dat]
name of LCT data file
python3.7.exe .\python\plot_sphere.py -h
usage: plot_sphere.py [-h] [-o OUTPUT] [-v VIEW] datafiles [datafiles ...]
Plot hemispherical distributions
positional arguments:
datafiles Input data file(s)
optional arguments:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output image file for headless mode
-v VIEW, --view VIEW Place camera at "x,y,z", looking at 0,0,0 point
Generate
LCTFit.exe gen_luts
Generated textures will be saved in .\out directory.
Sample .\out\lct.dat
LCTFit.exe sample_luts -t 0.85 -u 0.54 .\out\lut_bm_0.exr .\out\lut_bm_1.exr
Print reference GGX BRDF distribution to data file .\out\ggx.dat:
LCTFit.exe dist-ggx -t 0.85 -u 0.54
Plot GGX and LCT distributions on 2 separate spheres side by side:
python3.7.exe plot_sphere.py .\out\ggx.dat .\out\lct.dat
This command will show an interactive window. Drag around to visually inspect the two distributions from any direction.
If you want to plot these distributions headlessly and save them as an image directly, run
python3.7.exe plot_sphere.py -o distributions.png -v="-10,5,5" .\out\ggx.dat .\out\lct.dat
This command will plot the distributions, place the camera at (-10, 5, 5) and then take a screenshot of the plot and save the screenshot under the name distributions.png.
