iphoneopengl-esshaderopengl-es-lighting

Passing an array of structs into OpenGL ES 2.0 shader


I want to implement some kind of lighting. And i'm making a struct, that contains light sourse properties in vertex shader:

struct Light
{
    vec4 color;
    vec4 pos;
    ...
};

In my app i want to have several light sources. So i put:

uniform Light[10];

How can i then load these uniforms from the app ? Is it a good approach or better to have:

uniform vec4 LightColor[10];
uniform vec4 LightPos[10];
...

Solution

  • I think you can't pass structures to OpenGL ES shaders. Please check this SO discussion that seems to confirm it:

    Passing own struct into opengl es 2.0 shader

    I think it's safer to use your second proposal based on the arrays of vec4 uniforms.