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

Issues with dds format #4

Open
GeorgeAdamon opened this issue Feb 21, 2023 · 14 comments
Open

Issues with dds format #4

GeorgeAdamon opened this issue Feb 21, 2023 · 14 comments

Comments

@GeorgeAdamon
Copy link

GeorgeAdamon commented Feb 21, 2023

Hello @h3r2tic and thanks for your great work!

Unfortunately I had issues trying to open the .dds LUT in Unity 2022, therefore I tried converting it, without luck.

I also tried using the ktx2 file provided in #2, but both software mentioned above had issues opening that file as well.
Even an up-to-date Unity ktx importer failed.

Do the above ring a bell ?

Suggestion: A raw data dump of the LUT's contents would be useful, and trivial to directly load into an HLSL Texture3D object. I assume it's a W x H x D array of 32-bit floats ?

Thanks for your time!

@h3r2tic
Copy link
Owner

h3r2tic commented Feb 21, 2023

Ouch! That's painful xD

The DDS is rgb9e5, and maybe that's the problem for those loaders... You could try https://github.com/h3r2tic/tony-mc-mapface/blob/main/OCIO/lut-converter/tony_mc_mapface_f32.dds which is f32 :)

@Calinou
Copy link

Calinou commented Feb 22, 2023

I can confirm Godot 4.0.rc3 can't open the DDS provided on GitHub. Godot doesn't support KTX2 files either, so #2 isn't an option.

Unrecognized or unsupported color layout in DDS 'res://tony_mc_mapface.dds'.
Failed loading resource: res://tony_mc_mapface.dds. Make sure resources have been imported by opening the project in the editor at least once.
editor/editor_node.cpp:1208 - Condition "!res.is_valid()" is true. Returning: ERR_CANT_OPEN

Suggestion: A raw data dump of the LUT's contents would be useful, and trivial to directly load into an HLSL Texture3D object. I assume it's a W x H x D array of 32-bit floats ?

Could a Radiance HDR or OpenEXR image also be created in 2D format (with vertical or horizontal slices)? This would be the easiest to import in Godot as a 3D texture.

@h3r2tic
Copy link
Owner

h3r2tic commented Feb 22, 2023

Does Godot choke on both the rgb9e5 and the rgba32f DDS files?

@Calinou
Copy link

Calinou commented Feb 22, 2023

Does Godot choke on both the rgb9e5 and the rgba32f DDS files?

Yes, it can't open RGBA32F either. The DDS loader code is here: https://github.com/godotengine/godot/blob/master/modules/dds/texture_loader_dds.cpp

Running from a terminal prints more information:

unrecognized fourcc 30315844 format_flags: 4 - rgbbits 0 - red_mask 0 green mask 0 blue mask 0 alpha mask 0
ERROR: Unrecognized or unsupported color layout in DDS 'res://tony_mc_mapface_f32.dds'.
   at: load (modules/dds/texture_loader_dds.cpp:207)

unrecognized fourcc 30315844 format_flags: 4 - rgbbits 0 - red_mask 0 green mask 0 blue mask 0 alpha mask 0
ERROR: Unrecognized or unsupported color layout in DDS 'res://tony_mc_mapface.dds'.
   at: load (modules/dds/texture_loader_dds.cpp:207)

GIMP's DDS plugin also can't open both of those formats.

It should be feasible to add support for more DDS formats in a future Godot 4.x release. @fire may be interested in this 🙂

@h3r2tic
Copy link
Owner

h3r2tic commented Feb 22, 2023

Thanks for confirming! FWIW I exported the DDS using RenderDoc :) Will check whether it can output an unrolled 2D image instead.

@h3r2tic
Copy link
Owner

h3r2tic commented Feb 22, 2023

Perhaps this works?

hdr_exr.zip

No guarantees about the precision of those; I used RenderDoc for the conversion. Please check against some of the images in the README for whether there's no banding, and if the black levels look the same

@Calinou
Copy link

Calinou commented Feb 22, 2023

Perhaps this works?

Both import successfully in Godot 🙂

However, the green channel's direction is flipped compared to what Godot expects for color correction LUT textures (Y+ is downwards, not upwards).

I've flipped the 48 layers individually in GIMP to make the OpenEXR texture work correctly in Godot. The image is included in this Godot project as tony_mc_mapface_unrolled_inverted_y.exr: color_correction.zip

As a result, I'd recommend making Y-flipped textures available as part of the package if possible (that is, with individual layers flipped, not the entire image).

Edit: The finished project I used for testing is available here: godotengine/godot-demo-projects#857

Linear tonemapping

Screenshot_20230223_003050

Linear tonemapping + Tony Mc Mapface as color correction texture

