A few things in addition to @kidscancode’s correct, but minimal answer.
As explanation: you modify the coordinate at which the texture is read for each pixel (only for your eyes-texture, though).
Also I want to note that in your example, the masking seems to be incorrect. It looks like there are transparent pixels in the base texture which are also red, causing the eye texture to be displayed there aswell.
They don’t show up for these lines
col.rgb = vec3(abs(sin(TIME*3.0)));
col.rg = UV;
because these don’t change the pixel’s alpha value.
This one, however, overwrites the pixel’s alpha, aswell, causing you to see all masked pixels (even ones that are transparent)
col = tex;
Another thing you might want to avoid:
if(<some float variable> == <some constant>)
Because of inaccuracies or rounding errors == might not always work.
Personally I’d use something like (a >= 0.98f) just to be safe.
And lastly, looking at the UVs you might run into trouble with stretching for your eye-texture because of the UV difference. (it also looks like it in the 2nd gif you posted)
The factors 40 and 22.5 seem a bit arbitrary, did you calculate them or adjust them manually? You might run into problems if your texture size changes.
There is a way to calculate these using the dimensions of those text inside the shader.
Akorian | 2018-05-21 16:03
Right, should’ve made the shader calculate it so it works for everything. My game is 640x360 pixels, I divided that by 16, eyes texture is 16x16
nadomodan | 2018-05-21 16:14
I think it’s dependent on the size of the atlas texture that’s used for the tilemap and the size of your eye texture. (Unless you’re using this as an fullscreen postprocess shader and not an object shader)