Tiling SubUV Issues

Aha! You fool! You fell victim to one of the classic blunders - the most famous of which is “never use a texture with out proper padding” - but only slightly less well-known is this: “Never use a frac on a texture UV without calculating the derivates!”

Hahaha haha hahahhah haha ha …
https://i.makeagif.com/media/8-21-2017/Bs1J7-.gif

ahem

GPUs determine the mip level to use for a texture by how much the UV changes between pixels. When you use a frac you’re causing the UV to go from “0.99” to “0.0” in one pixel. That means the GPU thinks the entire texture is being “seen” between those two pixels, and thus it should use the smallest mip available.

There are a few solutions. The simplest one is to disable mip maps entirely on the texture, or manually set the mip level on the texture sample. This will cause aliasing issues if your texture is viewed with any amount of minification (would normally be showing less than the largest mip level).

What you want to do instead is to pass the derivatives (ddx & ddy) of the post-scale & pre-frac UVs into the texture sample.

I believe in UE4 you can select the texture sample node and change the MipValueMode to Derivatives and it’ll expose two inputs. Then make a ddx and a ddy node and input the output of the multiply node before the Frac into those. Then pipe the dd* nodes into the appropriate input on the texture sample node.

7 Likes