-
Notifications
You must be signed in to change notification settings - Fork 125
Replace Spline With Ramp For Shader Parameters #1499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
danieldresser-ie
wants to merge
16
commits into
ImageEngine:main
Choose a base branch
from
danieldresser-ie:splinesRound2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9792de0
TypeIdBinding : Remove bindings for TimeDurationData
danieldresser-ie 5d1bedc
Add a basic test for how splines work in SCC currently
danieldresser-ie de8f2b9
ShaderNetworkAlgo : Remove functions deprecated in 10.4.7.0
danieldresser-ie 3f92205
IECore : Add Ramp and RampData classes
danieldresser-ie addf6e6
Switch to using RampData for shader parameters instead of SplineData
danieldresser-ie 0fe766e
FIX : ShaderStateComponent comment
danieldresser-ie 15b62d4
FIX : Back off some renaming of spline to ramp
danieldresser-ie cf58037
FIX : Revert changes to DespatchTypedData ( since it's deprecated )
danieldresser-ie fffd722
FIX : Ramp : Fix indentation
danieldresser-ie a420d49
FIX : Ramp : Comments / using / oslStartPointMultiplicity name
danieldresser-ie 3ab97b6
FIX : RampBinding : Use interp enum name
danieldresser-ie 50495cd
FIX : SplineParameter : Change todo to note
danieldresser-ie cf46b25
FIX : SceneCache : Simplify
danieldresser-ie adb8516
FIX : ShaderNetworkAlgo : Prefer struct to tuple
danieldresser-ie 7c69161
FIX : IECore::Ramp changelog entry
danieldresser-ie 08c961d
FIX IECoreScene::ShaderNetworkAlgo : Changes
danieldresser-ie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.