Shader debug, is it possible?

Hello!



Last several days I am trying to solve why my shader behaves not as I expected. I was thinking is there any way to somehow debug a shader (set a breakpoint, trace and check whether the parameters, uniforms, etc are correct, etc.)? Ecpecially fragment shader. It’s just for some reason the final color of the pixel (which in my shader is based on 4 variables, and 2 passed from pixel shader) is always black. It would be nice if I had an opportunity to debug and see what caused the trouble.



And one more thing. How vec3 inPosition is differs with vec4 inPosition? What does the 4th part of vector is passed to inPosition when I declare it as vec4?

1 Like

About the shader debugging, I’ve already heard a answer for that months ago by a core member, and it’s not possible(it’s what I heard).

You have to get creative in how you debug assumptions in a shader. There is no “setting breakpoints”, etc… sometimes you use the output color to verify assumptions.



if( some condition ) gl_FragColor.r = 1;



…then see what comes out fully red, etc…



Why would you declare inPosition as a vec4?

@KayTrance said:
Last several days I am trying to solve why my shader behaves not as I expected. I was thinking is there any way to somehow debug a shader (set a breakpoint, trace and check whether the parameters, uniforms, etc are correct, etc.)? Ecpecially fragment shader. It's just for some reason the final color of the pixel (which in my shader is based on 4 variables, and 2 passed from pixel shader) is always black. It would be nice if I had an opportunity to debug and see what caused the trouble.

I wish there was a way, but unfortunately, I never found a good ogl shader development software.
I tried nvidia's rendermonkey, but it's designed for directX HLSL, and just barely supports OpenGL (for example you can't create a RGBA float texture,and dimensions of textures must be a power of 2...).
I do like @pspeed and output the values on screen and read the colors :p
But that's quite hardcore debugging i admit :p

@KayTrance said:
And one more thing. How vec3 inPosition is differs with vec4 inPosition? What does the 4th part of vector is passed to inPosition when I declare it as vec4?

I guess you'll have 0 in the 4th position, unless you specified a 4th value for each vertex in the vertexBuffer...

oh well, thank you for the answers. Trick with the color should be fine, I was thinking do it that way also :slight_smile:

I looked around a while back and found something called “GLSL Devil”. It may work? I installed it but never tried it. Even if it works well I assume you’d have to write OpenGL programs to run any tests, so it would be more work then doing what pspeed says - just be creative and use colors to figure out stuff etc. I’m no guru by any means tho.

@androlo said:
I looked around a while back and found something called "GLSL Devil". It may work?

I haven't found any way to get it working with jme apps :(