Fade a layer in and out based on its start and end points.
Posted: November 4th, 2011, 6:30 am
This expression fades the layer's opacity based on its start and end points.
The duration of the fade can be set individually for the fade in and fade out, either in seconds or frames.
It respects the initial value of the opacity. If you had set the opacity of the layer to 50% it will fade from 0% to 50%.
Apply the following expression controls to the layer you want to fade:
- Checkbox: "Time in frames"
- Checkbox: "Fade in"
- Checkbox: "Fade out"
- Slider: "Fade in time"
- Slider: "Fade out time"
Add the following expression to the same layer's opacity.
edit: fixed the issue where the layer would disappear when fade in time was set to 0 and either both or none of the fade in/fade out checkboxes were ticked.
The duration of the fade can be set individually for the fade in and fade out, either in seconds or frames.
It respects the initial value of the opacity. If you had set the opacity of the layer to 50% it will fade from 0% to 50%.
Apply the following expression controls to the layer you want to fade:
- Checkbox: "Time in frames"
- Checkbox: "Fade in"
- Checkbox: "Fade out"
- Slider: "Fade in time"
- Slider: "Fade out time"
Add the following expression to the same layer's opacity.
Code: Select all
framerate = 1/thisComp.frameDuration; // framerate
target = value;
if (effect("Time in frames")("Checkbox")==true){
//Time in frames is checked
fadeInTime =effect("Fade in time")("Slider")/framerate;
fadeOutTime = effect("Fade out time")("Slider")/framerate;
}else{
//Time in frames is unchecked
fadeInTime =effect("Fade in time")("Slider");
fadeOutTime = effect("Fade out time")("Slider");
}
if (effect("Fade in")("Checkbox")==true && effect("Fade out")("Checkbox")==false){
//if only Fade in is checked
Math.min(linear(time,inPoint,inPoint + fadeInTime,0,target),target);
}else if(effect("Fade in")("Checkbox")==false && effect("Fade out")("Checkbox")==true){
//if only Fade out is checked
Math.min(target,linear(time,outPoint - fadeOutTime,outPoint,target,0));
}else{
//if both fade in and fade out checkboxes are either checked or unchecked
if ( fadeInTime == 0 ){
Math.min(target,linear(time,outPoint - fadeOutTime,outPoint,target,0));
}else{
Math.min(linear(time,inPoint,inPoint + fadeInTime,0,target),linear(time,outPoint - fadeOutTime,outPoint,target,0));
}
}