Tuesday, December 2, 2014

[UE4 Quick Tip] Removing Frac Artifacts

So with the (new) possibility to sample textures in a custom node it's also possible again to remove any kind of artifacts caused by non-continuous UVs (e.g. texture cropping/frac coords, polar coords etc...)

Given a texture object (Tex), mapping coordinates (UV) and non-frac coordinates (UV1) this is the HLSL code:
return Tex.SampleGrad(TexSampler,UV,ddx(UV1),ddy(UV1));

Using SampleGrad is 10 instructions cheaper than the 'ComputeMipLevel' material function and also preserves anisotropic filtering, so that's a double win.

1 comment:

  1. just tested this on UE3 and it also works

    thanks for the tip ;)