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 MaterialX material tag detection for glTF PBR #3069

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pxr/imaging/hdSt/materialXFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ TF_DEFINE_PRIVATE_TOKENS(
((defaultInput, "default"))

// Opacity Parameters
(alpha)
(alpha_mode)
(alpha_cutoff)
(opacity)
(opacityThreshold)
(transmission)
Expand Down Expand Up @@ -705,6 +708,51 @@ _UpdatePrimvarNodes(
static std::string const&
_GetMaterialTag(HdMaterialNode2 const& terminal)
{
// The glTF PBR uses an explicit alpha_mode parameter unlike UsdPreviewSurface
// and StandardSurface. We detect it separately before handling the other BXDFs.
// The glTF PBR also has a transmission extension which's parameter behaves the
// same as the StandardSurface's. We do not return for alpha_mode OPAQUE to
// process it later.
auto const& alphaModeParamIt = terminal.parameters.find(_tokens->alpha_mode);
if (alphaModeParamIt != terminal.parameters.end() &&
alphaModeParamIt->second.IsHolding<int>()) {

int alphaMode = alphaModeParamIt->second.UncheckedGet<int>();
auto const& alphaConnIt = terminal.inputConnections.find(_tokens->alpha);
auto const& alphaParamIt = terminal.parameters.find(_tokens->alpha);

float alphaValue = 1.0f;
if (alphaParamIt != terminal.parameters.end() &&
alphaParamIt->second.IsHolding<float>()) {
alphaValue = alphaParamIt->second.UncheckedGet<float>();
}

if (alphaMode == 1/*MASK*/) {
auto const& alphaCutoffConnIt =
terminal.inputConnections.find(_tokens->alpha_cutoff);
auto const& alphaCutoffParamIt =
terminal.parameters.find(_tokens->alpha_cutoff);

float alphaCutoffValue = 0.5f;
if (alphaCutoffParamIt != terminal.parameters.end() &&
alphaCutoffParamIt->second.IsHolding<float>()) {
alphaCutoffValue = alphaCutoffParamIt->second.UncheckedGet<float>();
}

if (alphaConnIt != terminal.inputConnections.end() ||
alphaCutoffConnIt != terminal.inputConnections.end() ||
alphaValue > alphaCutoffValue) {
return HdStMaterialTagTokens->masked.GetString();
}
}
else if (alphaMode == 2/*BLEND*/) {
if (alphaConnIt != terminal.inputConnections.end() ||
alphaValue > 0.0f) {
return HdStMaterialTagTokens->translucent.GetString();
}
}
}

// Masked MaterialTag:
// UsdPreviewSurface: terminal.opacityThreshold value > 0
// StandardSurface materials do not have an opacityThreshold parameter
Expand Down Expand Up @@ -757,6 +805,7 @@ _GetMaterialTag(HdMaterialNode2 const& terminal)
|| opacityColor[1] < 1.0f
|| opacityColor[2] < 1.0f );
}
// StandardSurface and glTF PBR
if (currParam.first == _tokens->transmission &&
currParam.second.IsHolding<float>()) {
isTranslucent |= currParam.second.Get<float>() > 0.0f;
Expand Down
Loading