AcademySoftwareFoundation / AcademySoftwareFoundation/MaterialX

Regression: multiple color conversions generated in shader for nested multioutput image nodes

Open
#2,181 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.3k
Forks
451
Avg merge
4d 11h
Merged PRs (30d)
8

Description

### Description
@bowald found that `` generated very dark images in 1.38.10 (and 1.38.9). We have investigated and found that there seem to be a regression in 1.38.9 (Possibly https://github.com/AcademySoftwareFoundation/MaterialX/commit/d63431144a01eae129cd720222e530aff36b3459).

### To reproduce
The requirements for triggering this issue is:
1. An "inner" node which uses an `` node and exposes the filename input in its interface
2. An "outer" node which uses the "inner" node, is multioutput and also exposes the filename input in its interface

In that case shadergen will generate a colorspace transform for both nodes which in our case will apply srgb_texture to linrec_709 twice resulting in a very dark image.

[repro.zip](https://github.com/user-attachments/files/18395727/repro.zip)

### Expected result
(From 1.38.8)
![result_1 38 8](https://github.com/user-attachments/assets/d3104785-1ef2-4442-8b70-6a61be8f14e7)
```
void NG_image_inner(textureresource file, output color output1)
{
vector2 geomprop_UV0_out1 = vector2(u,v);
color image0_image_test_out = color(0.0);
mx_image_color3(file, "", color(0, 0, 0), geomprop_UV0_out1, "periodic", "periodic", "linear", "", 0, "constant", image0_image_test_out);
output1 = image0_image_test_out;
}

void NG_image_outer(textureresource file, output color output1, output float output2)
{
color image0_image_test_4_output1 = color(0.0);
NG_image_inner(file, image0_image_test_4_output1);
output1 = image0_image_test_4_output1;
output2 = 0.5;
}

NG_image_outer(image_test4_file, image_test4_output1, image_test4_output2);
color image_test4_output1_cm_out = color(0.0);
NG_srgb_texture_to_lin_rec709_color3(image_test4_output1, image_test4_output1_cm_out);
```

### Actual result
(From 1.38.10)
![result_1 38 10](https://github.com/user-attachments/assets/385da7c1-d950-4315-9032-568e2ce03a97)

```
void NG_image_inner(textureresource file, output color output1)
{
vector2 geomprop_UV0_out1 = vector2(u,v);
color image0_image_test_out = color(0.0);
mx_image_color3(file, "", color(0.000000, 0.000000, 0.000000), geomprop_UV0_out1, "periodic", "periodic", "linear", "", 0, "constant", image0_image_test_out);
color image0_image_test_out_cm_out = color(0.0);
NG_srgb_texture_to_lin_rec709_color3(image0_image_test_out, image0_image_test_out_cm_out);
output1 = image0_image_test_out_cm_out;
}

void NG_image_outer(textureresource file, output color output1, output float output2)
{
color image0_image_test_4_output1 = color(0.0);
NG_image_inner(file, image0_image_test_4_output1);
color image0_image_test_4_output1_cm_out = color(0.0);
NG_srgb_texture_to_lin_rec709_color3(image0_image_test_4_output1, image0_image_test_4_output1_cm_out);
output1 = image0_image_test_4_output1_cm_out;
output2 = 0.500000;
}

NG_image_outer(image_test4_file_, image_test4_output1, image_test4_output2);
surfaceshader standard_surface_out = surfaceshader(null_closure, null_closure, 1.0);
```

Contributor guide

Open the contributing guide

Research direction

Start with the attached repro.zip and compare shader generation using MaterialX 1.38.8, 1.38.9, and 1.38.10. Inspect the generated shader for nested multioutput image nodes; done means the colorspace conversion is emitted only once, matching the 1.38.8 output.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.