AcademySoftwareFoundation / AcademySoftwareFoundation/MaterialX

MaterialXView: baking can miss image size detection when using include files

Open
#1,139 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.3k
Forks
451
Avg merge
6d 6h
Merged PRs (30d)
5

Description

** Issue
Sometimes images are not detected since they are in xinclude files. If no images are found then it can appear
like baking has failed since 4x4 images are used which appear pretty much like constant values.

** Cause
The code to `ImageHandler::getReferencedImages()` always skips elements which are not from the main document
based on source URI. This will skip library files for instance but can also skip images which are part of shaders used for baking.
The code is like this:
```
ImageVec ImageHandler::getReferencedImages(DocumentPtr doc)
{
ImageVec imageVec;
for (ElementPtr elem : doc->traverseTree())
{
if (elem->getActiveSourceUri() != doc->getSourceUri())
{
// Always skips here <<<<<<<<<<<<<<<<<
continue;
}
```
This means files like `standard_surface_look_brass_tiled.mtlx which has only 2 xincludes will never find any of the images
used for the shaders to bake. This resutls in an erroneous value if {0,0} as the bake size -- which is clamped to {4,4}.

As a result the images when rendered appear pretty much like constant values which to a user might indicate some
failure has occurred in baking when in fact the baked images are just too low resolution.

Example looks like this:
```








```
| Result using look (containing calibration shader) file | Result using file directly containing same shader |
| ------------ | ---------------|
| ![image](https://user-images.githubusercontent.com/49369885/200918154-780d088d-a550-4ee7-a231-60e49f57c1c5.png) | ![image](https://user-images.githubusercontent.com/49369885/200917930-0c75ef83-4f4c-4b42-a35d-1bf4257d685c.png) |

This was found by comparing with the `texturebaker` script which sets a default of {1024,1024}.

## Suggestions
* Easiest is to allow a higher default value / or a consistent value with `texturebaker`.
* Another possibility is to allow an argument as to what URIs to exclud
such as library files. loadlibraries() returns this so not too hard to add.

Contributor guide

Open the contributing guide

Research direction

Start with ImageHandler::getReferencedImages() and compare its URI filtering with the texturebaker script's default size handling. Review loadlibraries() and the xinclude example, then verify that images referenced through included files are detected and baking no longer falls back to an erroneous 4x4 size.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.