#[Solved] How to add debug in a array ?
3 messages · Page 1 of 1 (latest)
Not like you can with GDScript, no.
Shaders are compiled to object code, then are run in parallel in chunks of hundreds or thousands at the same time by the GPU (running the function once per vertex, and once per fragment).
So even if the GPU could access the system commands that allows for printing, there'd be no real sensible way of knowing when and where to print, unless we just outputted up to 2 to 8.2 million print statements (1080p and 4K respectively)
That is also why you can't have break points in a shader. The GPU is running thousands to millions of computations every rendering frame - it's fed information by the CPU and then allowed off its leash.
It is possible to debug shaders to a degree by changing the output of it, however. You could replace the COLOR/ALBEDO output with one of the intermediary values as a vec4/vec3 and then see if it's what you expected it to be.
You can also rewrite your shader code in raw GDScript with 'simulated' inputs, to simulate a single fragment, and then you're free to print and debug with breakpoints to get what you want.
There's also some shader sorcery you can pull off with printing numbers to a texture and displaying said texture (https://www.shadertoy.com/view/clffRB though I didn't get it to work)
Thanks a lot 