[Mobile] Texture filtering missing when swapping uv's x and y

I want to swap uv x-y but it seems it remove the filtering so the texture looks pixelated. Is there any way to get the filtering work again. Also it seems to be happen only on mobile since in the editor everything work just fine…

Here’s the part of shader that switched it

  fixed3 n = IN.normals;
   fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
   fixed2 uvH = IN.uv_SandTex;
   fixed2 uvV = uvH;
//swap uv x <-> y
   uvV.x = lerp(uvH.y, uvH.x, step(n.r, 0.5)); // if these two lines is commented out
   uvV.y = lerp(uvH.x, uvH.y, step(n.r, 0.5)); // the texture looks smooth(filtered)

//Also tried this but still get pixelated
//f = step(n.r, 0.5);
//uvH.x = uvV.y;
//uvH.y = uvV.x;
//uvV = IN.uv_SandTex * (1 - f) + uvH * f;
  
   fixed4 s = tex2D(_SandTex, uvV);
...
//just output everything here

Here’s the picture of the pixelated one

And here’s when the uv xy swap removed

For the lerp try:
uvV.xy = lerp(uvH.xy, uvH.yx, (float)step(n.r, 0.5));

If that doesn’t work then just do:
uvV.xy = n.r > 0.5 ? uvH.xy : uvH.yx;

And yes, that’s an inline if statement, but so is the step() function.

1 Like

unfortunately, both still produce the same pixelated result…
btw, i ended up sampling both horizontal texture and vertical result and lerp between the two of them and it actually work on mobile, it might be slower though since it has to sample more texture…
but thanks anyway :wink:

Actually I just realised you’re using fixed instead of float for UVs. Try replacing all of the fixed2 with float2. You never want to use fixed for UVs, always at least half and more often float.

The reason why it might work when you comment out those lines is the shader compiler is it is probably optimizing away the setting of the variables and precision conversion (from float to fixed).

1 Like

Yes, it works, well, it didn’t at the first time since I forgot to change the fixed in the struct Input as well :p, but it actually work!
Thanks again mate :slight_smile: