All Questions


Orestis Konstantinidis

How to debug shaders (PRINT)?


I'm somewhere half-way through the course and enjoying it quite a bit so far. But I have a question that wasn't mentioned so far, on how to debug the shaders?

I noticed the godot shading language doesn't seem to have a print function, so many times I have a hard time to check what value a variable holds. I also tried to feed a Shader Parameter but that's not allowed, so I usually end up driving the COLOR of the shader, or so. But that's not always appropriate to display the values of a variable (it could be a value of 0.0003 or a value of 1,000,000 for that matter).

What is a recommended way of debugging code in the shading language?

  • Nathan Lovato replied

    There aren't great tools, indeed. That's a general issue with shaders. You have to output values to the screen as pixels. I think it's in part because they're generally really short programs, but also because they're sent on the GPU.

    When outputting values as colors, if you expect a value of 0.003, you can multiply it by 100 to see if you get a light grey. Basically, you want to remap values to be in the [0, 1] range to see the values you get.

  • K
    Orestis Konstantinidis replied

    That makes sense, I wanted to make sure I wasn't missing an obvious better way. Thanks for the response!