Skip to content

Commit

Permalink
Merge branch 'AcademySoftwareFoundation:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Morteeza authored Feb 24, 2023
2 parents e82661e + f8f9fd5 commit d78b4b3
Show file tree
Hide file tree
Showing 22 changed files with 905 additions and 754 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
compiler_version: "10"
python: 3.7
cmake_config: -DMATERIALX_BUILD_SHARED_LIBS=ON
static_analysis: ON

- name: Linux_Clang_13_Python39
os: ubuntu-22.04
Expand Down Expand Up @@ -80,7 +81,6 @@ jobs:
compiler: xcode
compiler_version: "13.3"
python: 3.9
static_analysis: ON

- name: Windows_VS2019_Win32_Python27
os: windows-2019
Expand Down Expand Up @@ -213,9 +213,9 @@ jobs:
python python/Scripts/generateshader.py resources/Materials/Examples/StandardSurface --path . --target essl --validator glslangValidator.exe
- name: Static Analysis Tests
if: matrix.static_analysis == 'ON' && runner.os == 'macOS'
if: matrix.static_analysis == 'ON' && runner.os == 'Linux'
run: |
brew install cppcheck
sudo apt-get install cppcheck
cppcheck --project=build/compile_commands.json --error-exitcode=1 --suppress=*:*/External/* --suppress=*:*/NanoGUI/*
- name: Initialize Virtual Framebuffer
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

## [1.38.7] - Development

### Added
- Added the [MaterialX Graph Editor](https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/DeveloperGuide/GraphEditor.md), an example application for visualizing, creating, and editing MaterialX graphs.
- Added support for the [adobergb and lin_adobergb](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1118) color spaces in shader generation.
- Added uisoftmin and uisoftmax attributes to [mix nodes](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1168) and [IOR inputs](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1151).
- Added support for [authored bitangent vectors](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1156) in GLSL, selected by the hwImplicitBitangents generator option.
- Added a [tangent input](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1157) to the glTF PBR shading model.
- Added a [Clang Format](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1174) step to GitHub Actions builds.

### Changed
- Improved the [support library](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1184) and [node implementations](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1185) for OSL generation.
- Improved the handling of [functional graphs](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1243) in MDL generation.
- Upgraded the [NanoGUI version](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1195) in the viewer to support Apple M1 builds.

### Fixed
- Fixed logic for [tangent basis orthogonalization](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1177) in generated GLSL.
- Fixed logic for [metallic F90](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1187) and an [opacity edge case](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1186) in UsdPreviewSurface.
- Fixed parsing of [inline source code variables](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1191) in node implementations.

## [1.38.6] - 2022-11-04

### Added
Expand Down
4 changes: 2 additions & 2 deletions documents/DeveloperGuide/Viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Select the `MATERIALX_BUILD_VIEWER` option in CMake to build the MaterialX Viewe

### Summary of Viewer Options

1. **Load Mesh**: Load a new geometry in the OBJ format.
1. **Load Mesh**: Load a new geometry in the OBJ or glTF format.
2. **Load Material**: Load a material document in the MTLX format.
3. **Load Environment**: Load a lat-long environment light in the HDR format.
4. **Property Editor**: View or edit properties of the current material.
Expand Down Expand Up @@ -78,7 +78,7 @@ By default, the MaterialX viewer loads and saves image files using `stb_image`,

The following are common command-line options for MaterialXView, and a complete list can be displayed with the `--help` option.
- `--material [FILENAME]` : Specify the filename of the MTLX document to be displayed in the viewer
- `--mesh [FILENAME]` : Specify the filename of the OBJ mesh to be displayed in the viewer
- `--mesh [FILENAME]` : Specify the filename of the OBJ or glTF mesh to be displayed in the viewer
- `--meshRotation [VECTOR3]` : Specify the rotation of the displayed mesh as three comma-separated floats, representing rotations in degrees about the X, Y, and Z axes (defaults to 0,0,0)
- `--meshScale [FLOAT]` : Specify the uniform scale of the displayed mesh
- `--cameraPosition [VECTOR3]` : Specify the position of the camera as three comma-separated floats (defaults to 0,0,5)
Expand Down
14 changes: 13 additions & 1 deletion python/MaterialXTest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,18 @@ def test_TraverseGraph(self):
self.assertFalse(output.hasUpstreamCycle())
self.assertTrue(doc.validate()[0])

def test_ReadXml(self):
def test_Xmlio(self):
# Read the standard library.
libs = []
for filename in _libraryFilenames:
lib = mx.createDocument()
mx.readFromXmlFile(lib, filename, _searchPath)
libs.append(lib)

# Declare write predicate for write filter test
def skipLibraryElement(elem):
return not elem.hasSourceUri()

# Read and validate each example document.
for filename in _exampleFilenames:
doc = mx.createDocument()
Expand Down Expand Up @@ -473,6 +477,14 @@ def test_ReadXml(self):
doc2.importLibrary(lib)
self.assertTrue(doc2.validate()[0])

# Write without definitions
writeOptions.writeXIncludeEnable = False
writeOptions.elementPredicate = skipLibraryElement
result = mx.writeToXmlString(doc2, writeOptions)
doc3 = mx.createDocument()
mx.readFromXmlString(doc3, result)
self.assertTrue(len(doc3.getNodeDefs()) == 0)

# Read the same document twice, and verify that duplicate elements
# are skipped.
doc = mx.createDocument()
Expand Down
28 changes: 14 additions & 14 deletions source/MaterialXGenMdl/MdlShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ MATERIALX_NAMESPACE_BEGIN
namespace
{

std::unordered_map<string, string> GEOMPROP_DEFINITIONS =
{
{ "Pobject", "base::transform_point(base::coordinate_internal, base::coordinate_object, state::position())" },
{ "Pworld", "base::transform_point(base::coordinate_internal, base::coordinate_world, state::position())" },
{ "Nobject", "base::transform_normal(base::coordinate_internal, base::coordinate_object, state::normal())" },
{ "Nworld", "base::transform_normal(base::coordinate_internal, base::coordinate_world, state::normal())" },
{ "Tobject", "base::transform_vector(base::coordinate_internal, base::coordinate_object, state::texture_tangent_u(0))" },
{ "Tworld", "base::transform_vector(base::coordinate_internal, base::coordinate_world, state::texture_tangent_u(0))" },
{ "Bobject", "base::transform_vector(base::coordinate_internal, base::coordinate_object, state::texture_tangent_v(0))" },
{ "Bworld", "base::transform_vector(base::coordinate_internal, base::coordinate_world, state::texture_tangent_v(0))" },
{ "UV0", "float2(state::texture_coordinate(0).x, state::texture_coordinate(0).y)" },
{ "Vworld", "state::direction()" }
};

const string MDL_VERSION = "1.6";

const vector<string> DEFAULT_IMPORTS =
Expand All @@ -67,6 +53,20 @@ const vector<string> DEFAULT_IMPORTS =

const string MdlShaderGenerator::TARGET = "genmdl";

const std::unordered_map<string, string> MdlShaderGenerator::GEOMPROP_DEFINITIONS =
{
{ "Pobject", "state::transform_point(state::coordinate_internal, state::coordinate_object, state::position())" },
{ "Pworld", "state::transform_point(state::coordinate_internal, state::coordinate_world, state::position())" },
{ "Nobject", "state::transform_normal(state::coordinate_internal, state::coordinate_object, state::normal())" },
{ "Nworld", "state::transform_normal(state::coordinate_internal, state::coordinate_world, state::normal())" },
{ "Tobject", "state::transform_vector(state::coordinate_internal, state::coordinate_object, state::texture_tangent_u(0))" },
{ "Tworld", "state::transform_vector(state::coordinate_internal, state::coordinate_world, state::texture_tangent_u(0))" },
{ "Bobject", "state::transform_vector(state::coordinate_internal, state::coordinate_object, state::texture_tangent_v(0))" },
{ "Bworld", "state::transform_vector(state::coordinate_internal, state::coordinate_world, state::texture_tangent_v(0))" },
{ "UV0", "float2(state::texture_coordinate(0).x, state::texture_coordinate(0).y)" },
{ "Vworld", "state::direction()" }
};

//
// MdlShaderGenerator methods
//
Expand Down
3 changes: 3 additions & 0 deletions source/MaterialXGenMdl/MdlShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class MX_GENMDL_API MdlShaderGenerator : public ShaderGenerator
/// Unique identifier for this generator target
static const string TARGET;

/// Map of code snippets for geomprops in MDL.
static const std::unordered_map<string, string> GEOMPROP_DEFINITIONS;

protected:
// Create and initialize a new MDL shader for shader generation.
ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const;
Expand Down
82 changes: 6 additions & 76 deletions source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,20 @@ void ClosureCompoundNodeMdl::addClassification(ShaderNode& node) const
node.addClassification(_rootGraph->getClassification());
}

void ClosureCompoundNodeMdl::emitFunctionDefinition(const ShaderNode&, GenContext& context, ShaderStage& stage) const
void ClosureCompoundNodeMdl::emitFunctionDefinition(const ShaderNode& node, GenContext& context, ShaderStage& stage) const
{
DEFINE_SHADER_STAGE(stage, Stage::PIXEL)
{
const ShaderGenerator& shadergen = context.getShaderGenerator();
const Syntax& syntax = shadergen.getSyntax();

const bool isMaterialExpr = (_rootGraph->hasClassification(ShaderNode::Classification::CLOSURE) ||
_rootGraph->hasClassification(ShaderNode::Classification::SHADER));

// Emit functions for all child nodes
shadergen.emitFunctionDefinitions(*_rootGraph, context, stage);

if (!_returnStruct.empty())
{
// Define the output struct.
shadergen.emitLine("struct " + _returnStruct, stage, false);
shadergen.emitScopeBegin(stage, Syntax::CURLY_BRACKETS);
for (const ShaderGraphOutputSocket* output : _rootGraph->getOutputSockets())
{
shadergen.emitLine(syntax.getTypeName(output->getType()) + " mxp_" + output->getName(), stage);
}
shadergen.emitScopeEnd(stage, true);
shadergen.emitLineBreak(stage);

// Begin function signature.
shadergen.emitLine(_returnStruct + " " + _functionName, stage, false);
}
else
{
// Begin function signature.
const ShaderGraphOutputSocket* outputSocket = _rootGraph->getOutputSocket();
const string& outputType = syntax.getTypeName(outputSocket->getType());
shadergen.emitLine(outputType + " " + _functionName, stage, false);
}

shadergen.emitScopeBegin(stage, Syntax::PARENTHESES);

const string uniformPrefix = syntax.getUniformQualifier() + " ";

// Emit all inputs
int count = int(_rootGraph->numInputSockets());
for (ShaderGraphInputSocket* input : _rootGraph->getInputSockets())
{
const string& qualifier = input->isUniform() || input->getType() == Type::FILENAME ? uniformPrefix : EMPTY_STRING;
const string& type = syntax.getTypeName(input->getType());
const string value = (input->getValue() ?
syntax.getValue(input->getType(), *input->getValue()) :
syntax.getDefaultValue(input->getType()));

const string& delim = --count > 0 ? Syntax::COMMA : EMPTY_STRING;
shadergen.emitLine(qualifier + type + " " + input->getVariable() + " = " + value + delim, stage, false);
}

// End function signature.
shadergen.emitScopeEnd(stage);
// Emit function signature.
emitFunctionSignature(node, context, stage);

// Special case for material expresions.
if (isMaterialExpr)
Expand Down Expand Up @@ -149,39 +107,11 @@ void ClosureCompoundNodeMdl::emitFunctionCall(const ShaderNode& node, GenContext
{
const ShaderGenerator& shadergen = context.getShaderGenerator();

// Emit calls for any closure dependencies upstream from this node.
// First emit calls for any closure dependencies upstream from this node.
shadergen.emitDependentFunctionCalls(node, context, stage, ShaderNode::Classification::CLOSURE);

// Begin function call.
if (!_returnStruct.empty())
{
// Emit the struct multioutput.
const string resultVariableName = node.getName() + "_result";
shadergen.emitLineBegin(stage);
shadergen.emitString(_returnStruct + " " + resultVariableName + " = ", stage);
}
else
{
// Emit the single output.
shadergen.emitLineBegin(stage);
shadergen.emitOutput(node.getOutput(0), true, false, context, stage);
shadergen.emitString(" = ", stage);
}

shadergen.emitString(_functionName + "(", stage);

// Emit inputs.
string delim = "";
for (ShaderInput* input : node.getInputs())
{
shadergen.emitString(delim, stage);
shadergen.emitInput(input, context, stage);
delim = ", ";
}

// End function call
shadergen.emitString(")", stage);
shadergen.emitLineEnd(stage);
// Then emit this nodes function call.
CompoundNodeMdl::emitFunctionCall(node, context, stage);
}
}

Expand Down
Loading

0 comments on commit d78b4b3

Please sign in to comment.