<p>A vertex consists of not just the position, but <em>all</em> of the values passed from the <a href="https://www.khronos.org/opengl/wiki/Vertex_Processing" rel="nofollow noreferrer">vertex processing stage</a> to the rasterizer. So if a vertex gets clipped, the new vertices generated in that process must <em>generate</em> new values for those vertex processing outputs. It does this using the same math that it uses to generate the new vertex position.</p>

CC BY-SA 4.0
2020-08-09T19:23:07.393Z
So the vertex attributes are interpolated, but is it also the case for every "out" variable that I pass to the pixel shader?
Voko
CC BY-SA 4.0
2020-08-09T20:12:04.680Z
@Kiosto: "*So the vertex attributes are interpolated*" Nowhere in my post did I mention "vertex attributes". Attributes are the *inputs* to the vertex shader. I spoke specifically about the *outputs* of the vertex processing pipeline.
Nicol Bolas
CC BY-SA 4.0
2020-08-08T19:54:14.060Z
2020-08-08T19:54:14.060Z
Nicol Bolas
<p>Clipping is down in homogeneous clip space, therefore after multiplying the vertices by the model-view matrix. But as we do clipping in clip space, the position of the new vertices that we interpolate is in clip space, so how can I translate back those new vertices coordinates into view space?</p>
<p>I could perform the inverse transformation, but it seems costly. So how exactly do clipping work in the graphics pipeline? I mean, how can we get the position of the new generated vertices in view space?</p>
<p>For example, with OpenGL, I would do the following in the vertex shader:</p>
<pre><code>layout (location = 0) in vec3 pos; // vertex position in model space

out vec3 posViewSpace;

// M V P are the model view projection matrices

void main() {
    posViewSpace = V * M * pos; // I want the pos in view space for shading
    gl_Position = vec4(P * V * M * pos, 1.0); // Give OpenGL the position in clip space
}
</code></pre>
<p>But how can this work, because <code>posViewSpace</code> that will be given to the pixel shader has nothing to do with the <em>new vertices</em> generated after clipping? Or maybe it doesn't matter, because <code>posViewSpace</code> will be interpolated from the <em>original</em> vertices, but the pixel shader won't notice? Will the interpolation be correct and usable in the pixel shader, even if it's performed from the original vertices and not the new generated vertices?</p>

<opengl><clipping><pixel-shader>
Using original vertices coordinates after clipping
Voko
# Using original vertices coordinates after clipping

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

Clipping is down in homogeneous clip space, therefore after multiplying the vertices by the model-view matrix. But as we do clipping in clip space, the position of the new vertices that we interpolate is in clip space, so how can I translate back those new vertices coordinates into view space?

I could perform the inverse transformation, but it seems costly. So how exactly do clipping work in the graphics pipeline? I mean, how can we get the position of the new generated vertices in view space?

For example, with OpenGL, I would do the following in the vertex shader:

```
layout (location = 0) in vec3 pos; // vertex position in model space

out vec3 posViewSpace;

// M V P are the model view projection matrices

void main() {
    posViewSpace = V * M * pos; // I want the pos in view space for shading
    gl_Position = vec4(P * V * M * pos, 1.0); // Give OpenGL the position in clip space
}

```

But how can this work, because `posViewSpace` that will be given to the pixel shader has nothing to do with the *new vertices* generated after clipping? Or maybe it doesn't matter, because `posViewSpace` will be interpolated from the *original* vertices, but the pixel shader won't notice? Will the interpolation be correct and usable in the pixel shader, even if it's performed from the original vertices and not the new generated vertices?

**Tags:** opengl, clipping, pixel-shader


---

## 1 answers

### Answer by username_1 on 2020-08-08. Score: 1

A vertex consists of not just the position, but *all* of the values passed from the [vertex processing stage](https://www.khronos.org/opengl/wiki/Vertex_Processing) to the rasterizer. So if a vertex gets clipped, the new vertices generated in that process must *generate* new values for those vertex processing outputs. It does this using the same math that it uses to generate the new vertex position.

> **Comments:**
> **username_0**: So the vertex attributes are interpolated, but is it also the case for every "out" variable that I pass to the pixel shader?  
> **username_1**: @Kiosto: "*So the vertex attributes are interpolated*" Nowhere in my post did I mention "vertex attributes". Attributes are the *inputs* to the vertex shader. I spoke specifically about the *outputs* of the vertex processing pipeline.  

---

