<p>A simple table could be a good choice. There are a few approach's the suggestion I'll put here is just my take on the description, but it can be tweaked to your needs. In psuedocode:</p>
<pre><code>const float table[6] = {0,60,30,20,18,5};
int table_index = asInt(floor(theta/15.0));
float result = table[table_index] * (theta &gt; range);
</code></pre>
<p>The above is implemented as the step function in increments of 15. The last bit of the result is a range check that can be used to zap out of range values. <code>(theta&gt;range)</code> evaluates to zero or one.</p>
<p>If this is a total miss on what you need let me know and I'll tweak it to help get closer.</p>

CC BY-SA 4.0
2021-07-17T13:23:31.313Z
2021-07-17T13:23:31.313Z
pmw1234
<p>I am trying to use the techniques discussed in <a href="https://diglib.eg.org/bitstream/handle/10.2312/EGWR.EGWR03.167-177/167-177.pdf?sequence=1&amp;isAllowed=y" rel="nofollow noreferrer">this</a> paper to implement a BTF into PBRT. I am stuck on how to actually interpolate the weights of the four closest sampling directions.</p>
<p>At the BTF, I have converted <span class="math-container">$w_o$</span> and <span class="math-container">$w_i$</span> from cartesian to spherical coordinates in order to do a lookup in the table of BTFs. The samples are taken with the following properties:</p>
<p><span class="math-container">$\theta$</span> light (and view angles) range from 0 to 75 in 15 degree increments. <span class="math-container">$\Delta\phi$</span> at each <span class="math-container">$\theta$</span> goes from 0 to (360 - <span class="math-container">$\Delta\phi$</span>) at -, 60, 30, 20, 18 and 5 degree increments respectively. In a table:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;"><span class="math-container">$\theta$</span></th>
<th style="text-align: center;"><span class="math-container">$\Delta\phi$</span> (0 - (360 - <span class="math-container">$\Delta\phi$</span>))</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">0</td>
<td style="text-align: center;">-</td>
</tr>
<tr>
<td style="text-align: left;">15</td>
<td style="text-align: center;">60</td>
</tr>
<tr>
<td style="text-align: left;">30</td>
<td style="text-align: center;">30</td>
</tr>
<tr>
<td style="text-align: left;">45</td>
<td style="text-align: center;">20</td>
</tr>
<tr>
<td style="text-align: left;">60</td>
<td style="text-align: center;">18</td>
</tr>
<tr>
<td style="text-align: left;">75</td>
<td style="text-align: center;">5</td>
</tr>
</tbody>
</table>
</div>
<p>How can I determine the four closest sampling directions given <span class="math-container">$w_o$</span> and <span class="math-container">$w_i$</span>? Retrieving the values/weights seems trivial, but I don't really have a clue on how to determine the four nearest directions and just don't know where to start.</p>

<brdf><sampling><pbrt>
BTF Find Four Closest Sampling Directions
Dave
# BTF Find Four Closest Sampling Directions

(Asked by: username_0 on 2021-07-16)

I am trying to use the techniques discussed in [this](https://diglib.eg.org/bitstream/handle/10.2312/EGWR.EGWR03.167-177/167-177.pdf?sequence=1&isAllowed=y) paper to implement a BTF into PBRT. I am stuck on how to actually interpolate the weights of the four closest sampling directions.

At the BTF, I have converted $w\_o$ and $w\_i$ from cartesian to spherical coordinates in order to do a lookup in the table of BTFs. The samples are taken with the following properties:

$\theta$ light (and view angles) range from 0 to 75 in 15 degree increments. $\Delta\phi$ at each $\theta$ goes from 0 to (360 - $\Delta\phi$) at -, 60, 30, 20, 18 and 5 degree increments respectively. In a table:

| $\theta$ | $\Delta\phi$ (0 - (360 - $\Delta\phi$)) |
| --- | --- |
| 0 | - |
| 15 | 60 |
| 30 | 30 |
| 45 | 20 |
| 60 | 18 |
| 75 | 5 |

How can I determine the four closest sampling directions given $w\_o$ and $w\_i$? Retrieving the values/weights seems trivial, but I don't really have a clue on how to determine the four nearest directions and just don't know where to start.

**Tags:** brdf, sampling, pbrt


---

## 1 answers

### Answer by username_1 on 2021-07-17. Score: 0

A simple table could be a good choice. There are a few approach's the suggestion I'll put here is just my take on the description, but it can be tweaked to your needs. In psuedocode:

```
const float table[6] = {0,60,30,20,18,5};
int table_index = asInt(floor(theta/15.0));
float result = table[table_index] * (theta > range);

```

The above is implemented as the step function in increments of 15. The last bit of the result is a range check that can be used to zap out of range values. `(theta>range)` evaluates to zero or one.

If this is a total miss on what you need let me know and I'll tweak it to help get closer.


---

