aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 70bc332dd8d6f16183676ecbbcf3612e4a7805f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Median Cut

The median cut algorithm is a method to deterministically sample an environment
map. This is achieved by splitting the environment map along the longest
dimension so that there is equal energy in both halves. This is repeated _n_
times recursively in each partition. Once there have been _n_ iterations, the
lights are placed in the centroid of each region. Below is an example with 6
splits, meaning there are 2^6 = 64 partitions.

![median cut](/data/median_cut6.jpg)

The average colour of each region is assigned to each light source that was
created in each region.

![median cut lights](/data/median_cut_radiance6.png)

Finally, these discrete lights can be used to light diffuse objects efficiently,
by only having to sample a few lights.

![lighting](/data/simple_sphere64.png)

## Build and run

To compile and run, one has to first download
[stack](https://docs.haskellstack.org/en/stable/README/)

The simplest way to do this is by executing the following command:

```
curl -sSL https://get.haskellstack.org/ | sh
```

Then run setup in this directory:

```
stack setup
```

Finally the executable can be built and run using the following:

```
stack build --exec median-cut
```

This project relies on a open source library that I wrote to load 
PFM files which is hosted at [PFM](https://github.com/ymherklotz/pfm).
It will automatically get downloaded when built with stack.