TIFF texture value mapping settings

I was working with GeoTIFF DEM(digital elevation model) files, and the texel value(DN) is of type Int16, corresponding to 1 meter in the real world. When I imported multiple .tiff textures into unity, I found them all mapped to the range 0~1 in the shader. I want to use them as a height map, due to unity’s mapping, the textures have a different (unknown)scale for their value which is unexpected (for example, the Himalayas may have the same altitude as the sea level).

The document: Unity - Manual: Importing Textures said:
“Unity automatically flattens multi-layer Photoshop PSD or TIFF files on import so that there is no size penalty for your game.”

I wonder if there is a way to change the default behavior when unity is importing a .tif asset, so the texel values keep intact instead of mapping to 0~1.

These are not multi-layer TIFF files, so that line from the documentation isn’t related to this.

The problem is GeoTIFF isn’t really TIFF. Well, it is, but it has additional meta-data to tell a program what the data it holds is … and in the case of DEMs, specify what the elevation range of the image data is.

Unity doesn’t know to look for that data, it’s just reading the file as a straight TIFF, and thus has no way to know how to scale the image.

Additionally, Unity doesn’t support 16 bit TIFF files, so the files are converted to 8 bit before import. To use GeoTIFF DEM data you’ll need to convert them to RAW or 16bit PNG files, as well as get the elevation data out of the file yourself.

1 Like

Hello, I am very interested in this topic, do you know if there is a method to retrieve a value of a tiff file. I have been trying this perform this for a while now but I don’t find some much information.

Are you talking about on a GPU, in script from a texture asset, or directly from a file?

On GPU or a texture asset, you have to access the color value and translate that into whatever value you need. And you’ll be limited to getting the float representation of that value.

If you want the exact value in the tiff file, you’d need to look up the tiff file format and parse it yourself.

What I have done is a python program which get all the values in my tiff as a 2 dimensional array, create an image, with PIL library, the same size a the length of my array dimensions and encode the values of the tiff (from -8000 to 4000) in the R and G channel of my PNG.

Then in Unity, I get the value of my color, and recreate my value.

float value = color.r * 255 * 255 + color.g * 255;