In C, I can debug code like:
fprintf(stderr, "blah: %f", some_var);
in GLSL ... is there anyway for me to just dump out a value in a Vertex or Fragment shader? I don't care if it's slow; I just want to dump out the value. Ideally, I want a setup like the following:
Is this feasible? (I don't care about performance; I just want to do this for one frame).
Thanks!
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^^).
gl_Position is a special variable that holds the position of the vertex in clip space. Since a vertex shader's main output is the position in clip space, it must always set gl_Position. This vertex shader just transforms each vertex position (by the VP matrix).
You port your OpenGL Shader Language (GLSL) code to Microsoft High Level Shader Language (HLSL) code when you port your graphics architecture from OpenGL ES 2.0 to Direct3D 11 to create a game for Universal Windows Platform (UWP).
Unfortunately it's not possible directly. One possible solution though, that I end up using a lot (but I'm sure it's pretty common among GLSL developers) is to "print" values as colors, in place of your intended final result.
Of course this has many limitations; for one, you have to make sure that your value maps in a (0,1.0)
range. Functions as mod
, fract
etc. turn out useful in these cases. But, in general, this is what I see as the "printf" equivalent in GLSL.
Instead of printing values, have you thought of trying a GLSL debugger?
For example, glslDevil will let you step through your shader's execution and examine the variables at each step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With