Creating custom material expression based on existing

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:


It works with gentle slopes, but on large height difference texture stretches:

I know that flat texture cannot be applied to volume, but I want something like that:

Tried to apply Noise expression instead of texture and result was fine:

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:
изображение
My question is how it works and how can I get the same behavior but with my own logic? Thank you.

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 :smiley:

You can achieve this in many different ways. I managed to create a solution for a post process effect: Elias Wick – 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.