Using an array of struct with texture members

This is probably not THREE related.
I have the following code that produces a compile error undeclared identifier 'angle_pnt_light’:

struct pointLight {

    sampler2D shad_tex;

  };

  uniform pointLight[2] pnt_light;

  uniform vec3 color;

  void main() {

    vec3 light = vec3(0.5);

    for(int i = 0; i < 2; i++) {

        vec4 pov_id = texture2D(pnt_light[i].shad_tex, vec2(0.0));   // <--- ERROR
      
    }

    gl_FragColor = vec4(light * color, 1.0);
  }

If I change pnt_light[i] to pnt_light[0] it works.

Could somebody explain to me what goes wrong here and how to fix it?

fiddle

Slightly rewriting the shader makes the error more obvious: Edit fiddle - JSFiddle - Code Playground

‘structure’ : structures must be uniform (structure contains a sampler)

so, what’s the right syntax in this case? or is it not possible to put samplers inside structures?

Correct. You have to manage them outside of structs.

1 Like