Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16-Bit raw greyscale map seems to be importing with reduced precision #161

Closed
DingboDingboDingbo opened this issue Apr 29, 2020 · 6 comments
Labels
enhancement New feature or request Fixed in master Fixed on latest Github version but not yet available from the asset library

Comments

@DingboDingboDingbo
Copy link

DingboDingboDingbo commented Apr 29, 2020

Describe the bug
A heightmap was cobbled together in GIMP, with bit depth set to 16 bit and color mode to greyscale. Exported as raw with default options. Built a simple test program in C++ to verify the export, everything appears normal. Upon importing the raw image as a heightmap for terrain, only a few (3-4?) different heights can be observed. When the png version of the same heightmap is imported (albeit at a lower bit depth), the terrain appears much smoother overall, (although still jagged due to the insufficient precision).

To Reproduce
Steps to reproduce the behavior:

  1. Create a new HTerrain
  2. Select it
  3. Click on "Terrain" and import the heightmap (any min/max height values, I used 0,100)
  4. Observe "low precision" terrain. Scale vertically to exaggerate stepping.

Expected behavior
The raw 16-bit heightmap should produce a significantly higher fidelity than the 8-bit png heightmap.

Screenshots
(png version):
pngterrain

(raw version)
rawterrain

Environment

  • OS: Tested on Windows 10 and Manjaro
  • Graphics card: Nvidia RTX 2080ti
  • Godot version: 3.2.stable.mono.official
  • Plugin version: 1.2.1
  • Renderer used: GLES3

Contents of attached heightmaps.zip:
world8bit.png - the png file mentioned above - directly converted from the raw file via custom program to make sure the GIMP output was correct.
world.raw - the 16-bit uncompressed raw heightmap exported from GIMP.

heightmaps.zip

@Zylann
Copy link
Owner

Zylann commented Apr 30, 2020

My first guess is that Gimp exported the data in a different endianess than what the plugin reads... but I'll need to take a closer look

@Zylann Zylann added the bug Something isn't working label Apr 30, 2020
@Zylann
Copy link
Owner

Zylann commented Apr 30, 2020

I was able to obtain a non-flat terrain by swapping endianess. The fact Gimp does not indicate this doesn't help^^"
But the result still shows very similar to the PNG result. Maybe your raw file really is 16-bit, but the tool you used inside Gimp might not have worked using those 16-bits of precision?
You could try exporting as EXR to see if that works.

When I import a 16-bit raw heightmap generated by the Scape terrain generator, I get smooth results.

I changed tag to enhancement because the import dialog needs an option to choose endianess.

@Zylann Zylann added enhancement New feature or request and removed bug Something isn't working labels Apr 30, 2020
@DingboDingboDingbo
Copy link
Author

I was about to report the same findings after swapping the endianess. I'll investigate the Gimp situation further, but I doubt that it'll be relevant here! Thank you for your time and hard work on this plugin!

@RonanZe
Copy link

RonanZe commented Apr 30, 2020

If you search for an immediat solution, I was able to export and import a perfect matching heightmap from blender by using EXR in float (32bits), then, convert it in Krita in the format "R32 Heightmap".

Then I had to change the code of the plug a little bit to support the R32 format.

If I remember well, I had to change the following points in the hterrain_data.gd script:

  1. FORMAT_RH to FORMAT_RF in hterrain_data.gd

  2. in the "func _import_heightmap" the ext "raw" to "r32" and the loop that read the data from "var gs = float(f.get_16()) / 65535.0" to "var gs = f.get_float()" because the R32 work in float and raw in integer.


    var gs = float(f.get_16()) / 65535.0

  3. change "var file_res = Util.integer_square_root(file_len / 2)" to var file_res = Util.integer_square_root(file_len / 4)

    var file_res = Util.integer_square_root(file_len / 2)

I was thinking to make a patch but I'm not skilled enough with Git and Github :)

@Zylann
Copy link
Owner

Zylann commented Apr 30, 2020

Added an endianess option in beb4502

@Zylann Zylann added the Fixed in master Fixed on latest Github version but not yet available from the asset library label Apr 30, 2020
@DingboDingboDingbo
Copy link
Author

I've confirmed that Gimp's raw export will output a 16 bit file, but the actual values are converted to 8 bit during the process, which is pretty silly.

I hope you don't mind my leaving this comment here in case someone else stumbles across a similar issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Fixed in master Fixed on latest Github version but not yet available from the asset library
Projects
None yet
Development

No branches or pull requests

3 participants