Midgardsormr
Fusionista
Posts: 582
Joined: Wed Nov 26, 2014 8:04 pm
Location: Los Angeles, CA, USA
Been thanked: 45 times
Contact:

Photoshop has a nice feature called a gradient map, which maps a linear gradient to the luminance of an input image. Here's a macro that replicates that feature in Fusion:

Code: Select all

{
Tools = ordered() {
GradientMap = MacroOperator {
Inputs = ordered() {
Gradient = InstanceInput {
},
InterpolationMethod = InstanceInput {
},
Offset = InstanceInput {
Source = "Offset",
Default = 0,
},
Repeat = InstanceInput {
Source = "Repeat",
},
SubPixel = InstanceInput {
Source = "SubPixel",
},
Map = InstanceInput {
SourceOp = "MapIn",
Source = "Input",
Name = "Map",
},
Blend = InstanceInput {
SourceOp = "Blend",
Source = "Mix",
Name = "Blend",
Default = 1,
},
EffectMask = InstanceInput {
SourceOp = "CustomTool1",
}
},
Outputs = {
Output = InstanceOutput {
SourceOp = "Blend",
Source = "Output",
}
},
ViewInfo = GroupInfo { Pos = { 0, 0 } },
Tools = ordered() {
Gradient = Background {
NameSet = true,
Inputs = {
Width = Input {
Value = 1920,
Expression = "MapIn.Input.Width",
},
Height = Input {
Value = 1080,
Expression = "MapIn.Input.Height",
},
Depth = Input { Value = 4, },
["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
Type = Input { Value = FuID { "Gradient" }, },
Gradient = Input {
Value = Gradient {
Colors = {
[0.204013377926421] = { 0.660606060606061, 0, 0, 1 },
[0.672240802675585] = { 1, 1, 0, 1 },
[0.862876254180602] = { 1, 1, 0.945025258325098, 1 }
}
},
},
},
ViewInfo = OperatorInfo { Pos = { 906, 88 } },
},
CustomTool1 = Custom {
CtrlWZoom = false,
Inputs = {
LUTIn1 = Input {
SourceOp = "CustomTool1LUTIn1",
Source = "Value",
},
LUTIn2 = Input {
SourceOp = "CustomTool1LUTIn2",
Source = "Value",
},
LUTIn3 = Input {
SourceOp = "CustomTool1LUTIn3",
Source = "Value",
},
LUTIn4 = Input {
SourceOp = "CustomTool1LUTIn4",
Source = "Value",
},
RedExpression = Input { Value = "getr2d(c1,c1)", },
GreenExpression = Input { Value = "getg2d(c1,c1)", },
BlueExpression = Input { Value = "getb2d(c1,c1)", },
Image1 = Input {
SourceOp = "MapIn",
Source = "Output",
},
Image2 = Input {
Source = "Output",
},
},
ViewInfo = OperatorInfo { Pos = { 911, 157 } },
},
CustomTool1LUTIn1 = 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 = 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 = 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 = 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 },
},
MapIn = BrightnessContrast {
NameSet = true,
ViewInfo = OperatorInfo { Pos = { 745, 158 } },
},
Blend = Dissolve {
Transitions = {
[0] = "DFTDissolve"
},
CtrlWZoom = false,
NameSet = true,
Inputs = {
Background = Input {
SourceOp = "MapIn",
Source = "Output",
},
Foreground = Input {
SourceOp = "CustomTool1",
Source = "Output",
},
},
ViewInfo = OperatorInfo { Pos = { 914, 211 } },
}
},
}
},
}


Tags:

Midgardsormr
Fusionista
Posts: 582
Joined: Wed Nov 26, 2014 8:04 pm
Location: Los Angeles, CA, USA
Been thanked: 45 times
Contact:

Re: Gradient Map Macro

Aaaand, about a day after I made that macro, I realize that it's just doing what the Texture tool does. CopyAux color to UVs, pipe to the Input, and put the Gradient in the Texture input.

Fusionator
Posts: 1243
Joined: Fri Aug 08, 2014 1:11 pm
Been thanked: 18 times

