1

I'm trying to turn a float array into a vector2 array since a float array is the only array I can pass over from Java code to the shader. I'm turning for example float 3.8 into vec2(3,8). But that's pretty irrelevant. The real problem is that the shader stops working when adding a certain line in the for loop. Here's my code:

attribute vec4 a_color;
attribute  vec3 a_position;
attribute vec2 a_texCoord0;

uniform float a_tileCoords[144];
uniform mat4 u_projTrans;

varying vec4 v_color;
varying vec2 v_texCoord0;
varying vec2 v_tileCoords[144];

int length = 144;

void main(){
    v_color = a_color;
    v_texCoord0 = a_texCoord0;
    for(int i = 0; i < length; i++){
       int x = int(a_tileCoords[i]);
       int y = int((a_tileCoords[i] - int(a_tileCoords[i])) * 10);
       v_tileCoords[i] = vec2(x,y);
    }
    gl_Position = u_projTrans * vec4(a_position + vec3(0, 1, 0), 1.);
}

It's about this line:

v_tileCoords[i] = vec2(x,y);

When I remove that line from the for loop the shader works again (the texture gets drawn.) But I want this line to work of course. So the question for you is: What could I have done wrong, or is this even possible what I want to achieve?

genpfault
  • 51,148
  • 11
  • 85
  • 139
A. Person
  • 111
  • 9
  • 4
    Your design (144 varying `vec2`s) doesn't seem right to me. – HolyBlackCat Jul 12 '17 at 13:05
  • I want the float array I passed over to the shader to be turned into a vector2 array. – A. Person Jul 12 '17 at 13:16
  • I'm trying to program a shader for lighting. The "tileCoords" are for the shader to know where light cannot pass through. The shader is applied to a transparent overlay the size of the window. It also will need to take multiple coordinates for the positions of light sources. It will make the pixels more transparent the closer they are to the light source and will make them opaque if they're inside a tile. Maybe you know a better way to do this than to pass over data to the shader and using just 1 window sized texture? – A. Person Jul 12 '17 at 13:26
  • I don't quite understand what you're doing, but the solution is probably to do this in two passes. Draw your occlusion data to a FrameBuffer texture. In a second shader, read from that texture. – Tenfour04 Jul 12 '17 at 18:18
  • btw. the error is not in the line itself, bespoken line just makes the shader optimizer not completely optimize away the loop and the varying. – LJᛃ Jul 12 '17 at 18:27

1 Answers1

4

The maximum number of varying vectors can be determined by MAX_VARYING_VECTORS and limits the number of vectors you can pass to the next shader stage. I'm very sure you exceeded the limit.

see also the following questions:

Rabbid76
  • 202,892
  • 27
  • 131
  • 174