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

use the un-linearized lambert transparency to author displayOpacity when using displayColors shading mode #751

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
26 changes: 17 additions & 9 deletions lib/mayaUsd/fileio/shading/shadingModeDisplayColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ class DisplayColorShadingModeExporter : public UsdMayaShadingModeExporter
return;
}

const UsdStageRefPtr& stage = context.GetUsdStage();
GfVec3f color;
GfVec3f transparency;

// We might use the Maya shading node's transparency to author a scalar
// displayOpacity value on the UsdGeomGprim, as well as an input on the
// shader prim. How we compute that value will depend on which Maya
// shading node we're working with.
float transparencyAvg;

const MFnLambertShader lambertFn(ssDepNode.object(), &status);
if (status == MS::kSuccess) {
const MColor mayaColor = lambertFn.color();
Expand All @@ -109,6 +115,11 @@ class DisplayColorShadingModeExporter : public UsdMayaShadingModeExporter
diffuseCoeff*GfVec3f(mayaColor[0], mayaColor[1], mayaColor[2]));
transparency = UsdMayaColorSpace::ConvertMayaToLinear(
GfVec3f(mayaTransparency[0], mayaTransparency[1], mayaTransparency[2]));
// Compute the average transparency using the un-linearized Maya
// value.
transparencyAvg = (mayaTransparency[0] +
mayaTransparency[1] +
mayaTransparency[2]) / 3.0f;
} else {
#if MAYA_API_VERSION >= 20200000
const MFnStandardSurfaceShader surfaceFn(ssDepNode.object(), &status);
Expand All @@ -121,6 +132,9 @@ class DisplayColorShadingModeExporter : public UsdMayaShadingModeExporter
base*GfVec3f(mayaColor[0], mayaColor[1], mayaColor[2]));
const float mayaTransparency = surfaceFn.transmission();
transparency = GfVec3f(mayaTransparency, mayaTransparency, mayaTransparency);
// We can directly use the scalar transmission value as the
// "average".
transparencyAvg = mayaTransparency;
#else
return;
#endif
Expand All @@ -129,19 +143,13 @@ class DisplayColorShadingModeExporter : public UsdMayaShadingModeExporter
VtVec3fArray displayColorAry;
displayColorAry.push_back(color);

// The simple UsdGeomGprim display shading schema only allows for a
// scalar opacity. We compute it as the unweighted average of the
// components since it would be ridiculous to apply the inverse weighting
// (of the common graycale conversion) on re-import
// The average is compute from the Maya color as is
VtFloatArray displayOpacityAry;
const float transparencyAvg = (transparency[0] +
transparency[1] +
transparency[2]) / 3.0f;
if (transparencyAvg > 0.0f) {
displayOpacityAry.push_back(1.0f - transparencyAvg);
}

const UsdStageRefPtr& stage = context.GetUsdStage();

TF_FOR_ALL(iter, assignments) {
const SdfPath& boundPrimPath = iter->first;
const VtIntArray& faceIndices = iter->second;
Expand Down