用于将数据传递给片段着色器的统一数组或纹理?
如果您有大量浮点数据要传递给片段着色器,那么使用统一数组或纹理是否是一个更好的主意?似乎统一数组是正确的方法,但数组大小似乎有限(特别是在 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?
纹理是处理大量浮点数据的方法。
如果可能的话,将数据打包到 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