Creating a GLSL Arrays of Uniforms?

前端 未结 2 802
灰色年华
灰色年华 2020-12-07 15:13

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.

Can we declare an array of uniforms in GLSL

2条回答
  •  独厮守ぢ
    2020-12-07 16:19

    Yes this is possible. You declare uniform arrays similar to how you'd do it in C, e.g.

    uniform float v[10];
    

    Then you can set their values using glUniform{1,2,3,4}{f,i}v

    GLfloat v[10] = {...};
    glUniform1fv(glGetUniformLocation(program, "v"), 10, v);
    

提交回复
热议问题