Expression to control opacity by color
Copy link to clipboard
Copied
Hello,
can someone explain how i can control the opacity of an layers by the color underneth the layer?
a bit like a color picker but i want that the opacity of an layers i changing based on the color of the layer underneth.
Thank in advance!
Copy link to clipboard
Copied
Color values come in a 4 position array like this [R, G, B, A];
If you change the workspace or the info panel to show you 32-Bit or Float colors you can see that these values range from zero to one. That means a color value of [1, 0, 0, 1] will give you Red as shown in this screenshot of the info panel:
You can pick a point in the comp panel to sample color using sampleImage(point, radius = [.5, .5], postEffect = true, t = time) from the Property>Effets Layer Menu>Layer>Properties menu available in the timeline.
Picking a point in the comp and retrieving the sample will give you the full 4 digit array. You have to then figure out which combination of values will give you which level of Opacity and write some if statements. If you wanted red to return an opacity 100% and blue to return an opacity value of 0% you would have to write a complex if statement that looks at the value of not only red and blue but of the total value of the two.
So here's the first step: Pick the color that you want to return 100% opacity, say something like: [.4, 0, .2, 1] and pick the color for an opacity value of 0% [0, .2, 1, 1] and start building your array. This is going to become very complex very quickly.
Now that I think of it an easier solution would be to move a copy of the layer you want to use to drive the opacity below the original layer and add Colorama to that layer. If you set the input phase to Hue and choose Ramp Gray as the output phase, you can edit the position of the black and white pointers you get to give you a black and white image based on color values. You can then sample that image and end up with a really simple linear expression like this for transparency:
point = thisComp.layer("Null 1").position; // the point I want to sample
v = thisComp.layer("Colorama layer").sampleImage(point, radius = [.5, .5], postEffect = true, t = time);
t = v[1];
ease(t, 0, 1, 0, 100)
Turning the image gray and adjusting the black and white point with Colorama means you only have to sample 1 color. Once you get the colors properly mapped in Colorama you can turn off the layer or set it to be a guide layer so that it will not affect render time.
This is what Colorama would look like:
To give you a visual reference of where the colors lie in the OutputModule when the Input Phase is set to color just look at any color wheel like this one from Colorista II:
In the Colorista screenshot above I have set the Black Point at about 2 o'clock between Red and Blue to kind of a Magenta color, and the White Point to a 6 o'clock or just left of cyan so when the color is cyan the opacity is 0% but when the layer is Magenta the opacity is 100%.
 
Copy link to clipboard
Copied
Copy link to clipboard
Copied
here is my projekt that i want to make:
Copy link to clipboard
Copied
I want that every time a white bar hits the top of the keyboard the keylight that i created apears.
Copy link to clipboard
Copied

