# Foliage instance position in Material editor

**URL:** <https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781>\
**Category:** Rendering\
**Tags:** position, unreal-engine, Foliage, UE4, question\
**Created:** [September 8, 2016, 10:42am UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781 "2016-09-08T10:42:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![akaPrometh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@akaPrometh](https://forums.unrealengine.com/u/akaPrometh)\
**Post date:** [September 8, 2016, 10:42am UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/1 "2016-09-08T10:42:47Z")

</div>

Hi there 🙂

I want to obtain the **global position of an instanced mesh from a Procedural Foliage Volume** in the material editor.  
This is already possible with a hand dropped mesh using the “ObjectPosition” node, but not with a PFV as it returns the PFV’s position instead of the mesh’s.

Question is: How can I achieve this, or perhaps cheat it around, or even just know if it’ll be implemented some day.

Thanks!

There already are many similar threads about this since UE4.9 in 2015 but none seem to get any love or attention :’(  
If you’re interested in this, you may follow these other threads as well as upvote (the UP arrow to the left of the question).

> **[Get foliage instance mesh position](https://forums.unrealengine.com/questions/384539/get-foliage-instance-mesh-position.html)**
>
> Is there a way to get position of foliage instance in material editor? There are per instance data in the HLSL shader, but I can't find a way to use them in the material editor.

> **[Instance Foliage Mesh Position](https://forums.unrealengine.com/questions/192240/instance-foliage-mesh-position.html)**
>
> So, I am trying to make a material that changes depending on the world position of the mesh. I can do this with individual meshes, but when I use the Foliage Editor and add in Instance Meshes to my scene, the Actor Position in the material gets the...

> **[Foliage Instance Position](https://forums.unrealengine.com/questions/449701/foliage-instance-position.html)**
>
> ObjectPosition and ObjectOrientation only give results for the foliage actor that manages the instances. How do i get the position of an instance of foliage in the material editor? PerInstanceFade and PerInstanceRandom are already there and pull...

> **[How can i get the properties of instance in Foliage?](https://forums.unrealengine.com/questions/321400/how-can-i-get-the-properties-of-instance-in-foliag.html)**
>
> I want get location of the instance member in Foliage. This is what I selected foliage in viewport and launch my function then return the instance's location. this is my code: AActor\* TargetActor = NULL; AInstancedFoliageActor\* CurrentIFA = NULL;...

To give an idea, I’m trying to achieve this effect on all instances of a PFV. Basically im trying to cheat lighting depth on tree leaves using the distance of the texel from the mesh’s origin.You can notice it works well on hand placed meshes but not on the PFVs placed behind.

 ![106151-awesome_fake_depth_lighting_effect.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/5/b/65b4908fd1e39eb6e19d1350b21233a4e9b80a00.jpeg)

If I scale up the values in my SphereMask node it gives this: (the trees way behind are lods with a different material)

 ![106153-when+applied+on+instances+of+a+pfv+with+increased+values.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/e/6ae026a29112a0725dfb5df444374b8692e6a604.jpeg)

And this the basic node operations to get the distance

 ![106154-blueprint+base.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/9/4/394602c08f2c7e827a1d0459cad3f6a5e96185f5.jpeg)

---

<div class="post-metadata">

**Author:** ![Deathrey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deathrey](https://forums.unrealengine.com/u/Deathrey)\
**Post date:** [September 8, 2016, 3:37pm UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/2 "2016-09-08T15:37:40Z")

</div>

Try passing object position through custom UVs. It should return per-instance position that way If i’m not mistaken.

---

<div class="post-metadata">

**Author:** ![RVillani](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rvillani/32/1194572_2.png) [@RVillani](https://forums.unrealengine.com/u/RVillani)\
**Post date:** [September 16, 2017, 11:20am UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/3 "2017-09-16T11:20:25Z")

</div>

It works! Thanks!  
Unfortunately not for ObjectBounds neither ObjectOrientation, though. ☹

---

<div class="post-metadata">

**Author:** ![Deathrey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deathrey](https://forums.unrealengine.com/u/Deathrey)\
**Post date:** [September 16, 2017, 5:41pm UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/4 "2017-09-16T17:41:44Z")

</div>

For Object Orientation is just a vector, that is constant through the whole instance. You can just transform (1,0,0) from local to world to get Instance X axis in world space. In case of object bound, it is not really applicable to individual instances.

---

<div class="post-metadata">

**Author:** ![gstyczen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gstyczen](https://forums.unrealengine.com/u/gstyczen)\
**Post date:** [January 6, 2018, 4:08am UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/5 "2018-01-06T04:08:47Z")

</div>

I love you Deathrey!

---

<div class="post-metadata">

**Author:** ![BOBtheROSS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BOBtheROSS](https://forums.unrealengine.com/u/BOBtheROSS)\
**Post date:** [January 5, 2019, 5:06pm UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/6 "2019-01-05T17:06:39Z")

</div>

I came across this problem recently and didn’t quite get what you meant because UVs are only 2-dimensinal, so I only had the X and Y position. But after I set the “Num custom UVs” to 2 (in the Material settings) I was able to get the Z axis as well.

 ![264239-instanceposition.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/c/d/dcd454823fff6d1436890fc46f8ec4bf7c959e1c.jpeg)

---

<div class="post-metadata">

**Author:** ![Deathrey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deathrey](https://forums.unrealengine.com/u/Deathrey)\
**Post date:** [January 5, 2019, 6:54pm UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/7 "2019-01-05T18:54:35Z")

</div>

You can use vertex interpolator material expression in newer versions.

---

<div class="post-metadata">

**Author:** ![BOBtheROSS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BOBtheROSS](https://forums.unrealengine.com/u/BOBtheROSS)\
**Post date:** [January 13, 2019, 3:38pm UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/8 "2019-01-13T15:38:28Z")

</div>

Oh you’re right. I never heard of that node before. This way it’s cheaper and no UVs will be harmed during the process, thx 😉

 ![265251-instancevertexposition.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/8/8/18893da4d3b3397f1e490d8d21206b82003f9f44.jpeg)

I’ll leave a txt file for easier copy-paste  
[link text][2]

Edit: Just to make clear how the setup would be for the sphere mask

![265255-instancespheremask.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/1/98133fdb4ac038993d8b9b0fd2873b5c9d5c8d25.jpeg)

---

<div class="post-metadata">

**Author:** ![pakinmaksim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@pakinmaksim](https://forums.unrealengine.com/u/pakinmaksim)\
**Post date:** [February 15, 2024, 3:36pm UTC](https://forums.unrealengine.com/t/foliage-instance-position-in-material-editor/369781/9 "2024-02-15T15:36:53Z")

</div>

Best!
