创建一个 GLSL 制服数组? [英] Creating a GLSL Arrays of Uniforms?
本文介绍了创建一个 GLSL 制服数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想放弃 OpenGL 的灯光并制作我自己的灯光.我希望我的着色器允许使用可变数量的灯光.
I would like to leave OpenGL's lights and make my own. I would like my shaders to allow for a variable number of lights.
我们可以在 GLSL 着色器中声明一个统一的数组吗?如果是这样,我们将如何设置这些制服的值?
Can we declare an array of uniforms in GLSL shaders? If so, how would we set the values of those uniforms?
推荐答案
是的,这是可能的.您声明的统一数组类似于您在 C 中的做法,例如
Yes this is possible. You declare uniform arrays similar to how you'd do it in C, e.g.
uniform float v[10];
然后您可以使用 glUniform{1,2,3,4}{f,i}v
GLfloat v[10] = {...};
glUniform1fv(glGetUniformLocation(program, "v"), 10, v);
这篇关于创建一个 GLSL 制服数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文