# Decals with "stretchable", non scaling material?

**URL:** <https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334>\
**Category:** Asset Creation\
**Tags:** unreal-engine\
**Created:** [January 17, 2023, 4:21pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334 "2023-01-17T16:21:44Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Graylord](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Graylord](https://forums.unrealengine.com/u/Graylord)\
**Post date:** [January 17, 2023, 4:21pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/1 "2023-01-17T16:21:44Z")

</div>

Hey, so I have this texture:

 ![2023-01-17 17_15_39-DashArrow.psd @ 100% (RGB_8)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/a/3/9a3f4dbd93ef5e36d3ea58ebad1477e27ae115ca.png)

I wish to use it to show when an enemy is charging up a dash attack, by “growing” from the bottom of the enemy.

So I want to scale it from the middle horizontal line, so that it doesn’t deform the arrows and end. Is that possible to set up in material?  
I suppose the decal actor should just be the max size to simplify things, and handle the size entirely in the material.

This seems like such a common graphical effect, so there’s probably established ways to do things like this.

Scaling it in general is easy, I just need to be able to scale it in one direction without deforming.

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [January 17, 2023, 7:05pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/2 "2023-01-17T19:05:34Z")

</div>

Hi Graylord,

Is this the kind of thing you were meaning?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/b/2/9b2b546b6cdeb205b883c1f09ca9e9757c9d2821.jpeg)

---

<div class="post-metadata">

