# applyDisplacementMap inverted uvScale

**URL:** <https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971>\
**Category:** Questions\
**Created:** [April 13, 2020, 7:33pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971 "2020-04-13T19:33:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luan\_Ngo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/luan_ngo/32/649_2.png) [@Luan\_Ngo](https://forum.babylonjs.com/u/Luan_Ngo)\
**Post date:** [April 13, 2020, 7:33pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971/1 "2020-04-13T19:33:23Z")

</div>

I can’t seem to invert the texture using uvScale. I’m sure it’s a simple answer:

```
plane2.applyDisplacementMap("/textures/worldHeightMap.jpg", 0,10,null,new BABYLON.Vector2(0,0),new BABYLON.Vector2(1,-1),true);

```

Here’s a playground:  
[[https://www.babylonjs-playground.com/#IKANKZ#1(https://www.babylonjs-playground.com/#IKANKZ#1)](https://www.babylonjs-playground.com/#IKANKZ#1(https://www.babylonjs-playground.com/#IKANKZ#1))

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 13, 2020, 7:45pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971/2 "2020-04-13T19:45:48Z")

</div>

Are you sure your PG matches your question?

There’s no `applyDisplacementMap` call nor any scaling in the PG, only a texture that is changed after 10s…

---

<div class="post-metadata">

**Author:** ![Luan\_Ngo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/luan_ngo/32/649_2.png) [@Luan\_Ngo](https://forum.babylonjs.com/u/Luan_Ngo)\
**Post date:** [April 13, 2020, 8:27pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971/3 "2020-04-13T20:27:35Z")

</div>

Totally screwed that up. I didn’t press save.

Here’s the updated playground:  
[https://www.babylonjs-playground.com/#IKANKZ#1](https://www.babylonjs-playground.com/#IKANKZ#1)

---

<div class="post-metadata">

**Author:** ![wulf11](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wulf11/32/2196_2.png) [@wulf11](https://forum.babylonjs.com/u/wulf11)\
**Post date:** [April 13, 2020, 10:08pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971/4 "2020-04-13T22:08:54Z")

</div>

Do you want to achieve this?:  
[https://www.babylonjs-playground.com/#IKANKZ#3](https://www.babylonjs-playground.com/#IKANKZ#3)  
or this?:  
[https://www.babylonjs-playground.com/#IKANKZ#7](https://www.babylonjs-playground.com/#IKANKZ#7)  
or this? 😄  
[https://www.babylonjs-playground.com/#IKANKZ#8](https://www.babylonjs-playground.com/#IKANKZ#8)

Sorry if I don’t got your question right 😅

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 13, 2020, 10:20pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971/5 "2020-04-13T22:20:52Z")

</div>

I think @Luan_Ngo wants to have the texture inverted in the u/v dimensions:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/d/d4d7ef1f48c270695a748afca1206b3dd727df91.png)

It’s not currently possible because there’s a `Math.abs()` in the code:

```auto
var u = ((Math.abs(uv.x * uvScale.x + uvOffset.x) * heightMapWidth) % heightMapWidth) | 0;
var v = ((Math.abs(uv.y * uvScale.y + uvOffset.y) * heightMapHeight) % heightMapHeight) | 0;

```

It is easy to change it as:

```auto
var u = (((uv.x * uvScale.x + uvOffset.x) * heightMapWidth) % heightMapWidth) | 0;
var v = (((uv.y * uvScale.y + uvOffset.y) * heightMapHeight) % heightMapHeight) | 0;

if (u < 0) { u = heightMapWidth + u; }
if (v < 0) { v = heightMapHeight + v; }

```

but that would be a breaking change, so I don’t know how it should be handled…

For the time being, I have overloaded the function in the PG so that you can do what you want:

[https://www.babylonjs-playground.com/#IKANKZ#4](https://www.babylonjs-playground.com/#IKANKZ#4)

---

<div class="post-metadata">

**Author:** ![wulf11](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wulf11/32/2196_2.png) [@wulf11](https://forum.babylonjs.com/u/wulf11)\
**Post date:** [April 13, 2020, 10:51pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971/6 "2020-04-13T22:51:59Z")

</div>

@Evgeni_Popov could you check against this one please?

> ```
> plane2.applyDisplacementMap("/textures/worldHeightMap.jpg", 0, 10, null, new BABYLON.Vector2(-1, 1), new BABYLON.Vector2(1, 1), true);
> 
> ```

from my pg [https://www.babylonjs-playground.com/#IKANKZ#8](https://www.babylonjs-playground.com/#IKANKZ#8)

It’s really late, but would that script not show the same behavoir? 😅

---

<div class="post-metadata">

**Author:** ![Luan\_Ngo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/luan_ngo/32/649_2.png) [@Luan\_Ngo](https://forum.babylonjs.com/u/Luan_Ngo)\
**Post date:** [April 13, 2020, 10:58pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971/7 "2020-04-13T22:58:48Z")

</div>

Oh, that’s it. Sorry, I thought the offset shifts it rather than flips it.

I was using the example of a diffusetexture:

groundTexture.diffuseTexture.uScale = -1

Thank you all!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 13, 2020, 11:31pm UTC](https://forum.babylonjs.com/t/applydisplacementmap-inverted-uvscale/9971/8 "2020-04-13T23:31:03Z")

</div>

Indeed, that does work with offset = -1 too and no need to update the code!
