Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
10.x.x.x (relative to 10.6.x.x)
========

Features
--------

- IECore : Added Rampff, RampfColor3f, RampfColor4f and corresponding Ramp*Data classes, for representing user facing shader ramp parameters.

Breaking Changes
----------------

- IECoreScene::ShaderNetworkAlgo : Switch support for Spline parameters to support for Ramp parameters.

10.6.x.x (relative to 10.6.1.0)
========
Expand Down
13 changes: 9 additions & 4 deletions contrib/IECoreUSD/src/IECoreUSD/ShaderAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ namespace
{

const pxr::TfToken g_blindDataToken( "cortex:blindData" );
pxr::TfToken g_legacyAdapterLabelToken( IECoreScene::ShaderNetworkAlgo::componentConnectionAdapterLabel().string() );

// Hardcoded to match an old name used by Cortex when writing USD with OSL version earlier than 1.10 (
// ie. a pre-2021 version of gafferDependencies ). We no longer expose this in the API, but I'm not sure
// if we're ready to drop support for loading these old files.
IECore::InternedString g_legacyAdapterLabelString( "cortex_autoAdapter" );
pxr::TfToken g_legacyAdapterLabelToken( g_legacyAdapterLabelString.string() );

std::pair<pxr::TfToken, std::string> shaderIdAndType( const pxr::UsdShadeConnectableAPI &connectable )
{
Expand Down Expand Up @@ -267,7 +272,7 @@ IECore::InternedString readShaderNetworkWalk( const pxr::SdfPath &anchorPath, co
pxr::VtValue metadataValue;
if( usdShader.GetPrim().GetMetadata( g_legacyAdapterLabelToken, &metadataValue ) && metadataValue.Get<bool>() )
{
newShader->blindData()->writable()[ IECoreScene::ShaderNetworkAlgo::componentConnectionAdapterLabel() ] = new IECore::BoolData( true );
newShader->blindData()->writable()[ g_legacyAdapterLabelString ] = new IECore::BoolData( true );
}

shaderNetwork.addShader( handle, std::move( newShader ) );
Expand Down Expand Up @@ -297,7 +302,7 @@ IECoreScene::ShaderNetwork::Parameter readShaderNetworkWalk( const pxr::SdfPath
IECoreScene::ConstShaderNetworkPtr adaptShaderNetworkForWriting( const IECoreScene::ShaderNetwork *shaderNetwork )
{
IECoreScene::ShaderNetworkPtr result = shaderNetwork->copy();
IECoreScene::ShaderNetworkAlgo::expandSplines( result.get() );
IECoreScene::ShaderNetworkAlgo::expandRamps( result.get() );
IECoreScene::ShaderNetworkAlgo::addComponentConnectionAdapters( result.get() );
return result;
}
Expand Down Expand Up @@ -524,7 +529,7 @@ IECoreScene::ShaderNetworkPtr IECoreUSD::ShaderAlgo::readShaderNetwork( const px
result->setOutput( outputHandle );

IECoreScene::ShaderNetworkAlgo::removeComponentConnectionAdapters( result.get() );
IECoreScene::ShaderNetworkAlgo::collapseSplines( result.get() );
IECoreScene::ShaderNetworkAlgo::collapseRamps( result.get() );

return result;
}
Expand Down
29 changes: 16 additions & 13 deletions contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2917,12 +2917,13 @@ def testShaders( self ) :
surface.parameters["c"] = IECore.StringData( "42" )
surface.parameters["d"] = IECore.Color3fData( imath.Color3f( 3 ) )
surface.parameters["e"] = IECore.V3fVectorData( [ imath.V3f( 7 ) ] )
surface.parameters["f"] = IECore.SplineffData( IECore.Splineff( IECore.CubicBasisf.bSpline(),
( ( 0, 1 ), ( 10, 2 ), ( 20, 0 ), ( 21, 2 ) ) )
)
surface.parameters["g"] = IECore.SplinefColor3fData( IECore.SplinefColor3f( IECore.CubicBasisf.linear(),
( ( 0, imath.Color3f(1) ), ( 10, imath.Color3f(2) ), ( 20, imath.Color3f(0) ) ) )
)
surface.parameters["f"] = IECore.RampffData( IECore.Rampff(
( ( 0, 1 ), ( 10, 2 ), ( 20, 0 ), ( 21, 2 ) ), IECore.RampInterpolation.BSpline
) )
surface.parameters["g"] = IECore.RampfColor3fData( IECore.RampfColor3f(
( ( 0, imath.Color3f(1) ), ( 10, imath.Color3f(2) ), ( 20, imath.Color3f(0) ) ),
IECore.RampInterpolation.Linear
) )

add1 = IECoreScene.Shader( "add", "ai:shader" )
add1.parameters["b"] = IECore.FloatData( 3.0 )
Expand Down Expand Up @@ -2978,11 +2979,13 @@ def testShaders( self ) :
dest.parameters["a"] = IECore.Color3fData( imath.Color3f( 0.0 ) )
dest.parameters["b"] = IECore.Color3fData( imath.Color3f( 0.0 ) )
dest.parameters["c"] = IECore.FloatData( 0.0 )
dest.parameters["sf"] = IECore.SplineffData( IECore.Splineff( IECore.CubicBasisf.catmullRom(),
( ( 0, 1 ), ( 10, 2 ), ( 20, 0 ), ( 30, 1 ) )
dest.parameters["sf"] = IECore.RampffData( IECore.Rampff(
( ( 0, 1 ), ( 10, 2 ), ( 20, 0 ), ( 30, 1 ) ),
IECore.RampInterpolation.CatmullRom
) )
dest.parameters["sc"] = IECore.SplinefColor3fData( IECore.SplinefColor3f( IECore.CubicBasisf.linear(),
( ( 0, imath.Color3f(1) ), ( 10, imath.Color3f(2) ), ( 20, imath.Color3f(0) ) )
dest.parameters["sc"] = IECore.RampfColor3fData( IECore.RampfColor3f(
( ( 0, imath.Color3f(1) ), ( 10, imath.Color3f(2) ), ( 20, imath.Color3f(0) ) ),
IECore.RampInterpolation.Linear
) )

componentConnectionNetwork = IECoreScene.ShaderNetwork()
Expand Down Expand Up @@ -3016,19 +3019,19 @@ def testShaders( self ) :
) )
componentConnectionNetwork.setOutput( IECoreScene.ShaderNetwork.Parameter( "dest", "" ) )

# Float to spline element connection
# Float to ramp element connection
componentConnectionNetwork.addConnection( IECoreScene.ShaderNetwork.Connection(
IECoreScene.ShaderNetwork.Parameter( "source1", "out" ),
IECoreScene.ShaderNetwork.Parameter( "dest", "sf[3].y" )
) )

# Color to spline element connection
# Color to ramp element connection
componentConnectionNetwork.addConnection( IECoreScene.ShaderNetwork.Connection(
IECoreScene.ShaderNetwork.Parameter( "source3", "out" ),
IECoreScene.ShaderNetwork.Parameter( "dest", "sc[2].y" )
) )

# Float to spline element component connection
# Float to ramp element component connection
componentConnectionNetwork.addConnection( IECoreScene.ShaderNetwork.Connection(
IECoreScene.ShaderNetwork.Parameter( "source1", "out" ),
IECoreScene.ShaderNetwork.Parameter( "dest", "sc[0].y.g" )
Expand Down
13 changes: 13 additions & 0 deletions include/IECore/DataAlgo.inl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "IECore/PathMatcherData.h"
#include "IECore/SimpleTypedData.h"
#include "IECore/SplineData.h"
#include "IECore/RampData.h"
#include "IECore/TransformationMatrixData.h"
#include "IECore/VectorTypedData.h"

Expand Down Expand Up @@ -132,6 +133,12 @@ typename std::invoke_result_t<F, Data *, Args&&...> dispatch( Data *data, F &&fu
return functor( static_cast<SplinefColor3fData *>( data ), std::forward<Args>( args )... );
case SplinefColor4fDataTypeId :
return functor( static_cast<SplinefColor4fData *>( data ), std::forward<Args>( args )... );
case RampffDataTypeId :
return functor( static_cast<RampffData *>( data ), std::forward<Args>( args )... );
case RampfColor3fDataTypeId :
return functor( static_cast<RampfColor3fData *>( data ), std::forward<Args>( args )... );
case RampfColor4fDataTypeId :
return functor( static_cast<RampfColor4fData *>( data ), std::forward<Args>( args )... );
case DateTimeDataTypeId :
return functor( static_cast<DateTimeData *>( data ), std::forward<Args>( args )... );
case BoolVectorDataTypeId :
Expand Down Expand Up @@ -286,6 +293,12 @@ typename std::invoke_result_t<F, const Data *, Args&&...> dispatch( const Data *
return functor( static_cast<const SplinefColor3fData *>( data ), std::forward<Args>( args )... );
case SplinefColor4fDataTypeId :
return functor( static_cast<const SplinefColor4fData *>( data ), std::forward<Args>( args )... );
case RampffDataTypeId :
return functor( static_cast<const RampffData *>( data ), std::forward<Args>( args )... );
case RampfColor3fDataTypeId :
return functor( static_cast<const RampfColor3fData *>( data ), std::forward<Args>( args )... );
case RampfColor4fDataTypeId :
return functor( static_cast<const RampfColor4fData *>( data ), std::forward<Args>( args )... );
case DateTimeDataTypeId :
return functor( static_cast<const DateTimeData *>( data ), std::forward<Args>( args )... );
case BoolVectorDataTypeId :
Expand Down
146 changes: 146 additions & 0 deletions include/IECore/Ramp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2025, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef IECORE_RAMP_H
#define IECORE_RAMP_H

#include "IECore/Export.h"
#include "IECore/Spline.h"
#include "IECore/MessageHandler.h"

IECORE_PUSH_DEFAULT_VISIBILITY
#include "Imath/ImathColor.h"
IECORE_POP_DEFAULT_VISIBILITY

#include <map>

namespace IECore
{

// This lives outside the class because we don't want multiple incompatible templated versions of
// the same enum floating around
enum class RampInterpolation
{
Linear = 0,
CatmullRom = 1,
BSpline = 2,
MonotoneCubic = 3,
Constant = 4,
};

/// A Ramp represents a spline-like curve as it is represented in a simple UI: with a set of independent
/// control points, and an interpolation type selected from RampInterpolation.
///
/// Rather than storing the lower level IECore::Spline*, we now store this Ramp type in shader networks,
/// and only convert to the lower level class with the evaluator() function when evaluation is needed.
///
/// This was chosen as superior to IECore::Spline* because IECoreS::spline* requires duplicating the
/// end points in order to make the curve reach the first and last control point.
template<typename X, typename Y>
class IECORE_EXPORT Ramp
{

public :

using XType = X;
using YType = Y;

using PointContainer = std::multimap<X, Y>;
using Point = typename PointContainer::value_type;

Ramp() : interpolation( RampInterpolation::CatmullRom )
{
}

Ramp( const PointContainer &p, RampInterpolation i )
: points( p ), interpolation( i )
{
}

PointContainer points;
RampInterpolation interpolation;


// Convert to Cortex Spline
// In the future, IECore::Spline may be replaced with IECore::SplineEvaluator, and this
// function would be the only way to setup one.
IECore::Spline<X, Y> evaluator() const;

// Convert to and from a set of arguments that could be passed to a pair of spline() and
// splineinverse() functions in OSL. This can be useful in converting ramps to parameters
// for OSL shaders.
//
// Some shader libraries use these arguments directly as shader parameters ( i.e. Gaffer ).
// Some shader libraries preprocess shader parameters before passing them to spline(),
// so they don't need some aspects of this conversion ( like endpoint duplication ), but
// the extra endpoint duplication doesn't cause problems ( i.e. PRMan ).
// Some shader libraries are doing their own thing, implementing their own custom math,
// but convention is still similar enough that these function can be a useful building
// block in converting to something that mostly works ( i.e. 3delight ).
void fromOSL( const std::string &basis, const std::vector<X> &positions, const std::vector<Y> &values, const std::string &identifier );
void toOSL( std::string &basis, std::vector<X> &positions, std::vector<Y> &values ) const;

/// The number of times `toOSL()` repeats the initial point.
int oslStartPointMultiplicity() const;

// In Cortex 10.6 and earlier, shader parameters were represented uing IECore::Spline*Data instead of
// IECore::Ramp*Data. This is used in converting SCC files to the new standard.
// \todo : This can probably be removed in the next major version - we're not actually aware of any
// significant users of Cortex who both use SCC files, and cache shaders, so this compatibility shim
// is only needed theoretically.
void fromDeprecatedSpline( const IECore::Spline<X, Y> &deprecated );

bool operator==( const Ramp<X,Y> &rhs ) const;
bool operator!=( const Ramp<X,Y> &rhs ) const;

};

using Rampff = Ramp<float, float>;
using RampfColor3f = Ramp<float, Imath::Color3f>;
using RampfColor4f = Ramp<float, Imath::Color4f>;

template<typename X, typename Y>
inline void murmurHashAppend( IECore::MurmurHash &h, const Ramp<X,Y> &data )
{
h.append( data.interpolation );
for ( auto &p : data.points )
{
h.append( p.first );
h.append( p.second );
}
}

} // namespace IECore

#endif // IECORE_RAMP_H
52 changes: 52 additions & 0 deletions include/IECore/RampData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2025, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef IECORE_RAMPDATA_H
#define IECORE_RAMPDATA_H

#include "IECore/Ramp.h"
#include "IECore/TypedData.h"

namespace IECore
{

// Ramp data types.

IECORE_DECLARE_TYPEDDATA( RampffData, Rampff, void, SharedDataHolder )
IECORE_DECLARE_TYPEDDATA( RampfColor3fData, RampfColor3f, void, SharedDataHolder )
IECORE_DECLARE_TYPEDDATA( RampfColor4fData, RampfColor4f, void, SharedDataHolder )

}

#endif // IECORE_RAMPDATA_H
6 changes: 6 additions & 0 deletions include/IECore/SplineParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
namespace IECore
{

// NOTE : Using Spline*Data has basically been deprecated in favour of Ramp*Data.
// Setting up shader data this way will no longer work with renderer backends.
//
// We do not plan to update this because Parameter itself is on the way to
// deprecation ( in favour of using Gaffer to build UIs ).

typedef TypedParameter<Splineff> SplineffParameter;
typedef TypedParameter<Splinedd> SplineddParameter;
typedef TypedParameter<SplinefColor3f> SplinefColor3fParameter;
Expand Down
6 changes: 3 additions & 3 deletions include/IECore/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ enum TypeId
YUVImageWriterTypeId = 265,
DateTimeDataTypeId = 269,
DateTimeParameterTypeId = 270,
TimeDurationDataTypeId = 272, // Obsolete
TimeDurationParameterTypeId = 273, // Obsolete
TimePeriodDataTypeId = 274, // Obsolete
RampffDataTypeId = 272,
RampfColor3fDataTypeId = 273,
RampfColor4fDataTypeId = 274,
TimePeriodParameterTypeId = 275, // Obsolete
FrameListTypeId = 279,
EmptyFrameListTypeId = 280,
Expand Down
Loading
Loading