<p>Let <span class="math-container">$[\lambda_0, \lambda_1, \lambda_2]$</span> be the barycentric coordinates with respect to triangle <span class="math-container">$v_0$</span>, <span class="math-container">$v_1$</span>, <span class="math-container">$v_2$</span>. In the following all subscripts are taken modulo <span class="math-container">$3$</span>.</p>
<p>For each side <span class="math-container">$s_i$</span> (the edge <span class="math-container">$v_iv_{i+1}$</span>) we can construct functions <span class="math-container">$h_i$</span>. Where <span class="math-container">$$h_i = 1 - \lambda_i - \lambda_{i+1}.$$</span></p>
<p>Then we can create rational blending functions <span class="math-container">$\alpha_i = \frac{h_{i-1}}{h_{i-1} + h_i}$</span> and <span class="math-container">$\beta_i = \frac{h_{i+1}}{h_{i+1} + h_i}$</span>.</p>
<p>By combining these blending functions we can set up the following function for side <span class="math-container">$s_i$</span></p>
<p><span class="math-container">$$e_i = \lambda_i \alpha_i + \lambda_{i+1} \beta_i.$$</span> This function has the following properties. It is <span class="math-container">$1$</span> everywhere on <span class="math-container">$s_i$</span> and <span class="math-container">$0$</span> on all <span class="math-container">$s_j$</span> where <span class="math-container">$i \neq j$</span>. It are singular at the vertices <span class="math-container">$v_i$</span> and <span class="math-container">$v_{i+1}$</span> (division by zero) and on the triangle it is smooth.</p>
<p>We can then interpolate edge values using:</p>
<p><span class="math-container">$$F(\lambda) = \frac{\text{biom}_0 \cdot e_0 + \text{biom}_1 \cdot e_1 + \text{biom}_2 \cdot e_2}{S}$$</span></p>
<p>where <span class="math-container">$S$</span> is the sum of all <span class="math-container">$e_i$</span> in order to normalize the equation (making all functions sum to one). However, given the nice properties of barycentric coordinates in turns out that the sum of <span class="math-container">$e_i$</span> is already <span class="math-container">$1$</span>. The function <span class="math-container">$\alpha_i$</span> and <span class="math-container">$\beta_i$</span> are singular at the vertices, but you said I should not worry about this.</p>
<p>I implemented this in a Shadertoy so you can see what the interpolation looks like:</p>
<p><a href="https://www.shadertoy.com/view/MfsSRs" rel="nofollow noreferrer">https://www.shadertoy.com/view/MfsSRs</a></p>

CC BY-SA 4.0
2024-01-18T10:38:21.193Z
wow, I am very impressed! The only thing I needed to change is: $F = (biom_0*e_1 + biom_1 * e_2 + biom_2 * e_0) / S$ so the equation was not set up for the varying biom index of the question. This is not a bad review, I just wanted to highlight it for others. Thank you very much!! +1
Thomas
CC BY-SA 4.0
2024-01-18T10:52:34.050Z
Indeed, I used an indexing scheme that seemed more natural to me.
Reynolds
CC BY-SA 4.0
2024-01-17T16:03:14.353Z
2024-01-18T21:33:32.310Z
2024-01-18T21:33:32.310Z
Reynolds
<p>Barycentric coordinates of a triangle are very useful for interpolating texture coordinates, for example. Each corner contains the texture coordinate and multiplies this coordinate by the barycentric coordinate. (very simple). Also very useful is that the addition of all 3 components of the barycentric coordinate is always <code>1</code>. The barycentric coordinate is therefore well suited for the interpolation of information based on corner points. But can it also be used to interpolate triangle edge based data instead of vertex based data?</p>
<p><strong>The problem:</strong></p>
<p>I have a triangular mesh that needs to be tessellated in different ways depending on a variable called <code>biome</code>. Within the tessellation control shader, each edge generates a <code>biome</code> number depending on the position and normals of the vertices. The normals are stored per vertex and not per face, so that neighboring faces receive the same normal for common vertices. The neighboring edge of two neighboring triangles will therefore generate the same <code>biome</code> number.
This is very important as otherwise holes will appear during the evaluation shader.
These <code>biome</code> numbers are stored in the following way:</p>
<p>A varying <code>vec3</code> patch variable contains the 3 <code>biom</code> numbers. The number generated by vertex0 and vertex1 is stored under index [2]. The number generated by vertex1 and vertex2 is stored under index [0]. And vertex0 and vertex2 is stored in index <a href="https://i.sstatic.net/pp9ko.png" rel="nofollow noreferrer">1</a>. In comparison to <code>gl_TessCoord</code>, the biome number of the edge is therefore stored in the opposite corner.
The tessellation evaluation shader receives the barycentric coordinates via the <code>gl_TessCoord</code> vector. So this is the point where I want to start.</p>
<p>Now I am looking for an algorithm that performs the interpolation between the edges.</p>
<p>An image shows more than 1000 words...</p>
<p><a href="https://i.sstatic.net/pp9ko.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pp9ko.png" alt="enter image description here" /></a></p>
<p>Within this triangle, the edges should retain their biome numbers (no interpolation at the edges), and the area in between should be an interpolation of the numbers.</p>
<p>So, as with barycentric coordinates, the sum of the weights should be around 1.</p>
<p>I know that the vertices are not defined within the interpolation. That will be handled later... so don't think about it.</p>

