Skip to content

Commit

Permalink
Remove HdStorm-compat option
Browse files Browse the repository at this point in the history
Recent changes to USD/Storm fix the transparency detection.
  • Loading branch information
pablode committed Sep 15, 2024
1 parent f45c5df commit c253023
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 57 deletions.
11 changes: 0 additions & 11 deletions src/guc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ static struct cag_option cmd_options[] = {
.value_name = NULL,
.description = "Convert and inline MaterialX materials into the USD layer using UsdMtlx"
},
{
.identifier = 'c',
.access_letters = "c",
.access_name = "hdstorm-compat",
.value_name = NULL,
.description = "Apply compatibility tweaks for the USD Storm Hydra render delegate"
},
{
.identifier = 'v',
.access_letters = "v",
Expand Down Expand Up @@ -75,7 +68,6 @@ int main(int argc, char* argv[])
struct guc_options options = {
.emit_mtlx = false,
.mtlx_as_usdshade = false,
.hdstorm_compat = false,
.default_material_variant = 0
};

Expand All @@ -91,9 +83,6 @@ int main(int argc, char* argv[])
case 'u':
options.mtlx_as_usdshade = true;
break;
case 'c':
options.hdstorm_compat = true;
break;
case 'v': {
const char* value = cag_option_get_value(&context);
options.default_material_variant = atoi(value); // fall back to 0 on error
Expand Down
3 changes: 0 additions & 3 deletions src/libguc/include/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ struct guc_options
// versions.
bool mtlx_as_usdshade;

// Workaround to make hdStorm recognize alpha materials as translucent.
bool hdstorm_compat;

// If the asset supports the KHR_materials_variants extension, select the material
// variant at the given index by default.
int default_material_variant;
Expand Down
2 changes: 1 addition & 1 deletion src/libguc/src/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace guc
, m_stage(stage)
, m_params(params)
, m_mtlxDoc(mx::createDocument())
, m_mtlxConverter(m_mtlxDoc, m_imgMetadata, params.hdStormCompat)
, m_mtlxConverter(m_mtlxDoc, m_imgMetadata)
, m_usdPreviewSurfaceConverter(m_stage, m_imgMetadata)
{
}
Expand Down
1 change: 0 additions & 1 deletion src/libguc/src/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ namespace guc
bool genRelativePaths;
bool emitMtlx;
bool mtlxAsUsdShade;
bool hdStormCompat;
int defaultMaterialVariant;
};

Expand Down
1 change: 0 additions & 1 deletion src/libguc/src/fileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ bool UsdGlTFFileFormat::Read(SdfLayer* layer,
params.genRelativePaths = false;
params.emitMtlx = data->emitMtlx;
params.mtlxAsUsdShade = true;
params.hdStormCompat = false;
params.defaultMaterialVariant = 0;

SdfLayerRefPtr tmpLayer = SdfLayer::CreateAnonymous(".usdc");
Expand Down
1 change: 0 additions & 1 deletion src/libguc/src/guc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ bool convertToUsd(fs::path src_dir,
params.genRelativePaths = true;
params.emitMtlx = options->emit_mtlx;
params.mtlxAsUsdShade = options->mtlx_as_usdshade;
params.hdStormCompat = options->hdstorm_compat;
params.defaultMaterialVariant = options->default_material_variant;

Converter converter(gltf_data, stage, params);
Expand Down
41 changes: 6 additions & 35 deletions src/libguc/src/materialx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,11 @@ namespace detail
namespace guc
{
MaterialXMaterialConverter::MaterialXMaterialConverter(mx::DocumentPtr doc,
const ImageMetadataMap& imageMetadataMap,
bool hdstorm_compat)
const ImageMetadataMap& imageMetadataMap)
: m_doc(doc)
, m_imageMetadataMap(imageMetadataMap)
, m_defaultColorSetName(makeColorSetName(0))
, m_defaultOpacitySetName(makeOpacitySetName(0))
, m_hdstormCompat(hdstorm_compat)
{
}

Expand Down Expand Up @@ -490,20 +488,6 @@ namespace guc
auto sheenRoughnessFactorDefault = 0.0f; // according to spec
addFloatTextureInput(nodeGraph, shaderNode, "sheen_roughness", sheen->sheen_roughness_texture, 3, sheen->sheen_roughness_factor, sheenRoughnessFactorDefault);
}

// Unfortunately, hdStorm blending is messed up because the material is not flagged as 'translucent':
// https://github.com/PixarAnimationStudios/USD/blob/db8e3266dcaa24aa26b7201bc20ff4d8e81448d6/pxr/imaging/hdSt/materialXFilter.cpp#L441-L507
// For alpha materials, set a non-zero transmission input to make the renderer believe that we are a translucent Standard Surface.
if (material->alpha_mode != cgltf_alpha_mode_opaque && m_hdstormCompat)
{
mx::InputPtr transmissionInput = material->has_transmission ? shaderNode->getInput("transmission") : shaderNode->addInput("transmission", MTLX_TYPE_FLOAT);

if (!transmissionInput->hasValue() || (transmissionInput->getValue()->isA<float>() && transmissionInput->getValue()->asA<float>() == 0.0f))
{
float valueCloseToZero = 0.00001f;
transmissionInput->setValue(valueCloseToZero);
}
}
}

void MaterialXMaterialConverter::addDiffuseTextureInput(mx::NodeGraphPtr nodeGraph,
Expand Down Expand Up @@ -934,18 +918,7 @@ namespace guc

if (texValueType != MTLX_TYPE_FLOAT)
{
bool remapChannelToAlpha = false;

// USD probably handles greyscale+alpha textures like it does for the UsdPreviewSurface spec:
// "If a two-channel texture is fed into a UsdUVTexture, the r, g, and b components of the rgb output will
// repeat the first channel's value, while the single a output will be set to the second channel's value."
if (m_hdstormCompat)
{
int channelCount = getTextureChannelCount(textureView);
remapChannelToAlpha = (channelCount == 2 && channelIndex == 1);
}

valueNode = detail::makeExtractChannelNode(nodeGraph, valueNode, remapChannelToAlpha ? 3 : channelIndex);
valueNode = detail::makeExtractChannelNode(nodeGraph, valueNode, channelIndex);
}

return valueNode;
Expand Down Expand Up @@ -1218,15 +1191,13 @@ namespace guc

int channelCount = metadata.channelCount;

if (channelCount == 3 || (m_hdstormCompat && channelCount == 1))
if (channelCount == 4)
{
// USD promotes single-channel textures to RGB
return color ? MTLX_TYPE_COLOR3 : MTLX_TYPE_VECTOR3;
return color ? MTLX_TYPE_COLOR4 : MTLX_TYPE_VECTOR4;
}
else if (channelCount == 4 || (m_hdstormCompat && channelCount == 2))
else if (channelCount == 3)
{
// And for greyscale-alpha textures, to RGBA (with vec2[1] being alpha)
return color ? MTLX_TYPE_COLOR4 : MTLX_TYPE_VECTOR4;
return color ? MTLX_TYPE_COLOR3 : MTLX_TYPE_VECTOR3;
}
else if (channelCount == 2)
{
Expand Down
5 changes: 1 addition & 4 deletions src/libguc/src/materialx.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ namespace guc
{
public:
MaterialXMaterialConverter(mx::DocumentPtr doc,
const ImageMetadataMap& imageMetadataMap,
bool hdstormCompat);
const ImageMetadataMap& imageMetadataMap);

void convert(const cgltf_material* material, const std::string& materialName);

Expand All @@ -41,8 +40,6 @@ namespace guc
std::string m_defaultColorSetName;
std::string m_defaultOpacitySetName;

bool m_hdstormCompat;

private:
void createUnlitSurfaceNodes(const cgltf_material* material,
const std::string& materialName);
Expand Down

0 comments on commit c253023

Please sign in to comment.