# Use World Position.xz for texture sampling?

**URL:** <https://forum.babylonjs.com/t/use-world-position-xz-for-texture-sampling/32729>\
**Category:** Questions\
**Created:** [August 2, 2022, 10:28pm UTC](https://forum.babylonjs.com/t/use-world-position-xz-for-texture-sampling/32729 "2022-08-02T22:28:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [August 2, 2022, 10:28pm UTC](https://forum.babylonjs.com/t/use-world-position-xz-for-texture-sampling/32729/1 "2022-08-02T22:28:12Z")

</div>

I would know how to make a custom shader for this but I was wondering if anyone can think of an easy way to do this with a full PBR material. Ideally it would be a PBRCustomMaterial or one of the new Materials classes we have to make custom mats.

I was also thinking because the mesh in question is static, at runtime I could update the uv0 buffers to the global position of the vertex and that would work right out the box with the normal material.

Just looking for opinions and ideas.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [August 3, 2022, 12:10am UTC](https://forum.babylonjs.com/t/use-world-position-xz-for-texture-sampling/32729/2 "2022-08-03T00:10:18Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#9ISZY2)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

This is basically what I would think is easiest for a static mesh, but again looking for ideas.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [August 4, 2022, 11:04am UTC](https://forum.babylonjs.com/t/use-world-position-xz-for-texture-sampling/32729/3 "2022-08-04T11:04:54Z")

</div>

@Evgeni_Popov might know? 🤔

---

<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:** [August 4, 2022, 11:34am UTC](https://forum.babylonjs.com/t/use-world-position-xz-for-texture-sampling/32729/4 "2022-08-04T11:34:15Z")

</div>

One way would be to override the `vMainUV` variable at the end of the vertex shader.

Here’s a modified PG that is doing this by mean of a material plugin:

> **[Babylon.js Playground](https://playground.babylonjs.com/#9ISZY2%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [August 4, 2022, 3:35pm UTC](https://forum.babylonjs.com/t/use-world-position-xz-for-texture-sampling/32729/5 "2022-08-04T15:35:01Z")

</div>

Perfect, that is kind exactly what I was looking for! Im glad you did it with the new material thing, I’ve been meaning to learn it. Thank you Evgeni \<3.
