Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a GLSL shader?

I need to debug a GLSL program but I don't know how to output intermediate result. Is it possible to make some debug traces (like with printf) with GLSL ?

like image 680
Franck Freiburger Avatar asked Oct 25 '22 14:10

Franck Freiburger


People also ask

How do I edit a GLSL file?

You can also open and edit GLSL files with source code editors, such as Microsoft Visual Studio Code (multiplatform). Since GLSL files are saved in plain text, you can use any text editor, such as Microsoft Notepad (bundled with Windows), Apple TextEdit (bundled with macOS), or gedit (Linux) to open and edit them.

Can you print in shader?

In general, you cannot print from shaders, because they are executed on the graphic card, and even if you could, the output would be so flooded that you would be unable to see anything relevant (that thing gets run for every vertice and every pixel, you know^^).


1 Answers

You can't easily communicate back to the CPU from within GLSL. Using glslDevil or other tools is your best bet.

A printf would require trying to get back to the CPU from the GPU running the GLSL code. Instead, you can try pushing ahead to the display. Instead of trying to output text, output something visually distinctive to the screen. For example you can paint something a specific color only if you reach the point of your code where you want add a printf. If you need to printf a value you can set the color according to that value.

like image 145
Mr. Berna Avatar answered Oct 27 '22 04:10

Mr. Berna