# Creating custom material expression based on existing

**URL:** <https://forums.unrealengine.com/t/creating-custom-material-expression-based-on-existing/897630>\
**Category:** Blueprint\
**Tags:** unreal-engine, Rendering, Shaders, question, CPP, Blueprint\
**Created:** [April 12, 2023, 8:20pm UTC](https://forums.unrealengine.com/t/creating-custom-material-expression-based-on-existing/897630 "2023-04-12T20:20:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PazDim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PazDim](https://forums.unrealengine.com/u/PazDim)\
**Post date:** [April 12, 2023, 8:20pm UTC](https://forums.unrealengine.com/t/creating-custom-material-expression-based-on-existing/897630/1 "2023-04-12T20:20:41Z")

</div>

Hi. I’m creating custom mesh based on array of heights.  
Each element of array contains vertex with its own positions (world and UV). UV is just takes 2D from world position. Then I create polygons:

 ![vertices](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/a/35a71fa6cc41caf51ff858357cd345dbb75ad00c.jpeg)  
It works with gentle slopes, but on large height difference texture stretches:  
 ![grid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/3/0/630e68abdc12d2a62ba44289a41d0519ad119e37.jpeg)  
I know that flat texture cannot be applied to volume, but I want something like that:  
 ![gridWanted](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/3/3/6337544f4a1e4e1e3d7b3f15006e74e93b345575.jpeg)  
Tried to apply Noise expression instead of texture and result was fine:  
 ![noise](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/3/fb32f8b0a6465b8ffa83e013422a6cb4c356c481.jpeg)  
I don’t know, how it works, but somehow it applies noise texture without stretches.  
Now I’m trying to read source code of this node expression. Found several files:  
MaterialExpressionNoise.h  
MaterialExpressions.cpp  
Common.ush  
and I don’t see any magic: UMaterialExpressionNoise::Compile takes input argument Position and passes it to Compiler-\>Noise. So, my idea is replace Noise function by Texture. But I don’t pass Position in Material:  
 ![изображение](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/6/3/d63409f92cac9ac74947fa06bb3a4c659d062419.png)  
My question is how it works and how can I get the same behavior but with my own logic? Thank you.

---

<div class="post-metadata">

**Author:** ![PazDim](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PazDim](https://forums.unrealengine.com/u/PazDim)\
**Post date:** [April 13, 2023, 4:40pm UTC](https://forums.unrealengine.com/t/creating-custom-material-expression-based-on-existing/897630/2 "2023-04-13T16:40:04Z")

</div>

Ok, I thinks I understood how Noise works. It is 3D noise and requires 3D position (instead of UV in texture). So, I need 3D texture 😃

---

<div class="post-metadata">

**Author:** ![EliasWick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eliaswick/32/1175208_2.png) [@EliasWick](https://forums.unrealengine.com/u/EliasWick)\
**Post date:** [April 14, 2023, 2:52pm UTC](https://forums.unrealengine.com/t/creating-custom-material-expression-based-on-existing/897630/3 "2023-04-14T14:52:03Z")

</div>

You can achieve this in many different ways. I managed to create a solution for a post process effect: [Elias Wick – Texture Projection](https://eliaswick.com/products/texture-projection)

For ordinary models and applied materials you should be able to use the world aligned materials.

If you want something similar to the noise, you got it: a 3D texture or at least something that is generated in 3D.
