Making a quad cover the screen

I'm trying to make a shader and I need a fullscreen quad to do so.

I have everything set up and working, but when I render the quad it appears as a small square. This would probably be because I'm passing the cameras world, projection and view matrix into the shader and so the quad appears as a normal object. If I remove this it doesn't appear at all.

How do I go from it rendering as a part of the scene which moves with the camera to being something that completely covers the screen?

edit:

Vertices:

new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 0)),
new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 0)),
new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 1)),
new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 1))


Indices:

ushort[] indices = { 0, 1, 2, 2, 1, 3 };


Render:

        for (int l = 0; l < loader.GlowShader.CurrentTechnique.Passes.Count; l++)
{

}

• The default screen coordinates are (-1,-1) in the bottom left and (1,1) in the upper right. Just use those coordinates and don't apply any matrices. So no ftransform and no matrix multiplication. – PeterT Sep 15 '13 at 15:52
• Hmmm, I think I understand what you're saying, but the changes I've made don't seem to have worked, could you elaborate a little bit? I've updated my original post with the vertices and indices. I changed my vertices to match the coordinates you gave and removed the code that passes in the world, view, projection matrix. – user1157885 Sep 15 '13 at 16:44

Your vertex and index buffer look fine. However, your vertex shader for a full-screen quad should simply copy the input vertex position to the output position. There is no need to pass any of the matrices in because the vertex shader shouldn't use any of them. This is not the same vertex shader you would use for ordinary scene elements.

BTW, your UVs are upside down. The UV origin is in the upper left for D3D.

• In the code example the projections are commented out, aren't I doing exactly what you said? Am I missing something? And within the shader I am passing the vertex position input to the output. – user1157885 Sep 16 '13 at 17:00
• @user1157885 So it doesn't show up still? The next thing to check would be if backface culling is getting rid of it. Try disabling that. – Nathan Reed Sep 16 '13 at 17:10
• Thanks for the help, it's working now. I'm a giant idiot. I thought I was passing the input.Pos to the output but I wasn't. In my head I had changed it but apparently not physically haha. – user1157885 Sep 16 '13 at 17:55
• Although now that it's fixed, I'm curious as to what you meant by the UV's being upside down, could you elaborate on that please? – user1157885 Sep 16 '13 at 22:53
• @user1157885 Um, not much to elaborate...they're upside down, so if you render to a texture, then sample the texture in a full-screen quad using those UVs, it's going to come out upside down. (There will also be a half-pixel offset needed to exactly map the pixels one-to-one.) – Nathan Reed Sep 16 '13 at 22:58

Nathan Reed is right, when using pretransformed vertices you should no apply World, View of Projection matrix, because the coordiantes are already in screen space. If I don't get is wrong you are defining your two triangles counter-clock-wise, which is culled away by default by XNA. You can simply proof this by setting your RasterizerState to RasterizerState.CullNone. If the quad appear, this was your problem. After that you can choose between two options:

1. Change the winding order of the triangle by changing your indices to 0,2,1,1,2,3
2. Change your RasterizerState to RasterizerState.CullClockWise.

I prefer to leave the RasterizeState in its default behavior (CullCounterClockWise) and change your indices.