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

Add color4 type to Sdr #1894

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
// oslc -o TestShaderPropertiesNodeOSL.oso TestShaderPropertiesNodeOSL.osl
//

// Currently not parsing these standard OSL types.
// #include "color4"
// #include "vector2"
// #include "vector4"
// #include "matrix33"

struct TestStruct {
float foo;
};
Expand Down
20 changes: 20 additions & 0 deletions pxr/usd/sdr/shaderParserTestUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,23 @@ def TestShaderPropertiesNode(node):
assert property.GetImplementationName() == "aliasedNormalInput"
assert Ndr._ValidateProperty(node, property)

if node.GetName() != "TestShaderPropertiesNodeOSL":
# We will parse color4 in MaterialX and UsdShade. Not currently
# supported in OSL.
property = nodeInputs["inputColor4"]
assert property.GetType() == Sdr.PropertyTypes.Color4
assert GetType(property) == Tf.Type.FindByName("GfVec4f")
assert Ndr._ValidateProperty(node, property)

# oslc v1.11.14 does not allow arrays of structs as parameter.
property = nodeInputs["inputColor4Array"]
assert property.GetType() == Sdr.PropertyTypes.Color4
assert GetType(property) == Tf.Type.FindByName("VtArray<GfVec4f>")
assert Ndr._ValidateProperty(node, property)

property = nodeInputs["inputColor4RoleNone"]
assert property.GetType() == Sdr.PropertyTypes.Float
assert GetType(property) == Tf.Type.FindByName("GfVec4f")
assert Ndr._ValidateProperty(node, property)


