Skip to content

Commit 4fb3a18

Browse files
Switch to using RampData for shader parameters instead of SplineData
1 parent b68a2f9 commit 4fb3a18

File tree

11 files changed

+461
-397
lines changed

11 files changed

+461
-397
lines changed

contrib/IECoreUSD/src/IECoreUSD/ShaderAlgo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ IECoreScene::ShaderNetwork::Parameter readShaderNetworkWalk( const pxr::SdfPath
302302
IECoreScene::ConstShaderNetworkPtr adaptShaderNetworkForWriting( const IECoreScene::ShaderNetwork *shaderNetwork )
303303
{
304304
IECoreScene::ShaderNetworkPtr result = shaderNetwork->copy();
305-
IECoreScene::ShaderNetworkAlgo::expandSplines( result.get() );
305+
IECoreScene::ShaderNetworkAlgo::expandRamps( result.get() );
306306
IECoreScene::ShaderNetworkAlgo::addComponentConnectionAdapters( result.get() );
307307
return result;
308308
}
@@ -529,7 +529,7 @@ IECoreScene::ShaderNetworkPtr IECoreUSD::ShaderAlgo::readShaderNetwork( const px
529529
result->setOutput( outputHandle );
530530

531531
IECoreScene::ShaderNetworkAlgo::removeComponentConnectionAdapters( result.get() );
532-
IECoreScene::ShaderNetworkAlgo::collapseSplines( result.get() );
532+
IECoreScene::ShaderNetworkAlgo::collapseRamps( result.get() );
533533

534534
return result;
535535
}

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,12 +2917,13 @@ def testShaders( self ) :
29172917
surface.parameters["c"] = IECore.StringData( "42" )
29182918
surface.parameters["d"] = IECore.Color3fData( imath.Color3f( 3 ) )
29192919
surface.parameters["e"] = IECore.V3fVectorData( [ imath.V3f( 7 ) ] )
2920-
surface.parameters["f"] = IECore.SplineffData( IECore.Splineff( IECore.CubicBasisf.bSpline(),
2921-
( ( 0, 1 ), ( 10, 2 ), ( 20, 0 ), ( 21, 2 ) ) )
2922-
)
2923-
surface.parameters["g"] = IECore.SplinefColor3fData( IECore.SplinefColor3f( IECore.CubicBasisf.linear(),
2924-
( ( 0, imath.Color3f(1) ), ( 10, imath.Color3f(2) ), ( 20, imath.Color3f(0) ) ) )
2925-
)
2920+
surface.parameters["f"] = IECore.RampffData( IECore.Rampff(
2921+
( ( 0, 1 ), ( 10, 2 ), ( 20, 0 ), ( 21, 2 ) ), IECore.RampInterpolation.BSpline
2922+
) )
2923+
surface.parameters["g"] = IECore.RampfColor3fData( IECore.RampfColor3f(
2924+
( ( 0, imath.Color3f(1) ), ( 10, imath.Color3f(2) ), ( 20, imath.Color3f(0) ) ),
2925+
IECore.RampInterpolation.Linear
2926+
) )
29262927

29272928
add1 = IECoreScene.Shader( "add", "ai:shader" )
29282929
add1.parameters["b"] = IECore.FloatData( 3.0 )
@@ -2978,11 +2979,13 @@ def testShaders( self ) :
29782979
dest.parameters["a"] = IECore.Color3fData( imath.Color3f( 0.0 ) )
29792980
dest.parameters["b"] = IECore.Color3fData( imath.Color3f( 0.0 ) )
29802981
dest.parameters["c"] = IECore.FloatData( 0.0 )
2981-
dest.parameters["sf"] = IECore.SplineffData( IECore.Splineff( IECore.CubicBasisf.catmullRom(),
2982-
( ( 0, 1 ), ( 10, 2 ), ( 20, 0 ), ( 30, 1 ) )
2982+
dest.parameters["sf"] = IECore.RampffData( IECore.Rampff(
2983+
( ( 0, 1 ), ( 10, 2 ), ( 20, 0 ), ( 30, 1 ) ),
2984+
IECore.RampInterpolation.CatmullRom
29832985
) )
2984-
dest.parameters["sc"] = IECore.SplinefColor3fData( IECore.SplinefColor3f( IECore.CubicBasisf.linear(),
2985-
( ( 0, imath.Color3f(1) ), ( 10, imath.Color3f(2) ), ( 20, imath.Color3f(0) ) )
2986+
dest.parameters["sc"] = IECore.RampfColor3fData( IECore.RampfColor3f(
2987+
( ( 0, imath.Color3f(1) ), ( 10, imath.Color3f(2) ), ( 20, imath.Color3f(0) ) ),
2988+
IECore.RampInterpolation.Linear
29862989
) )
29872990

29882991
componentConnectionNetwork = IECoreScene.ShaderNetwork()
@@ -3016,19 +3019,19 @@ def testShaders( self ) :
30163019
) )
30173020
componentConnectionNetwork.setOutput( IECoreScene.ShaderNetwork.Parameter( "dest", "" ) )
30183021

3019-
# Float to spline element connection
3022+
# Float to ramp element connection
30203023
componentConnectionNetwork.addConnection( IECoreScene.ShaderNetwork.Connection(
30213024
IECoreScene.ShaderNetwork.Parameter( "source1", "out" ),
30223025
IECoreScene.ShaderNetwork.Parameter( "dest", "sf[3].y" )
30233026
) )
30243027

3025-
# Color to spline element connection
3028+
# Color to ramp element connection
30263029
componentConnectionNetwork.addConnection( IECoreScene.ShaderNetwork.Connection(
30273030
IECoreScene.ShaderNetwork.Parameter( "source3", "out" ),
30283031
IECoreScene.ShaderNetwork.Parameter( "dest", "sc[2].y" )
30293032
) )
30303033

3031-
# Float to spline element component connection
3034+
# Float to ramp element component connection
30323035
componentConnectionNetwork.addConnection( IECoreScene.ShaderNetwork.Connection(
30333036
IECoreScene.ShaderNetwork.Parameter( "source1", "out" ),
30343037
IECoreScene.ShaderNetwork.Parameter( "dest", "sc[0].y.g" )

include/IECore/SplineParameter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
namespace IECore
4242
{
4343

44+
// \todo : Using Spline*Data has basically been deprecated in favour of Ramp*Data.
45+
// Setting up data this way will no longer work with renderer backends. In theory,
46+
// the right thing to do might be to replace this with RampParameter ... but on
47+
// the other hand, Parameter itself probably should be deprecated ( these days,
48+
// anyone using Cortex to build UIs is probably using Gaffer ).
49+
4450
typedef TypedParameter<Splineff> SplineffParameter;
4551
typedef TypedParameter<Splinedd> SplineddParameter;
4652
typedef TypedParameter<SplinefColor3f> SplinefColor3fParameter;

include/IECoreImage/SplineToImage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ namespace IECoreImage
5454

5555
/// This Op creates ImagePrimitives from SplineData.
5656
/// \todo Different projections would be nice.
57+
/// \todo If we wanted to keep this up to date, it should probably take RampData instead
58+
/// of SplineData, but ImagePrimitive is on the path to deprecation anyway.
5759
/// \ingroup imageProcessingGroup
5860
class IECOREIMAGE_API SplineToImage : public IECore::Op
5961
{

include/IECoreScene/ShaderNetworkAlgo.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,39 @@ IECORESCENE_API void deregisterJoinAdapter( const std::string &destinationShader
103103
/// For OSL prior to 1.10, intermediate shaders are inserted to emulate connections between components.
104104
/// For later versions, no new shaders are inserted, but components are renamed from our `.x, .y, .z`
105105
/// suffixes to OSL's `[0], [1], [2]` suffixes.
106-
/// - Splines
107-
/// We support SplineData as a parameter type. For OSL, these must be converted to 3 parameters named
108-
/// `<splineName>Positions`, `<splineName>Values` and `<splineName>Basis`. We also support input
109-
/// connections to spline Y values, specified as `<splineName>[N].y`, which currently must be implemented
106+
/// - Ramps
107+
/// We support RampData as a parameter type. For OSL, these must be converted to 3 parameters named
108+
/// `<rampName>Positions`, `<rampName>Values` and `<rampName>Basis`. We also support input
109+
/// connections to ramp Y values, specified as `<rampName>[N].y`, which currently must be implemented
110110
/// using an adapter shader.
111111
IECORESCENE_API void convertToOSLConventions( ShaderNetwork *network, int oslVersion );
112112

113113
/// Converts from the legacy ObjectVector format previously used to represent shader networks.
114114
IECORESCENE_API ShaderNetworkPtr convertObjectVector( const IECore::ObjectVector *network );
115115

116-
/// We use a convention where ramps are represented by a single SplineData in Cortex, but must be expanded
116+
/// We use a convention where ramps are represented by a single RampData in Cortex, but must be expanded
117117
/// out into basic types when being passed to a renderer. We need two functions to convert back and forth.
118118

119-
120-
/// Look throughout the network for parameters matching our spline convention, for any possible <prefix> :
119+
/// Look throughout the network for parameters matching our ramp convention, for any possible <prefix> :
121120
/// <prefix>Positions, a float vector parameter
122121
/// <prefix>Values, a vector of a value type, such as float or color
123122
/// <prefix>Basis, a string parameter
124123
/// For each set of parameters found matching this convention, the 3 parameters will be replaced with one
125-
/// spline parameter named <prefix>. If input connections are represented using an adapter shader, they
126-
/// will be converted to direct connections to the spline using our support for spline element
124+
/// ramp parameter named <prefix>. If input connections are represented using an adapter shader, they
125+
/// will be converted to direct connections to the ramp using our support for ramp element
127126
/// connections.
128127
/// If `targetPrefix` is given, only translates connections to shaders with a type starting with this string
129-
IECORESCENE_API void collapseSplines( ShaderNetwork *network, std::string targetPrefix = "" );
128+
IECORESCENE_API void collapseRamps( ShaderNetwork *network, std::string targetPrefix = "" );
130129

131-
/// Look throughout the network for spline parameters. If any are found, they will be expanded out into
130+
/// Look throughout the network for ramp parameters. If any are found, they will be expanded out into
132131
/// 3 parameters named <name>Positions, <name>Values and <name>Basis.
133-
/// We also support input connections to spline Y values, specified as `<splineName>[N].y`, which currently
132+
/// We also support input connections to ramp Y values, specified as `<rampName>[N].y`, which currently
134133
/// must be implemented by inserting an adapter shader.
135134
/// If `targetPrefix` is given, only translates connections to shaders with a type starting with this string
136-
IECORESCENE_API void expandSplines( ShaderNetwork *network, std::string targetPrefix = "" );
135+
IECORESCENE_API void expandRamps( ShaderNetwork *network, std::string targetPrefix = "" );
136+
137+
/// Used when dealing with SCC files written before Cortex 10.7, which used Spline*Data instead of Ramp*Data
138+
IECORESCENE_API void convertDeprecatedSplines( ShaderNetwork *network );
137139

138140
} // namespace ShaderNetworkAlgo
139141

src/IECoreGL/ShaderStateComponent.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class ShaderStateComponent::Implementation : public IECore::RefCounted
132132
if( p->type == GL_SAMPLER_2D )
133133
{
134134
ConstTexturePtr texture = nullptr;
135+
// TODO - this probably should actually be updated to take Ramp, but in order to test
136+
// that, I need to figure out where this is used.
135137
if(
136138
it->second->typeId() == (IECore::TypeId)IECoreImage::ImagePrimitiveTypeId ||
137139
it->second->typeId() == IECore::CompoundDataTypeId ||

src/IECoreScene/SceneCache.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "IECore/MessageHandler.h"
4848
#include "IECore/ObjectInterpolator.h"
4949
#include "IECore/SimpleTypedData.h"
50+
#include "IECore/SplineData.h"
5051
#include "IECore/TransformationMatrixData.h"
5152
#include "IECore/PathMatcherData.h"
5253

@@ -1156,6 +1157,31 @@ class SceneCache::ReaderImplementation : public SceneCache::Implementation
11561157
}
11571158
}
11581159

1160+
if( const ShaderNetwork *shaderNetwork = runTimeCast<const ShaderNetwork>( result.get() ) )
1161+
{
1162+
bool needsDeprecatedSplineConversion = false;
1163+
for( const auto &s : shaderNetwork->shaders() )
1164+
{
1165+
for( const auto &p : s.second->parameters() )
1166+
{
1167+
IECore::TypeId typeId = p.second->typeId();
1168+
if(
1169+
typeId == SplineffData::staticTypeId() ||
1170+
typeId == SplinefColor3fData::staticTypeId()
1171+
)
1172+
needsDeprecatedSplineConversion = true;
1173+
}
1174+
}
1175+
1176+
if( needsDeprecatedSplineConversion )
1177+
{
1178+
ShaderNetworkPtr resultNetwork = shaderNetwork->copy();
1179+
1180+
ShaderNetworkAlgo::convertDeprecatedSplines( resultNetwork.get() );
1181+
result = resultNetwork;
1182+
}
1183+
}
1184+
11591185
return result;
11601186
}
11611187

0 commit comments

Comments
 (0)