GLSL可以同时输出到两个/多个纹理吗?

发布于 2024-10-03 00:01:38 字数 97 浏览 0 评论 0原文

我可以让着色器读取两个纹理,但对于输出来说,似乎只有 gl_FragColor。有没有办法从一个着色器渲染到两个不同的纹理?顺便说一句,我正在使用处理和 GLGraphics 库。

I can get a shader to read in two textures but for output it seems there is only gl_FragColor. Is there any way to render to two different textures from one shader? I am using Processing and the GLGraphics library btw.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

命硬 2024-10-10 00:01:38

是的,您可以写入 gl_FragData,它是一个输出数组(大小取决于您的实现)。或者,对于较新版本的 GL,gl_FragColor 和 gl_FragData 均已弃用,您可以声明自己的 out 变量供片段着色器写入。为多个输出缓冲区声明多个这样的 out 变量。

Yes, you can write to gl_FragData, which is an array of outputs (size depends on your implementation). Or with newer versions of GL, both gl_FragColor and gl_FragData are deprecated and you declare your own out variables for the fragment shader to write to. Declare multiple such out vars for multiple output buffers.

铁憨憨 2024-10-10 00:01:38

是的。我们可以。但请注意,GLSL 4.0 不再支持 gl_FragData。指定位置为:

glBindFragDataLocation(programHandle, 0, "FragColor");

.....

希望您能阅读《glsl 4.0 着色语言cookbook》这本书。

Yes. We can. BUT Notice that gl_FragData is no longer supported in GLSL 4.0. Specify the location as:

glBindFragDataLocation(programHandle, 0, "FragColor");

.....

I hope you could read the book of glsl 4.0 shading language cookbook.

若水般的淡然安静女子 2024-10-10 00:01:38

我不知道这是否正是您想要做的,但是使用 帧缓冲区对象 (FBO) 您可以同时绘制到多个颜色缓冲区。

不过,在着色器中,您仍然就像在编写一个片段一样。也就是说,着色器不知道 FBO 有多少个附件。

I don't know if this is exactly what you're trying to do, but with Frame Buffer Objects (FBOs) you can draw to multiple color buffers simultaneously.

Within the shader, though, it will still just be as if you're writing one fragment. That is, the shader is unaware of how many attachments the FBO has.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文