I’m creating a 2D rendering engine with WebGL in which I’m using Texture Atlases and batching hundreds of entities at once. I need to set a unique alpha value for each entity, and I’m at a loss of how to do this.
My current fragment shader is this:
I’d like to change that global uniform into a uniform buffer or an array of unique values that will be applied to the v_texCoord, but I don’t know how to do this.
You need to pass those values in as an attribute just like v_texCoord
.
in vertex shader
in fragment shader
Instead of using a separate attribute you could also just make your texture coordinates have 3 values. u, v, and alpha. In other words, change v_texCoord
to a vec3
. Update the attribute in the vertex shader to take a vec3
. Update your UV data so each UV also has an alpha. Change your fragment shader to.