How does Unreal store height information of a Landscape?
I have difficulties in accessing the height information (per vertex) of a landscape in C++.
There is literally zero documentation for the Landscape classes (ALandscape, ULandscapeComponent etc.) within the engine code. Which makes things really really hard. I have following issues and questions:
However this time all values written to height is gibberish. Visual Studio Debugger shows strange characters for the FColor channels instead of meaningful grayscale values.
I would greatly appreaciate all help.
I had to dig deep into the UE code but I think I've found the answer.
The height map pixels use 32bit (4 channel) RGBA format. The first two channels represent the 16 bit height map. Therefore you need to bit shift the R channel by 8 bits and then use logical or operator to get the actual height. Se the code sample I've posted above and plug the below piece of code.
The B and A channels encode the tangents of the height map.
The first mip map (0) gives the full resolution height map. Other mip maps are divided by 2 in order. Also terrain mipmaps are generated differently than other texture mipmaps and they consider the 16 bit height values in the first two channels. Therefore it is safe to use the higher index mip maps (with lower resolution) if you desire.
Unreal height maps range from -256 to 256 meters within the scene. Therefore the height map having uint16:max would correspond to 256 meters. Of course you also need to take the Landscape actors scale into account. The z axis scale can effect this value in the game.
Another issue is that I think that the ULandscapeComponent's HeightMapTexture members all correspond to the same height map that is the landscape height map. When I see this member within the ULandscapeComponent I thought that all components of the landscape do keep their own vertex height data within a separate texture. But this was wrong. So you need to sample the one and the unique Landscape actor heightmap for each vertex within a component if you want to export this height data somewhere.
answered May 12 '17 at 03:15 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here