# Float-based images (e.g. for precise terrains) full support: 4 float-based image classes (passed to GPU and shaders), loading 16-bit PNG, loading float-based KTX, loading 16/32-bit TIFFs, Castle Image Viewer improvements

**URL:** https://forum.castle-engine.io/t/float-based-images-e-g-for-precise-terrains-full-support-4-float-based-image-classes-passed-to-gpu-and-shaders-loading-16-bit-png-loading-float-based-ktx-loading-16-32-bit-tiffs-castle-image-viewer-improvements/1267
**Category:** News
**Created:** [July 12, 2024, 1:31pm UTC](https://forum.castle-engine.io/t/float-based-images-e-g-for-precise-terrains-full-support-4-float-based-image-classes-passed-to-gpu-and-shaders-loading-16-bit-png-loading-float-based-ktx-loading-16-32-bit-tiffs-castle-image-viewer-improvements/1267 "2024-07-12T13:31:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [July 12, 2024, 1:31pm UTC](https://forum.castle-engine.io/t/float-based-images-e-g-for-precise-terrains-full-support-4-float-based-image-classes-passed-to-gpu-and-shaders-loading-16-bit-png-loading-float-based-ktx-loading-16-32-bit-tiffs-castle-image-viewer-improvements/1267/1 "2024-07-12T13:31:02Z")

</div>

| [![Great lakes - terrain from precise 16-bit PNG ( https://www.motionforgepictures.com/height-maps/ )](https://forum.castle-engine.io/uploads/default/original/2X/b/beb7781d35ba1e2e83936bf8c5512651c314d4bc.png)](https://castle-engine.io/wp/wp-content/uploads/2024/07/screenshot_great_lakes.png "Great lakes - terrain from precise 16-bit PNG ( https://www.motionforgepictures.com/height-maps/ )") |
| [![Rugged terrain - from precise 16-bit PNG height map (from https://www.motionforgepictures.com/height-maps/ )](https://forum.castle-engine.io/uploads/default/original/2X/7/7ff892c7249c846a2db6df5da659146c72911e1f.jpeg)](https://castle-engine.io/wp/wp-content/uploads/2024/07/screenshot-with-diffuse.jpeg "Rugged terrain - from precise 16-bit PNG height map (from https://www.motionforgepictures.com/height-maps/ )") |
| [![Rugged terrain - no diffuse - from precise 16-bit PNG height map (from https://www.motionforgepictures.com/height-maps/ )](https://forum.castle-engine.io/uploads/default/original/2X/c/c24f863751500e6c5d7be119f0896dfafdb6e071.jpeg)](https://castle-engine.io/wp/wp-content/uploads/2024/07/screenshot-no-diffuse.jpeg "Rugged terrain - no diffuse - from precise 16-bit PNG height map (from https://www.motionforgepictures.com/height-maps/ )") |
| [![Big 16-bit TIFF (from https://sbcode.net/topoearth/gebco-heightmap-21600x10800/ )](https://forum.castle-engine.io/uploads/default/original/2X/b/b185525aa6e0cfea5c5610485d44ded50db4fa63.png)](https://castle-engine.io/wp/wp-content/uploads/2024/07/screenshot-image-viewer-tiff.png "Big 16-bit TIFF (from https://sbcode.net/topoearth/gebco-heightmap-21600x10800/ )") |
| [![PNG test suite](https://forum.castle-engine.io/uploads/default/original/2X/7/7bc70b38dde8849dd7eaccdc091759bcee782ba9.png)](https://castle-engine.io/wp/wp-content/uploads/2024/07/png_test_suite.png "PNG test suite") |

We added to _Castle Game Engine_ capability to read 16-bit and higher precision image formats. This is useful for precise terrains (where you want to store heightmaps with more precision than 8-bit) or any other data that you may want to process (in shaders or using Pascal code) where 0..255 range (8-bit integer, i.e. byte) is not enough.

Overall, this is a collection of inter-connected features and developments. We hope you enjoy our long news announcements :), here goes:

1. First of all, **grab the demo [test-high-precision-terrains: Test loading terrains from 16-bit and higher precision image formats](https://github.com/castle-engine/test-high-precision-terrains)**. It’s in a separate repository (not in CGE main repo) because it necessarily has quite large data files.

Just explore it, in editor and also run it, to see what this all means.

2. We have implemented a full set of **4 float-based image formats** :

3. **16-bit PNG images** can be loaded to 4 float-based image formats mentioned above. (Previously, they have been loaded to 8-bit image formats, losing precision.)

4. **Float-based [KTX](https://castle-engine.io/ktx) images** can be loaded to 4 float-based image formats mentioned above. This is great if you really need max precision. KTX contains float values, we read float values, there’s no conversion at all — everything is simple, fast, and using floats.

5. Likewise, **16/32-bit TIFF images** can be loaded to float-based image formats mentioned above.

6. **`TCastleTerrainImage` uses `TGrayscaleFloatImage`** to read terrain data from images. This means that it always operates on float precision, and you will enjoy extra precision if you image contains it — that is, if you use 16-bit PNG, or float-based KTX, or 16/32-bit TIFF.

7. Our **[Castle Image Viewer](https://castle-engine.io/castle-image-viewer) (test the snapshot version) also got some improvements** along the way:

8. Note: [saving float-based images is a TODO. It is documented in the roadmap.](https://castle-engine.io/roadmap#saving_float_images) As always, ping me if you need it.

## Credits

Big thanks go to _Erik Johnson_ for supporting _Castle Game Engine_ development, both on [Patreon](https://www.patreon.com/castleengine) and by actually using the engine to develop new projects, and providing a ton of useful feedback on our forum! See the [forum thread that initiated this](https://forum.castle-engine.io/t/request-for-tif-support/1240/26).

The sample data has been provided by:

- [Landscape Height Maps](https://www.motionforgepictures.com/height-maps/) – great detailed terrains, including 16-bit PNG images.

- [Topographical Earth Tutorials](https://sbcode.net/topoearth/gebco-heightmap-21600x10800/) for the big 16-bit TIFF image.

Engine features described in this post done by Michalis — [thanks to your support](https://www.patreon.com/castleengine).
