Skip to content
Open
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
2 changes: 1 addition & 1 deletion libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
<!-- <transformmatrix> -->
<implementation name="IM_transformmatrix_vector2M3_genosl" nodedef="ND_transformmatrix_vector2M3" function="mx_transformmatrix_vector2M3" file="mx_transformmatrix_vector2M3.osl" target="genosl" />
<implementation name="IM_transformmatrix_vector3_genosl" nodedef="ND_transformmatrix_vector3" target="genosl" sourcecode="transform({{mat}}, {{in}})" />
<implementation name="IM_transformmatrix_vector3M4_genosl" nodedef="ND_transformmatrix_vector3M4" target="genosl" sourcecode="transform({{mat}}, {{in}})" />
<implementation name="IM_transformmatrix_vector3M4_genosl" nodedef="ND_transformmatrix_vector3M4" target="genosl" sourcecode="transform({{mat}}, point({{in}}))" />
<implementation name="IM_transformmatrix_vector4_genosl" nodedef="ND_transformmatrix_vector4" target="genosl" sourcecode="transform({{mat}}, {{in}})" />

<!-- <transpose> -->
Expand Down
39 changes: 39 additions & 0 deletions source/MaterialXTest/MaterialXGenOsl/GenOsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,45 @@ TEST_CASE("GenShader: OSL Metadata", "[genosl]")
REQUIRE(shader != nullptr);
}

TEST_CASE("GenShader: OSL TransformMatrix Point Semantics", "[genosl]")
{
const std::string expectedSourceCode = "transform({{mat}}, point({{in}}))";
const std::string testDocumentString = R"(<materialx version="1.39">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One downside of inlining an example file is that it won't be included when we perform syntax upgrades and reformatting on our example data, and a better approach would be to leverage our standard test suite, which includes MaterialX documents that leverage transformmatrix:

https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/resources/Materials/TestSuite/stdlib/math/transform.mtlx

If there's already an appropriate example there, feel free to load and test it here; if not, then you can add another example to the same document in the test suite.

<nodegraph name="NG_transformmatrix_vector3M4">
<transformmatrix name="transform" type="vector3">
<input name="in" type="vector3" value="1.0, 2.0, 3.0" />
<input name="mat" type="matrix44" value="1.0,0.0,0.0,0.0, 0.0,1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 4.0,5.0,6.0,1.0" />
</transformmatrix>
<output name="out" type="vector3" nodename="transform" />
</nodegraph>
</materialx>)";

mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();
mx::DocumentPtr libraries = mx::createDocument();
mx::loadLibraries({ "libraries" }, searchPath, libraries);

mx::ImplementationPtr implementation = libraries->getImplementation("IM_transformmatrix_vector3M4_genosl");
REQUIRE(implementation != nullptr);
REQUIRE(implementation->getAttribute("sourcecode") == expectedSourceCode);

mx::DocumentPtr doc = mx::createDocument();
mx::readFromXmlString(doc, testDocumentString);
doc->setDataLibrary(libraries);

mx::NodeGraphPtr nodeGraph = doc->getNodeGraph("NG_transformmatrix_vector3M4");
REQUIRE(nodeGraph != nullptr);

mx::OutputPtr output = nodeGraph->getOutput("out");
REQUIRE(output != nullptr);

mx::GenContext context(mx::OslShaderGenerator::create());
context.registerSourceCodeSearchPath(searchPath);

mx::ShaderPtr shader = context.getShaderGenerator().generate("transformmatrix_point_semantics", output, context);
REQUIRE(shader != nullptr);
REQUIRE(shader->getSourceCode().find("point(") != std::string::npos);
}

static void generateOslCode()
{
mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();
Expand Down
Loading