AcademySoftwareFoundation / AcademySoftwareFoundation/MaterialX
MaterialXView: baking can miss image size detection when using include files
- 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 |
| ------------ | ---------------|
|  |  |
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
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