Skip to content

Commit d634311

Browse files
Improvements to color transform handling
- 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.
1 parent 4cd0dcf commit d634311

File tree

5 files changed

+184
-313
lines changed

5 files changed

+184
-313
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<materialx version="1.38">
3+
<nodedef name="ND_network_surface" node="network_surface">
4+
<input name="base_color_filename" type="filename" value="" />
5+
<output name="out" type="surfaceshader" />
6+
</nodedef>
7+
<nodegraph name="NG_network_surface" nodedef="ND_network_surface">
8+
<tiledimage name="base_color_image" type="color3">
9+
<input name="file" type="filename" interfacename="base_color_filename" />
10+
</tiledimage>
11+
<standard_surface name="standard_surface" type="surfaceshader">
12+
<input name="base_color" type="color3" nodename="base_color_image" />
13+
</standard_surface>
14+
<output name="out" type="surfaceshader" nodename="standard_surface" />
15+
</nodegraph>
16+
<network_surface name="N_surfaceshader" type="surfaceshader">
17+
<input name="base_color_filename" type="filename" value="resources/Images/grid.png" colorspace="srgb_texture" />
18+
</network_surface>
19+
<surfacematerial name="N_surfacematerial" type="material">
20+
<input name="surfaceshader" type="surfaceshader" nodename="N_surfaceshader" />
21+
</surfacematerial>
22+
</materialx>

source/MaterialXGenShader/GenContext.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ class MX_GENSHADER_API GenContext
125125
return _closureContexts.size() ? _closureContexts.back() : nullptr;
126126
}
127127

128+
/// Push a parent node onto the stack
129+
void pushParentNode(ConstNodePtr node)
130+
{
131+
_parentNodes.push_back(node);
132+
}
133+
134+
/// Pop the current parent node from the stack.
135+
void popParentNode()
136+
{
137+
_parentNodes.pop_back();
138+
}
139+
140+
/// Return the current stack of parent nodes.
141+
const vector<ConstNodePtr>& getParentNodes()
142+
{
143+
return _parentNodes;
144+
}
145+
128146
/// Add user data to the context to make it
129147
/// available during shader generator.
130148
void pushUserData(const string& name, GenUserDataPtr data)
@@ -216,6 +234,7 @@ class MX_GENSHADER_API GenContext
216234
std::unordered_map<const ShaderOutput*, string> _outputSuffix;
217235

218236
vector<ClosureContext*> _closureContexts;
237+
vector<ConstNodePtr> _parentNodes;
219238

220239
ApplicationVariableHandler _applicationVariableHandler;
221240
};

0 commit comments

Comments
 (0)