Re: Gradient Map Macro

Or use FN with gradient.

Midgardsormr
Fusionista
Posts: 582
Joined: Wed Nov 26, 2014 8:04 pm
Location: Los Angeles, CA, USA
Been thanked: 45 times
Contact:

Re: Gradient Map Macro

Well sure, if what you need is a fractal noise the tool already exists. But that doesn't help if you have an alpha from another source. Hyposometric tinting for cartographic visualization, for instance. Or you want to fake thermal imaging or something of that sort.
Untitled.jpg
You do not have the required permissions to view the files attached to this post.

Fusionista
Posts: 413
Joined: Sun Sep 21, 2014 6:17 am
Been thanked: 23 times

Re: Gradient Map Macro

It also works with the FN tool if you don't need Fractal noise. This following is from years ago at the Pigsfly Forum from Daniel Koch
Now here's the non-obvious solution, a demented combination of Bitmap Mask and FastNoise tool (you did know that FastNoise did gradient mapping, didn't you?).

Set the Bitmap mask to Luminance, connect it to FN's Noise Brightness Map input, set Noise Detail to 0, turn up Brightness, and have fun.

It's faster than a Custom tool and more flexible too. You can even add perlin noise into the mix as well.

Attached is an example image, and a macro to make it all easy. Don't forget to remove the .txt extension on the macro.
Attached Thumbnails

Van <http://www.pigsfly.com/forums/index.php ... =fastnoise>

Midgardsormr
Fusionista
Posts: 582
Joined: Wed Nov 26, 2014 8:04 pm
Location: Los Angeles, CA, USA
Been thanked: 45 times
Contact:

Re: Gradient Map Macro

Ahhhh. I never even noticed those extra inputs on FN! So now I've done needless work twice!

Fusionista
Posts: 413
Joined: Sun Sep 21, 2014 6:17 am
Been thanked: 23 times

Re: Gradient Map Macro

Yes, doing needless work twice. Now you're a true VFX-artist!

vivi
Posts: 46
Joined: Tue Dec 02, 2014 6:34 pm

Re: Gradient Map Macro

Midgardsormr wrote:Aaaand, about a day after I made that macro, I realize that it's just doing what the Texture tool does. CopyAux color to UVs, pipe to the Input, and put the Gradient in the Texture input.
You mean a Background tool set to gradient?

vivi
Posts: 46
Joined: Tue Dec 02, 2014 6:34 pm

Re: Gradient Map Macro

Midgardsormr wrote:Aaaand, about a day after I made that macro, I realize that it's just doing what the Texture tool does. CopyAux color to UVs, pipe to the Input, and put the Gradient in the Texture input.
Also, it seems in the the Texture tool Swap UVs needs to be checked. Well I am not sure but in one image not doing so, causes the very bright spots to actually get the darkest color.

Midgardsormr
Fusionista
Posts: 582
Joined: Wed Nov 26, 2014 8:04 pm
Location: Los Angeles, CA, USA
Been thanked: 45 times
Contact:

Re: Gradient Map Macro

vivi wrote: You mean a Background tool set to gradient?
It can be a gradient from any source, actually. A Background set to Gradient is the simplest way to set it up, but you could get the ramp from anywhere. In fact, the ramp doesn't even have to be the same size as your brightness map. A 1-pixel high ramp (assuming it's a horizontal ramp) gives the same result as an HD one. The horizontal resolution matters, but apparently not much. I didn't see any banding in a test I just did until the width of my BG tool dropped below 10 pixels.
Also, it seems in the the Texture tool Swap UVs needs to be checked. Well I am not sure but in one image not doing so, causes the very bright spots to actually get the darkest color.
The tool isn't mapping brightness from the gradient. If you put in a grad that's dark on the right and bright on the left, then the gradient map, regardless of the method, will map those dark tones to the brightest pixels in your brightness map. In this situation, the U channel is coming from your source's red, and V is coming from green. If you have a horizontal ramp, only the red channel matters because it doesn't matter which y-location you're sampling from; they all have the same value. If you swap UVs, you're just using the green channel to select the color.