问题描述
我是新手..尝试学习着色器.我觉得编写和调试它不是那么容易.我在互联网上看到的示例和教程允许将它们编码为文本文件,并将其读取为char指针,以将其传递给着色器编译器.有没有编码方面的最佳实践-具有智能,编译,调试(至少在控制台上的某个位置打印值?)以及如何在庞大的源代码中维护和组织多个着色器?
我正在使用Visual Studio.是否有任何工具或扩展程序可以支持opengl着色器?
如果没有,那么仅适用于opengl着色器的专用IDE? -如果是这样,如何在Visual Studio中与其他c ++源文件一起组织它们?
他们实际上是如何做到的?
谢谢.
绝对的最低要求是可以访问GLSL编译和链接日志,例如:
-
只需在代码中查找
glsl_log
.
对于非常困难的东西,最好将着色器编写为 CPU 端的 C ++ 代码,并在完全调试后将其作为着色器运行.但是为此,您需要编写某种可以模拟着色器的框架.对于初学者,您需要 GLSL 中的1/2/3/4D
向量和矩阵算术.编写代码并不是那么容易,但是还有诸如 GLM 之类的其他选项.我正在使用我的模板,但由于启用了vec
数据类型,因此它的228 KByte丑陋代码由于其getters setters的详细信息而在此处查看:
另一个绝对最小值是处理输入和输出.由于有趣的部分通常位于片段中,因此通常仅足以处理这种片段着色器,因此您只需要2个嵌套循环,循环遍历测试图像即可调用着色器main
函数并根据其结果设置像素.我通常放置#define texture(...)...
来模拟纹理访问,这简而言之.例如,这些着色器将无法以其他方式调试:
正如在注释中提到的用于更简单的着色器一样,您可以在任何 C ++ IDE 中编写它们以启用语法突出显示.但是在目标应用程序中编写/调试内容是个好主意,您只需在其中添加一些子窗口,然后在每次编译后在其中将GLSL信息日志呈现为打开文本文件的方式添加子窗口,便是沉闷的点击工作.
开始为着色器编码时,我已经厌倦了这种情况,并为着色器编写了自己的 IDE .它的越野车远非完美,但可以满足我的需求.看起来像这样:
指向它的链接在(edit3)中:
有一些类似的工具,但是拥有自己的源代码可以使用很多东西,例如使用目标应用程序 CPU 辅助代码等...
另一个非常有用的事情是能够打印来自片段着色器的某些变量值.正是我能够做到这一点:
您只需要确定整个打印区域的正确条件(因此,在打印所有像素时,您要打印的值是相同的).尤其是第一次使用3D纹理和在纹理中编码的几何图形,这对我有很大帮助.
但是,在大多数情况下,您可以使用彩色输出代替调试打印,但是具有打印实际数字的功能可以节省大量时间.
I'm a newbie.. trying to learn shaders. I feel like its not that easy to code and debug it. Examples and tutorials I see on internet allows to code them in text files and read them as char pointer to pass them to shader compiler. Is there any best practices for coding - with intellisence , compiling , debugging ( printing the value some where in console atleast? ) And how to maintain and organise multiple shaders in a giant source code?
I'm using visual studio. Is there any tools or extensions for it to support opengl shaders?
If not is there any dedicated IDE only for opengl shaders? - if so how to organise them with other c++ source files in visual studio?.
How do they actually do it?
Thanks.
The absolute minimum is to have access to GLSL compile and link logs here example:
complete GL+GLSL+VAO/VBO C++ example
just look for
glsl_log
in the code.
For really hard stuff its best to write your shader as CPU side C++ code and when fully debugged then run it as shader. But for that you would need to write some kind of framework that would emulate shaders. For starters you need 1/2/3/4D
vector and matrix arithmetics from GLSL. It is not that easy to code it but there are also another options like GLM. I am using my template but just to enable vec
datatypes its around 228 KByte of hideous code due to its getters setters for more info look here:
And another absolute minimum is handling input and output. As the fun part is usually located in fragment itst often enough to process only fragment shader this way so you need just 2 nested loops looping through test image calling your shader main
function and setting the pixel according to its result. I usually place #define texture(...)...
to emulate texture access and that is in nutshell all. For example these shaders I would not be possible to debug otherwise:
As was mentioned in comments for simpler shaders you can write them in any C++ IDE to enable syntax highlight. But its a good idea to write/debug the stuff in your target App where you simply add some subwindow where you render the GLSL info logs as opening text file after each compilation is a dull click work.
When I started coding shaders I was tired of such and write my own IDE for shaders. Its buggy and far from perfect but it fulfills my needs. It looks like this:
Link to it is in (edit3) here:
There are some similar tools out there but having my own with source code allows a whole lot of stuff like using targets app CPU side code etc ...
Another very useful thing is to be able to print some variable value from fragment shader. Exactly that I was able to do like this:
you just need to decide correct conditions for entire area of the print (so the value you are printing is the same while printing all its pixels). This help me a lot especially to use 3D textures and geometry encoded in textures for the first time...
However in most cases you can use color output instead of debug prints but having the ability to print actual numbers can save you a lot of time.
这篇关于在opengl中编码,编译,调试和维护着色器程序的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!