**Author:** ![Graylord](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Graylord](https://forums.unrealengine.com/u/Graylord)\
**Post date:** [January 17, 2023, 7:33pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/3 "2023-01-17T19:33:15Z")

</div>

Yeah! That’s exactly what I meant! Thank you!

The only issue I have is that the the transition has tiny gap in the opacity mask, I can probably fix that, but I obviously wouldn’t mind suggestions.

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [January 17, 2023, 7:49pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/4 "2023-01-17T19:49:21Z")

</div>

Can you show me a snapshot of the gap? I can’t see one here…

---

<div class="post-metadata">

**Author:** ![Graylord](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Graylord](https://forums.unrealengine.com/u/Graylord)\
**Post date:** [January 17, 2023, 7:53pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/5 "2023-01-17T19:53:55Z")

</div>

Sure:

 ![2023-01-17 20_53_24-DashArrow_Mat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/c/4/ac4a1c14d9a82175e5f9143592fc67cb70d6194b.png)  
 ![2023-01-17 20_51_49-Winstick - Unreal Editor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/9/d/b9d60f0c8028903fff9af130a988c080bd605d19.jpeg)

Edit: I’ll share the actual texture in case that helps:

 ![DashArrow](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/0/e/80e76c60874145c84638c112b282724bd87a16b5.png)

Edit: It appears to be a mipmapping issue.

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [January 17, 2023, 8:19pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/6 "2023-01-17T20:19:57Z")

</div>

I still haven’t been able to reproduce a gap like that I’m afraid - the texture you shared didn’t have any transparency though so I added it in photoshop - perhaps that has something to do with it?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/c/e/4cefa9d80573e0fc6adfc090fe264033ab086cc1.jpeg)

EDIT: after uploading this snapshot, I can see the grid underneath the decal - that could well be the culprit 🙂

---

<div class="post-metadata">

**Author:** ![BananableOffense](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BananableOffense](https://forums.unrealengine.com/u/BananableOffense)\
**Post date:** [January 18, 2023, 3:06am UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/7 "2023-01-18T03:06:14Z")

</div>

Messing with UVs almost always does ruin mipmaps because they are automatically generated by looking at the difference in UV space. These effects interfere with the shaders ability to rely on the standard calculation. You’ll need to explicitly derive the mips.  
Change the texture samples mip mode to allow it to be manually derived. Use an unmodified Texture Coordinate and feed it into DDX and DDY nodes, and those into the DDX and DDY slot of the texture sample. This will force it to generate mips based on an unaltered coordinate instead of the modified UVs.

---

<div class="post-metadata">

**Author:** ![BananableOffense](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BananableOffense](https://forums.unrealengine.com/u/BananableOffense)\
**Post date:** [January 18, 2023, 3:58am UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/9 "2023-01-18T03:58:09Z")

</div>

If I’m not mistaken, each dimension only needs to individually be a power of 2. Because both 128 and 512 are power of 2 numbers, the engine should be able to mip them even though the whole image itself is not perfectly square.

---

<div class="post-metadata">

**Author:** ![Graylord](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Graylord](https://forums.unrealengine.com/u/Graylord)\
**Post date:** [January 18, 2023, 9:12am UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/11 "2023-01-18T09:12:30Z")

</div>

It’s not the grid I’m afraid, I get a 1 pixel gap wherever I define my “shearing point” to be.  
Using preserve border exacerbates it.

In this particular instance I could get away with not using mips.

Perhaps a way to duplicate a line of pixels and moving the rest to make it longer, instead of making a cut to make it shorter would be an alternate method?

---

<div class="post-metadata">

**Author:** ![BananableOffense](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BananableOffense](https://forums.unrealengine.com/u/BananableOffense)\
**Post date:** [January 18, 2023, 3:37pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/12 "2023-01-18T15:37:55Z")

</div>

There is no need to disable mips or find and alternate way to achieve the effect. Just calculate the mips using an unaltered texture coordinate like I mentioned and it should work fine.  
To be more precise, the shader guesses which mip it needs by comparing two adjacent coordinates in screen space. So if you skip a bunch of pixels in your UVs, it will look like the texture is really far away to the shader when it sees the coords change fast. This will cause it to choose the lowest quality mip for that spot, which creates a seam.  
So you simply need a second texture coordinate that isn’t altered to calculate DDX and DDY from. DDX and DDY are a measure of rate of change in X and Y. If you want smooth mips, you need a smooth rate of change in your coordinates. It’s basically always necessary to do this extra step when messing with the UVs non linearly.

---

<div class="post-metadata">

**Author:** ![Graylord](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Graylord](https://forums.unrealengine.com/u/Graylord)\
**Post date:** [January 18, 2023, 5:14pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/14 "2023-01-18T17:14:19Z")

</div>

My game is at a rather large scale, maybe you could scale it up a lot and move away to make sure mipmapping is taking place. I ended up using the green channel instead of opacity, but the opacity map doesn’t seem to be related to the issue and it indeed being due to mips.

> There is no need to disable mips or find and alternate way to achieve the effect. Just calculate the mips using an unaltered texture coordinate like I mentioned and it should work fine.  
> To be more precise, the shader guesses which mip it needs by comparing two adjacent coordinates in screen space. So if you skip a bunch of pixels in your UVs, it will look like the texture is really far away to the shader when it sees the coords change fast. This will cause it to choose the lowest quality mip for that spot, which creates a seam.  
> So you simply need a second texture coordinate that isn’t altered to calculate DDX and DDY from. DDX and DDY are a measure of rate of change in X and Y. If you want smooth mips, you need a smooth rate of change in your coordinates. It’s basically always necessary to do this extra step when messing with the UVs non linearly.

I think I get the idea, but it’s currently far past my skill level, but I’ll see what I can figure out with some google-fu ing about setting DDY and DDX

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [January 18, 2023, 5:21pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/15 "2023-01-18T17:21:05Z")

</div>

I went back to another place I’m doing something like this - I turn off mips (they’re small textures, they don’t need mips like you say) - just set it to no mips:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/5/9/f592f884bb2fe1b4e413a40945e8b0ee2892ebea.png)

---

<div class="post-metadata">

**Author:** ![BananableOffense](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BananableOffense](https://forums.unrealengine.com/u/BananableOffense)\
**Post date:** [January 18, 2023, 5:43pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/16 "2023-01-18T17:43:31Z")

</div>

> [@How to stop Textures from looking bad from afar?](https://forums.unrealengine.com/t/how-to-stop-textures-from-looking-bad-from-afar/749210/4):
>
> This is exclusively due to MipMapping and texture filtering. The farther from the camera, the blurrier the texture becomes. This is important to prevent aliasing, moiré and shimmering. You actually have explicit control over this. Here is an example of a grid texture using default computed mips, vs a texture using explicitly derived mips. I’m using DDX & DDY multiplied by some value that satisfies a compromise between blurriness vs shimmering. This is a setting within the texture sample called …

Here’s an example I shared for another case that called for explicit mip calculation.  
Just use these nodes except you won’t need the multiply.

---

<div class="post-metadata">

**Author:** ![Graylord](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Graylord](https://forums.unrealengine.com/u/Graylord)\
**Post date:** [January 18, 2023, 6:03pm UTC](https://forums.unrealengine.com/t/decals-with-stretchable-non-scaling-material/751334/17 "2023-01-18T18:03:05Z")

</div>

That was way simpler than I thought, thank you!

Edit: Works perfectly!
