While rendering a static mesh, like a tree or rock, i need to get the Landscape height in the material.
I know how to get the ‘Absolute World Position’ in the material, I need to get the ‘Landscape height’ at that current absolute world position.
Loading a copy of my height map the terrain is using and working out height values for any world position may be possible but that seems like a hack way to go if I can just query the terrain landscape from ‘any’ material applied to any static mesh and get the height value.
To clarify, I need to do this in a material NOT applied the the landscape, but applied to static mesh.
I’ve searched forums and just cant find any info or doc’s on this.
The question has been asked in the forums.
Using 16bit heightmap in material to recreate landscape
The Epic ‘Kite Demo’ has Terrain Heightmap sampling from a Material applied to static mesh on the rivers and lakes in the sub level maps.
For best results the height map needs to be 16 bit .png (can use 8 bit but that may cause stair stepping ).
Load the .png Heightmap as HDR (RGB, no sRGB) compression. In the material your Heightmap sample type should be ‘Linear Color’ and sample from the Red channel.
Material node example: Here is the material nodes, I got the UV calculation and Heightmap lookup from the ‘KiteDemo’.
Your ‘HeightmapScaleZ’ and ‘TerrainOffset’ will differ, I found mine through trial and error. Subtracting ‘Absolute World Position’ locks the height to your terrain, so what ever your vertices world Z is, this node graph will give you an offset to your terrain. The ‘MakeFloat3’ vector plugs into your materials ‘WorldPositionOffset’ attribute. The ‘KiteDemo’ has this graph as a material function, great idea, I am going to do the same so it can be easily applied in any material.
If you don’t have your height map or have modified one with sculpting, the Unreal Editor can export it for you in 16bit ‘,png’ format.