diff --git a/Changes.md b/Changes.md index 900e4c0013c..810961790b1 100644 --- a/Changes.md +++ b/Changes.md @@ -6,6 +6,7 @@ Fixes - Arnold : Fixed screen window export for Lentil cameras. - Application : Fixed the `-threads` argument to clamp the number of threads to the number of available hardware cores (#5403). +- CompareFloat, CompareColor, CompareVector : Worked around crashes in OSL's batched shading system (#5430). 1.2.10.1 (relative to 1.2.10.0) ======== diff --git a/python/GafferOSLTest/ShadingEngineTest.py b/python/GafferOSLTest/ShadingEngineTest.py index 74ea15c8b15..230e92a03dc 100644 --- a/python/GafferOSLTest/ShadingEngineTest.py +++ b/python/GafferOSLTest/ShadingEngineTest.py @@ -971,5 +971,26 @@ def testReadConstantArraySize1( self ) : imath.Color3f( 1, 2, 3 ) ) + def testCompareFloat( self ) : + + e = GafferOSL.ShadingEngine( IECoreScene.ShaderNetwork( + shaders = { + "globals" : IECoreScene.Shader( "Utility/Globals", "osl:shader" ), + "compareFloat" : IECoreScene.Shader( "Utility/CompareFloat", "osl:shader" ), + "output" : IECoreScene.Shader( "Surface/Constant", "osl:surface" ) + }, + connections = [ + ( ( "globals", "globalU" ), ( "compareFloat", "a" ) ), + ( ( "globals", "globalV" ), ( "compareFloat", "b" ) ), + ( ( "compareFloat", "success" ), ( "output", "Cs.r" ) ), + ], + output = "output" + ) ) + + r = e.shade( self.rectanglePoints() ) + for x in range( 0, 10 ) : + for y in range( 0, 10 ) : + self.assertEqual( r["Ci"][y*10+x].r, 1 if x == y else 0 ) + if __name__ == "__main__": unittest.main() diff --git a/shaders/Utility/CompareColor.osl b/shaders/Utility/CompareColor.osl index 2f532882dd1..b3508c0b1c8 100644 --- a/shaders/Utility/CompareColor.osl +++ b/shaders/Utility/CompareColor.osl @@ -58,10 +58,10 @@ shader CompareColor { if( condition == CONDITION_EQUAL ) { - success = a == b; + success = a == b ? 1 : 0; } else { - success = a != b; + success = a != b ? 1 : 0; } } diff --git a/shaders/Utility/CompareFloat.osl b/shaders/Utility/CompareFloat.osl index 9eb56c153e5..da8f5985ad3 100644 --- a/shaders/Utility/CompareFloat.osl +++ b/shaders/Utility/CompareFloat.osl @@ -62,26 +62,26 @@ shader CompareFloat { if( condition == CONDITION_EQUAL ) { - success = a == b; + success = a == b ? 1 : 0; } else if( condition == CONDITION_NOT_EQUAL ) { - success = a != b; + success = a != b ? 1 : 0; } else if( condition == CONDITION_GREATER ) { - success = a > b; + success = a > b ? 1 : 0; } else if( condition == CONDITION_GREATER_OR_EQUAL ) { - success = a >= b; + success = a >= b ? 1 : 0; } else if( condition == CONDITION_LESS ) { - success = a < b; + success = a < b ? 1 : 0; } else { - success = a <= b; + success = a <= b ? 1 : 0; } } diff --git a/shaders/Utility/CompareVector.osl b/shaders/Utility/CompareVector.osl index c6747396a71..4706e7cd2b5 100644 --- a/shaders/Utility/CompareVector.osl +++ b/shaders/Utility/CompareVector.osl @@ -58,10 +58,10 @@ shader CompareVector { if( condition == CONDITION_EQUAL ) { - success = a == b; + success = a == b ? 1 : 0; } else { - success = a != b; + success = a != b ? 1 : 0; } }