Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass uniform array of struct to shader via C++ code

for eg. in FragmentShader:-

struct LightSource
{
        int Type;
        vec3 Position;
        vec3 Attenuation;
        vec3 Direction;
        vec3 Color;
};

uniform LightSource Light[4];

main(){
        //somecode
}

Now how can i send values for Light[4].

like image 547
jpm Avatar asked May 11 '14 10:05

jpm


1 Answers

You will need to get the location of each field of the struct for each array element and send the value separately. See the OpenGL wiki page for reference: https://www.khronos.org/opengl/wiki/Uniform_(GLSL)#Uniform_management.

For example to set the value of Light[0].Type you would do the following:

GLuint loc = glGetUniformLocation(shader_program_id, "Light[0].Type");
glUniform1i(loc, value);
like image 143
user3256930 Avatar answered Sep 20 '22 21:09

user3256930