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

Simplify OSL node implementations #1185

Merged
merged 1 commit into from
Jan 3, 2023
Merged

Simplify OSL node implementations #1185

merged 1 commit into from
Jan 3, 2023

Conversation

jstone-lucasfilm
Copy link
Member

This changelist simplifies the OSL implementations of common nodes such as 'if', 'add', and 'subtract', removing duplicate code and harmonizing inline implementations where possible.

This changelist simplifies the OSL implementations of common nodes such as 'if', 'add', and 'subtract', removing duplicate code and harmonizing inline implementations where possible.
@jstone-lucasfilm
Copy link
Member Author

Updated render comparisons between GLSL and OSL:

MaterialXRenderTests_01_02_2023.pdf

@jstone-lucasfilm jstone-lucasfilm merged commit f66296b into AcademySoftwareFoundation:main Jan 3, 2023
// Support functions for OSL implementations of the MaterialX nodes.
//

float mx_ternary(int expr, float v1, float v2) { if (expr) return v1; else return v2; }
Copy link
Contributor

Choose a reason for hiding this comment

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

N.B. You can say expr ? v1 : v2 in OSL.

Copy link
Member Author

Choose a reason for hiding this comment

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

@lgritz I took that approach at first, but it looks like OSL's built-in ternary operator doesn't yet handle values that are structures, which is the case when v1 and v2 are of type color4, vector4, vector2, or matrix33. Let me know if I should write this up as an issue on the OSL GitHub, or if perhaps I'm missing a detail that would allow me to use this approach across all types.

Copy link
Contributor

Choose a reason for hiding this comment

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

OH. Hmmm. Yeah, please file an issue. You can 'return' a struct, and you can assign a struct, so probably there's just some little missing bit of logic that prevents a struct from being the operands to a ternary operator.

Of course, 50/50 chance I simply don't remember that I looked at this ages ago and bailed when it turned out to be disproportionately difficult. Sometimes you turn over a rock, and when you see what's under there, you just put the rock back and slowly back away. :-)

Michaelredaa pushed a commit to Michaelredaa/MaterialX that referenced this pull request Oct 21, 2023
This changelist simplifies the OSL implementations of common nodes such as 'if', 'add', and 'subtract', removing duplicate code and harmonizing inline implementations where possible.
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 this pull request may close these issues.

2 participants