Clipping appears as white, as linear tonemapping in Godot doesn't support whitepoint adjustments. When used with an appropriate whitepoint value (typically around 6), other tonemapping modes supported by Godot (Reinhard, Filmic, ACES) don't exhibit this white clipping as much when using the color correction texture.

Screenshot_20230223_003058

@h3r2tic
Copy link
Owner

h3r2tic commented Feb 22, 2023

Are you using HDR stimulus to look up into the LUT using the x/(x+1) remap from the provided shader? If you're looking it up using clipped LDR data then the output will not be correct.

It might need to be its own separate tone mapper in Godot -- or, if Godot's Reinhard is exactly x/(x+1) applied separately to each of the R, G, and B channels, then that might match the input remap the LUT expects.

Also note that the range remap for the LUT is important (the * 47.0/48 + 0.5/48 thing). Perhaps Godot does that for its color correction textures, but perhaps not.

@Calinou
Copy link

Calinou commented Feb 22, 2023

Are you using HDR stimulus to look up into the LUT using the x/(x+1) remap from the provided shader?

No, I'm using Godot's built-in color correction functionality, which doesn't provide a way to do this. It's possible to run custom post-processing shaders but they're slower and have various limitations.

If you're looking it up using clipped LDR data then the output will not be correct.

Unfortunately, color correction runs after tonemapping, and the output data from all tonemappers is clamped between 0 and 1: https://github.com/godotengine/godot/blob/19c9fd6926b958016d562e3b2e93b0e9480300f5/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl#L491-L493

or, if Godot's Reinhard is exactly x/(x+1) applied separately to each of the R, G, and B channels, then that might match the input remap the LUT expects.

The Reinhard tonemap formula used is here: https://github.com/godotengine/godot/blob/19c9fd6926b958016d562e3b2e93b0e9480300f5/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl#L243-L245

The color correction doesn't look too bad with Reinhard – it helps against the "desaturated" effect that Reinhard often has. It's quite close to Linear without any color correction, but without visible clipping.

Reinhard tonemapping, whitepoint = 6.0

Screenshot_20230223_005556

Reinhard tonemapping, whitepoint = 6.0 + Tony Mc Mapface as color correction texture

Screenshot_20230223_005604

Also note that the range remap for the LUT is important (the * 47.0/48 + 0.5/48 thing). Perhaps Godot does that for its color correction textures, but perhaps not.

It's not doing any remap: https://github.com/godotengine/godot/blob/19c9fd6926b958016d562e3b2e93b0e9480300f5/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl#L343-L353

I agree this will need to be a built-in tonemap mode to be implemented correctly in Godot (without the limitations of custom post-processing).

PS: Sorry for going off-topic on this thread, I figure I'd go down this Godot rabbit hole so others don't have to 🙂

@h3r2tic
Copy link
Owner

h3r2tic commented Feb 23, 2023

Yeah let's not hijack this topic more 😅 With the formulation that Godot uses for its Reinhard and color correction, TonyMcMapface will not work correctly. It's not really intended to be a color correction LUT; there was a chance it would work if all the planets aligned, but it doesn't seem like they are aligning. Please open a separate issue about Godot if you wish to discuss it further 🙏

@GeorgeAdamon
Copy link
Author

GeorgeAdamon commented Feb 23, 2023

Ouch! That's painful xD

The DDS is rgb9e5, and maybe that's the problem for those loaders... You could try https://github.com/h3r2tic/tony-mc-mapface/blob/main/OCIO/lut-converter/tony_mc_mapface_f32.dds which is f32 :)

@h3r2tic Thanks for this!

The NVIDIA Texture Tools app doesn't complain now, but... Unity of course doesn't open it. Unity's .dds importer is quite limited in scope apparently.

That being said, with the knowledge that I'm dealing with 32bit uncompressed RGBA and a proper read of the microsoft docs, I wrote a Unity importer, which I will publish today when I clean it up. @Calinou Maybe my C# importer will be a useful starting point for Godot as well.
image

@GeorgeAdamon
Copy link
Author

GeorgeAdamon commented Feb 23, 2023

Perhaps this works?

hdr_exr.zip

No guarantees about the precision of those; I used RenderDoc for the conversion. Please check against some of the images in the README for whether there's no banding, and if the black levels look the same

I happily confirm that the .hdr and .exr versions work in Unity with the right import settings.
image
image

@GeorgeAdamon
Copy link
Author

GeorgeAdamon commented Feb 23, 2023

I use this in a Unity shader that blends textures additively over time. All 3 methods (uncompressed .dds imported with my custom importer, .hdr and .exr files) work like a charm!

Before:
image
After:
image

@h3r2tic
Copy link
Owner

h3r2tic commented Feb 23, 2023

Nice, happy to hear you've convinced Unity to load it :)

Looks like someone else managed that too, including the rgb9e5 format: https://github.com/Dan3dd/tony-mc-mapface_unity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants