godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.24k stars 20.23k forks source link

Errors when trying to import and open EXR files with multiple layers #23723

Open qarmin opened 5 years ago

qarmin commented 5 years ago

Godot version: 3.1 66c6dfb

OS/device including version: Windows 10

Issue description: When I copy exr file(created in Krita 4 without merging layers) to godot project, and later open this project and file, then this error is shown:

ERROR: load_image: TinyEXR: R channel not found.
   At: modules/tinyexr/image_loader_tinyexr.cpp:111
ERROR: _reimport_file: Error importing: res://Places/Flag/flaga.exr
   At: editor/editor_file_system.cpp:1540
ERROR: Failed loading resource: res://Places/Flag/flaga.exr
   At: core/io/resource_loader.cpp:192
ERROR: load_resource: Condition ' !res.is_valid() ' is true. returned: ERR_CANT_OPEN
   At: editor/editor_node.cpp:583

Example file(need change extension to .exr) flaga.zip

akien-mga commented 5 years ago

You should report it upstream to https://github.com/syoyo/tinyexr. I confirmed that their test project can't load it either:

$ git clone https://github.com/syoyo/tinyexr
$ cd tinyexr
$ make
$ ./test_tinyexr ../flaga.exr
Load EXR err: R channel not found(code -4)

Though it looks to me like it's a bad export from Krita, as the header contains Polish layer names when (apparently) TinyEXR expects to have R, G, B or A:

$ exrheader flaga.exr 

file flaga.exr:

file format version: 2, flags 0x0
channels (type chlist):
    Warstwa 1.A, 16-bit floating-point, sampling 1 1
    Warstwa 1.B, 16-bit floating-point, sampling 1 1
    Warstwa 1.G, 16-bit floating-point, sampling 1 1
    Warstwa 1.R, 16-bit floating-point, sampling 1 1
    Warstwa 2.A, 16-bit floating-point, sampling 1 1
    Warstwa 2.B, 16-bit floating-point, sampling 1 1
    Warstwa 2.G, 16-bit floating-point, sampling 1 1
    Warstwa 2.R, 16-bit floating-point, sampling 1 1
compression (type compression): zip, multi-scanline blocks
dataWindow (type box2i): (0 0) - (127 63)
displayWindow (type box2i): (0 0) - (127 63)
krita_layers_info (type string): "<!DOCTYPE krita-extra-layers-info>
<root>
 <layer colorspacename="RGBAF16" y="0" locked="0" x="0" uuid="{9fb391dc-dd03-48ff-a109-2f0c663e3234}" compositeop="normal" intimeline="0" colorlabel="0" visible="1" nodetype="paintlayer" filename="layer0" exr_name="Warstwa 1" collapsed="0" name="Warstwa 1" channellockflags="1111" opacity="255" onionskin="0" channelflags=""/>
 <layer colorspacename="RGBAF16" y="0" locked="0" x="0" uuid="{0004e2f7-893c-4dfc-9996-535a479f2fa7}" compositeop="normal" intimeline="0" colorlabel="0" visible="1" nodetype="paintlayer" filename="layer0" exr_name="Warstwa 2" collapsed="0" name="Warstwa 2" channellockflags="1111" opacity="255" onionskin="0" channelflags=""/>
</root>
"
lineOrder (type lineOrder): increasing y
pixelAspectRatio (type float): 1
screenWindowCenter (type v2f): (0 0)
screenWindowWidth (type float): 1
type (type string): "scanlineimage"
fire commented 5 years ago

That's the default way layers are done in openexr.

I think the problem is Godot doesn't parse layers correctly.

Warstwa 1 and Warstwa 2 are two layers.

fire commented 5 years ago

See https://github.com/syoyo/tinyexr/issues/53 for documentation on using layers.

fire commented 5 years ago

What should be the behavior for image formats that have different layers? One of my pet goals is to have a openexr file handled by Godot to have all the necessary maps for a mesh (pbr) in one file, for example normal, albedo, ao and roughness, metalness.

I believe both PSD and EXR handle layers.

Things that come to mind is:

  1. merge down all the [layers] using the transparent parts to allow the top to go through
  2. split into different images based on import
akien-mga commented 5 years ago

See syoyo/tinyexr#53 for documentation on using layers.

@qarmin No need to report it upstream, the issue @fire linked is already the right one.

@fire Option (1) might be the easier way to have support for importing such multi-layered EXR files in Godot, even if you lose the layer details. That would at least fix this issue, and people could still keep their layers for edition and use the auto-merged version in Godot.

Then option (2) might be interesting to support the workflow you're describing, but IMO it's a lot more complex and would need more discussion. It could always be implemented later on, and users could toggle between (1) and (2) in import options.

fire commented 5 years ago

I only need "split into different images based on import" for the pbr in one file workflow. "Merge down" is for the standard workflow where people have lots of layers but don't merge which is the subject of this issue.

Edited due to edit.

akien-mga commented 5 years ago

My bad, I wrote (1) where I meant (2), I'll fix that up.

fire commented 4 years ago

Upstream added support for Layers in OpenEXR..

fire commented 3 years ago

What is the status of this?

qarmin commented 3 years ago

Now different error is shown:

 modules/tinyexr/image_loader_tinyexr.cpp:137 - Condition "idxR == -1" is true. Returning: ERR_FILE_CORRUPT
 core/io/image_loader.cpp:68 - Error loading image: res://flaga.exr
 editor/editor_file_system.cpp:1732 - Error importing 'res://flaga.exr'.