Welcome to WSL!

New to the forum? Please read this and this.

Modulus in CustomTool returns unexpected values

Moderator: Chad

User avatar
Midgardsormr
Fusionator
Posts: 2086
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 24
Location: Los Angeles, CA, USA
Been thanked: 22 times
Contact:

Modulus in CustomTool returns unexpected values

#1

Post by Midgardsormr »

Fusion version: Fusion Studio 9.02 - 17.1. I haven't tested Resolve, but if it's in every Fusion version it probably happens there, too.



OS and version: Windows 10 Pro



Additional relevant system info:



Description of the bug: The modulus operator in a CustomTool's Channels expressions sometimes returns values that should not be possible. In a CT with the expression (x*w)%2, the result should be stripes with the value 0.0 and 1.0 alternating for each pixel. However, it returns a value of 2.0 for some values of x.



Severity (Trivial, Minor, Major, Critical) Minor to Major.



Steps to reproduce: Paste the following nodes into Fusion, view the CustomTool, and normalize the Viewer. The overbright stripes should be apparent.

Code: Select all

{
	Tools = ordered() {
		Background1_1 = Background {
			Inputs = {
				GlobalIn = Input { Value = 1001, },
				GlobalOut = Input { Value = 3000, },
				Width = Input { Value = 1920, },
				Height = Input { Value = 1080, },
				["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
			},
			ViewInfo = OperatorInfo { Pos = { 275, 33.5 } },
		},
		CustomTool1_1 = Custom {
			CtrlWZoom = false,
			Inputs = {
				NumberIn1 = Input { Value = 1, },
				NumberIn2 = Input { Value = 1920, },
				NumberIn3 = Input { Value = 1080, },
				LUTIn1 = Input {
					SourceOp = "CustomTool1LUTIn1_1",
					Source = "Value",
				},
				LUTIn2 = Input {
					SourceOp = "CustomTool1LUTIn2_1",
					Source = "Value",
				},
				LUTIn3 = Input {
					SourceOp = "CustomTool1LUTIn3_1",
					Source = "Value",
				},
				LUTIn4 = Input {
					SourceOp = "CustomTool1LUTIn4_1",
					Source = "Value",
				},
				Intermediate1 = Input { Value = "(abs(floor((x-p1x)*(w/n1)))%2)", },
				Intermediate2 = Input { Value = "(abs(floor((y-p1y)*(h/n1)))%2)", },
				RedExpression = Input { Value = "(x*w)%2", },
				GreenExpression = Input { Value = "y*(h)%2", },
				BlueExpression = Input { Value = "abs(i1-i2)", },
				NumberControls = Input { Value = 1, },
				NameforNumber1 = Input { Value = "SquareSize", },
				ShowNumber2 = Input { Value = 0, },
				NameforNumber2 = Input { Value = "Width", },
				ShowNumber3 = Input { Value = 0, },
				NameforNumber3 = Input { Value = "Height", },
				ShowNumber4 = Input { Value = 0, },
				ShowNumber5 = Input { Value = 0, },
				ShowNumber6 = Input { Value = 0, },
				ShowNumber7 = Input { Value = 0, },
				ShowNumber8 = Input { Value = 0, },
				PointControls = Input { Value = 1, },
				NameforPoint1 = Input { Value = "Center", },
				ShowPoint2 = Input { Value = 0, },
				ShowPoint3 = Input { Value = 0, },
				ShowPoint4 = Input { Value = 0, },
				ShowLUT1 = Input { Value = 0, },
				ShowLUT2 = Input { Value = 0, },
				ShowLUT3 = Input { Value = 0, },
				ShowLUT4 = Input { Value = 0, },
				Image1 = Input {
					SourceOp = "Background1_1",
					Source = "Output",
				},
				CheckerSize = Input {
					Value = 0,
					Expression = "246%2",
				},
			},
			ViewInfo = OperatorInfo { Pos = { 275, 65.5 } },
			UserControls = ordered() {
				CheckerSize = {
					INP_MinScale = 0,
					INP_Integer = true,
					INP_MinAllowed = 0,
					LINKID_DataType = "Number",
					INPID_InputControl = "SliderControl",
					IC_ControlPage = 0,
					INP_MaxScale = 100,
					INP_Default = 64,
				}
			}
		},
		CustomTool1LUTIn1_1 = LUTBezier {
			KeyColorSplines = {
				[0] = {
					[0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } },
					[1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } }
				}
			},
			SplineColor = { Red = 204, Green = 0, Blue = 0 },
		},
		CustomTool1LUTIn2_1 = LUTBezier {
			KeyColorSplines = {
				[0] = {
					[0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } },
					[1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } }
				}
			},
			SplineColor = { Red = 0, Green = 204, Blue = 0 },
		},
		CustomTool1LUTIn3_1 = LUTBezier {
			KeyColorSplines = {
				[0] = {
					[0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } },
					[1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } }
				}
			},
			SplineColor = { Red = 0, Green = 0, Blue = 204 },
		},
		CustomTool1LUTIn4_1 = LUTBezier {
			KeyColorSplines = {
				[0] = {
					[0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } },
					[1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } }
				}
			},
			SplineColor = { Red = 204, Green = 204, Blue = 204 },
		}
	}
}

Please, if possible, provide a Fusion setup to help demonstrate the behaviour, either as an attachment or between [code] tags:

User avatar
UserNoah
Fusioneer
Posts: 147
Joined: Mon Mar 09, 2020 11:43 am
Been thanked: 2 times
Contact:

Re: Modulus in CustomTool returns unexpected values

#2

Post by UserNoah »

Thank you! Haha :mrgreen: I was so disappointed in myself because I couldn't figure out what the heck I was doing wrong when I used the modulus a while back. I assumed my math was wrong but it seems like there was at least another factor.