How can we manipulate a texture’s UVs from a shader?
I’ve taken a look at the Shader Reference, but am still quite new to shaders and would like to be pointed in the right direction. Edit: Your help is greatly appreciated, sorry if the question was too vague.
which kind of shader are you asking about?
for example, for surface shaders, you can modify IN.uv_TexName parameter.
this is usual line to read rgb value from tex to model surface:
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
this will swap X and Y of texture’s UV:
o.Albedo = tex2D(_MainTex, float2(IN.uv_MainTex.y, IN.uv_MainTex.x)).rgb;
It might be easier than you think. You really just need to be creative with even simple vertex/fragment shaders. If you look at the link below, then whenever you see
you’re really just dealing with a vector2. Manipulate the values of that vector in creative ways (translate them, multiply them, swap them) and you’ll see you get interesting results.
// make your texture appear half as big
o.uv = v.uv * 2;
// use your object's vertices as UV data
o.uv = mul(unity_ObjectToWorld, v.vertex).xz;
// creates a weird tartan pattern
float bentU = sin(v.uv.x + v.vertex.x * 2);
float bentV = sin(v.uv.y + v.vertex.z * 3);
o.uv = float2(bentU, bentV);
So, just be creative with your math!