Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Expression to control opacity by color

New Here ,
Sep 27, 2019 Sep 27, 2019

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!

2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 27, 2019 Sep 27, 2019

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:

Screenshot_2019-09-27 08.50.37_I73FbM.pngexpand image

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:

Screenshot_2019-09-27 09.14.55_emGLve.pngexpand image

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:

Screenshot_2019-09-27 11.12.49_HOzFzO.pngexpand image

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%.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 08, 2019 Oct 08, 2019
Oh i think I expressed myself wrong, I meant it differently.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 08, 2019 Oct 08, 2019

here is my projekt that i want to make:Unbenannt.PNGexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 08, 2019 Oct 08, 2019

I want that every time a white bar hits the top of the keyboard the keylight that i created apears.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 08, 2019 Oct 08, 2019
LATEST
sorry if i wasted your time :c
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines