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

Codegen improvements to surfaceshader mix operator #1104

Conversation

niklasharrysson
Copy link
Contributor

This change list improves the handling of surfaceshader mix operator in code generation. One notable change is for OSL shader generation, which now implements the surfaceshader type as a struct of separate BSDF, EDF and Opacity components, in order to simplify operations like mixing.

Also adds new logic to HW transparency detection to support generations of GLSL shaders with transparency when mixing surface shaders.

Attached are some results of mixing surface shaders. There may be some additional changes need on GLSL side to match transparency results better with OSL when mixing shaders. This is left for a future change list to keep this reasonably small.

mix_shader.pdf

"}\n\n";

const ShaderGenerator& shadergen = context.getShaderGenerator();
shadergen.emitBlock(FUNCTION_DEFINITION, FilePath(), context, stage);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Material node is now responsible for composing the surfaceshader components into a single closure.

const bool isBsdfOutput = singleOutput && singleOutput->getType() == Type::BSDF;
#endif

if (isSurfaceShaderOutput)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic added here is a bit hacky with hard coded handling of surfaceshader and BSDF as output types. The reason for this is to keep supporting output of nodegraphs / documents that does not have a material node as the final output terminal (there are many exampels of this in out test suite).

For now this is hard coded here for surfaceshader and BSDF types. I have a plan for how to improve and generalize this, but it includes change to our Syntax and TypeSyntax classes that I think is too intrusive for 1.38.6. So I'll hold on this until 1.39.

{"alpha", 1.0f},
{"transmission", 0.0f} };

if (node->getCategory() == MIX_CATEGORY)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New logic for transparency detection of mixed surface shaders.

@niklasharrysson
Copy link
Contributor Author

Results for running the whole render testsuite:
testsuite_compressed.pdf

Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

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

This looks like a really worthwhile change, thanks @niklasharrysson!

@jstone-lucasfilm jstone-lucasfilm merged commit 75f1b35 into AcademySoftwareFoundation:main Oct 16, 2022
@niklasharrysson niklasharrysson deleted the mix_surfaceshader branch October 17, 2022 17:13
Michaelredaa pushed a commit to Michaelredaa/MaterialX that referenced this pull request Oct 21, 2023
…undation#1104)

This change list improves the handling of surfaceshader mix operator in code generation. One notable change is for OSL shader generation, which now implements the surfaceshader type as a struct of separate BSDF, EDF and Opacity components, in order to simplify operations like mixing.

Also adds new logic to HW transparency detection to support generations of GLSL shaders with transparency when mixing surface shaders.
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