我需要调试一个GLSL程序,但我不知道如何输出中间结果。 是否有可能使用GLSL进行一些调试跟踪(如printf) ?


当前回答

GLSL沙盒已经相当方便我的着色器。

不是调试本身(被回答为不能调试),而是方便地快速查看输出中的更改。

其他回答

我发现变换反馈是调试顶点着色器的有用工具。您可以使用它来捕获VS输出的值,并在CPU端读取它们,而不必通过光栅化器。

这里是另一个转换反馈教程的链接。

GLSL沙盒已经相当方便我的着色器。

不是调试本身(被回答为不能调试),而是方便地快速查看输出中的更改。

我发现了一个非常好的github库(https://github.com/msqrt/shader-printf) 你可以在着色器文件中使用printf函数。

void main(){
  float bug=0.0;
  vec3 tile=texture2D(colMap, coords.st).xyz;
  vec4 col=vec4(tile, 1.0);

  if(something) bug=1.0;

  col.x+=bug;

  gl_FragColor=col;
}

你可以试试这个:https://github.com/msqrt/shader-printf,它是一个叫做“GLSL的简单打印功能”的实现。

You might also want to try ShaderToy, and maybe watch a video like this one (https://youtu.be/EBrAdahFtuo) from "The Art of Code" YouTube channel where you can see some of the techniques that work well for debugging and visualising. I can strongly recommend his channel as he writes some really good stuff and he also has a knack for presenting complex ideas in novel, highly engaging and and easy to digest formats (His Mandelbrot video is a superb example of exactly that : https://youtu.be/6IWXkV82oyY)

我希望没有人介意这个迟到的回复,但这个问题在谷歌搜索GLSL调试中排名很高,当然在9年里发生了很大变化:-)

PS:其他替代方案也可以是NVIDIA nSight和AMD ShaderAnalyzer,它们为着色器提供了一个完整的步进调试器。