使用 Texture1D 而不是制服

Using Texture1D instead of uniforms

我在我的游戏中使用了 5 种颜色的调色板,每次我将每种颜色作为 uniform vec3 传递给程序。如果我使用包含所有 5 种颜色(纹理中有 15 个浮点数)的一维纹理,它会更有效吗?

这只是我想做这种事情的其中一种情况。另一种方法是立即将所有 matrices/variables 发送到着色器程序。每次我想渲染时,一次发送一个变量似乎有点低效。将它们全部分组到一个纹理中并一次发送它们会更好吗?

是否有另一种更有效的方法来完成我想做的事情?

Would it be more efficient if I was using a one dimensional texture that contains all 5 colors (15 floats in the texture)?

不,纹理读取很可能会降低性能,但在您的情况下应该不会有太大区别。

Is there maybe another, even more efficient way of doing what I'm trying to do?

好吧,如果它们总是和你说的一样,那么就把它们作为常量放在着色器中。

That's just one of the situations where I would like to do this kind of thing. Another would be to send all the matrices/variables at once to the shader program. I seems a little bit inefficient to send every variable, one at the time, every time I want to render. Would it be better to group them all in a single Texture and send them all at once?

修改纹理不会比设置一些制服快。

并且如果您打算按顶点或按片段使用矩阵,那么它会导致大量纹理读取。这实际上可能会导致性能显着下降,具体取决于您拥有的 vertices/fragments/matrices 数量。即使该纹理数据最终进入 L1 纹理缓存,它仍然不会优于统一读取。

如果您不想独立发送所有变量,可以使用统一缓冲区对象。