Search code examples
3dshadervertex-shader

Is a vertex shader called before or after clipping?


I thought the answer should be before. But I have a shader which seems to contradict this:

float4 vp(
        // Vertex Inputs
        in float4 position        : POSITION,
        uniform float4x4 worldViewProj) : TEXCOORD6
{
    float4 p = mul(worldViewProj, position);
    p.y /= 2.0;
    return p;
}

worldViewProj is the combined matrix converting world position to screen coords. I expected this vertex shader would squash the output into the top half of the render-target, and indeed it does do this - but the bottom half of the view then gets filled with more geometry which normally is out of view.

Is this simply due to the GPU's culling being quite crude?


Solution

  • First comes Vertex Shader, then comes Clipping (see http://download.microsoft.com/download/f/2/d/f2d5ee2c-b7ba-4cd0-9686-b6508b5479a1/direct3d10_web.pdf for full D3D10 pipeline)

    So you basically in your Vertex Shader project ALL vertices to screen and then scale them in screen space by 0.5. Thus modified vertices are then clipped resulting in whole screen filled with geometry. I suppose you expected to see half a screen filled and half a screen blank?