# Artifacts Found When Tiling UVs with Clamp Sample & Frac

**URL:** <https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [May 2, 2021, 11:40am UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450 "2021-05-02T11:40:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunoda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arunoda/32/464764_2.png) [@arunoda](https://forums.unrealengine.com/u/arunoda)\
**Post date:** [May 2, 2021, 11:40am UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/1 "2021-05-02T11:40:08Z")

</div>

Here’s I’m trying to tile UVs and apply some random rotation for those tiles. In order to do that, I need to tile UVs with the `frac` node. And I need to use the texture sampling with the `Clamp` mode.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/a/6ae57d34f9ffd6bbc37842cc2383adf60ff9ba8a.jpeg)

As you can see, now there are some artifacts around the border of the texture.

---

<div class="post-metadata">

**Author:** ![arunoda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arunoda/32/464764_2.png) [@arunoda](https://forums.unrealengine.com/u/arunoda)\
**Post date:** [May 2, 2021, 11:41am UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/2 "2021-05-02T11:41:04Z")

</div>

I got this fixed using by sending custom Mip Levels like this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/c/5c5cd2ac9b573089509180cd67d612b9b4b30735.jpeg)

But still, I’d like to see the reason behind this.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 3, 2021, 6:48am UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/3 "2021-05-03T06:48:53Z")

</div>

Toss in a ceil node instead of the fract node.  
if you set a box as the preview and zoom in you’ll see that the line is actually a small fraction of the image repeating over and over.

My guess is that it’s actually a mip artifact due to floating point precision of frac.  
Probably should be reported as a bug really.  
it seems that it is ignoring at least a range from .001 to .01

Not sure how to test this. Would actually be cool to be able to get a step by step result of every operation call logged somewhere to review what numbers FRAC is cutting

---

<div class="post-metadata">

**Author:** ![arunoda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arunoda/32/464764_2.png) [@arunoda](https://forums.unrealengine.com/u/arunoda)\
**Post date:** [May 3, 2021, 9:39am UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/4 "2021-05-03T09:39:49Z")

</div>

I got this for both ceil & floor as well. See:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/d/adb440855efb87b96c7ddc5e9441437826d9a3f8.jpeg)

So, this shouldn’t be something with `frac`.

May be it’s something with Anisotropic Filtering:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/3/7/370102f3d02d3bbca92b7686919af46653986ba0.png)

---

<div class="post-metadata">

**Author:** ![arunoda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arunoda/32/464764_2.png) [@arunoda](https://forums.unrealengine.com/u/arunoda)\
**Post date:** [May 3, 2021, 9:45am UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/5 "2021-05-03T09:45:46Z")

</div>

> [@MostHost\_LA](#):
>
> Probably should be reported as a bug really.

I just tested on 4.24 as well. I get the same result.  
May be that’s how it is from the beginning.  
Anyway, I will do a bug report.

---

<div class="post-metadata">

**Author:** ![Arkiras](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arkiras/32/1008648_2.png) [@Arkiras](https://forums.unrealengine.com/u/Arkiras)\
**Post date:** [May 3, 2021, 12:06pm UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/6 "2021-05-03T12:06:35Z")

</div>

This has been an issue for as long as I can remember. It’s extremely bad with world projected UVs; If the edges of a face line up right with the edge of a tile, you’ll get what looks like z-fighting. I posted about this [in this thread](https://forums.unrealengine.com/t/world-uvs-creating-glitchy-lines/155005) 6 months ago, and encouraged another user to report it as a bug.

Unfortunately Epic’s bug reporting process ensures the community will have virtually no idea if this is a bug, if it will ever be fixed, or if they’re even aware of it.

---

<div class="post-metadata">

**Author:** ![Arkiras](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arkiras/32/1008648_2.png) [@Arkiras](https://forums.unrealengine.com/u/Arkiras)\
**Post date:** [May 3, 2021, 12:36pm UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/7 "2021-05-03T12:36:16Z")

</div>

In case you’re curious this problem is also present in all light functions applied to point lights. I’m guessing whatever they’re doing to create the equirectangular projection probably involves using frac/ceil/floor.

 ![UE4_LightFunctionSeam](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/c/ac974b9ed6bef60c52d6e93c07f7306db53fdd78.jpeg)

---

<div class="post-metadata">

**Author:** ![Chosker](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chosker/32/710746_2.png) [@Chosker](https://forums.unrealengine.com/u/Chosker)\
**Post date:** [May 3, 2021, 12:59pm UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/8 "2021-05-03T12:59:45Z")

</div>

the reason frac does this is due to the continuous nature of UVs.  
think of UVs like a continuous field of values, going 0-\>1-\>2-\>N, and interpolating the values in between.  
“zoom in” and you’d see something like 0-\>0.25-\>0.5-\>0.75-\>1.0-\>1.25. zoom in closer to 1.0 and you’d see something like 0.98-\>0.99-\>1.0-\>1.1  
now the moment you do frac you’re actually making it do 0.98-\>0.99-\>0.0-\>0.1, which means that in the span from 0.999999 to 0.0 due to its continuous nature it has to wrap around back and interpolate all values from 0.999999 back down to zero, which happens in the span of a single pixel.  
what you see in the artifact area is a UV warping artifact. the entire texture is warp-squashed into a single pixel

I’m sure someone can find a more eloquent way to explain it but in [not so] short that’s the reason UV’s can’t just have cuts or jumps. and it doesn’t matter if you use frac, ceil, round, floor, if, etc. anything that causes a hard discontinuity in the field of values will cause a single-pixel UV warping artifact, similar to how using lerp on UVs will cause a UV warping artifact (just on a larger area)

a common workaround is to use the Derivative mipvalue mode. simply plug DDX and DDY nodes to your UVs and plug them to the derivative inputs of the texture sampler

---

<div class="post-metadata">

**Author:** ![Arkiras](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arkiras/32/1008648_2.png) [@Arkiras](https://forums.unrealengine.com/u/Arkiras)\
**Post date:** [May 3, 2021, 1:49pm UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/9 "2021-05-03T13:49:16Z")

</div>

> [@Chosker](#):
>
> a common workaround is to use the Derivative mipvalue mode. simply plug DDX and DDY nodes to your UVs and plug them to the derivative inputs of the texture sampler

Thank you so much for the explanation man, this problem has been a thorn in my side for a long time.

---

<div class="post-metadata">

**Author:** ![arunoda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arunoda/32/464764_2.png) [@arunoda](https://forums.unrealengine.com/u/arunoda)\
**Post date:** [May 3, 2021, 2:55pm UTC](https://forums.unrealengine.com/t/artifacts-found-when-tiling-uvs-with-clamp-sample-frac/227450/10 "2021-05-03T14:55:07Z")

</div>

> [@Chosker](#):
>
> a common workaround is to use the Derivative mipvalue mode. simply plug DDX and DDY nodes to your UVs and plug them to the derivative inputs of the texture sampler

Thanks. I think that’s exactly what `ComputeMipLevel` function does.

> [@Chosker](#):
>
> now the moment you do frac you’re actually making it do 0.98-\>0.99-\>0.0-\>0.1, which means that in the span from 0.999999 to 0.0 due to its continuous nature it has to wrap around back and interpolate all values from 0.999999 back down to zero, which happens in the span of a single pixel.  
> what you see in the artifact area is a UV warping artifact. the entire texture is warp-squashed into a single pixel

Thanks for the explanation.
