Pergunta

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].

Foi útil?

Solução

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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top