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?


A vertex consists of not just the position, but all of the values passed from the vertex processing stage 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.

  • $\begingroup$ So the vertex attributes are interpolated, but is it also the case for every "out" variable that I pass to the pixel shader? $\endgroup$ – Jojolatino Aug 9 '20 at 19:23
  • $\begingroup$ @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. $\endgroup$ – Nicol Bolas Aug 9 '20 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.