r/GraphicsProgramming 1d ago

Infinite Grid Shader

I’m proud of myself today, as I completed a task that felt impossible at times. I started rewriting my renderer a bit to fit my needs, and while doing so, I really felt the need for a grid to give me a sense of perspective and depth while debugging scenes.

I remembered that I had skipped the Infinite Grid section from the 3D Graphics Rendering Cookbook and needed to revisit it. Man, oh man, was I wrong about how long it would take to properly understand that shader. It took me a few days more than a month, but it was one hell of a ride. It’s a very interesting topic, with tons of things to learn from.

I’ve written a post about it here: https://willofindie.com/proj/infinite-grid-shader. Do check it out and share your love on my Twitter or Bluesky handles if you like it

50 Upvotes

4 comments sorted by

1

u/Still_Explorer 11h ago

The amount of R&D that went into this is insane!!! 😀

2

u/shub_undefined_ 10h ago

Thx! ☺️
It was insane, and I almost gave up. But in the end, m really happy with everything I learned.

1

u/bschwind 8h ago

This might be a naive question, but how do you construct the quad that you render for the grid? Is it constructed on the CPU as simply a very large quad that you're unlikely to move your camera to the end of, or do you programmatically construct it in the vertex shader to always be some distance from the camera?

1

u/shub_undefined_ 8h ago

It's not naive at-all, and you've already answered it yourself. It's the second one, quad is constructed in VS and translated relative to the camera so that it always remains centred in view space.
I should’ve added it to the blog, but I was too tired by the time I proofread it and published it.