<interpolation>
triangle barycentric coordinates interpolate edge dependent
Thomas
# triangle barycentric coordinates interpolate edge dependent

(Asked by: username_0 on 2024-01-17)

Barycentric coordinates of a triangle are very useful for interpolating texture coordinates, for example. Each corner contains the texture coordinate and multiplies this coordinate by the barycentric coordinate. (very simple). Also very useful is that the addition of all 3 components of the barycentric coordinate is always `1`. The barycentric coordinate is therefore well suited for the interpolation of information based on corner points. But can it also be used to interpolate triangle edge based data instead of vertex based data?

**The problem:**

I have a triangular mesh that needs to be tessellated in different ways depending on a variable called `biome`. Within the tessellation control shader, each edge generates a `biome` number depending on the position and normals of the vertices. The normals are stored per vertex and not per face, so that neighboring faces receive the same normal for common vertices. The neighboring edge of two neighboring triangles will therefore generate the same `biome` number.
This is very important as otherwise holes will appear during the evaluation shader.
These `biome` numbers are stored in the following way:

A varying `vec3` patch variable contains the 3 `biom` numbers. The number generated by vertex0 and vertex1 is stored under index [2]. The number generated by vertex1 and vertex2 is stored under index [0]. And vertex0 and vertex2 is stored in index [1](https://i.sstatic.net/pp9ko.png). In comparison to `gl_TessCoord`, the biome number of the edge is therefore stored in the opposite corner.
The tessellation evaluation shader receives the barycentric coordinates via the `gl_TessCoord` vector. So this is the point where I want to start.

Now I am looking for an algorithm that performs the interpolation between the edges.

An image shows more than 1000 words...

[![enter image description here](https://i.sstatic.net/pp9ko.png)](https://i.sstatic.net/pp9ko.png)

Within this triangle, the edges should retain their biome numbers (no interpolation at the edges), and the area in between should be an interpolation of the numbers.

So, as with barycentric coordinates, the sum of the weights should be around 1.

I know that the vertices are not defined within the interpolation. That will be handled later... so don't think about it.

**Tags:** interpolation


---

## 1 answers

### Answer by username_1 on 2024-01-17. Score: 2 | Accepted answer

Let $[\lambda\_0, \lambda\_1, \lambda\_2]$ be the barycentric coordinates with respect to triangle $v\_0$, $v\_1$, $v\_2$. In the following all subscripts are taken modulo $3$.

For each side $s\_i$ (the edge $v\_iv\_{i+1}$) we can construct functions $h\_i$. Where $$h\_i = 1 - \lambda\_i - \lambda\_{i+1}.$$

Then we can create rational blending functions $\alpha\_i = \frac{h\_{i-1}}{h\_{i-1} + h\_i}$ and $\beta\_i = \frac{h\_{i+1}}{h\_{i+1} + h\_i}$.

By combining these blending functions we can set up the following function for side $s\_i$

$$e\_i = \lambda\_i \alpha\_i + \lambda\_{i+1} \beta\_i.$$ This function has the following properties. It is $1$ everywhere on $s\_i$ and $0$ on all $s\_j$ where $i \neq j$. It are singular at the vertices $v\_i$ and $v\_{i+1}$ (division by zero) and on the triangle it is smooth.

We can then interpolate edge values using:

$$F(\lambda) = \frac{\text{biom}\_0 \cdot e\_0 + \text{biom}\_1 \cdot e\_1 + \text{biom}\_2 \cdot e\_2}{S}$$

where $S$ is the sum of all $e\_i$ in order to normalize the equation (making all functions sum to one). However, given the nice properties of barycentric coordinates in turns out that the sum of $e\_i$ is already $1$. The function $\alpha\_i$ and $\beta\_i$ are singular at the vertices, but you said I should not worry about this.

I implemented this in a Shadertoy so you can see what the interpolation looks like:

<https://www.shadertoy.com/view/MfsSRs>

> **Comments:**
> **username_0**: wow, I am very impressed! The only thing I needed to change is: $F = (biom_0*e_1 + biom_1 * e_2 + biom_2 * e_0) / S$ so the equation was not set up for the varying biom index of the question. This is not a bad review, I just wanted to highlight it for others. Thank you very much!! +1  
> **username_1**: Indeed, I used an indexing scheme that seemed more natural to me.  

---

