Screen-aligned Quads

Screen-aligned quads are the bread and butter of deferred rendering, or any rendering that requires full screen passes. Therefore we should be keen to make the drawing of screen-aligned (SA) quads as simple and efficient as possible, so that we can lose sleep over the real performance bottleneck - the fragment shaders which they invoke.

Here's a few tips that I've picked up which may come in handy:

#1 - No indices!

I've seen some advice out there which advocates rendering a single big triangle that covers the viewport. I can't imagine that this is worth the hastle of computing the texture coordinates for the tiny (TINY) increase in efficiency, which probably doesn't happen anyway because of clipping. Instead, I'd reckon that drawing a triangle strip is the best way to do it; you only need to specify 4 verts, and no indices!

f1: 4 vertices of a triangle strip

This is instead of specifying 6 verts (for two triangles) or 4 verts and 6 indices (for two triangles, sharing two vertices).

#2 - No transformations!

Normally before rendering vertices undergo at least one transformation (by the model/view/projection matrix). We can completely avoid having to do this by specifying the quad's vertices as normalized device coordinates, which fall in the range [-1, 1].

f2: Vertex positions specified in NDC

#3 - No attributes!

Except position, of course. The only vertex attribute we really need when rendering an SA quad is a texture coordinate, which we can calculate in the vertex program directly from the vertex position using a simple scale and bias: texcoord = position * 0.5 + 0.5, which can be done as a single operation in hardware.