Skip to content

Commit

Permalink
Improvements to color transform handling
Browse files Browse the repository at this point in the history
- Add support for a wider set of use cases for color space bindings, including surface shader nodes with filename-type inputs.
- Add support for scoped color space bindings in shader translation.
- Add a test suite example that covers newly-supported use cases.

Supporting changes include:

- Merge the protected method ShaderGraph::createSurfaceShader into ShaderGraph::create, allowing surface shader nodes to be handled in the same fashion as other nodes.
- Update the interface of ShaderGraph::createNode, allowing greater flexibility in accessing parent nodes during shader generation.  We've omitted a deprecated wrapper for this API update, as it would not be straightforward to write one in a memory-safe fashion, but fortunately this method only appears to be used within the ShaderGraph class.
  • Loading branch information
jstone-lucasfilm committed Feb 25, 2024
1 parent 4cd0dcf commit d634311
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 313 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<materialx version="1.38">
<nodedef name="ND_network_surface" node="network_surface">
<input name="base_color_filename" type="filename" value="" />
<output name="out" type="surfaceshader" />
</nodedef>
<nodegraph name="NG_network_surface" nodedef="ND_network_surface">
<tiledimage name="base_color_image" type="color3">
<input name="file" type="filename" interfacename="base_color_filename" />
</tiledimage>
<standard_surface name="standard_surface" type="surfaceshader">
<input name="base_color" type="color3" nodename="base_color_image" />
</standard_surface>
<output name="out" type="surfaceshader" nodename="standard_surface" />
</nodegraph>
<network_surface name="N_surfaceshader" type="surfaceshader">
<input name="base_color_filename" type="filename" value="resources/Images/grid.png" colorspace="srgb_texture" />
</network_surface>
<surfacematerial name="N_surfacematerial" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="N_surfaceshader" />
</surfacematerial>
</materialx>
19 changes: 19 additions & 0 deletions source/MaterialXGenShader/GenContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ class MX_GENSHADER_API GenContext
return _closureContexts.size() ? _closureContexts.back() : nullptr;
}

/// Push a parent node onto the stack
void pushParentNode(ConstNodePtr node)
{
_parentNodes.push_back(node);
}

/// Pop the current parent node from the stack.
void popParentNode()
{
_parentNodes.pop_back();
}

/// Return the current stack of parent nodes.
const vector<ConstNodePtr>& getParentNodes()
{
return _parentNodes;
}

/// Add user data to the context to make it
/// available during shader generator.
void pushUserData(const string& name, GenUserDataPtr data)
Expand Down Expand Up @@ -216,6 +234,7 @@ class MX_GENSHADER_API GenContext
std::unordered_map<const ShaderOutput*, string> _outputSuffix;

vector<ClosureContext*> _closureContexts;
vector<ConstNodePtr> _parentNodes;

ApplicationVariableHandler _applicationVariableHandler;
};
Expand Down
Loading

0 comments on commit d634311

Please sign in to comment.