Skip to content

Commit

Permalink
Remove explicit colorspace transformations
Browse files Browse the repository at this point in the history
Not needed anymore since USD v23.08
  • Loading branch information
pablode committed Apr 21, 2024
1 parent d20fea5 commit 62cf6d4
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 244 deletions.
7 changes: 0 additions & 7 deletions src/guc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ void print_usage()
fprintf(stderr, "Options:\n");
fprintf(stderr, "--emit-mtlx Emit MaterialX materials in addition to UsdPreviewSurfaces\n");
fprintf(stderr, "--mtlx-as-usdshade Convert and inline MaterialX materials with UsdMtlx\n");
fprintf(stderr, "--explicit-colorspace-transforms Explicitly transform colorspaces using MaterialX nodes\n");
fprintf(stderr, "--hdstorm-compat Apply compatibility tweaks for the USD hdStorm renderer\n");
fprintf(stderr, "--default-material-variant <number> Index of the material variant that is selected by default\n");
}
Expand All @@ -48,7 +47,6 @@ int main(int argc, const char* argv[])
struct guc_options options;
options.emit_mtlx = false;
options.mtlx_as_usdshade = false;
options.explicit_colorspace_transforms = false;
options.hdstorm_compat = false;
options.default_material_variant = 0;

Expand All @@ -70,11 +68,6 @@ int main(int argc, const char* argv[])
options.mtlx_as_usdshade = true;
continue;
}
else if (!strcmp(arg, "explicit-colorspace-transforms"))
{
options.explicit_colorspace_transforms = true;
continue;
}
else if (!strcmp(arg, "hdstorm-compat"))
{
options.hdstorm_compat = true;
Expand Down
14 changes: 1 addition & 13 deletions src/libguc/include/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,7 @@ struct guc_options
// versions.
bool mtlx_as_usdshade;

// MaterialX's 'colorspace' functionality may not be fully supported by an
// application. We work around this by implementing colorspace transformations using
// native MaterialX math nodes. MaterialX image nodes are assumed to return raw,
// untransformed values, since the default document colorspace is 'linear'.
bool explicit_colorspace_transforms;

// HdMtlx and therefore Storm do not seem to properly support MaterialX colorspaces.
// https://github.com/PixarAnimationStudios/USD/issues/1523
// https://github.com/PixarAnimationStudios/USD/issues/1632
// To work around this issue, we force-enable explicit colorspace transformations and
// undo colorspace transformations that exist because of USD's sRGB detection logic:
// https://github.com/PixarAnimationStudios/USD/blob/857ffda41f4f1553fe1019ac7c7b4f08c233a7bb/pxr/imaging/plugin/hioOiio/oiioImage.cpp#L470-L471
// Additionally, we make hdStorm recognize alpha materials as translucent.
// Workaround to make hdStorm recognize alpha materials as translucent.
bool hdstorm_compat;

// If the asset supports the KHR_materials_variants extension, select the material
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 @@ -236,7 +236,7 @@ namespace guc
, m_stage(stage)
, m_params(params)
, m_mtlxDoc(mx::createDocument())
, m_mtlxConverter(m_mtlxDoc, m_imgMetadata, params.explicitColorspaceTransforms, params.hdStormCompat)
, m_mtlxConverter(m_mtlxDoc, m_imgMetadata, params.hdStormCompat)
, 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 explicitColorspaceTransforms;
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 @@ -134,7 +134,6 @@ bool UsdGlTFFileFormat::Read(SdfLayer* layer,
params.genRelativePaths = false;
params.emitMtlx = data->emitMtlx;
params.mtlxAsUsdShade = true;
params.explicitColorspaceTransforms = false;
params.hdStormCompat = false;
params.defaultMaterialVariant = 0;

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 @@ -52,7 +52,6 @@ bool convertToUsd(fs::path src_dir,
params.genRelativePaths = true;
params.emitMtlx = options->emit_mtlx;
params.mtlxAsUsdShade = options->mtlx_as_usdshade;
params.explicitColorspaceTransforms = options->explicit_colorspace_transforms;
params.hdStormCompat = options->hdstorm_compat;
params.defaultMaterialVariant = options->default_material_variant;

Expand Down
9 changes: 2 additions & 7 deletions src/libguc/src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace guc
return false;
}

bool readImageMetadata(const char* path, int& channelCount, bool& isSrgbInUSD)
bool readImageMetadata(const char* path, int& channelCount)
{
#ifdef GUC_USE_OIIO
using namespace OIIO;
Expand All @@ -189,9 +189,6 @@ namespace guc
{
const ImageSpec& spec = image->spec();
channelCount = spec.nchannels;
// Detection logic of HioOIIO_Image::IsColorSpaceSRGB for _sourceColorSpace auto (default value)
// https://github.com/PixarAnimationStudios/USD/blob/857ffda41f4f1553fe1019ac7c7b4f08c233a7bb/pxr/imaging/plugin/hioOiio/oiioImage.cpp
isSrgbInUSD = (channelCount == 3 || channelCount == 4) && spec.format == TypeDesc::UINT8;
image->close();
return true;
}
Expand All @@ -200,8 +197,6 @@ namespace guc
int ok = stbi_info(path, &width, &height, &channelCount);
if (ok)
{
bool isHdr = bool(stbi_is_hdr(path));
isSrgbInUSD = (channelCount == 3 || channelCount == 4) && !isHdr; // UINT8 by default in stb_image
return true;
}
#endif
Expand Down Expand Up @@ -313,7 +308,7 @@ namespace guc
metadata.refPath = dstRefPath;

// Read the metadata required for MaterialX shading network creation
if (!readImageMetadata(dstFilePath.c_str(), metadata.channelCount, metadata.isSrgbInUSD))
if (!readImageMetadata(dstFilePath.c_str(), metadata.channelCount))
{
TF_RUNTIME_ERROR("unable to read metadata of image %s", dstFilePath.c_str());
return std::nullopt;
Expand Down
8 changes: 1 addition & 7 deletions src/libguc/src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ namespace guc
{
std::string filePath;
std::string refPath;
// Needed to determine the type of MaterialX <image> nodes
int channelCount;
// USD makes an incorrect assumption that we have to work around by undoing an incorrect sRGB-to-linear transform in our MaterialX network gen:
// https://github.com/PixarAnimationStudios/USD/blob/857ffda41f4f1553fe1019ac7c7b4f08c233a7bb/pxr/imaging/plugin/hioOiio/oiioImage.cpp#L470-L471
// The stb_image sRGB detection logic is slightly different, but since guc requires OIIO, we don't have to care about it.
// Our UsdPreviewSurface generator is fine too, since there we set explicit sourceColorSpace inputs.
bool isSrgbInUSD;
int channelCount; // Needed to determine the type of MaterialX <image> nodes
};

using ImageMetadataMap = std::unordered_map<const cgltf_image*, ImageMetadata>;
Expand Down
Loading

0 comments on commit 62cf6d4

Please sign in to comment.