Skip to main content
Participant
February 17, 2023
Answered

Expression Opacity based on brightness of another layer

  • February 17, 2023
  • 2 replies
  • 1396 views

Hi!

 

Does anyone know an expression to change a layer's opacity based on another layer's brightness?

For example: if the layer behind it is too dark, I want the opacity of the layer on top to be 100, but if the layer behind it is too bright, I want the layer on top to have an opacity of 0.

This topic has been closed for replies.
Correct answer Dan Ebberts

Something like this maybe:

bg = thisComp.layer("background");
rgb = bg.sampleImage([bg.width,bg.height]/2,[.5,.5],true);
hsl = rgbToHsl(rgb);
hsl[2] > .5 ? 0 : 100

2 replies

Participant
February 17, 2023

Thank you! This one works! 🙂 

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
February 17, 2023

Something like this maybe:

bg = thisComp.layer("background");
rgb = bg.sampleImage([bg.width,bg.height]/2,[.5,.5],true);
hsl = rgbToHsl(rgb);
hsl[2] > .5 ? 0 : 100
Adam24585301qycn
Inspiring
February 20, 2023

Hi Dan, could we change the sample size as well as the precise timing of this as well ? so like an average of a certain zone of the image, and at a specific time ?

Dan Ebberts
Community Expert
Community Expert
February 20, 2023

Yes, sure. This is the parameter setup for sampleImage():

sampleImage(point, radius = [.5, .5], postEffect=true, t=time)