From 864f9beb71265608fbbaf55fad75af27b4615097 Mon Sep 17 00:00:00 2001 From: Daniel Dresser Date: Mon, 8 Dec 2025 16:30:27 -0800 Subject: [PATCH] Forward compatibility for Gaffer 1.7 RampPlugs / shaders --- Changes.md | 1 + startup/Gaffer/rampPlugCompatibility.py | 48 ++++++++++++++++++++ startup/GafferOSL/shaderNameCompatibility.py | 18 +++++++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 startup/Gaffer/rampPlugCompatibility.py diff --git a/Changes.md b/Changes.md index 8baf604838a..fbaad471d54 100644 --- a/Changes.md +++ b/Changes.md @@ -16,6 +16,7 @@ Improvements - Parameters dragged from non-terminal shaders create tweaks that include the shader name to correctly identify the parameter. - Added array parameter types to the tweak creation menu. - PlugCreationWidget : User defaults are now applied to newly created `TweakPlug.mode` plugs. +- OSLShader : Added forward compatibility for spline parameters saved from Gaffer 1.7. Fixes ----- diff --git a/startup/Gaffer/rampPlugCompatibility.py b/startup/Gaffer/rampPlugCompatibility.py new file mode 100644 index 00000000000..e6f0015a80d --- /dev/null +++ b/startup/Gaffer/rampPlugCompatibility.py @@ -0,0 +1,48 @@ +########################################################################## +# +# 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 John Haddon 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. +# +########################################################################## + +import Gaffer +import IECore + +IECore.RampInterpolation = Gaffer.SplineDefinitionInterpolation + +IECore.Rampff = Gaffer.SplineDefinitionff +IECore.RampfColor3f = Gaffer.SplineDefinitionfColor3f +IECore.RampfColor4f = Gaffer.SplineDefinitionfColor4f + +Gaffer.RampffPlug = Gaffer.SplineffPlug +Gaffer.RampfColor3fPlug = Gaffer.SplinefColor3fPlug +Gaffer.RampfColor4fPlug = Gaffer.SplinefColor4fPlug diff --git a/startup/GafferOSL/shaderNameCompatibility.py b/startup/GafferOSL/shaderNameCompatibility.py index d28b2147c23..10b0eb820e2 100644 --- a/startup/GafferOSL/shaderNameCompatibility.py +++ b/startup/GafferOSL/shaderNameCompatibility.py @@ -34,6 +34,8 @@ # ########################################################################## +import Gaffer + import GafferOSL __nameMapping = { @@ -48,6 +50,8 @@ "Maths/FloatMultiply" : "Maths/MultiplyFloat", "Maths/VectorAdd" : "Maths/AddVector", "Maths/VectorMultiply" : "Maths/ScaleVector", + "Pattern/FloatRamp" : "Pattern/FloatSpline", + "Pattern/ColorRamp" : "Pattern/ColorSpline", # A whole bunch of MaterialX shaders were renamed from `mx__` # to `mx___` here : # @@ -149,8 +153,20 @@ def __loadShaderWrapper( originalLoadShader ) : def loadRenamedShader( self, shaderName, **kwargs ) : renamed = __nameMapping.get( shaderName, shaderName ) - return originalLoadShader( self, renamed, **kwargs ) + result = originalLoadShader( self, renamed, **kwargs ) + if shaderName in [ "Pattern/FloatRamp", "Pattern/ColorRamp" ]: + self["parameters"]["direction"].setValue( "v" ) + return result return loadRenamedShader GafferOSL.OSLShader.loadShader = __loadShaderWrapper( GafferOSL.OSLShader.loadShader ) + +def __rampAliasForSplines( plug ) : + + if plug.node()["name"].getValue() in [ "Pattern/ColorSpline", "Pattern/FloatSpline" ]: + return "spline" + + return None + +Gaffer.Metadata.registerValue( GafferOSL.OSLShader, "parameters", "compatibility:childAlias:ramp", __rampAliasForSplines )