Skip to content

Commit e2c65a2

Browse files
committed
ShaderNetworkAlgo : Allow customisation of component adaptors
The main motivation here is that the MaterialX shaders we were using as adaptors don't really make sense - they're not actually available as OSL shaders any more, so they have zero chance of working in other DCCs when we export shading to USD from Gaffer. Instead we can now register renderer-specific adaptors that are available everywhere the renderer is. This also somewhat changes our approach to removing adaptors. Instead of just tagging them as "an adaptor" and figuring the rest out based on the shader name, we now register all the necessary information as blind data. This will allow us to reliably remove an adaptor even if adaptor registrations change in the future. It should also be useful at a certain studio which rewrites the `info:id` attribute on export to USD, in such a way that it broke our old adaptor removal code.
1 parent c657c1f commit e2c65a2

File tree

6 files changed

+464
-150
lines changed

6 files changed

+464
-150
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Improvements
1010
- IECoreUSD::ShaderAlgo :
1111
- Stopped writing `cortex_autoAdaptor` metadata, which would cause errors in DCCs without the definition registered.
1212
- Added round-tripping of all blind data stored on Shaders.
13+
- IECoreScene::ShaderNetworkAlgo : Added a mechanism for customising the adapter shaders used by `addComponentConnectionAdapters()`.
1314

1415
10.5.9.5 (relative to 10.5.9.4)
1516
========

include/IECoreScene/ShaderNetworkAlgo.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,39 @@ IECORESCENE_API void removeUnusedShaders( ShaderNetwork *network );
6363
template<typename Visitor>
6464
void depthFirstTraverse( const ShaderNetwork *network, Visitor &&visitor, IECore::InternedString shader = "" );
6565

66-
/// Replace connections between sub components of colors or vectors with connections to whole parameters
67-
/// on adapter shaders. Currently uses the OSL shaders mx_pack_color and mx_swizzle_color_float as adapters.
68-
/// The newly created shaders will be labelled with a blind data so they can be identified.
69-
/// If `targetPrefix` is given, only translates connections to shaders with a type starting with this string
66+
/// Replaces connections between sub components of colors or vectors with
67+
/// connections to whole parameters on adapter shaders. If `targetPrefix` is
68+
/// given, only translates connections to shaders with a type starting with this
69+
/// string.
7070
IECORESCENE_API void addComponentConnectionAdapters( ShaderNetwork *network, std::string targetPrefix = "" );
7171

72-
/// Find adapters that were created by addComponentConnectionAdapters ( based on the blind data label ),
73-
/// and remove them, replacing them with the original component connections
72+
/// Finds adapters that were created by addComponentConnectionAdapters, and
73+
/// removes them, replacing them with the original component connections.
7474
IECORESCENE_API void removeComponentConnectionAdapters( ShaderNetwork *network );
7575

76-
/// The name of the boolean blindData label used by add/removeComponentConnectionAdapters
76+
/// Registers an adapter to split a component from a color or vector output, ready for connection into
77+
/// a scalar input. Used by `addComponentConnectionAdapters()`.
78+
///
79+
/// - `destinationShaderType` : The type prefix for the shader receiving the connection - e.g. "ai", "osl".
80+
/// - `component` : "r", "g", "b", "a", "x", "y", or "z".
81+
/// - `adapter` : The shader to be used as the adapter.
82+
/// - `inParameter` : The parameter that receives the color or vector input.
83+
/// - `outParameter` : The parameter that outputs the component.
84+
IECORESCENE_API void registerSplitAdapter( const std::string &destinationShaderType, IECore::InternedString component, const IECoreScene::Shader *adapter, IECore::InternedString inParameter, IECore::InternedString outParameter );
85+
/// Removes an adapter registration.
86+
IECORESCENE_API void deregisterSplitAdapter( const std::string &destinationShaderType, IECore::InternedString component );
87+
88+
/// Registers an adapter to join multiple scalar components into a color or vector output. Used by `addComponentConnectionAdapters()`.
89+
///
90+
/// - `destinationShaderType` : The type prefix for the shader receiving the connection - e.g. "ai", "osl".
91+
/// - `destinationParameterType` : `(V2i|V3i|V2f|V3f|Color3f|Color4f)DataTypeId`.
92+
/// - `inParameters` : The parameters that receives the individual components of the vector or color.
93+
/// - `outParameter` : The parameter that outputs the vector or color.
94+
IECORESCENE_API void registerJoinAdapter( const std::string &destinationShaderType, IECore::TypeId destinationParameterType, const IECoreScene::Shader *adapter, const std::array<IECore::InternedString, 4> &inParameters, IECore::InternedString outParameter );
95+
/// Removes an adapter registration.
96+
IECORESCENE_API void deregisterJoinAdapter( const std::string &destinationShaderType, IECore::TypeId destinationParameterType );
97+
98+
/// \deprecated
7799
IECORESCENE_API const IECore::InternedString &componentConnectionAdapterLabel();
78100

79101
/// Converts various aspects of how shaders are stored to be ready to pass directly to OSL.

0 commit comments

Comments
 (0)