mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Add opacityMode attrib support(introduced from UsdPreviewSurface v2.6)
This commit is contained in:
@@ -2451,6 +2451,23 @@ std::string to_string(tinyusdz::CollectionInstance::ExpansionRule rule) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string to_string(const tinyusdz::UsdPreviewSurface::OpacityMode v) {
|
||||
std::string s;
|
||||
|
||||
switch (v) {
|
||||
case tinyusdz::UsdPreviewSurface::OpacityMode::Transparent: {
|
||||
s = "transparent";
|
||||
break;
|
||||
}
|
||||
case tinyusdz::UsdPreviewSurface::OpacityMode::Presence: {
|
||||
s = "presence";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string to_string(const tinyusdz::UsdUVTexture::SourceColorSpace v) {
|
||||
std::string s;
|
||||
|
||||
@@ -3947,6 +3964,8 @@ static std::string print_shader_params(const UsdPreviewSurface &shader,
|
||||
indent);
|
||||
ss << print_typed_attr(shader.roughness, "inputs:roughness", indent);
|
||||
ss << print_typed_attr(shader.opacity, "inputs:opacity", indent);
|
||||
ss << print_typed_token_attr(shader.opacityMode, "inputs:opacityMode",
|
||||
indent);
|
||||
ss << print_typed_attr(shader.opacityThreshold, "inputs:opacityThreshold",
|
||||
indent);
|
||||
ss << print_typed_attr(shader.normal, "inputs:normal", indent);
|
||||
|
||||
@@ -209,6 +209,8 @@ std::string to_string(const UsdPrimvarReader_float4 &shader,
|
||||
std::string to_string(const UsdPrimvarReader_int &shader,
|
||||
const uint32_t indent = 0, bool closing_brace = true);
|
||||
|
||||
std::string to_string(const UsdPreviewSurface::OpacityMode v);
|
||||
|
||||
std::string to_string(const UsdUVTexture::SourceColorSpace v);
|
||||
std::string to_string(const UsdUVTexture::Wrap v);
|
||||
|
||||
|
||||
@@ -3985,6 +3985,18 @@ bool ReconstructShader<UsdPreviewSurface>(
|
||||
(void)references;
|
||||
(void)options;
|
||||
|
||||
auto OpacityModeHandler = [](const std::string &tok)
|
||||
-> nonstd::expected<UsdPreviewSurface::OpacityMode, std::string> {
|
||||
using EnumTy = std::pair<UsdPreviewSurface::OpacityMode, const char *>;
|
||||
const std::vector<EnumTy> enums = {
|
||||
std::make_pair(UsdPreviewSurface::OpacityMode::Transparent, "transparent"),
|
||||
std::make_pair(UsdPreviewSurface::OpacityMode::Presence, "presence"),
|
||||
};
|
||||
|
||||
return EnumHandler<UsdPreviewSurface::OpacityMode>(
|
||||
"inputs:opacityMode", tok, enums);
|
||||
};
|
||||
|
||||
std::set<std::string> table;
|
||||
table.insert("info:id"); // `info:id` is already parsed in ReconstructPrim<Shader>
|
||||
for (auto &prop : properties) {
|
||||
@@ -4004,6 +4016,11 @@ bool ReconstructShader<UsdPreviewSurface>(
|
||||
UsdPreviewSurface, surface->clearcoatRoughness)
|
||||
PARSE_TYPED_ATTRIBUTE(table, prop, "inputs:opacity", UsdPreviewSurface,
|
||||
surface->opacity)
|
||||
// From 2.6
|
||||
PARSE_TIMESAMPLED_ENUM_PROPERTY(table, prop, "inputs:opacityMode",
|
||||
UsdPreviewSurface::OpacityMode, OpacityModeHandler, UsdPreviewSurface,
|
||||
surface->opacityMode, options.strict_allowedToken_check)
|
||||
|
||||
PARSE_TYPED_ATTRIBUTE(table, prop, "inputs:opacityThreshold",
|
||||
UsdPreviewSurface, surface->opacityThreshold)
|
||||
PARSE_TYPED_ATTRIBUTE(table, prop, "inputs:ior", UsdPreviewSurface,
|
||||
|
||||
@@ -198,6 +198,13 @@ struct UsdUVTexture : ShaderNode {
|
||||
// $USD/pxr/usdImaging/plugin/usdShaders/shaders/shaderDefs.usda
|
||||
|
||||
struct UsdPreviewSurface : ShaderNode {
|
||||
|
||||
// From 2.6
|
||||
// NOTE: When opacityThreshold is non-zero, opacityMode is ignored.
|
||||
enum class OpacityMode {
|
||||
Transparent, // "transparent" : the material will still receive a lighting response
|
||||
Presence, // "presence" : no lighting response
|
||||
};
|
||||
|
||||
TypedAttributeWithFallback<Animatable<value::color3f>> diffuseColor{value::color3f{0.18f, 0.18f, 0.18f}}; // "inputs:diffuseColor"
|
||||
TypedAttributeWithFallback<Animatable<value::color3f>> emissiveColor{value::color3f{0.0f, 0.0f, 0.0f}}; // "inputs:emissiveColor"
|
||||
@@ -216,6 +223,9 @@ struct UsdPreviewSurface : ShaderNode {
|
||||
TypedAttributeWithFallback<Animatable<float>> clearcoatRoughness{0.01f}; // "inputs:clearcoatRouighness"
|
||||
TypedAttributeWithFallback<Animatable<float>> roughness{0.5f}; // "inputs:roughness"
|
||||
TypedAttributeWithFallback<Animatable<float>> opacity{1.0f}; // "inputs:opacity"
|
||||
|
||||
TypedAttributeWithFallback<Animatable<OpacityMode>> opacityMode{OpacityMode::Transparent}; // "inputs:opacityMode"
|
||||
|
||||
TypedAttributeWithFallback<Animatable<float>> opacityThreshold{0.0f}; // "inputs:opacityThreshold"
|
||||
TypedAttributeWithFallback<Animatable<float>> ior{1.5f}; // "inputs:ior"
|
||||
|
||||
|
||||
10
tests/usda/shader-opacityMode-000.usda
Normal file
10
tests/usda/shader-opacityMode-000.usda
Normal file
@@ -0,0 +1,10 @@
|
||||
#usda 1.0
|
||||
|
||||
def Shader "OpacityMode"
|
||||
{
|
||||
uniform token info:id = "UsdPreviewSurface"
|
||||
token inputs:opacityMode = "transparent"
|
||||
|
||||
token outputs:displacement
|
||||
token outputs:surface
|
||||
}
|
||||
10
tests/usda/shader-opacityMode-001.usda
Normal file
10
tests/usda/shader-opacityMode-001.usda
Normal file
@@ -0,0 +1,10 @@
|
||||
#usda 1.0
|
||||
|
||||
def Shader "OpacityMode"
|
||||
{
|
||||
uniform token info:id = "UsdPreviewSurface"
|
||||
token inputs:opacityMode = "presence"
|
||||
|
||||
token outputs:displacement
|
||||
token outputs:surface
|
||||
}
|
||||
BIN
tests/usdc/shader-opacityMode-000.usdc
Normal file
BIN
tests/usdc/shader-opacityMode-000.usdc
Normal file
Binary file not shown.
BIN
tests/usdc/shader-opacityMode-001.usdc
Normal file
BIN
tests/usdc/shader-opacityMode-001.usdc
Normal file
Binary file not shown.
Reference in New Issue
Block a user