用于将数据传递给片段着色器的统一数组或纹理?

发布于 12-10 20:31 字数 158 浏览 0 评论 0原文

如果您有大量浮点数据要传递给片段着色器,那么使用统一数组或纹理是否是一个更好的主意?似乎统一数组是正确的方法,但数组大小似乎有限(特别是在 WebGL 中,这就是我工作的地方)如果我想发送有关数千个对象的信息(出于光线跟踪的目的)是除了使用纹理传递数据之外,还有其他现实的替代方法吗?这是坏事还是好事?

If you have a lot of floating point data to pass to a fragment shader, is it a better idea to use uniform arrays or textures? It seems like uniform arrays are the proper way to do it, but the array size seems limited (especially in WebGL, which is where I'm working) If I want to send information about thousands of objects (for the purposes of raytracing) is there any realistic alternative to using textures for passing data? Is this a bad thing or a good thing?

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

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

发布评论

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

评论(1

苦行僧2024-12-17 20:31:22

纹理是处理大量浮点数据的方法。

如果可能的话,将数据打包到 4 分量向量中,并从片段着色器中删除尽可能多的分支指令。其想法是在 GPU 上执行尽可能少的逻辑,并将着色器简化为需要对大量数据执行的少数操作。

大规模并行硬件编程与 CPU 编码完全不同,并且许多关于性能的标准直觉在并行环境中是完全相反的。一个很好的起点是:

http://developer.download.nvidia.com/GPU_Programming_Guide /GPU_Programming_Guide.pdf

Textures are the way to go for huge amounts of floating point data.

If at all possible, pack the data into 4-component vectors and remove as many branching instructions as you can from your fragment shader. The idea is to perform as little logic as possible on the GPU and boil your shaders down to a few operations that need to be performed on a huge amount of data.

Programming massively parallel hardware is totally different than coding for a CPU, and a lot of the standard intuition about performance is completely opposite in a parallel environment. A good place to start is here:

http://developer.download.nvidia.com/GPU_Programming_Guide/GPU_Programming_Guide.pdf

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