Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDL implementation of mx_hsvtorgb is incorrect #1583

Closed
pablode opened this issue Oct 26, 2023 · 0 comments · Fixed by #1584
Closed

MDL implementation of mx_hsvtorgb is incorrect #1583

pablode opened this issue Oct 26, 2023 · 0 comments · Fixed by #1584

Comments

@pablode
Copy link
Contributor

pablode commented Oct 26, 2023

I've been checking out the Blender Hydra/MaterialX support, and believe to have stumbled upon a bug in the MDL implementation of the HSV to RGB color space transformation logic.

The following images show shading networks parametrized with different Hue values in (1) Blender's Cycles, (2) Storm (via Hydra) using the MaterialX GLSL backend, (3) Gatling (via Hydra) using the MaterialX MDL backend and (4) Gatling, with the correct logic.
Cycles Storm GLSL
Gatling MDL (old) Gatling MDL (new)

Discrepancies between the MaterialX GLSL and MDL backends can only be seen for high hue values (0.9, 1.0) and stem from a differing line of code in their mx_hsvtorgb functions. For GLSL, the hue is first floored and then brought into the range 0-6:

h = 6.0f * (h - floor(h)); // expand to [0..6)
int hi = int(trunc(h));
float f = h - float(hi);

whereas for MDL, the value is first brought into the range 0-6 and is then floored:
float h_prime = (hsv.x < 1.0f) ? hsv.x * 6.0f : 0.0f; // H * 360.0/60.0
float h_floor = math::floor(h_prime);
float f = h_prime - h_floor;

I can't tell whether this is an implementation mistake or an error in the referenced literature (Reinhard et al.), as the book is not openly available. However, the GLSL logic also matches OpenColorIO:
https://github.com/AcademySoftwareFoundation/OpenColorIO/blob/8add374dade5a7e3ee802269b71e1c0b75f8b8f0/src/OpenColorIO/ops/fixedfunction/FixedFunctionOpGPU.cpp#L413

cc @krohmerNV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant