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

Implement basic support for MaterialX closures in testrender #1533

Merged

Conversation

fpsunflower
Copy link
Contributor

  • Extend the bsdf interface in testrender to use Color3 instead of float in preparation for MaterialX closures which are almost all tinted

  • Add stub parameters and IDs for all MaterialX closures

  • Register all MaterialX closure types

  • Implement most MaterialX closures, reusing the existing implementations for now

This commit is mainly intended to do the busy work of adding the new closures, no new BSDFs are actually implemented yet. This means that some of the closures are handled in a very rudimentary way, ignoring some key parameters. The intent is to improve support for these over time.

@fpsunflower fpsunflower force-pushed the mx-closure-stubs branch 3 times, most recently from f459abb to d27d521 Compare July 17, 2022 00:10
float /*rz*/, OSL::Dual2<OSL::Vec3>& wi,
float& pdf) const
float& pdf) const override
Copy link
Contributor

Choose a reason for hiding this comment

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

This patch looks good to me, thanks! But I'm going to abuse it to open a discussion on the BSDF API:

  1. Should we return a struct like { weight, pdf } to avoid output args?
  2. Can we drop the full sg as argument and instead pass a Vec3 wo (meaning I) so you can evaluate them in an SG-less context?
  3. Does anybody need accurate derivs from wi? If not, can we stop pretending we can compute them?
  4. Should we add roughness to the output? I believe most renders track it. You can guess it from pdf following a convention (like reversing an isotropic GGX), but wanted to get opinions. A normalized [0-1] roughness can be used as a measure of specularity for AOVs. If we sign off on BSDFs being single lobe the roughness can be just a BSDF property and not an output from sample()/eval().

I volunteer to making any of these changes after you merge this, of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Yes - good idea. I can do that refactor in another PR. Would you have a { weight, pdf, dir } struct for sample() then?
  2. Yes - good idea.
  3. Yes - definitely. Only the reflection() and refraction() cases do anything sensible. Do you want to submit a patch that switches to ray cones? That would be a nice simplification for the bsdf API.
  4. I wouldn't bother with this for now. I prefer keeping testrender minimal for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes { color, wi, pdf } in any order you like works for me. I will do the cone tracing.

}
case MX_SHEEN_ID:
case MX_LAYER_ID: {
OSL_ASSERT(false && "MaterialX closure not yet implemented");
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a suggestion on how to implement this. Add a

virtual Color3 filter_base(Vec3 wo);

You call it here, scale the weight of base and just add_bsdf() both. Recurse where needed. Works for us by making assumptions on wi. Eliminates the need of recursion at eval/sample time. De-virtualize and you are ready for GPU.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats what I was thinking too. Maybe it can even just use the existing "get_albedo()" method?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea, although the coating may want to add absorption according to some thickness. So maybe a different method that by default does 1 - get_albedo().

  * Extend the bsdf interface in testrender to use Color3 instead of float in preparation for MaterialX closures which are almost all tinted

  * Add stub parameters and IDs for all MaterialX closures

  * Register all MaterialX closure types

  * Implement most MaterialX closures, reusing the existing implementations for now

This commit is mainly intended to do the busy work of adding the new closures, no new BSDFs are actually implemented yet. This means that some of
the closures are handled in a very rudimentary way, ignoring some key parameters. The intent is to improve support for these over time.

Signed-off-by: Chris Kulla <[email protected]>
@fpsunflower
Copy link
Contributor Author

I haven't found any workaround yet ... I'll keep updating render-microfacet's reference image for now. Hopefully the next few commits won't require touching any related code so it will be stable for a while.

@fpsunflower
Copy link
Contributor Author

Any further comments on this PR?

@aconty
Copy link
Contributor

aconty commented Jul 19, 2022

LGTM!

@fpsunflower fpsunflower merged commit 3bb4196 into AcademySoftwareFoundation:main Jul 19, 2022
lgritz pushed a commit to lgritz/OpenShadingLanguage that referenced this pull request Jul 23, 2022
…SoftwareFoundation#1533)

* Extend the bsdf interface in testrender to use Color3 instead of float in preparation for MaterialX closures which are almost all tinted

  * Add stub parameters and IDs for all MaterialX closures

  * Register all MaterialX closure types

  * Implement most MaterialX closures, reusing the existing implementations for now

This commit is mainly intended to do the busy work of adding the new closures, no new BSDFs are actually implemented yet. This means that some of
the closures are handled in a very rudimentary way, ignoring some key parameters. The intent is to improve support for these over time.

Signed-off-by: Chris Kulla <[email protected]>
chellmuth pushed a commit to chellmuth/OpenShadingLanguage that referenced this pull request Sep 6, 2024
Relevant changes:

  * GPU string fix -- needed missing cast (AcademySoftwareFoundation#1553)
  * Fix typo error that prevented correct typecheck of ternary (AcademySoftwareFoundation#1552)
  * testrender now supports the standard MaterialX closure:
  * testrender improvements: modernize sampler (AcademySoftwareFoundation#1534), switch to cone
    tracing (AcademySoftwareFoundation#1543), support MaterialX closures (AcademySoftwareFoundation#1533, AcademySoftwareFoundation#1536, AcademySoftwareFoundation#1537,
    AcademySoftwareFoundation#1538, AcademySoftwareFoundation#1541, AcademySoftwareFoundation#1542, AcademySoftwareFoundation#1547)
  * Bump LLVM to 14.0
  * Help reduce PTX nondeterminism (AcademySoftwareFoundation#1570)

See merge request spi/dev/3rd-party/osl-feedstock!30
@fpsunflower fpsunflower deleted the mx-closure-stubs branch October 28, 2024 03:43
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