<p>Points in front of the camera have <span class="math-container">$w &gt; 0$</span> strictly, by definition. I would say that if clipping is giving you points with <span class="math-container">$w = 0$</span> then something is going wrong.</p>
<p>Consider the left/right/top/bottom clip planes. There is no way that a triangle can span from part of the visible frustum, to the <span class="math-container">$w = 0$</span> camera plane or behind it, without also crossing outside one of the frustum side planes—or else the near plane, which lies at some positive distance <span class="math-container">$w_\text{near} &gt; 0$</span>.</p>
<p>You mentioned skyboxes and setting <span class="math-container">$z = w$</span> in the vertex shader output. Such geometry must cross the frustum side planes before it can get to the near plane. (How could part of a skybox get close enough to the camera to be clipped by the near plane only?) If you are correctly clipping it against <em>all</em> of the frustum planes, you must end up with <span class="math-container">$w &gt; 0$</span> in the final vertex.</p>

CC BY-SA 4.0
2020-08-30T00:12:42.037Z
2020-08-30T00:12:42.037Z
Nathan Reed
<p>When we clip in homogeneous clip space, we have to generate a new vertex located at the intersection between the edge and the clip plane. We thus have to interpolate the <span class="math-container">$(x , y, z , w)$</span> position of both vertices to generate the new vertex position. It seems all well and good, but what should I do when the generated vertex after interpolation has a w of 0?</p>
<p>It doesn’t work because the w-divide makes the point go to infinity (division by zero).</p>
<p>So should I ensure that I never generate vertices with a w of 0 (how?)? Or should I just deal with the null w (how?)?</p>
<p>You might say that this situation never happen, but it actually does happen, especially when the z of the vertices are set to their w, for skyboxes for example. In this case, when we clip against the near plane (z = 0 in clip space) and interpolate the position, we will end up with a z of 0 but also a w of 0...</p>

CC BY-SA 4.0
2020-08-24T16:39:56.533Z
"*it actually does happen, especially when the z of the vertices are set to their w, for skyboxes for example.*" That changes nothing about the math here. The whole point of (near) clipping is to ensure that all vertices have a positive value for `w`. If you get a value of `w` for a near-clipped vertex, then you did your clipping computation wrong.
Nicol Bolas
<interpolation><rasterizer><clipping>
How to interpolate vertices when clipping?
Voko
# How to interpolate vertices when clipping?

(Asked by: username_0 on 2020-08-16)

When we clip in homogeneous clip space, we have to generate a new vertex located at the intersection between the edge and the clip plane. We thus have to interpolate the $(x , y, z , w)$ position of both vertices to generate the new vertex position. It seems all well and good, but what should I do when the generated vertex after interpolation has a w of 0?

It doesn’t work because the w-divide makes the point go to infinity (division by zero).

So should I ensure that I never generate vertices with a w of 0 (how?)? Or should I just deal with the null w (how?)?

You might say that this situation never happen, but it actually does happen, especially when the z of the vertices are set to their w, for skyboxes for example. In this case, when we clip against the near plane (z = 0 in clip space) and interpolate the position, we will end up with a z of 0 but also a w of 0...

**Tags:** interpolation, rasterizer, clipping

> **Comments:**
> **username_1**: "*it actually does happen, especially when the z of the vertices are set to their w, for skyboxes for example.*" That changes nothing about the math here. The whole point of (near) clipping is to ensure that all vertices have a positive value for `w`. If you get a value of `w` for a near-clipped vertex, then you did your clipping computation wrong.  

---

## 1 answers

### Answer by username_2 on 2020-08-30. Score: 2

Points in front of the camera have $w > 0$ strictly, by definition. I would say that if clipping is giving you points with $w = 0$ then something is going wrong.

Consider the left/right/top/bottom clip planes. There is no way that a triangle can span from part of the visible frustum, to the $w = 0$ camera plane or behind it, without also crossing outside one of the frustum side planes—or else the near plane, which lies at some positive distance $w\_\text{near} > 0$.

You mentioned skyboxes and setting $z = w$ in the vertex shader output. Such geometry must cross the frustum side planes before it can get to the near plane. (How could part of a skybox get close enough to the camera to be clipped by the near plane only?) If you are correctly clipping it against *all* of the frustum planes, you must end up with $w > 0$ in the final vertex.


---

