Debug glsl fragment shaders on the CPU

2017 - present

shdr (2017 - present)

Debug glsl fragment shaders on the CPU

An experimental emulator for glsl fragment shaders that runs on the CPU. shdr is useful when standard GPU debugging methods won't cut it; it lets you inspect variables on a standard CPU debugger. The shader output can also be exported to a png file.


To debug glsl, the easiest method is to dump suspect variables out to gl_FragColor. This method provides fast visual feedback about where errors are. It is usually the best method for debugging glsl, and is particularly useful in conjunction with a tool like ShaderToy.

This debugging method stops being effective with more complex shaders. When you need to debug multiple variables. Sometimes, you just want to look at all of the suspect variables in a standard debugger, or to dump specific variables out to the console.

I think the Visual Studio Code javascript debugger is the best available for any IDE or programming language, and it's what I've been testing this on. Javascript is also a good choice as an emulation language, since it already has very similar syntax to glsl.

This library may also be useful as a server-based program that can be used to generate static images with glsl, particularly in cases when an OpenGL context is impossible to create.