25

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

3
  • 1
    Is this for OpenGL or OpenGL ES? In GL (3.1+), the best way to do this would be with a Uniform Buffer. Commented May 12, 2014 at 2:02
  • @AndonM.Coleman can i use it with GLES 2.0 ? Commented May 13, 2014 at 5:07
  • No, and that is why I was asking you to be more specific with your tags. You have this tagged for ES and GL. Commented May 17, 2014 at 0:55

1 Answer 1

39

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.