26 changes: 26 additions & 0 deletions pxr/usd/sdr/shaderProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace {
{SdrPropertyTypes->String, SdfValueTypeNames->String},
{SdrPropertyTypes->Float, SdfValueTypeNames->Float},
{SdrPropertyTypes->Color, SdfValueTypeNames->Color3f},
{SdrPropertyTypes->Color4, SdfValueTypeNames->Color4f},
{SdrPropertyTypes->Point, SdfValueTypeNames->Point3f},
{SdrPropertyTypes->Normal, SdfValueTypeNames->Normal3f},
{SdrPropertyTypes->Vector, SdfValueTypeNames->Vector3f},
Expand All @@ -73,6 +74,7 @@ namespace {
{SdrPropertyTypes->String, SdfValueTypeNames->StringArray},
{SdrPropertyTypes->Float, SdfValueTypeNames->FloatArray},
{SdrPropertyTypes->Color, SdfValueTypeNames->Color3fArray},
{SdrPropertyTypes->Color4, SdfValueTypeNames->Color4fArray},
{SdrPropertyTypes->Point, SdfValueTypeNames->Point3fArray},
{SdrPropertyTypes->Normal, SdfValueTypeNames->Normal3fArray},
{SdrPropertyTypes->Vector, SdfValueTypeNames->Vector3fArray},
Expand Down Expand Up @@ -129,6 +131,11 @@ namespace {
{SdrPropertyRole->None, {SdrPropertyTypes->Float, 3}}
}
},
{SdrPropertyTypes->Color4,
{
{SdrPropertyRole->None, {SdrPropertyTypes->Float, 4}}
}
},
{SdrPropertyTypes->Point,
{
{SdrPropertyRole->None, {SdrPropertyTypes->Float, 3}}
Expand Down Expand Up @@ -472,6 +479,12 @@ namespace {
} else {
isSdrValueConformed = sdrDefaultValue.IsHolding<VtArray<GfVec3f>>();
}
} else if (sdrType == SdrPropertyTypes->Color4) {
if (!isArray) {
isSdrValueConformed = sdrDefaultValue.IsHolding<GfVec4f>();
} else {
isSdrValueConformed = sdrDefaultValue.IsHolding<VtArray<GfVec4f>>();
}
} else if (sdrType == SdrPropertyTypes->Matrix) {
if (!isArray) {
isSdrValueConformed = sdrDefaultValue.IsHolding<GfMatrix4d>();
Expand Down Expand Up @@ -742,6 +755,19 @@ SdrShaderProperty::CanConnectTo(const NdrProperty& other) const
return true;
}

bool inputIsFloat4 =
(inputType == SdrPropertyTypes->Color4) ||
(sdfInputType == SdfValueTypeNames->Float4);

bool outputIsFloat4 =
(outputType == SdrPropertyTypes->Color4) ||
(sdfOutputType == SdfValueTypeNames->Float4);

// Connections between float-4 types are possible
if (inputIsFloat4 && outputIsFloat4) {
return true;
}

// Special cases
if ((outputType == SdrPropertyTypes->Vstruct)
&& (inputType == SdrPropertyTypes->Float)) {
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/sdr/shaderProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ PXR_NAMESPACE_OPEN_SCOPE
((String, "string")) \
((Float, "float")) \
((Color, "color")) \
((Color4, "color4")) \
((Point, "point")) \
((Normal, "normal")) \
((Vector, "vector")) \
Expand Down
4 changes: 4 additions & 0 deletions pxr/usd/usdMtlx/testenv/testUsdMtlxParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def test_NodeParser(self):
nodes = Sdr.Registry().GetShaderNodesByFamily('UsdMtlxTestNode')
self.assertEqual(sorted([node.GetName() for node in nodes]), [
'UsdMtlxTestNamespace:nd_boolean',
'UsdMtlxTestNamespace:nd_color3',
'UsdMtlxTestNamespace:nd_color4',
'UsdMtlxTestNamespace:nd_customtype',
'UsdMtlxTestNamespace:nd_float',
'UsdMtlxTestNamespace:nd_integer',
Expand All @@ -58,6 +60,8 @@ def test_NodeParser(self):
# Verify converted types.
typeNameMap = {
'boolean': 'bool',
'color3': 'color',
'color4': 'color4',
'customtype': 'customtype',
'float': 'float',
'integer': 'int',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file for testing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file for testing
12 changes: 12 additions & 0 deletions pxr/usd/usdMtlx/testenv/testUsdMtlxParser.testenv/test.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
<input name="note" type="string" value="" uniform="true" />
<output name="out" type="vector3" />
</nodedef>
<nodedef name="nd_color3" node="UsdMtlxTestNode">
<input name="in" type="color3" />
<input name="note" type="string" value="" uniform="true" />
<output name="out" type="color3" />
</nodedef>
<nodedef name="nd_color4" node="UsdMtlxTestNode">
<input name="in" type="color4" />
<input name="note" type="string" value="" uniform="true" />
<output name="out" type="color4" />
</nodedef>
<nodedef name="nd_boolean" node="UsdMtlxTestNode">
<input name="in" type="boolean" />
<input name="note" type="string" value="" uniform="true" />
Expand All @@ -44,6 +54,8 @@
<implementation name="im_float" nodedef="nd_float" file="mx_constant_float.osl" function="mx_constant_float" />
<implementation name="im_string" nodedef="nd_string" file="mx_constant_string.osl" function="mx_constant_string" />
<implementation name="im_vector" nodedef="nd_vector" file="mx_constant_vector.osl" function="mx_constant_vector" />
<implementation name="im_color3" nodedef="nd_color3" file="mx_constant_color3.osl" function="mx_constant_color3" />
<implementation name="im_color4" nodedef="nd_color4" file="mx_constant_color4.osl" function="mx_constant_color4" />
<implementation name="im_boolean" nodedef="nd_boolean" file="mx_constant_bool.osl" function="mx_constant_bool" />
<implementation name="im_surface" nodedef="nd_surface" file="mx_add_surfaceshader.osl" function="mx_add_surfaceshader" />
<implementation name="im_customtype" nodedef="nd_customtype" file="mx_constant_filename.osl" function="FUNC" />
Expand Down
4 changes: 2 additions & 2 deletions pxr/usd/usdMtlx/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ UsdMtlxGetUsdType(const std::string& mtlxTypeName)
{ "color2", TUPLEN(Float2, false, Float, 2)},
{ "color3array", TUPLE3(Color3fArray, true, Color) },
{ "color3", TUPLE3(Color3f, true, Color) },
{ "color4array", TUPLEX(Color4fArray, true, noMatch) },
{ "color4", TUPLEN(Color4f, true, Float, 4)},
{ "color4array", TUPLE3(Color4fArray, true, Color4) },
{ "color4", TUPLE3(Color4f, true, Color4) },
{ "filename", TUPLE3(Asset, true, String) },
{ "floatarray", TUPLE3(FloatArray, true, Float) },
{ "float", TUPLE3(Float, true, Float) },
Expand Down
4 changes: 4 additions & 0 deletions pxr/usd/usdShade/shaderDefUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ _GetShaderPropertyTypeAndArraySize(
typeName == SdfValueTypeNames->Color3fArray) {
return std::make_pair(SdrPropertyTypes->Color,
_GetArraySize(defaultValue));
} else if (typeName == SdfValueTypeNames->Color4f ||
typeName == SdfValueTypeNames->Color4fArray) {
return std::make_pair(SdrPropertyTypes->Color4,
_GetArraySize(defaultValue));
} else if (typeName == SdfValueTypeNames->Point3f ||
typeName == SdfValueTypeNames->Point3fArray) {
return std::make_pair(SdrPropertyTypes->Point,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def Shader "TestShaderPropertiesNodeUSD" (
string inputs:inputString = "foo"
float inputs:inputFloat = 1.0
color3f inputs:inputColor = (1.0, 1.0, 1.0)
color4f inputs:inputColor4 = (1.0, 1.0, 1.0, 1.0)
point3f inputs:inputPoint = (0.0, 0.0, 0.0)
normal3f inputs:inputNormal = (1.0, 1.0, 1.0)
vector3f inputs:inputVector = (0.0, 0.0, 0.0)
Expand All @@ -20,6 +21,7 @@ def Shader "TestShaderPropertiesNodeUSD" (
string[] inputs:inputStringArray = [ "foo", "bar", "baz", "moo" ]
float[] inputs:inputFloatArray = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]
color3f[] inputs:inputColorArray = [ (1.0, 1.0, 1.0), (1.0, 1.0, 1.0) ]
color4f[] inputs:inputColor4Array = [ (1.0, 1.0, 1.0, 1.0), (1.0, 1.0, 1.0, 1.0) ]
point3f[] inputs:inputPointArray = [ (0.0, 0.0, 0.0), (0.0, 0.0, 0.0) ]
normal3f[] inputs:inputNormalArray = [ (1.0, 1.0, 1.0), (1.0, 1.0, 1.0) ]
vector3f[] inputs:inputVectorArray = [ (0.0, 0.0, 0.0), (0.0, 0.0, 0.0) ]
Expand All @@ -36,6 +38,11 @@ def Shader "TestShaderPropertiesNodeUSD" (
string role = "none"
}
)
color4f inputs:inputColor4RoleNone = (1.0, 2.0, 3.0, 4.0) (
sdrMetadata = {
string role = "none"
}
)
point3f inputs:inputPointRoleNone = (1.0, 2.0, 3.0) (
sdrMetadata = {
string role = "none"
Expand Down