Skip to content

Commit

Permalink
Add additional testing for Arnold OSL output (#1127)
Browse files Browse the repository at this point in the history
* Add in a "Arnold OSL" save option to viewer.
Update upgrade path to have test for issue 1126.

* Update test.
  • Loading branch information
bernardkwok authored Feb 23, 2021
1 parent 715b581 commit 7302e72
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,25 @@
<constant name="constant3" type="filename">
<input name="value" type="filename" value="grid.png" />
</constant>
<output name="out" type="color3" nodename="ramp4" />
<output name="out1" type="color3" nodename="splittb" />
<output name="out2" type="vector3" nodename="tangent" />
<output name="ramp4_out" type="color3" nodename="ramp4" />
<output name="splittb_out" type="color3" nodename="splittb" />
<output name="tangent_out" type="vector3" nodename="tangent" />
</nodegraph>
<nodegraph name="constant_graph_upgrade">
<standard_surface name="standard_surface" type="surfaceshader">
<input name="base_color" type="color3" nodename="add" />
<input name="base" type="float" value="0.8" />
</standard_surface>
<add name="add" type="color3">
<input name="in1" type="color3" nodename="constant" />
<input name="in2" type="color3" nodename="constant1" />
</add>
<constant name="constant" type="color3">
<parameter name="value" type="color3" value="1, 0, 0" />
</constant>
<constant name="constant1" type="color3">
<parameter name="value" type="color3" value="0, 0, 1" />
</constant>
<output name="constant_parameter_value_out" type="surfaceshader" nodename="standard_surface" />
</nodegraph>
</materialx>
3 changes: 3 additions & 0 deletions source/MaterialXView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ endif()
if (MATERIALX_BUILD_GEN_MDL)
LIST(APPEND LIBS MaterialXGenMdl)
endif()
if (MATERIALX_BUILD_GEN_ARNOLD)
LIST(APPEND LIBS MaterialXGenArnold)
endif()

target_link_libraries(
${LIBS}
Expand Down
26 changes: 26 additions & 0 deletions source/MaterialXView/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include <MaterialXGenMdl/MdlShaderGenerator.h>
#include <MaterialXGenOsl/OslShaderGenerator.h>
#ifdef MATERIALX_BUILD_GEN_ARNOLD
#include <MaterialXGenArnold/ArnoldShaderGenerator.h>
#endif

#include <MaterialXFormat/Environ.h>
#include <MaterialXFormat/Util.h>
Expand Down Expand Up @@ -229,6 +232,9 @@ Viewer::Viewer(const std::string& materialFilename,
#endif
#if MATERIALX_BUILD_GEN_MDL
_genContextMdl(mx::MdlShaderGenerator::create()),
#endif
#if MATERIALX_BUILD_GEN_ARNOLD
_genContextArnold(mx::ArnoldShaderGenerator::create()),
#endif
_unitRegistry(mx::UnitConverterRegistry::create()),
_splitByUdims(true),
Expand Down Expand Up @@ -1395,6 +1401,14 @@ void Viewer::saveShaderSource(mx::GenContext& context)
writeTextFile(pixelShader, baseName + ".mdl");
new ng::MessageDialog(this, ng::MessageDialog::Type::Information, "Saved MDL source: ", baseName);
}
#endif
#if MATERIALX_BUILD_GEN_ARNOLD
else if (context.getShaderGenerator().getTarget() == mx::ArnoldShaderGenerator::TARGET)
{
const std::string& pixelShader = shader->getSourceCode(mx::Stage::PIXEL);
writeTextFile(pixelShader, baseName + "_arnold.osl");
new ng::MessageDialog(this, ng::MessageDialog::Type::Information, "Saved Arnold OSL source: ", baseName);
}
#endif
}
}
Expand Down Expand Up @@ -1532,6 +1546,9 @@ void Viewer::loadStandardLibraries()
#if MATERIALX_BUILD_GEN_MDL
initContext(_genContextMdl);
#endif
#if MATERIALX_BUILD_GEN_ARNOLD
initContext(_genContextArnold);
#endif
}

bool Viewer::keyboardEvent(int key, int scancode, int action, int modifiers)
Expand Down Expand Up @@ -1594,6 +1611,15 @@ bool Viewer::keyboardEvent(int key, int scancode, int action, int modifiers)
}
#endif

#if MATERIALX_BUILD_GEN_ARNOLD
// Save MDL shader source to file.
if (key == GLFW_KEY_A && action == GLFW_PRESS)
{
saveShaderSource(_genContextArnold);
return true;
}
#endif

// Load shader source from file. Editing the source files before loading
// provides a way to debug and experiment with shader source code.
if (key == GLFW_KEY_L && action == GLFW_PRESS)
Expand Down
3 changes: 3 additions & 0 deletions source/MaterialXView/Viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ class Viewer : public ng::Screen
#if MATERIALX_BUILD_GEN_MDL
mx::GenContext _genContextMdl;
#endif
#if MATERIALX_BUILD_GEN_ARNOLD
mx::GenContext _genContextArnold;
#endif

// Unit registry
mx::UnitConverterRegistryPtr _unitRegistry;
Expand Down

0 comments on commit 7302e72

Please sign in to comment.