MaterialX 1.38.10
Loading...
Searching...
No Matches
Util.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_SHADERGEN_UTIL_H
7#define MATERIALX_SHADERGEN_UTIL_H
8
11
13
15
16#include <unordered_set>
17
18MATERIALX_NAMESPACE_BEGIN
19
20class ShaderGenerator;
21
34MX_GENSHADER_API bool isTransparentSurface(ElementPtr element, const string& target = EMPTY_STRING);
35
40MX_GENSHADER_API void mapValueToColor(ConstValuePtr value, Color4& color);
41
43MX_GENSHADER_API bool requiresImplementation(ConstNodeDefPtr nodeDef);
44
46MX_GENSHADER_API bool elementRequiresShading(ConstTypedElementPtr element);
47
51MX_GENSHADER_API vector<TypedElementPtr> findRenderableMaterialNodes(ConstDocumentPtr doc);
52
57MX_GENSHADER_API vector<TypedElementPtr> findRenderableElements(ConstDocumentPtr doc);
58
61MX_GENSHADER_API InputPtr getNodeDefInput(InputPtr nodeInput, const string& target);
62
67MX_GENSHADER_API void tokenSubstitution(const StringMap& substitutions, string& source);
68
71MX_GENSHADER_API vector<Vector2> getUdimCoordinates(const StringVec& udimIdentifiers);
72
75MX_GENSHADER_API void getUdimScaleAndOffset(const vector<Vector2>& udimCoordinates, Vector2& scaleUV, Vector2& offsetUV);
76
81MX_GENSHADER_API NodePtr connectsToWorldSpaceNode(OutputPtr output);
82
87MX_GENSHADER_API bool hasElementAttributes(OutputPtr output, const StringVec& attributes);
88
89//
90// These are deprecated wrappers for older versions of the function interfaces in this module.
91// Clients using these interfaces should update them to the latest API.
92//
93MX_GENSHADER_API [[deprecated]] void findRenderableMaterialNodes(ConstDocumentPtr doc, vector<TypedElementPtr>& elements, bool, std::unordered_set<ElementPtr>&);
94MX_GENSHADER_API [[deprecated]] void findRenderableElements(ConstDocumentPtr doc, vector<TypedElementPtr>& elements, bool includeReferencedGraphs = false);
95
96MATERIALX_NAMESPACE_END
97
98#endif
shared_ptr< const NodeDef > ConstNodeDefPtr
A shared pointer to a const NodeDef.
Definition: Definition.h:34
The top-level Document class.
shared_ptr< const Document > ConstDocumentPtr
A shared pointer to a const Document.
Definition: Document.h:24
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
shared_ptr< const TypedElement > ConstTypedElementPtr
A shared pointer to a const TypedElement.
Definition: Element.h:38
shared_ptr< Input > InputPtr
A shared pointer to an Input.
Definition: Interface.h:31
shared_ptr< Output > OutputPtr
A shared pointer to an Output.
Definition: Interface.h:36
vector< string > StringVec
A vector of strings.
Definition: Library.h:57
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:59
Macros for declaring imported and exported symbols.
MX_GENSHADER_API void tokenSubstitution(const StringMap &substitutions, string &source)
Perform token substitutions on the given source string, using the given substituation map.
Definition: Util.cpp:445
MX_GENSHADER_API bool hasElementAttributes(OutputPtr output, const StringVec &attributes)
Returns true if there is are any value elements with a given set of attributes either on the starting...
Definition: Util.cpp:555
MX_GENSHADER_API NodePtr connectsToWorldSpaceNode(OutputPtr output)
Determine whether the given output is directly connected to a node that generates world-space coordin...
Definition: Util.cpp:544
MX_GENSHADER_API bool elementRequiresShading(ConstTypedElementPtr element)
Determine if a given element requires shading / lighting for rendering.
Definition: Util.cpp:356
MX_GENSHADER_API vector< TypedElementPtr > findRenderableMaterialNodes(ConstDocumentPtr doc)
Find all renderable material nodes in the given document.
Definition: Util.cpp:366
MX_GENSHADER_API bool isTransparentSurface(ElementPtr element, const string &target=EMPTY_STRING)
Returns true if the given element is a surface shader with the potential of being transparent.
Definition: Util.cpp:239
MX_GENSHADER_API InputPtr getNodeDefInput(InputPtr nodeInput, const string &target)
Given a node input, return the corresponding input within its matching nodedef.
Definition: Util.cpp:424
MX_GENSHADER_API void mapValueToColor(ConstValuePtr value, Color4 &color)
Maps a value to a four channel color if it is of the appropriate type.
Definition: Util.cpp:295
MX_GENSHADER_API bool requiresImplementation(ConstNodeDefPtr nodeDef)
Return whether a nodedef requires an implementation.
Definition: Util.cpp:340
MX_GENSHADER_API vector< Vector2 > getUdimCoordinates(const StringVec &udimIdentifiers)
Compute the UDIM coordinates for a set of UDIM identifiers.
Definition: Util.cpp:473
MX_GENSHADER_API void getUdimScaleAndOffset(const vector< Vector2 > &udimCoordinates, Vector2 &scaleUV, Vector2 &offsetUV)
Get the UV scale and offset to transform uv coordinates from UDIM uv space to 0..1 space.
Definition: Util.cpp:505
MX_GENSHADER_API vector< TypedElementPtr > findRenderableElements(ConstDocumentPtr doc)
Find all renderable elements in the given document, including material nodes if present,...
Definition: Util.cpp:379
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:24
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition: Value.h:31
A four-component color value.
Definition: Types.h:364
Base class for shader generators All third-party shader generators should derive from this class.
Definition: ShaderGenerator.h:31
A vector of two floating-point values.
Definition: Types.h:286