Sending an array of `vec2` values to fragment shader

Hi all, I’m having some problems when I try to send a bunch of vec2 values to the fragment shader. I need to send multiple vec2 values, each vec2 value defines a position of some character.

 this.material.setParameter('positions[0]', [playerPos.x, playerPos.z]);
this.material.setParameter('positions[1]', [playerPos.x + 1.0, playerPos.z + 1.0]);

My shader:

uniform vec2 positions[2]; // trying to create an array of vec2 value with capacity 2

This works:

getSelectedCharPosition(positions[0]);

But this does not work:

getSelectedCharPosition(positions[1]);

Any ideas?

Hi @Ertugrul_Cetin,

Yes, it requires flattening and passing your whole array at once. Check this post for instructions, and also check the WebGL 1 vs 2 compatibility follow up at the end:

2 Likes

Thanks @Leonidas

Here’s an example, search for ‘tints’ in it:

3 Likes