# Implementing Valve's checkerboard rendering technique

I've been trying to implement Valve's VR checkerboard rendering technique (original document) and was wondering which way would be the best to proceed.

The thing is that I need to "abort" the execution of 2x2 blocks of fragments in a checkerboard pattern considering how GPUs work in blocks of pixels.

I've thought of several approaches which are the following :

• Discard fragments in the fragment shader using a condition like this one :
float mod2 = gl_FragCoord.x + gl_FragCoord.y;
float res = mod(mod2, 2.0f);
if (res == 0.0f)

• Use the stencil buffer and write a checkerboard pattern on it using an image or such.

• Use some kind of clipping method where I have several quads in front of the camera forming a checkerboard pattern.

The first approach seems to be the worse because I have to branch and after, discard fragments. And considering the fact that GPUs work in blocks of 2x2 pixels, I need to find a way to abort block by block so that I don't get the fragment shader processed anyway (even with a discard). And I'm not even sure this would force a block to abort and skip the fragment shader.

The second method seems OK, but I'm not sure if there's a better way to do it. Would the fragment shader be processed anyway ?

The third seems to need to process more polygons which is not really a good idea I guess even though it does not require a lot of processing considering they would be simple quads.

What would be the most efficient method (listed here or not) for skipping these blocks ?

• Can you olease add a link to the original resource? – Bálint Oct 12 '16 at 9:51
• @Bálint: Well I only checked used the first link I provided. But I'll try to find the original and edit my question. EDIT: Done. – CpCd0y Oct 12 '16 at 10:04

In other words, it should work, theoretically, but you better test there is an actual increase of performance. I'd also expect if + discard to work, but just like the other methods, I'd want to test and verify first if it actually results in a performance increase.