Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Substance Painter: Thumbnail errors with PBR Texture Set #6127

Merged
merged 7 commits into from
Jan 15, 2024

Conversation

moonyuet
Copy link
Member

@moonyuet moonyuet commented Jan 12, 2024

Changelog Description

When publishing with PBR Metallic Roughness as Output Template, Emissive Map errors out because of the missing channel in the material and the map can't be generated in Substance Painter. This PR is to make sure imagestance.data["publish"] = False so that the related "empty" texture instance would be skipped to generate the output.

Additional info

Need to double check if the maps have some colorspace issues after publishing.

Testing notes:

  1. Launch Substance Painter with your project
  2. Create Instance with PBR metallic roughness as output template.
  3. Publish
  4. Create Instance with default output template(2D_View)
  5. Publish
  6. They should be published successfully and the colorspace of the maps is correct

@ynbot
Copy link
Contributor

ynbot commented Jan 12, 2024

Task linked: OP-7704 Substance: thumbnail error

@ynbot ynbot added type: bug Something isn't working size/XS Denotes a PR changes 0-99 lines, ignoring general files host: Substance Painter labels Jan 12, 2024
Copy link
Member

@LiborBatek LiborBatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested both scenarios with and without Emission channel and both correctly Publish.
If not Emission present then the texture set doesnt contain it and if so then it is correctly added into texture set.

Also when creating publish instance for 2d view preset for texture set, all seems working normally.

Screenshot 2024-01-12 153353

Copy link
Collaborator

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity - wasn't allowing an export to pass if a channel does not exist for the template basically this toggle on the instance?

openpype/hosts/substancepainter/api/lib.py Outdated Show resolved Hide resolved
openpype/hosts/substancepainter/api/lib.py Outdated Show resolved Hide resolved
openpype/hosts/substancepainter/api/lib.py Outdated Show resolved Hide resolved
openpype/hosts/substancepainter/api/lib.py Outdated Show resolved Hide resolved
@moonyuet moonyuet requested a review from BigRoy January 12, 2024 16:16
@BigRoy
Copy link
Collaborator

BigRoy commented Jan 12, 2024

When publishing with PBR Metallic Roughness as Output Template, Emissive Map errors out because of the missing channel in the material and the map can't be generated in Substance Painter. This PR is to check if the texture stack has Emissive included in the material before creating image instance for Emissive.

This is now fixed by setting the instance.data["publish"] = False if the instance does not generate any output.
Basically saying - if a map of an export preset currently won't generate any output because the user hasn't drawn any of the related maps to that output file - like an "emissive" texture - then skip it completely.

Besides, this PR fixes the bug where the monochromic maps (such as Height and Roughness) when they are being processed with extract thumbnail. Make sure the colorspace info would be added only when the maps have color channels(RGB).

This is related to this error:

DEBUG: Reading C:\Users\Kayla\AppData\Local\Temp\pyblish_tmp_2htjws24\Business_Man_aiStandardSurface1_Height_Utility - Raw.1011.png
<ImageSpec version="25">
<x>0</x>
<y>0</y>
<z>0</z>
<width>1024</width>
<height>1024</height>
<depth>1</depth>
<full_x>0</full_x>
<full_y>0</full_y>
<full_z>0</full_z>
<full_width>1024</full_width>
<full_height>1024</full_height>
<full_depth>1</full_depth>
<tile_width>0</tile_width>
<tile_height>0</tile_height>
<tile_depth>1</tile_depth>
<format>uint16</format>
<nchannels>1</nchannels>
<channelnames>
<channelname>Y</channelname>
</channelnames>
<alpha_channel>-1</alpha_channel>
<z_channel>-1</z_channel>
<deep>0</deep>
<attrib name="ResolutionUnit" type="string">inch</attrib>
<attrib name="XResolution" type="float">72.009</attrib>
<attrib name="YResolution" type="float">72.009</attrib>
</ImageSpec>

