PDA

View Full Version : How to debug with shader, I've been stuck for 2 days and having no clue...



Sobeit
12-05-2012, 10:25 PM
I'm a beginner in opengl, recently I'm learning GLSL.
but I find it's really difficult to dubug because I can't make break piont in shader files(that't usually how I do it).
I also tried use transform feedback to retrieve data from shader files but ended up getting (0, 0, 0, 0) all the time, so I assume there must be something wrong in my setup of transform feedback.

How do you guys debug with shaders efficiently? can some tell me how to use transform feedback?

tonyo_au
12-06-2012, 12:03 AM
I usually end up changing the colour render to something based on the shader logic; eg if I expect some value to be say < 0.5 I out vec4(1,0,0,1) if it is and vec4(0,1,0,1) if it is not.
It is a bit slow but without a proper debugger there is not much else

AllForum
12-06-2012, 12:47 AM
I am a beginner too.
I used the color to verify some values. For example :
gl_FragColor = vec4(N.x, N.y, N.z, 1); // N is a normal
if ((N.x < 0.019) &&(N.y < 0.019) && (N.z < 0.019)) gl_FragColor = vec4(1,0,0,1);
When I had problems with lights I rendered with ambient only then with diffuse only, etc...

It's like the old "printf" debug... Not easy...

dukey
12-06-2012, 02:26 AM
debugging shaders is hard
I've done the old, debug to colour output. But when that's clamped to 0-1 can make it hard.

nuclear_bro
12-06-2012, 03:04 AM
When color coding is not enough, i use RGBA32UI texture as another render target and modify shader to pack needed information of its execution as bitfields and render it to that texture. Then i hover mouse pointer on suspicious pixel, read that pixel by pressing a key and decode info.

It's not easy to setup all that stuff, but it helps.

tonyo_au
12-06-2012, 04:08 AM
nuclear_bro - thats not a bad idea - I might try that.

Sobeit
12-06-2012, 10:00 PM
thank you guys. debug with color is a great idea, I'll try that out.