Is it possible to resize a specific texture on a texture atlas in GLSL without affecting the other textures? Let's assume there is a texture atlas containing 16 different textures.
https://i.sstatic.net/ik0Fl.png
A formula I discovered for identifying the required texture is:
float scale = 1.0/0.25;
vec2 idx = vec2(1.0,2.0);
vec2 newUvForTexture = (vUv+idx)*scale;
vec4 tex = texture2D(texArray[0],newUvForTexture);
The texture located at position (1.0,2.0):
https://i.sstatic.net/NdNn7.jpg
Once the appropriate UV coordinates are obtained (resulting in the image above), what should be done if the texture needs to be resized, for example by using newUvForTexture*2.0
while preserving its original offset? Can someone showcase a GLSL code snippet illustrating this?
HERE IS A WORKING EXAMPLE: https://codepen.io/miguel007/pen/VwGpjvm
The goal is to resize the texture while retaining the offset and excluding other textures from being visible:
float scale = 1.0/4.0;
vec2 offset = vec2(1.0,2.0);
vec2 newUv = (vUv+offset)*scale;
gl_FragColor = vec4(texture2D(u_tex,newUv).rgb,1.0);
/*
vec2 scaledUp = newUv*.8;
gl_FragColor = vec4(texture2D(u_tex,scaledUp).rgb,1.0);
or
vec2 scaledDown = newUv*2.0;
gl_FragColor = vec4(texture2D(u_tex,scaledDown).rgb,1.0);
*/