Traceback (most recent call last):
  File "D:\kayla\OpenPype\.venv\lib\site-packages\pyblish\plugin.py", line 527, in __explicit_process
    runner(*args)
  File "D:\kayla\OpenPype\openpype\plugins\publish\extract_thumbnail.py", line 55, in process
    self._main_process(instance)
  File "D:\kayla\OpenPype\openpype\plugins\publish\extract_thumbnail.py", line 180, in _main_process
    thumbnail_created = self._create_thumbnail_oiio(
  File "D:\kayla\OpenPype\openpype\plugins\publish\extract_thumbnail.py", line 342, in _create_thumbnail_oiio
    resolution_arg = self._get_resolution_arg("oiiotool", src_path)
  File "D:\kayla\OpenPype\openpype\plugins\publish\extract_thumbnail.py", line 491, in _get_resolution_arg
    return get_rescaled_command_arguments(
  File "D:\kayla\OpenPype\openpype\lib\transcoding.py", line 1287, in get_rescaled_command_arguments
    _, channels_arg = get_oiio_input_and_channel_args(
  File "D:\kayla\OpenPype\openpype\lib\transcoding.py", line 1389, in get_oiio_input_and_channel_args
    raise ValueError(
ValueError: Couldn't find channels that can be used for conversion.

Which basically shows that the thumbnail extractor is incapable of generating a thumbnail for an image that has only one channel - but I think we're best of - for those cases - to generate a single channel preview image (basically the luminance). If the input image has only one channel, there's hardly any discussion about what channel should we use?

So I'd argue that for that case we should instead solve the Thumbnail Extractor/Encoding logic so that if an input image has only one channel - to just always rely on that channel.

To me that's a sensible default behavior.


Since unfortunately in Substance Painter API there's no way of really knowing for sure what channels are in an output image of an export preset (I haven't found that code in the API at least) there isn't really any way to know whether the file called height or h or _Y or whatever it may be called in the output templates contains just one channel (it might pack multiple single channels into it?) or whether it contains the height channel to begin with. We can only guess - which I'd say isn't reliable enough for the pipeline to be built on. So we should instead work with what we don't need to guess, like knowing a single channel will always be the channel that describes the image best - which is what we need to know for thumbnails to solve this particular error.

@iLLiCiTiT @mkolar thoughts?

@antirotor
Copy link
Member

We can only guess

we might analyze the image using oiio tool as we are already doing in extrac review I think. That should give you information about channels. See

def should_convert_for_ffmpeg(src_filepath):
that is used in extract review. Maybe we could just use it in separate collector to set the flag on thumbnail if it should be generated or not?

@BigRoy
Copy link
Collaborator

BigRoy commented Jan 15, 2024

We can only guess

we might analyze the image using oiio tool as we are already doing in extrac review I think. That should give you information about channels. See

def should_convert_for_ffmpeg(src_filepath):

that is used in extract review. Maybe we could just use it in separate collector to set the flag on thumbnail if it should be generated or not?

It wouldn't tell us whether the image is the Specular, Diffuse, Metalness, Height, etc. map. It would only tell us whether the image has one or more channels. (Also, this channel data retrieval is already being done by e.g. the thumbnail extractor). (Note that in substance painter you can mix any channels, e.g. metalness, specular, etc. into a single output file as well - all depending on the output template used; which the API doesn't allow us to parse for what type of channels are in a particular output)

As such, as my recommendation. I think we should disregard 'what type of output channel it is' in the context of substance painter since the API doesn't reliably allow us to retrieve that data (yet?). But, if e.g. a Height image is written and thus it exists of only one channel as opposed to multiple then we can be sure that the output thumbnail should be a preview of that single channel.

@antirotor
Copy link
Member

I mean we could change the logic in extract thumbnail so it doesn't look only for rgba channels but if there is at least one, use it and copy it to rgb. We'll need to solve somehow how to deal with data that are not image (like point positions).

Anyway, I think this is work for another PR that would touch how thumbnail are generated in that case.

@BigRoy
Copy link
Collaborator

BigRoy commented Jan 15, 2024

Anyway, I think this is work for another PR that would touch how thumbnail are generated in that case.

If that's the case - then keep only the publish = False fix in this PR, remove the other code and start the work on this other PR to solve the "height" map thumbnail extractor issue. Keeping this PR focused solely on the fix for the 'non existing maps'.

👍

@moonyuet
Copy link
Member Author

moonyuet commented Jan 15, 2024

Anyway, I think this is work for another PR that would touch how thumbnail are generated in that case.

If that's the case - then keep only the publish = False fix in this PR, remove the other code and start the work on this other PR to solve the "height" map thumbnail extractor issue. Keeping this PR focused solely on the fix for the 'non existing maps'.

👍

already made a update to remove the related codes.

@moonyuet
Copy link
Member Author

moonyuet commented Jan 15, 2024

@LiborBatek can you test again? And please keep in mind that the current code would error out height map in extract_thumbnail. Thanks!

Copy link
Member

@LiborBatek LiborBatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the thumbnail error on height map it works ok and evaluates well when present/lacking emission channel.

image

Also worth noting that if capturing the thumbnail via capture screen in the Publisher then it does not crash on thumbnail speaking of height map because asset using user defined thumbnail instead (working well and without any errors in this situation)

image

@moonyuet moonyuet merged commit b60e90f into develop Jan 15, 2024
3 checks passed
@moonyuet moonyuet deleted the bugfix/OP-7704_Substance-thumbnail-error branch January 15, 2024 14:07
@ynbot ynbot added this to the next-patch milestone Jan 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
host: Substance Painter size/XS Denotes a PR changes 0-99 lines, ignoring general files type: bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants